/* Web UI: document viewer, signing panel, signature pad, admin. */

@font-face { font-family: "Great Vibes"; src: url("../fonts/GreatVibes-Regular.woff") format("woff"); font-weight: 400; font-display: block; }
@font-face { font-family: "Dancing Script"; src: url("../fonts/DancingScript-SemiBold.woff") format("woff"); font-weight: 600; font-display: block; }
@font-face { font-family: "Homemade Apple"; src: url("../fonts/HomemadeApple-Regular.woff") format("woff"); font-weight: 400; font-display: block; }

:root {
  --ink: #15181d;
  --ink-2: #3c4350;
  --muted: #687080;
  --line: #e3e6eb;
  --line-2: #d2d7de;
  --bg: #f6f7f9;
  --viewer: #e6e9ee;
  --surface: #ffffff;
  --accent: #0074d9;       /* Olewave brand blue (logo wordmark) */
  --accent-hover: #0061b6;
  --accent-soft: #e8f2fc;
  --accent-ring: rgba(0, 116, 217, 0.2);
  --field: #fff4c4;
  --field-line: #e3b21c;
  --field-ink: #6f5300;
  --ok: #157f3c;
  --ok-soft: #e5f5eb;
  --warn: #965a00;
  --warn-soft: #fff3df;
  --danger: #b42318;
  --danger-soft: #fdeceb;
  --signature-ink: #0f1f4b;
  --radius: 10px;
  --topbar: 56px;
  --font-ui: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: light;
}

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; }
body {
  min-height: 100vh;
  font-family: var(--font-ui);
  font-size: 14px;
  line-height: 1.45;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.muted { color: var(--muted); }
.mono { font-family: var(--font-mono); font-size: 12px; overflow-wrap: anywhere; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 12px;
  height: var(--topbar);
  padding: 0 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.brand { display: inline-flex; align-items: center; gap: 8px; text-decoration: none; }
.brand-mark { display: block; width: 30px; height: 30px; }
.brand-wordmark { display: block; width: auto; height: 18px; }
.topbar-sep { width: 1px; height: 20px; background: var(--line-2); }
.topbar-title { color: var(--ink-2); font-weight: 500; white-space: nowrap; }
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.topbar-actions form { margin: 0; }

/* ---------- buttons, pills, inputs ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 38px;
  padding: 0 16px;
  border: 1px solid transparent;
  border-radius: 8px;
  font: inherit;
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
  transition: background-color 0.15s, border-color 0.15s, color 0.15s, box-shadow 0.15s;
}
.btn:focus-visible, .tab:focus-visible, .sig-slot:focus-visible, .doc .sig-empty:focus-visible, .icon-btn:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px var(--accent-ring);
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:disabled { opacity: 0.65; cursor: progress; }
.btn-ghost { background: var(--surface); border-color: var(--line-2); color: var(--ink); }
.btn-ghost:hover { background: #f2f4f7; }
.btn-danger-ghost { background: var(--surface); border-color: #efc6c1; color: var(--danger); }
.btn-danger-ghost:hover { background: var(--danger-soft); }
.btn-sm { height: 32px; padding: 0 12px; font-size: 13px; }
.btn-block { display: flex; width: 100%; height: 44px; font-size: 15px; }
.icon-btn { display: grid; place-items: center; width: 32px; height: 32px; border: 0; border-radius: 8px; background: none; color: var(--muted); cursor: pointer; }
.icon-btn:hover { background: #f2f4f7; color: var(--ink); }

.pill { display: inline-flex; align-items: center; gap: 6px; height: 24px; padding: 0 10px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.pill-sign { background: var(--accent-soft); color: var(--accent); }
.pill-awaiting_countersign { background: var(--warn-soft); color: var(--warn); }
.pill-completed { background: var(--ok-soft); color: var(--ok); }
.pill-void { background: #eef0f3; color: var(--muted); }

.field { display: block; margin: 0 0 12px; }
.field-label { display: block; margin-bottom: 5px; font-size: 12.5px; font-weight: 500; color: var(--ink-2); }
.field input, .input {
  display: block;
  width: 100%;
  height: 38px;
  padding: 0 11px;
  border: 1px solid var(--line-2);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.field input::placeholder { color: #a0a6b1; }
.field input:focus, .input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-ring); }
.field input[aria-invalid="true"] { border-color: var(--danger); }
.field-hint { display: block; margin-top: 5px; font-size: 12px; color: var(--muted); }
.check { display: flex; gap: 10px; align-items: flex-start; margin: 10px 0 0; font-size: 13px; color: var(--ink-2); cursor: pointer; }
.check input { flex: none; width: 16px; height: 16px; margin: 1px 0 0; accent-color: var(--accent); }
.check.is-invalid span { color: var(--danger); }
.form-error { margin: 14px 0 0; padding: 10px 12px; border-radius: 8px; background: var(--danger-soft); color: var(--danger); font-size: 13px; }
.fineprint { margin: 12px 0 0; font-size: 12px; color: var(--muted); }
.notice { margin: 0 0 20px; padding: 12px 14px; border-radius: var(--radius); font-size: 13.5px; }
.notice-success { background: var(--ok-soft); color: #0f5528; }
.notice-warn { background: var(--warn-soft); color: #6f4300; }
.hp { position: absolute; left: -10000px; width: 1px; height: 1px; overflow: hidden; }

/* ---------- workspace: viewer + panel ---------- */
.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 400px;
  height: calc(100vh - var(--topbar));
  height: calc(100dvh - var(--topbar));
}
.viewer { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--viewer); }
.viewer-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 16px;
  background: #eef0f4;
  border-bottom: 1px solid var(--line-2);
  color: var(--ink-2);
  font-size: 13px;
}
.viewer-doc { display: flex; align-items: center; gap: 8px; min-width: 0; font-weight: 500; }
.viewer-doc span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.viewer-actions { display: flex; gap: 8px; flex: none; }
.viewer-scroll { flex: 1; min-height: 0; overflow: auto; padding: 32px 24px 72px; scroll-padding: 24px; }

