:root {
  color: #111827;
  background: #ffffff;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: #ffffff;
}

button,
input {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

.mobile-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 28px;
}

.entry-actions {
  width: min(100%, 360px);
  display: grid;
  gap: 14px;
  text-align: center;
}

.primary-button {
  min-height: 58px;
  border-radius: 8px;
  background: #111827;
  color: #ffffff;
  font-size: 20px;
  font-weight: 700;
}

.secondary-text {
  display: inline-flex;
  justify-content: center;
  color: #8b94a3;
  font-size: 13px;
  text-decoration: none;
}

.customer-choice {
  gap: 16px;
}

.choice-button {
  min-height: 58px;
  background: #eef0f4;
  color: #111827;
  font-size: 20px;
  font-weight: 700;
}

.reader-page {
  min-height: 100vh;
  min-height: 100dvh;
  background: #eef1f6;
  padding: 64px 12px 92px;
}

.reader-toolbar {
  position: fixed;
  top: max(10px, env(safe-area-inset-top));
  left: 12px;
  right: 12px;
  z-index: 20;
  width: min(calc(100% - 24px), 420px);
  min-height: 42px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px;
  padding: 6px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.14);
  backdrop-filter: blur(8px);
}

.reader-tool {
  min-height: 34px;
  border-radius: 6px;
  background: #edf0f4;
  color: #172033;
  font-size: 14px;
  font-weight: 700;
}

.reader-pages {
  width: min(100%, 760px);
  margin: 0 auto;
  display: grid;
  gap: 12px;
  justify-items: center;
  overflow-x: auto;
  padding-bottom: 8px;
}

.reader-loading {
  min-height: 68vh;
  display: grid;
  place-items: center;
  color: #64748b;
  background: #ffffff;
  border-radius: 8px;
}

.reader-canvas {
  display: block;
  max-width: none;
  border-radius: 8px;
  background: #ffffff;
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.08);
}

.reader-sign-button {
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: max(16px, env(safe-area-inset-bottom));
  z-index: 20;
  width: min(calc(100% - 32px), 520px);
  min-height: 54px;
  margin: 0 auto;
  border-radius: 8px;
  background: #111827;
  color: #ffffff;
  font-size: 18px;
  font-weight: 700;
  box-shadow: 0 10px 28px rgba(15, 23, 42, 0.24);
}

.sign-page {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 0;
  background: #f4f7fc;
  overflow: hidden;
}

.signature-panel {
  width: min(100vw, 460px);
  height: min(100vh, 820px);
  height: min(100dvh, 820px);
  display: grid;
  grid-template-columns: 108px minmax(0, 1fr);
  gap: 14px;
  padding: 22px 18px;
  border-radius: 0;
  background: #ffffff;
}

.signature-wrap {
  position: relative;
  width: 100%;
  height: 100%;
  min-height: 0;
  justify-self: stretch;
  align-self: stretch;
  border: 1px solid #e2e6ee;
  border-radius: 8px;
  overflow: hidden;
  background: #fbfcfe;
  touch-action: none;
}

.signature-hint {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: #b4bbc6;
  font-size: 26px;
  transform: rotate(90deg);
  white-space: nowrap;
  pointer-events: none;
}

#signatureCanvas {
  width: 100%;
  height: 100%;
  display: block;
}

.sign-actions {
  width: 100%;
  height: 100%;
  min-height: 0;
  justify-self: stretch;
  align-self: stretch;
  display: grid;
  grid-template-rows: 1fr 1fr;
  gap: 12px;
}

.plain-button,
.dark-button {
  min-height: 0;
  width: 100%;
  border-radius: 8px;
  font-size: 18px;
  font-weight: 700;
  display: grid;
  place-items: center;
}

.plain-button,
.dark-button {
  white-space: nowrap;
}

.rotated-label {
  transform: rotate(90deg);
  white-space: nowrap;
}

.plain-button {
  background: #eef0f4;
  color: #0f172a;
}

.dark-button {
  background: #111827;
  color: #ffffff;
}

.done {
  text-align: center;
  display: grid;
  gap: 10px;
}

.done h1 {
  margin: 0;
  font-size: 28px;
}

.done p {
  margin: 0;
  color: #818999;
}

.admin-shell {
  min-height: 100vh;
  background: #f7f8fa;
  padding: 18px;
}

.admin-login {
  min-height: 100vh;
  display: grid;
  place-items: center;
  background: #f7f8fa;
  padding: 20px;
}

.login-box,
.panel {
  width: 100%;
  background: #ffffff;
  border: 1px solid #e6e8ec;
  border-radius: 8px;
}

