:root {
  --bg: #f4f5f2;
  --surface: #ffffff;
  --surface-soft: #f8faf7;
  --text: #17201b;
  --muted: #657166;
  --line: #d9ded6;
  --line-strong: #b9c2b8;
  --primary: #0f6b5f;
  --primary-strong: #094f47;
  --accent: #be6a2b;
  --danger: #b42318;
  --warn: #a15c07;
  --success: #14734a;
  --shadow: 0 18px 48px rgba(19, 29, 24, 0.12);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--bg);
}

body {
  min-height: 100%;
  margin: 0;
  color: var(--text);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.72), rgba(244, 245, 242, 0.88) 320px),
    var(--bg);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    "Noto Sans TC", "Microsoft JhengHei", sans-serif;
  letter-spacing: 0;
}

body.modal-open {
  overflow: hidden;
}

a {
  color: inherit;
  text-decoration: none;
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.56;
}

.hidden {
  display: none !important;
}

.topbar {
  position: sticky;
  z-index: 20;
  top: 0;
  display: flex;
  align-items: center;
  gap: 22px;
  min-height: 68px;
  padding: 0 28px;
  border-bottom: 1px solid rgba(217, 222, 214, 0.86);
  background: rgba(250, 251, 249, 0.94);
  backdrop-filter: blur(18px);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-width: max-content;
  font-weight: 760;
}

.brand-mark {
  display: inline-grid;
  width: 34px;
  height: 34px;
  place-items: center;
  border-radius: 8px;
  color: #ffffff;
  background: var(--primary);
  font-size: 13px;
  font-weight: 820;
}

.nav {
  display: flex;
  align-items: center;
  gap: 4px;
  flex: 1;
}

.nav a {
  padding: 9px 12px;
  border-radius: 8px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 650;
}

.nav a.active,
.nav a:hover {
  color: var(--text);
  background: #e9eee8;
}

.admin-shell,
.reader-shell {
  width: min(1180px, calc(100% - 36px));
  margin: 0 auto;
  padding: 34px 0 84px;
}

.admin-shell.narrow {
  width: min(760px, calc(100% - 36px));
}

.page-heading,
.reader-header,
.annotate-toolbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 22px;
}

.page-heading h1,
.reader-header h1,
.annotate-toolbar h1 {
  margin: 2px 0 8px;
  font-size: 34px;
  line-height: 1.16;
  letter-spacing: 0;
}

.page-heading p,
.reader-header p,
.annotate-toolbar p {
  max-width: 760px;
  margin: 0;
  color: var(--muted);
  line-height: 1.7;
}

.eyebrow,
.auth-kicker {
  margin: 0;
  color: var(--accent);
  font-size: 12px;
  font-weight: 790;
  letter-spacing: 0;
  text-transform: uppercase;
}

.panel,
.metric,
.auth-panel,
.sign-card,
.signature-modal,
.success-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.7) inset;
}

.panel {
  margin-bottom: 18px;
  padding: 20px;
}

.panel-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 16px;
}

.panel-heading h2 {
  margin: 0;
  font-size: 19px;
  line-height: 1.3;
}

.panel-heading p {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.6;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

.metric {
  padding: 18px;
}

.metric span {
  display: block;
  color: var(--muted);
  font-size: 13px;
  font-weight: 650;
}

.metric strong {
  display: block;
  margin-top: 6px;
  font-size: 32px;
  line-height: 1;
}

.primary-btn,
.secondary-btn,
.ghost-btn,
.small-btn,
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 0 14px;
  font-weight: 720;
  white-space: nowrap;
  transition:
    background 150ms ease,
    border-color 150ms ease,
    color 150ms ease,
    transform 150ms ease;
}

.primary-btn {
  color: #ffffff;
  border-color: var(--primary);
  background: var(--primary);
}

.primary-btn:hover:not(:disabled) {
  background: var(--primary-strong);
  transform: translateY(-1px);
}

.primary-btn.large {
  min-height: 48px;
  padding: 0 20px;
  font-size: 16px;
}