.page {
  max-width: 816px;
  margin: 0 auto;
  padding: 84px 92px 96px;
  background: #fff;
  border-radius: 2px;
  box-shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 12px 32px rgba(16, 24, 40, 0.08);
  font-size: 15.5px;
}

.panel { min-height: 0; overflow: auto; background: var(--surface); border-left: 1px solid var(--line); }
.panel-inner { padding: 28px 28px 40px; }
.eyebrow { margin: 0 0 6px; font-size: 12px; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase; color: var(--muted); }
.panel-title { margin: 0 0 6px; font-size: 21px; font-weight: 600; letter-spacing: -0.015em; }
.panel-lede { margin: 0 0 20px; color: var(--muted); }
.section-title { margin: 28px 0 10px; font-size: 13px; font-weight: 600; color: var(--ink); }

.step { padding: 18px 0 6px; border-top: 1px solid var(--line); }
.step-head { display: flex; align-items: center; gap: 10px; margin: 0 0 12px; font-size: 14px; font-weight: 600; }
.step-num {
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
  transition: background-color 0.2s, color 0.2s;
}
.step.is-done .step-num { background: var(--ok); color: #fff; }
.panel-actions { margin-top: 18px; }
.panel-actions .form-error { margin: 0 0 12px; }

/* signature slot in the panel */
.sig-slot {
  display: grid;
  place-items: center;
  width: 100%;
  height: 96px;
  padding: 8px;
  border: 1.5px dashed var(--line-2);
  border-radius: var(--radius);
  background: #fafbfc;
  color: var(--muted);
  font: inherit;
  font-weight: 500;
  cursor: pointer;
  transition: border-color 0.15s, background-color 0.15s, color 0.15s;
}
.sig-slot:hover { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.sig-slot-empty { display: inline-flex; align-items: center; gap: 8px; }
.sig-slot.has-sig { border-style: solid; border-color: var(--line-2); background: #fff; }
.sig-slot.has-sig:hover { border-color: var(--accent); }
.sig-slot-img { max-width: 92%; max-height: 76px; }
.sig-slot.is-invalid { border-color: var(--danger); }

/* ---------- fields and signature boxes inside the document ---------- */
.doc .fld { padding: 0 2px; border-radius: 3px; background: var(--accent-soft); box-shadow: inset 0 -1px 0 #9fc8ef; }
.doc .fld-empty {
  padding: 1px 6px;
  background: var(--field);
  box-shadow: inset 0 -2px 0 var(--field-line);
  color: var(--field-ink);
  font-family: var(--font-ui);
  font-size: 0.78em;
  font-weight: 600;
  letter-spacing: 0.01em;
  white-space: nowrap;
}
.doc .fld-link { cursor: pointer; }
.doc .fld.fld-blank { display: inline-block; width: 60%; height: 1em; padding: 0; vertical-align: baseline; background: none; box-shadow: none; border-bottom: 1px solid currentColor; border-radius: 0; }
.doc-final .fld { padding: 0; background: none; box-shadow: none; }

.doc .sig { display: inline-flex; align-items: flex-end; padding: 0; font: inherit; color: inherit; }
.doc .sig-empty, .doc .sig-pending {
  align-items: center;
  justify-content: center;
  border-radius: 6px;
}
.doc .sig-empty {
  border: 1.5px dashed var(--field-line);
  background: var(--field);
  color: var(--field-ink);
  cursor: pointer;
  animation: nudge 2.4s ease-in-out 1.2s 2;
}
.doc .sig-empty:hover { background: #ffeca6; }
.doc .sig-pending { border: 1px dashed #c6ccd5; background: #f4f5f7; color: var(--muted); }
.doc .sig-presigned { align-items: center; justify-content: center; border: 1px solid #b6e0c3; border-radius: 6px; background: var(--ok-soft); color: var(--ok); }
.doc .sig-cta { font-family: var(--font-ui); font-size: 12.5px; font-weight: 600; }
.doc .sig-signed { background: none; border: 0; border-bottom: 1px solid #16191d; border-radius: 0; }
.doc button.sig-signed { cursor: pointer; }
.doc button.sig-signed:hover { background: #f7f9ff; }
@keyframes nudge { 0%, 100% { transform: none; } 50% { transform: translateY(-2px); box-shadow: 0 4px 12px rgba(227, 178, 28, 0.35); } }
@media (prefers-reduced-motion: reduce) { .doc .sig-empty { animation: none; } }

/* ---------- agreement status panel ---------- */
.timeline { list-style: none; margin: 4px 0 20px; padding: 0; }
.timeline li { position: relative; padding: 0 0 16px 28px; }
.timeline li::before {
  content: "";
  position: absolute;
  left: 4px;
  top: 4px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 2px solid var(--line-2);
  background: #fff;
}
.timeline li.done::before { border-color: var(--ok); background: var(--ok); }
.timeline li.void::before { border-color: var(--muted); background: var(--muted); }
.timeline li:not(:last-child)::after { content: ""; position: absolute; left: 9px; top: 20px; bottom: 0; width: 2px; background: var(--line); }
.t-title { font-weight: 600; }
.t-meta { margin-top: 2px; font-size: 12.5px; color: var(--muted); }
.actions-row { display: flex; gap: 8px; }
.actions-row .btn { flex: 1; }
.block { margin-top: 8px; }
.block .btn-block { margin-top: 16px; }
.block .btn-danger-ghost { margin-top: 8px; height: 38px; font-size: 14px; }
.copy-row { display: flex; gap: 8px; }
.copy-row .input { flex: 1; min-width: 0; height: 32px; font-size: 12px; }
.kv { display: grid; grid-template-columns: 96px minmax(0, 1fr); gap: 7px 12px; margin: 0; font-size: 13px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; overflow-wrap: anywhere; }
.activity { list-style: none; margin: 0; padding: 0; font-size: 12.5px; }
.activity li { display: grid; gap: 1px; padding: 8px 0; border-top: 1px solid var(--line); }
.a-label { font-weight: 600; }
.a-meta { color: var(--muted); overflow-wrap: anywhere; }
.activity-email_failed .a-label { color: var(--danger); }

/* ---------- signature dialog ---------- */
.sig-dialog {
  width: min(640px, calc(100vw - 24px));
  max-height: calc(100dvh - 24px);
  padding: 0;
  border: 0;
  border-radius: 14px;
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 24px 64px rgba(16, 24, 40, 0.28);
}
.sig-dialog::backdrop { background: rgba(15, 18, 24, 0.5); }
.sig-dialog-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 16px 6px 20px; }
.sig-dialog-head h2 { margin: 0; font-size: 17px; font-weight: 600; }
.tabs { display: flex; gap: 4px; padding: 0 20px; border-bottom: 1px solid var(--line); }
.tab {
  margin-bottom: -1px;
  padding: 10px 12px;
  border: 0;
  border-bottom: 2px solid transparent;
  background: none;
  color: var(--muted);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}
.tab[aria-selected="true"] { color: var(--accent); border-bottom-color: var(--accent); }
.tab-panel { padding: 16px 20px 4px; }
.pad { position: relative; aspect-ratio: 5 / 2; border: 1px solid var(--line-2); border-radius: var(--radius); background: #fff; overflow: hidden; }
.pad-canvas { position: absolute; inset: 0; width: 100%; height: 100%; cursor: crosshair; touch-action: none; }
.pad-line { position: absolute; left: 7%; right: 7%; bottom: 27%; border-bottom: 1px solid #c9ced6; pointer-events: none; }
.pad-line span { position: absolute; left: -4px; bottom: 2px; font-size: 20px; line-height: 1; color: #a3a9b4; }
.pad-hint { position: absolute; inset: 0 0 30% 0; display: grid; place-items: center; color: #a3a9b4; font-size: 14px; pointer-events: none; }
.pad.has-ink .pad-hint { display: none; }
.pad-tools { display: flex; justify-content: flex-end; gap: 8px; margin-top: 10px; }
.type-styles { display: grid; gap: 8px; }
.type-style {
  display: flex;
  align-items: center;
  gap: 14px;
  min-height: 68px;
  padding: 8px 14px;
  border: 1px solid var(--line-2);
  border-radius: var(--radius);
  cursor: pointer;
}
.type-style:has(input:checked) { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-ring); }
.type-style input { flex: none; accent-color: var(--accent); }
.type-preview { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--signature-ink); line-height: 1.3; }
.font-sig-0 { font-family: "Great Vibes", cursive; font-size: 38px; }
.font-sig-1 { font-family: "Dancing Script", cursive; font-weight: 600; font-size: 32px; }
.font-sig-2 { font-family: "Homemade Apple", cursive; font-size: 22px; }
.sig-error { margin: 12px 20px 0; }
.sig-dialog-foot { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 14px 20px 18px; }
.sig-dialog-foot .fineprint { margin: 0; max-width: 300px; }
.sig-dialog-actions { display: flex; gap: 8px; flex: none; }

/* ---------- admin ---------- */
.admin { max-width: 1040px; margin: 0 auto; padding: 32px 20px 64px; }
.admin-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 20px; margin-bottom: 20px; }
.admin-head h1 { margin: 0 0 4px; font-size: 24px; letter-spacing: -0.015em; }
.admin-head p { margin: 0; }
.stats { display: flex; gap: 10px; margin: 0; }
.stats div { min-width: 96px; padding: 10px 14px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.stats dt { font-size: 12px; color: var(--muted); }
.stats dd { margin: 2px 0 0; font-size: 20px; font-weight: 600; font-variant-numeric: tabular-nums; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; }
.share { display: flex; align-items: flex-end; gap: 12px; padding: 14px 16px; margin-bottom: 16px; }
.share > div { flex: 1; min-width: 0; }
.share-label { margin-bottom: 6px; font-size: 12.5px; font-weight: 500; color: var(--ink-2); }
.presign { display: flex; align-items: center; gap: 16px; padding: 14px 16px; margin-bottom: 16px; }
.presign .share-label { display: flex; align-items: center; gap: 8px; margin-bottom: 2px; }
.presign-sig { display: grid; place-items: center; flex: none; width: 132px; height: 52px; padding: 4px 8px; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
.presign-sig img { max-width: 100%; max-height: 100%; }
.presign-text { flex: 1; min-width: 0; }
.presign-text p { margin: 0; font-size: 13px; }
.presign-actions { display: flex; gap: 8px; flex: none; }
.presign-actions form { margin: 0; }
.table-card { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; }
.table th { padding: 10px 16px; border-bottom: 1px solid var(--line); text-align: left; font-size: 12px; font-weight: 500; color: var(--muted); }
.table td { padding: 12px 16px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table .muted { font-size: 12.5px; margin-top: 2px; }
.row-link { color: var(--ink); font-weight: 600; text-decoration: none; }
.row-link:hover { color: var(--accent); }
.table .empty { padding: 40px 16px; text-align: center; color: var(--muted); }

.center { display: grid; place-items: center; min-height: calc(100vh - var(--topbar)); padding: 24px 16px; }
.login { width: min(380px, 100%); padding: 28px; }
.login h1 { margin: 0 0 4px; font-size: 20px; }
.login .muted { margin: 0 0 20px; }
.login .form-error { margin: 0 0 14px; }
.login .btn-block { margin-top: 8px; }

/* ---------- desktop: keep the main action in view ---------- */
@media (min-width: 901px) {
  .panel-actions {
    position: sticky;
    bottom: 0;
    margin: 18px -28px 0;
    padding: 14px 28px 20px;
    background: var(--surface);
    border-top: 1px solid var(--line);
    box-shadow: 0 -10px 18px -14px rgba(16, 24, 40, 0.25);
  }
  #sign-form.panel-inner { padding-bottom: 0; }
}

/* ---------- mobile ---------- */
.mobile-cta { display: none; }
.panel { scroll-margin-top: calc(var(--topbar) + 8px); }

@media (max-width: 1100px) {
  .workspace { grid-template-columns: minmax(0, 1fr) 360px; }
  .page { padding: 64px 64px 72px; }
}

@media (max-width: 900px) {
  .workspace { display: block; height: auto; }
  .viewer-bar { position: sticky; top: var(--topbar); z-index: 10; }
  .viewer-scroll { overflow: visible; padding: 16px 12px 24px; }
  .page { padding: 32px 22px 40px; font-size: 15px; }
  .doc p, .doc li { text-align: left; }
  .panel { border-left: 0; border-top: 1px solid var(--line); overflow: visible; }
  .panel-inner { max-width: 560px; margin: 0 auto; padding: 24px 16px 96px; }
  body[data-page="sign"] .mobile-cta, body[data-page="countersign"] .mobile-cta {
    display: block;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 25;
    padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
    background: rgba(255, 255, 255, 0.94);
    border-top: 1px solid var(--line);
    backdrop-filter: blur(6px);
  }
  .mobile-cta.is-hidden { display: none !important; }
  .admin-head { flex-direction: column; align-items: stretch; }
  .stats div { flex: 1; min-width: 0; }
}

@media (max-width: 600px) {
  .topbar { padding: 0 12px; gap: 10px; }
  .topbar-sep, .topbar-title { display: none; }
  .viewer-doc span { max-width: 46vw; }
  .page { padding: 24px 16px 32px; font-size: 14.5px; }
  .doc h1 { font-size: 1.15em; }
  .doc table.signature-block th, .doc table.signature-block td { padding-right: 0.7em; font-size: 0.92em; }
  .doc .sig { width: 72%; }
  .pad { aspect-ratio: 2 / 1; }
  .sig-dialog-foot { flex-direction: column; align-items: stretch; }
  .sig-dialog-foot .fineprint { max-width: none; }
  .sig-dialog-actions .btn { flex: 1; }
  .share { flex-direction: column; align-items: stretch; }
  .presign { flex-wrap: wrap; }
  .table th:nth-child(2), .table td:nth-child(2), .table th:nth-child(3), .table td:nth-child(3) { display: none; }
}
