/* ===========================================================
   PDF Filler — styles
   Mobile-first. Theming via CSS vars + [data-theme] on <body>.
   =========================================================== */

@font-face {
  font-family: "Sign Script";
  src: url("./vendor/dancing-script.woff2") format("woff2");
  font-weight: 700;
  font-display: swap;
}

:root {
  --bg: #f4f5f9;
  --surface: #ffffff;
  --surface-2: #eef0f6;
  --border: #d9dce6;
  --text: #1b1d24;
  --muted: #5b6075;
  --primary: #4f46e5;
  --primary-ink: #ffffff;
  --primary-hover: #4338ca;
  --accent: #f59e0b;
  --danger: #dc2626;
  --shadow: 0 6px 24px rgba(20, 22, 40, 0.12);
  --radius: 12px;
  --radius-sm: 8px;
  --tap: 44px;
}

body[data-theme="dark"] {
  --bg: #0f1117;
  --surface: #1a1d27;
  --surface-2: #232735;
  --border: #333849;
  --text: #e9eaf0;
  --muted: #9aa0b5;
  --primary: #818cf8;
  --primary-ink: #0f1117;
  --primary-hover: #a5b4fc;
  --shadow: 0 6px 24px rgba(0, 0, 0, 0.5);
}

@media (prefers-color-scheme: dark) {
  body[data-theme="auto"] {
    --bg: #0f1117;
    --surface: #1a1d27;
    --surface-2: #232735;
    --border: #333849;
    --text: #e9eaf0;
    --muted: #9aa0b5;
    --primary: #818cf8;
    --primary-ink: #0f1117;
    --primary-hover: #a5b4fc;
    --shadow: 0 6px 24px rgba(0, 0, 0, 0.5);
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
}

body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  -webkit-text-size-adjust: 100%;
}

/* ---------- Buttons ---------- */
.btn {
  font: inherit;
  min-height: var(--tap);
  padding: 0 14px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
  transition: background .12s, border-color .12s, transform .04s;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary {
  background: var(--primary);
  border-color: var(--primary);
  color: var(--primary-ink);
  font-weight: 600;
}
.btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn-lg { min-height: 52px; padding: 0 26px; font-size: 1.05rem; }
.icon-btn { width: var(--tap); padding: 0; justify-content: center; font-size: 1.2rem; }

/* ---------- Top bar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 12px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 30;
  flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 8px; }
.brand-logo { border-radius: 6px; }
.brand-name { font-weight: 700; font-size: 1.1rem; }
.privacy-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: .78rem;
  color: var(--muted);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px 10px;
  cursor: pointer;
  margin-left: 4px;
}
.privacy-badge .dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: #16a34a;
  box-shadow: 0 0 0 3px rgba(22,163,74,.18);
}
.topbar-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

/* ---------- Toolbar ---------- */
.toolbar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 8px 12px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
  overflow-x: auto;
  scrollbar-width: thin;
}
.tool-group { display: flex; align-items: center; gap: 6px; flex: 0 0 auto; }
.tool-group + .tool-group { border-left: 1px solid var(--border); padding-left: 14px; }
.tool {
  font: inherit;
  min-height: 40px;
  padding: 0 12px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text);
  border-radius: var(--radius-sm);
  cursor: pointer;
  white-space: nowrap;
}
.tool:hover { background: var(--surface-2); }
.tool[aria-pressed="true"] {
  background: color-mix(in srgb, var(--primary) 16%, transparent);
  border-color: var(--primary);
  color: var(--primary);
  font-weight: 600;
}
.tool:disabled { opacity: .4; cursor: not-allowed; }
.inline-label { display: inline-flex; align-items: center; gap: 6px; font-size: .85rem; color: var(--muted); }
.inline-label input[type="number"] {
  width: 56px; min-height: 38px; padding: 4px 8px;
  border: 1px solid var(--border); border-radius: 6px;
  background: var(--surface); color: var(--text); font: inherit;
}
input[type="color"] {
  width: 38px; height: 38px; padding: 2px;
  border: 1px solid var(--border); border-radius: 6px; background: var(--surface); cursor: pointer;
}
.zoom-group { margin-left: auto; }
.zoom-label { min-width: 48px; text-align: center; font-variant-numeric: tabular-nums; color: var(--muted); }