.secondary-btn {
  color: var(--primary);
  border-color: #b7d0ca;
  background: #eff7f4;
}

.secondary-btn:hover:not(:disabled),
.secondary-btn.is-active {
  color: #ffffff;
  border-color: var(--primary);
  background: var(--primary);
}

.ghost-btn,
.small-btn,
.icon-btn {
  color: var(--text);
  border-color: var(--line);
  background: #ffffff;
}

.ghost-btn:hover:not(:disabled),
.small-btn:hover:not(:disabled),
.icon-btn:hover:not(:disabled) {
  border-color: var(--line-strong);
  background: #f0f3ef;
}

.small-btn,
.icon-btn {
  min-height: 34px;
  padding: 0 11px;
  font-size: 13px;
}

.full {
  width: 100%;
}

.stack-form {
  display: grid;
  gap: 16px;
}

.stack-form label {
  display: grid;
  gap: 8px;
}

.stack-form label span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 690;
}

input {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  padding: 0 12px;
  color: var(--text);
  background: #ffffff;
  outline: none;
}

input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(15, 107, 95, 0.13);
}

.file-input {
  padding: 10px 12px;
}

.form-actions,
.toolbar-actions,
.modal-actions,
.sign-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
}

.auth-shell,
.sign-shell {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 28px;
}

.auth-panel,
.sign-card {
  width: min(520px, 100%);
  padding: 30px;
  box-shadow: var(--shadow);
}

.auth-panel h1,
.sign-card h1 {
  margin: 8px 0 10px;
  font-size: 30px;
  line-height: 1.2;
}

.auth-panel p,
.sign-card p {
  margin: 0 0 22px;
  color: var(--muted);
  line-height: 1.7;
}

.alert,
.status-line {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px 14px;
  background: var(--surface-soft);
  color: var(--muted);
  line-height: 1.55;
}

.alert.error,
.status-line.error {
  color: var(--danger);
  border-color: #efb5ad;
  background: #fff2f0;
}

.status-line.success {
  color: var(--success);
  border-color: #9ed7bd;
  background: #edf8f2;
}

.status-line.warn {
  color: var(--warn);
  border-color: #e8c488;
  background: #fff8e8;
}

.status-line.info {
  color: var(--primary-strong);
  border-color: #b7d0ca;
  background: #eff7f4;
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 760px;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 13px 10px;
  text-align: left;
  vertical-align: middle;
}

th {
  color: var(--muted);
  font-size: 12px;
  font-weight: 780;
  text-transform: uppercase;
}

td {
  color: var(--text);
  font-size: 14px;
}

tbody tr:hover {
  background: #fafbf8;
}

.table-title {
  font-weight: 760;
}

.muted,
.small {
  color: var(--muted);
}

.small {
  font-size: 12px;
}

.empty-cell {
  padding: 28px 10px;
  color: var(--muted);
  text-align: center;
}

.copy-line,
.share-box {
  display: flex;
  align-items: center;
  gap: 8px;
}

.copy-line input,
.share-box input {
  min-width: 240px;
  color: var(--muted);
  font-size: 13px;
}

.share-box input {
  flex: 1;
}

.download-links {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.download-links a {
  display: inline-flex;
  min-height: 30px;
  align-items: center;
  border: 1px solid #c7d9d3;
  border-radius: 8px;
  padding: 0 10px;
  color: var(--primary);
  background: #f2faf7;
  font-weight: 690;
}

.file-list {
  display: grid;
  gap: 10px;
}

.file-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: var(--surface-soft);
}

.pill {
  display: inline-flex;
  min-height: 28px;
  align-items: center;
  border-radius: 999px;
  padding: 0 10px;
  font-size: 12px;
  font-weight: 760;
}

.pill.good {
  color: var(--success);
  background: #e8f6ef;
}

.pill.warn {
  color: var(--warn);
  background: #fff1d8;
}

.annotate-shell {
  width: min(1240px, calc(100% - 28px));
}