.login-box {
  max-width: 360px;
  padding: 22px;
  display: grid;
  gap: 14px;
}

.login-box h1,
.admin-header h1 {
  margin: 0;
  font-size: 22px;
}

.field {
  display: grid;
  gap: 7px;
  color: #4b5563;
  font-size: 14px;
}

.field input {
  width: 100%;
  height: 44px;
  border: 1px solid #d7dbe2;
  border-radius: 8px;
  padding: 0 12px;
  background: #ffffff;
}

.field input[type="number"] {
  max-width: 140px;
}

.admin-header {
  max-width: 1120px;
  margin: 0 auto 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.admin-grid {
  max-width: 1280px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: 340px 1fr;
  gap: 14px;
}

.panel {
  padding: 16px;
  display: grid;
  gap: 14px;
  align-content: start;
}

.panel h2 {
  margin: 0;
  font-size: 17px;
}

.status {
  min-height: 20px;
  color: #64748b;
  font-size: 13px;
}

.preview-panel {
  min-height: calc(100vh - 92px);
}

.preview-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.preview-head-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}

.pill {
  min-width: 64px;
  padding: 5px 9px;
  border-radius: 999px;
  background: #edf7f4;
  color: #047857;
  text-align: center;
  font-size: 12px;
  font-weight: 700;
}

.link-box {
  min-height: 42px;
  display: grid;
  grid-template-columns: 1fr auto auto;
  align-items: center;
  gap: 10px;
  padding: 8px;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  background: #fafafa;
  color: #475569;
  font-size: 13px;
  overflow: hidden;
}

.small-link {
  min-height: 40px;
  display: inline-grid;
  place-items: center;
  padding: 0 12px;
  border-radius: 8px;
  background: #edf0f4;
  color: #172033;
  text-decoration: none;
  font-weight: 700;
}

.link-box span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.preview-tools {
  display: grid;
  grid-template-columns: 150px 1fr repeat(3, minmax(110px, auto));
  align-items: end;
  gap: 10px;
}

.preview-stage {
  position: relative;
  height: calc(100vh - 190px);
  min-height: 520px;
  border: 1px solid #d9dde5;
  border-radius: 8px;
  background: #eef1f5;
  overflow: auto;
  cursor: grab;
}

.preview-stage.panning {
  cursor: grabbing;
}

.empty-preview {
  width: 100%;
  height: 100%;
  display: grid;
  place-items: center;
  color: #94a3b8;
}

.page-layer {
  position: relative;
  min-width: 0;
  min-height: 0;
  margin: 0 auto;
  display: none;
}

.pdf-page-image {
  width: 100%;
  height: 100%;
  display: block;
  background: #ffffff;
  object-fit: fill;
  border: 1px solid #d8dee8;
}

.signature-box {
  position: absolute;
  left: 62%;
  top: 72%;
  width: 22%;
  aspect-ratio: 3 / 1;
  border: 2px solid #0f766e;
  background: rgba(20, 184, 166, 0.12);
  color: #0f766e;
  display: grid;
  place-items: center;
  font-weight: 700;
  user-select: none;
  touch-action: none;
}

.range-row {
  display: grid;
  gap: 8px;
}

.range-row input {
  width: 100%;
}

.row {
  display: flex;
  gap: 10px;
}

.row > * {
  flex: 1;
}

.small-button {
  min-height: 40px;
  border-radius: 8px;
  background: #edf0f4;
  color: #172033;
  font-weight: 700;
}

.order-list {
  max-height: calc(100vh - 260px);
  overflow: auto;
  display: grid;
  gap: 8px;
}

.order-item {
  width: 100%;
  min-height: 68px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: stretch;
  padding: 8px;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  background: #ffffff;
  color: #111827;
}

.order-item.active {
  border-color: #111827;
  background: #f9fafb;
}

.order-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 700;
}

.order-select {
  min-width: 0;
  display: grid;
  gap: 5px;
  align-content: center;
  text-align: left;
  background: transparent;
  color: inherit;
}

.order-delete {
  width: 52px;
  border-radius: 8px;
  background: #fff1f2;
  color: #be123c;
  font-size: 13px;
  font-weight: 700;
}

.order-meta,
.empty-list {
  color: #64748b;
  font-size: 12px;
}

@media (max-width: 760px) {
  .admin-grid {
    grid-template-columns: 1fr;
  }

  .preview-tools {
    grid-template-columns: 1fr;
  }

  .preview-stage {
    height: 62vh;
    min-height: 420px;
  }

  .link-box {
    grid-template-columns: 1fr;
  }
}