/* ---------- Workspace ---------- */
.workspace { flex: 1; display: flex; min-height: 0; }
.thumbs {
  width: 132px;
  flex: 0 0 auto;
  background: var(--surface);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.thumb {
  border: 2px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
  cursor: pointer;
  background: #fff;
  position: relative;
  line-height: 0;
}
.thumb canvas { width: 100%; height: auto; display: block; }
.thumb.active { border-color: var(--primary); }
.thumb .thumb-num {
  position: absolute; bottom: 2px; right: 4px;
  font-size: .7rem; color: #fff; background: rgba(0,0,0,.55);
  padding: 0 5px; border-radius: 4px; line-height: 1.4;
}

/* ---------- Dropzone ---------- */
.dropzone {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  text-align: center;
}
.dropzone.dragover .dropzone-inner {
  border-color: var(--primary);
  background: color-mix(in srgb, var(--primary) 8%, var(--surface));
}
.dropzone-inner {
  max-width: 460px;
  width: 100%;
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 40px 28px;
  background: var(--surface);
}
.dropzone-icon { font-size: 3rem; }
.dropzone h1 { margin: 12px 0 6px; font-size: 1.5rem; }
.dropzone p { color: var(--muted); margin: 0 0 20px; }
.features { list-style: none; padding: 0; margin: 22px 0 0; text-align: left; display: inline-block; color: var(--muted); font-size: .9rem; }
.features li { margin: 6px 0; }

/* ---------- Stage / pages ---------- */
.stage {
  flex: 1;
  overflow: auto;
  padding: 20px;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  background: var(--bg);
}
.page-wrap {
  position: relative;
  box-shadow: var(--shadow);
  background: #fff;
  line-height: 0;
}
#pdfCanvas { display: block; }
#overlayCanvas { position: absolute; left: 0; top: 0; }
.canvas-container { position: absolute !important; left: 0; top: 0; } /* fabric wrapper */

/* ---------- Bottom page nav ---------- */
.pagenav {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 8px 12px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  position: sticky;
  bottom: 0;
  z-index: 20;
}
.page-indicator { color: var(--muted); display: inline-flex; align-items: center; gap: 6px; }
.page-indicator input {
  width: 56px; min-height: 38px; text-align: center;
  border: 1px solid var(--border); border-radius: 6px;
  background: var(--surface); color: var(--text); font: inherit;
}

/* ---------- Quick-fill chips ---------- */
.quickfill {
  position: sticky;
  bottom: 60px;
  z-index: 19;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: var(--surface-2);
  border-top: 1px solid var(--border);
  overflow-x: auto;
}
.quickfill-label { color: var(--muted); font-size: .82rem; flex: 0 0 auto; }
.quickfill-chips { display: flex; gap: 6px; }
.chip {
  font: inherit; font-size: .85rem;
  padding: 6px 12px; min-height: 36px;
  border: 1px solid var(--border); border-radius: 999px;
  background: var(--surface); color: var(--text); cursor: pointer; white-space: nowrap;
}
.chip:hover { border-color: var(--primary); color: var(--primary); }

/* ---------- Modals ---------- */
.modal {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(10, 12, 22, .55);
  display: flex; align-items: center; justify-content: center;
  padding: 16px;
  backdrop-filter: blur(2px);
}
.modal[hidden] { display: none; }
.modal-card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  width: 100%;
  max-width: 640px;
  max-height: 92dvh;
  overflow: auto;
  border: 1px solid var(--border);
}
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 18px; border-bottom: 1px solid var(--border);
}
.modal-head h2 { margin: 0; font-size: 1.2rem; }
.modal-close {
  border: none; background: transparent; color: var(--muted);
  font-size: 1.6rem; line-height: 1; cursor: pointer; width: 40px; height: 40px; border-radius: 8px;
}
.modal-close:hover { background: var(--surface-2); }
.modal-foot {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 14px 18px; border-top: 1px solid var(--border); flex-wrap: wrap;
}
.foot-buttons { display: flex; gap: 8px; margin-left: auto; }
.muted { color: var(--muted); font-size: .9rem; padding: 0 18px; }