.annotate-toolbar {
  position: sticky;
  z-index: 15;
  top: 68px;
  margin: -10px 0 14px;
  border: 1px solid rgba(217, 222, 214, 0.88);
  border-radius: 8px;
  padding: 16px;
  background: rgba(250, 251, 249, 0.96);
  backdrop-filter: blur(18px);
}

.annotate-toolbar h1 {
  font-size: 23px;
}

.pdf-workspace,
.user-pdf-reader {
  display: grid;
  gap: 18px;
}

.pdf-workspace.is-adding .signature-layer {
  cursor: crosshair;
}

.pdf-page-frame {
  display: grid;
  justify-items: center;
  gap: 8px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: #e7ebe4;
}

.pdf-page-frame.user {
  background: #e9ece7;
}

.pdf-page-label {
  width: min(100%, 960px);
  color: var(--muted);
  font-size: 12px;
  font-weight: 720;
}

.pdf-page-wrap {
  position: relative;
  max-width: 100%;
  overflow: hidden;
  border-radius: 4px;
  background: #ffffff;
  box-shadow: 0 12px 28px rgba(31, 40, 34, 0.15);
}

.pdf-page-wrap canvas {
  display: block;
  max-width: 100%;
  height: auto;
}

.signature-layer {
  position: absolute;
  inset: 0;
  touch-action: none;
}

.signature-field {
  position: absolute;
  display: grid;
  place-items: center;
  overflow: hidden;
  border: 2px solid var(--accent);
  border-radius: 6px;
  padding: 0;
  color: #7a3f14;
  background: rgba(190, 106, 43, 0.14);
  font-size: 12px;
  font-weight: 820;
}

.signature-field span {
  padding: 2px 6px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.86);
}

.signature-field.draft {
  pointer-events: none;
  border-style: dashed;
}

.document-list {
  display: grid;
  gap: 8px;
  margin: 0 0 24px;
  padding: 0;
  list-style: none;
}

.document-list li {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 11px 12px;
  background: var(--surface-soft);
  font-weight: 680;
}

.reader-shell {
  padding-bottom: 128px;
}

.reader-header {
  position: sticky;
  z-index: 14;
  top: 0;
  align-items: center;
  border-bottom: 1px solid rgba(217, 222, 214, 0.86);
  margin: 0 -18px 22px;
  padding: 16px 18px;
  background: rgba(244, 245, 242, 0.96);
  backdrop-filter: blur(18px);
}

.reader-header h1 {
  font-size: 24px;
}

.reader-document {
  display: grid;
  gap: 14px;
}

.reader-document + .reader-document {
  margin-top: 26px;
}

.reader-document-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px 16px;
  background: var(--surface);
}

.reader-document-heading h2 {
  margin: 0;
  font-size: 18px;
  line-height: 1.35;
}

.reader-document-heading span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 720;
}

.reader-end {
  width: max-content;
  margin: 28px auto 0;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 8px 12px;
  color: var(--muted);
  background: #ffffff;
  font-size: 12px;
  font-weight: 720;
}

.bottom-signbar {
  position: fixed;
  z-index: 30;
  right: 18px;
  bottom: 18px;
  left: 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  width: min(960px, calc(100% - 36px));
  margin: 0 auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px 14px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.bottom-signbar strong,
.bottom-signbar span {
  display: block;
}

.bottom-signbar span {
  margin-top: 2px;
  color: var(--muted);
  font-size: 13px;
}

.modal-backdrop {
  position: fixed;
  z-index: 60;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(23, 32, 27, 0.55);
}

.signature-modal {
  width: min(720px, 100%);
  max-height: calc(100vh - 36px);
  overflow-y: auto;
  padding: 20px;
  box-shadow: var(--shadow);
}

.modal-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
}

.modal-heading h2 {
  margin: 4px 0 0;
  font-size: 22px;
}

.icon-only {
  display: inline-grid;
  width: 38px;
  height: 38px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  background: #ffffff;
  font-size: 24px;
  line-height: 1;
}