/* ---------- Tabs ---------- */
.tabs { display: flex; gap: 4px; padding: 12px 18px 0; flex-wrap: wrap; }
.tab {
  font: inherit; padding: 8px 14px; min-height: 40px;
  border: 1px solid var(--border); border-bottom: none;
  background: var(--surface-2); color: var(--muted);
  border-radius: 8px 8px 0 0; cursor: pointer;
}
.tab[aria-selected="true"] { background: var(--surface); color: var(--text); font-weight: 600; border-color: var(--border); }
.sigpanel { padding: 16px 18px; }

/* ---------- Signature pads ---------- */
.sigpad-wrap, .sig-preview-wrap {
  position: relative;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: repeating-linear-gradient(45deg, #fafafa, #fafafa 10px, #f0f0f0 10px, #f0f0f0 20px);
  overflow: hidden;
}
body[data-theme="dark"] .sigpad-wrap,
body[data-theme="dark"] .sig-preview-wrap { background: #f7f7fa; }
@media (prefers-color-scheme: dark) {
  body[data-theme="auto"] .sigpad-wrap,
  body[data-theme="auto"] .sig-preview-wrap { background: #f7f7fa; }
}
#sigPad, #sigTypeCanvas, #sigUploadCanvas { width: 100%; height: auto; display: block; touch-action: none; cursor: crosshair; }
.sigpad-baseline { position: absolute; left: 6%; right: 6%; bottom: 28%; border-bottom: 2px dashed #bbb; pointer-events: none; }
.sig-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 12px; }
.text-input {
  font: inherit; width: 100%; min-height: var(--tap); padding: 8px 12px;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text);
}
.text-input.small { width: 160px; min-height: 36px; }
#sigTypeCanvas { margin-top: 12px; background: #fff; }
.checkbox-line { display: inline-flex; align-items: center; gap: 8px; color: var(--muted); font-size: .9rem; margin-top: 12px; }
.checkbox-line input[type="checkbox"] { width: 18px; height: 18px; }
.save-line { margin-top: 0; flex-wrap: wrap; }

/* ---------- Saved signatures ---------- */
.saved-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.saved-sig {
  border: 1px solid var(--border); border-radius: 8px; padding: 8px; background: #fff;
  cursor: pointer; position: relative; text-align: center;
}
.saved-sig img { max-width: 100%; height: 56px; object-fit: contain; }
.saved-sig .sig-name { font-size: .75rem; color: #555; margin-top: 4px; word-break: break-word; }
.saved-sig .sig-del {
  position: absolute; top: 2px; right: 2px; border: none; background: rgba(0,0,0,.5); color: #fff;
  width: 22px; height: 22px; border-radius: 50%; cursor: pointer; font-size: .8rem; line-height: 1;
}
.saved-sig.selected { border-color: var(--primary); box-shadow: 0 0 0 2px color-mix(in srgb, var(--primary) 40%, transparent); }

/* ---------- Profile grid ---------- */
.profile-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; padding: 12px 18px; }
.profile-field { display: flex; flex-direction: column; gap: 4px; }
.profile-field label { font-size: .8rem; color: var(--muted); }
.profile-field input { font: inherit; min-height: 40px; padding: 6px 10px; border: 1px solid var(--border); border-radius: 6px; background: var(--surface); color: var(--text); }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  background: var(--text); color: var(--bg);
  padding: 12px 20px; border-radius: 999px; box-shadow: var(--shadow);
  z-index: 80; font-size: .9rem; max-width: 90vw; text-align: center;
}
.toast[hidden] { display: none; }

/* ---------- Privacy list ---------- */
.privacy-list { padding: 8px 26px 0; margin: 0; color: var(--text); }
.privacy-list li { margin: 10px 0; line-height: 1.45; }

/* ===========================================================
   Responsive
   =========================================================== */
@media (max-width: 760px) {
  .thumbs { display: none; }
  .thumbs.show { display: flex; position: fixed; left: 0; top: 0; bottom: 0; z-index: 40; width: 120px; box-shadow: var(--shadow); }
  .brand-name { display: none; }
  .topbar-actions .btn { padding: 0 10px; }
  .profile-grid { grid-template-columns: 1fr; }
  .stage { padding: 10px; }
  .zoom-group { margin-left: 12px; }
}

@media (min-width: 761px) {
  .topbar { padding: 10px 18px; }
}