.signature-pad-wrap {
  overflow: hidden;
  border: 1px dashed var(--line-strong);
  border-radius: 8px;
  background:
    linear-gradient(transparent 96%, rgba(101, 113, 102, 0.12) 96%),
    #fbfcfb;
  background-size: 100% 48px;
}

.signer-info-form {
  display: grid;
  gap: 12px;
  margin-bottom: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: var(--surface-soft);
}

.signer-form-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
}

.signer-form-heading h3 {
  margin: 0;
  font-size: 16px;
  line-height: 1.35;
}

.signer-form-heading p {
  margin: 1px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
  text-align: right;
}

.signer-field-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.signer-field-grid label {
  display: grid;
  gap: 6px;
}

.signer-field-grid span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 720;
}

.signer-field-grid input {
  min-height: 40px;
  background: #ffffff;
}

.signer-field-grid input.invalid {
  border-color: var(--danger);
  box-shadow: 0 0 0 3px rgba(180, 35, 24, 0.12);
}

.modal-status {
  border: 1px solid #efb5ad;
  border-radius: 8px;
  margin-bottom: 12px;
  padding: 10px 12px;
  color: var(--danger);
  background: #fff2f0;
  font-size: 13px;
  font-weight: 680;
  line-height: 1.5;
}

.modal-status.warn {
  color: var(--warn);
  border-color: #e8c488;
  background: #fff8e8;
}

#signaturePad {
  display: block;
  width: 100%;
  height: 240px;
  touch-action: none;
}

.modal-actions {
  margin-top: 14px;
}

.success-screen {
  position: fixed;
  z-index: 70;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(244, 245, 242, 0.94);
}

.success-card {
  width: min(430px, 100%);
  padding: 30px;
  text-align: center;
  box-shadow: var(--shadow);
}

.success-mark {
  display: grid;
  width: 56px;
  height: 56px;
  place-items: center;
  margin: 0 auto 14px;
  border-radius: 999px;
  color: #ffffff;
  background: var(--success);
  font-size: 32px;
  font-weight: 820;
}

.success-card h2 {
  margin: 0 0 8px;
  font-size: 26px;
}

.success-card p {
  margin: 0;
  color: var(--muted);
  line-height: 1.7;
}

@media (max-width: 760px) {
  .topbar {
    align-items: flex-start;
    flex-wrap: wrap;
    gap: 12px;
    padding: 12px 16px;
  }

  .nav {
    order: 3;
    width: 100%;
  }

  .admin-shell,
  .reader-shell,
  .admin-shell.narrow {
    width: min(100% - 24px, 1180px);
    padding-top: 22px;
  }

  .page-heading,
  .reader-header,
  .annotate-toolbar,
  .panel-heading {
    display: grid;
  }

  .page-heading h1 {
    font-size: 27px;
  }

  .metric-grid {
    grid-template-columns: 1fr;
  }

  .file-row {
    grid-template-columns: 1fr;
  }

  .copy-line,
  .share-box,
  .bottom-signbar {
    align-items: stretch;
    flex-direction: column;
  }

  .copy-line input,
  .share-box input {
    min-width: 0;
  }

  .toolbar-actions,
  .form-actions,
  .modal-actions {
    justify-content: stretch;
  }

  .toolbar-actions > *,
  .form-actions > *,
  .modal-actions > * {
    flex: 1;
  }

  .signer-form-heading,
  .signer-field-grid {
    grid-template-columns: 1fr;
    display: grid;
  }

  .signer-form-heading p {
    text-align: left;
  }

  .annotate-toolbar {
    top: 108px;
  }

  .reader-header {
    margin-right: -12px;
    margin-left: -12px;
  }

  .bottom-signbar {
    right: 12px;
    bottom: 12px;
    left: 12px;
    width: auto;
  }

  .auth-panel,
  .sign-card {
    padding: 22px;
  }

  .auth-panel h1,
  .sign-card h1 {
    font-size: 25px;
  }
}
