/* ── Reset & base ─────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --navy:   #0f1e3c;
  --navy2:  #162d56;
  --amber:  #d4732a;
  --amber2: #f0935a;
  --bg:     #f4f5f7;
  --card:   #ffffff;
  --border: #e2e5ea;
  --muted:  #6b7280;
  --text:   #111827;
  --green:  #16a34a;
  --red:    #dc2626;
  --blue:   #2563eb;
  --radius: 10px;
  --shadow: 0 1px 4px rgba(0,0,0,.08), 0 4px 16px rgba(0,0,0,.06);
  --bg-soft: #eef0f3;
}

/* ── Dark mode ────────────────────────────────────────────────────────────── */
body.dark {
  --bg:     #0f1e3c;
  --bg-soft: #162d56;
  --card:   #1a2d4f;
  --border: #2a3d5f;
  --muted:  #a0b0c0;
  --text:   #f0f4f8;
  --shadow: 0 1px 4px rgba(0,0,0,.25), 0 4px 16px rgba(0,0,0,.2);
}

body.dark .card,
body.dark .settings-panel,
body.dark .doc-card,
body.dark .template-card,
body.dark .contact-card,
body.dark .stat-card,
body.dark .panel {
  background: var(--card);
  border-color: var(--border);
}

body.dark input,
body.dark select,
body.dark textarea {
  background: #162d56;
  border-color: var(--border);
  color: var(--text);
}

body.dark input::placeholder,
body.dark textarea::placeholder {
  color: var(--muted);
}

body.dark .table th {
  background: #162d56;
  color: var(--text);
}

body.dark .table td {
  border-color: var(--border);
  color: var(--text);
}

body.dark .dropdown-item:hover,
body.dark .user-dropdown .dropdown-item:hover {
  background: #162d56;
}

body.dark .btn-outline {
  border-color: var(--border);
  color: var(--text);
}

body.dark .btn-ghost:hover {
  background: #162d56;
}

/* Navigation & sidebars */
body.dark .settings-nav { background: var(--bg-soft); }
body.dark .settings-nav-link.active { background: var(--bg); color: var(--amber); font-weight: 600; }
body.dark .folder-item.active { background: var(--bg); color: var(--amber); }
body.dark .folder-item-system.active .folder-name { color: var(--amber); }
/* Tables */
body.dark .docs-table tr:hover td { background: var(--bg-soft); }
/* Interactive rows */
body.dark .task-row:hover { background: var(--bg-soft); }
/* Notifications */
body.dark .bell-item:hover { background: var(--bg-soft); }
body.dark .bell-item.unread { background: var(--bg-soft); }
/* Prepare page field tools */
body.dark .field-tool-btn:hover { background: var(--bg-soft); color: var(--text); border-color: var(--border); }
body.dark .field-tool-btn.active { background: var(--bg-soft); color: var(--amber); border-color: var(--amber); }
body.dark #sig-canvas-wrap { background: var(--bg-soft); }
/* Upload */
body.dark .upload-zone { background: var(--bg-soft); }
body.dark .signer-chip.drag-over { background: var(--bg-soft); }
/* Button states */
body.dark .btn-outline:hover { border-color: var(--border); color: var(--text); }
/* Status badges */
body.dark .badge-draft { background: var(--bg-soft); color: var(--muted); }
body.dark .badge-sent { background: #1e3a5f; color: #93c5fd; }
body.dark .badge-completed { background: #14391f; color: #86efac; }
body.dark .badge-pending { background: #3b2d00; color: #fde68a; }
body.dark .badge-signed { background: #14391f; color: #86efac; }
body.dark .badge-voided { background: #3b1414; color: #fca5a5; }
/* Modals */
body.dark .ss-modal { background: var(--card); }
body.dark .ss-modal-title { color: var(--text); }
body.dark .ss-modal-body { color: var(--muted); }
body.dark .ss-modal-header { border-bottom: 1px solid var(--border); }
body.dark .ss-modal-header.danger  { background: #3b1414; }
body.dark .ss-modal-header.upgrade { background: #3b2d00; }
body.dark .ss-modal-header.info    { background: #1e3a5f; }
body.dark .ss-btn-ghost { background: transparent; color: var(--text); border-color: var(--border); }

/* Dark mode toggle button */
.dark-mode-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: rgba(255,255,255,.7);
  padding: 6px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color .15s, background .15s;
  flex-shrink: 0;
}
.dark-mode-btn:hover {
  color: #fff;
  background: rgba(255,255,255,.1);
}


html { font-size: 15px; }
html { height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Inter', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
  display: flex;
  flex-direction: column;
}
.page-content { flex: 1; }
.app-footer { flex-shrink: 0; }

a { color: var(--amber); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Shared header ────────────────────────────────────────────────────────── */
.app-header {
  background: var(--navy);
  color: #fff;
  height: 56px;
  display: flex;
  align-items: center;
  padding: 0 24px;
  gap: 16px;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 8px rgba(0,0,0,.25);
}
.app-logo {
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: -.02em;
  color: #fff;
}
.app-logo span { color: var(--amber); }
.header-spacer { flex: 1; }
.header-link {
  color: rgba(255,255,255,.65);
  font-size: .85rem;
  cursor: pointer;
  background: none;
  border: none;
  padding: 6px 10px;
  border-radius: 6px;
  transition: background .15s;
}
.header-link:hover { background: rgba(255,255,255,.1); color: #fff; }

/* ── Buttons ──────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 18px;
  border-radius: var(--radius);
  border: none;
  font-size: .875rem;
  font-weight: 600;
  cursor: pointer;
  transition: all .15s;
  white-space: nowrap;
}
.btn-primary   { background: var(--navy);  color: #fff; }
.btn-primary:hover  { background: var(--navy2); }
.btn-amber     { background: var(--amber); color: #fff; }
.btn-amber:hover    { background: var(--amber2); }
.btn-outline   { background: transparent; border: 1.5px solid var(--border); color: var(--text); }
.btn-outline:hover  { border-color: var(--navy); color: var(--navy); }
.btn-danger    { background: transparent; border: 1.5px solid #fca5a5; color: var(--red); }
.btn-danger:hover   { background: #fef2f2; }
.btn-warning   { background: transparent; border: 1.5px solid #fcd34d; color: #b45309; }
.btn-warning:hover  { background: #fffbeb; }
.btn-ghost     { background: transparent; color: var(--muted); }
.btn-ghost:hover    { color: var(--text); background: var(--bg); }
.btn-sm  { padding: 6px 12px; font-size: .8rem; }
.btn-lg  { padding: 13px 28px; font-size: 1rem; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ── Badges ───────────────────────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: .75rem;
  font-weight: 600;
}
.badge-draft     { background: #f3f4f6; color: #6b7280; }
.badge-sent      { background: #dbeafe; color: #1d4ed8; }
.badge-completed { background: #dcfce7; color: #15803d; }
.badge-pending   { background: #fef9c3; color: #a16207; }
.badge-signed    { background: #dcfce7; color: #15803d; }
.badge-voided    { background: #fee2e2; color: #dc2626; }

/* ── Cards ────────────────────────────────────────────────────────────────── */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

/* ── Form elements ────────────────────────────────────────────────────────── */
.field-group { margin-bottom: 14px; }
.field-group label {
  display: block;
  font-size: .78rem;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 5px;
  text-transform: uppercase;
  letter-spacing: .05em;
}
.field-group input,
.field-group select,
.field-group textarea {
  width: 100%;
  padding: 9px 12px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  font-size: .9rem;
  font-family: inherit;
  color: var(--text);
  background: var(--card);
  outline: none;
  transition: border-color .15s;
}
.field-group input:focus,
.field-group select:focus,
.field-group textarea:focus { border-color: var(--navy); }

/* ── Login page ───────────────────────────────────────────────────────────── */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--navy);
  padding: 24px;
}
.login-card {
  background: #fff;
  border-radius: 16px;
  padding: 40px 36px;
  width: 100%;
  max-width: 360px;
  box-shadow: 0 8px 40px rgba(0,0,0,.3);
}
.login-logo {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -.03em;
  color: var(--navy);
  margin-bottom: 4px;
}
.login-logo span { color: var(--amber); }
.login-sub {
  color: var(--muted);
  font-size: .85rem;
  margin-bottom: 28px;
}
.error-banner {
  background: #fef2f2;
  border: 1px solid #fca5a5;
  color: var(--red);
  padding: 10px 14px;
  border-radius: 8px;
  font-size: .85rem;
  margin-bottom: 16px;
}

/* ── Dashboard ────────────────────────────────────────────────────────────── */
.page-wrap { max-width: 1100px; margin: 0 auto; padding: 28px 24px; }
.page-title {
  font-size: 1.3rem;
  font-weight: 700;
  margin-bottom: 4px;
  letter-spacing: -.02em;
}
.page-sub { color: var(--muted); font-size: .875rem; margin-bottom: 24px; }

.toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.upload-form {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  flex-wrap: wrap;
  padding: 16px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 24px;
}

.docs-table { width: 100%; border-collapse: collapse; }
.docs-table th {
  text-align: left;
  padding: 10px 14px;
  font-size: .75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
}
.docs-table td {
  padding: 13px 14px;
  font-size: .875rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.docs-table tr:last-child td { border-bottom: none; }
.docs-table tr:hover td { background: var(--bg-soft); }
.doc-title { font-weight: 600; color: var(--text); }
.doc-meta  { font-size: .78rem; color: var(--muted); margin-top: 2px; }
.action-row { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }

.empty-state {
  text-align: center;
  padding: 60px 24px;
  color: var(--muted);
}
.empty-icon { font-size: 2.5rem; margin-bottom: 12px; }
.empty-title { font-size: 1rem; font-weight: 600; margin-bottom: 6px; color: var(--text); }

/* ── Dashboard toolbar ────────────────────────────────────────────────────── */
.dash-toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.filter-tabs {
  display: flex;
  gap: 2px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 3px;
  flex-shrink: 0;
}
.filter-tab {
  padding: 6px 14px;
  border-radius: 7px;
  font-size: .8rem;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  transition: all .15s;
  text-decoration: none;
  white-space: nowrap;
}
.filter-tab:hover { color: var(--text); text-decoration: none; }
.filter-tab.active { background: var(--navy); color: #fff; }

.dash-search {
  flex: 1;
  min-width: 180px;
  max-width: 360px;
  position: relative;
  display: flex;
  align-items: center;
}
.dash-search input {
  width: 100%;
  padding: 8px 32px 8px 12px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  font-size: .875rem;
  font-family: inherit;
  outline: none;
  transition: border-color .15s;
}
.dash-search input:focus { border-color: var(--navy); }
.search-clear {
  position: absolute;
  right: 10px;
  color: var(--muted);
  font-size: .9rem;
  cursor: pointer;
  text-decoration: none;
  line-height: 1;
}
.search-clear:hover { color: var(--text); }

/* ── Document detail ──────────────────────────────────────────────────────── */
.detail-grid {
  display: grid;
  grid-template-columns: 1fr 320px;
  gap: 16px;
  align-items: start;
}
@media (max-width: 900px) {
  .detail-grid { grid-template-columns: 1fr; }
}
.signer-detail-row {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}
.signer-detail-row:last-child { border-bottom: none; }
.signer-detail-order {
  width: 26px; height: 26px;
  border-radius: 50%;
  background: var(--navy);
  color: #fff;
  font-size: .78rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  margin-top: 2px;
}

/* ── Prepare page ─────────────────────────────────────────────────────────── */
.prepare-layout {
  display: grid;
  grid-template-columns: 280px 1fr;
  height: calc(100vh - 56px);
  overflow: hidden;
}
.prepare-sidebar {
  background: var(--card);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}
.prepare-main {
  overflow-y: auto;
  padding: 28px 32px;
  background: #e8eaed;
}

.sidebar-section { }
.sidebar-title {
  font-size: .7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--muted);
  margin-bottom: 10px;
}

/* Signer chips */
.signer-list { display: flex; flex-direction: column; gap: 6px; margin-bottom: 8px; }
.signer-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  border-radius: 8px;
  border: 1.5px solid var(--border);
  cursor: pointer;
  transition: all .15s;
  position: relative;
}
.signer-chip.active { border-width: 2px; }
.signer-dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}
.signer-info { flex: 1; overflow: hidden; }
.signer-name { font-size: .82rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.signer-email { font-size: .72rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.signer-remove {
  background: none; border: none; color: var(--muted);
  cursor: pointer; font-size: 1rem; padding: 0 2px;
}
.signer-remove:hover { color: var(--red); }
.signer-order-badge {
  width: 20px; height: 20px;
  border-radius: 50%;
  color: #fff;
  font-size: .7rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.signer-move-btn {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: .75rem;
  padding: 1px 3px;
  border-radius: 4px;
  line-height: 1;
}
.signer-move-btn:hover:not(:disabled) { background: var(--bg); color: var(--text); }
.signer-move-btn:disabled { opacity: .3; cursor: default; }

/* Add signer form inline */
.add-signer-form {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.add-signer-form input {
  padding: 7px 10px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  font-size: .83rem;
  font-family: inherit;
  outline: none;
}
.add-signer-form input:focus { border-color: var(--navy); }

/* Field type buttons */
.field-tools {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 7px;
}
.field-tool-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 10px 6px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  background: #fff;
  cursor: pointer;
  font-size: .75rem;
  font-weight: 600;
  color: var(--muted);
  transition: all .15s;
}
.field-tool-btn .icon { font-size: 1.1rem; }
.field-tool-btn:hover { border-color: var(--navy); color: var(--navy); background: #f0f4ff; }
.field-tool-btn.active { border-color: var(--amber); color: var(--amber); background: #fff8f3; }

/* Active signer indicator */
.active-signer-badge {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 8px;
  font-size: .8rem;
  font-weight: 600;
  border: 1.5px dashed;
}

/* PDF pages in prepare */
.pdf-pages { display: flex; flex-direction: column; gap: 24px; align-items: center; }
.pdf-page-wrap {
  position: relative;
  background: #fff;
  box-shadow: 0 2px 16px rgba(0,0,0,.18);
}
.pdf-page-wrap canvas { display: block; }
.page-label {
  text-align: center;
  font-size: .75rem;
  color: #888;
  margin-top: 6px;
}

/* Field overlays in prepare */
.field-overlay {
  position: absolute;
  cursor: move;
  border: 2px solid;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  user-select: none;
  min-width: 60px;
  min-height: 22px;
}
.field-overlay-label {
  font-size: .65rem;
  font-weight: 700;
  opacity: .8;
  pointer-events: none;
  padding: 2px 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}
.field-overlay-delete {
  position: absolute;
  top: -8px; right: -8px;
  width: 16px; height: 16px;
  border-radius: 50%;
  background: #fff;
  border: 1.5px solid #ccc;
  font-size: 10px;
  cursor: pointer;
  display: none;
  align-items: center;
  justify-content: center;
  line-height: 1;
  color: var(--red);
}
.field-overlay:hover .field-overlay-delete { display: flex; }
.field-overlay-resize {
  position: absolute;
  bottom: 0; right: 0;
  width: 10px; height: 10px;
  cursor: se-resize;
}
.field-overlay-resize::after {
  content: '';
  position: absolute;
  bottom: 2px; right: 2px;
  width: 6px; height: 6px;
  border-right: 2px solid;
  border-bottom: 2px solid;
  opacity: .6;
}

/* ── Sign page ────────────────────────────────────────────────────────────── */
.sign-layout {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}
.sign-header {
  background: var(--navy);
  color: #fff;
  padding: 0 24px;
  height: 56px;
  display: flex;
  align-items: center;
  gap: 16px;
  flex-shrink: 0;
}
.sign-logo { font-size: 1rem; font-weight: 700; color: #fff; }
.sign-logo span { color: var(--amber); }
.sign-doc-title { font-size: .9rem; opacity: .8; }
.sign-spacer { flex: 1; }
.sign-step-info { font-size: .82rem; opacity: .7; }

.sign-body {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr 320px;
  overflow: hidden;
}
.sign-pdf-area {
  overflow-y: auto;
  padding: 24px;
  background: #e8eaed;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
}
.sign-sidebar {
  background: var(--card);
  border-left: 1px solid var(--border);
  overflow-y: auto;
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.sign-field-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  transition: all .15s;
  font-size: .85rem;
}
.sign-field-item.completed {
  border-color: #86efac;
  background: #f0fdf4;
}
.sign-field-item.active {
  border-color: var(--amber);
  background: #fff8f3;
}
.sign-field-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}
.sign-field-dot.empty  { background: #d1d5db; }
.sign-field-dot.done   { background: var(--green); }

.sign-footer {
  flex-shrink: 0;
  background: var(--card);
  border-top: 1px solid var(--border);
  padding: 14px 20px;
  display: flex;
  align-items: center;
  gap: 12px;
}
.sign-progress {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: .85rem;
  color: var(--muted);
}
.sign-progress-bar {
  flex: 1;
  height: 6px;
  background: #e5e7eb;
  border-radius: 3px;
  overflow: hidden;
}
.sign-progress-fill {
  height: 100%;
  background: var(--green);
  border-radius: 3px;
  transition: width .3s;
}

/* Signing field overlays on sign page */
.sign-field-overlay {
  position: absolute;
  border: 2px dashed var(--amber);
  border-radius: 4px;
  background: rgba(212, 115, 42, .06);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .15s;
}
.sign-field-overlay:hover {
  background: rgba(212, 115, 42, .14);
}
.sign-field-overlay.filled {
  border-style: solid;
  border-color: var(--green);
  background: rgba(22, 163, 74, .04);
  cursor: default;
}
.sign-field-overlay.filled:hover {
  background: rgba(22, 163, 74, .08);
}
.sign-field-overlay img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  pointer-events: none;
}
.sign-field-overlay .field-prompt {
  font-size: .72rem;
  font-weight: 600;
  color: var(--amber);
  pointer-events: none;
  padding: 2px 6px;
}
.sign-field-overlay input[type="text"] {
  width: 100%;
  height: 100%;
  border: none;
  background: transparent;
  padding: 2px 6px;
  font-size: .82rem;
  font-family: inherit;
  outline: none;
  color: var(--text);
}

/* ── Signature modal ──────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.55);
  z-index: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.modal {
  background: var(--card);
  border-radius: 14px;
  width: 100%;
  max-width: 520px;
  box-shadow: 0 8px 40px rgba(0,0,0,.3);
  overflow: hidden;
}
.modal-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.modal-title { font-weight: 700; font-size: 1rem; }
.modal-close {
  background: none;
  border: none;
  font-size: 1.3rem;
  cursor: pointer;
  color: var(--muted);
  line-height: 1;
}
.modal-close:hover { color: var(--text); }
.modal-body { padding: 20px; }
.modal-footer {
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.sig-tabs {
  display: flex;
  gap: 0;
  margin-bottom: 16px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}
.sig-tab {
  flex: 1;
  padding: 8px;
  background: none;
  border: none;
  font-size: .82rem;
  font-weight: 600;
  cursor: pointer;
  color: var(--muted);
  transition: all .15s;
}
.sig-tab.active { background: var(--navy); color: #fff; }

#sig-canvas-wrap {
  border: 1.5px solid var(--border);
  border-radius: 8px;
  background: var(--bg-soft);
  overflow: hidden;
  position: relative;
}
#sig-canvas {
  display: block;
  width: 100%;
  touch-action: none;
  cursor: crosshair;
}
.sig-hint {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #ccc;
  font-size: .875rem;
  pointer-events: none;
  transition: opacity .2s;
}

#sig-type-wrap textarea {
  width: 100%;
  padding: 12px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  font-size: 1.6rem;
  font-family: 'Brush Script MT', cursive;
  resize: none;
  outline: none;
  height: 100px;
}
#sig-type-wrap textarea:focus { border-color: var(--navy); }

/* ── Completed / success states ───────────────────────────────────────────── */
.success-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--navy);
  padding: 24px;
}
.success-card {
  background: #fff;
  border-radius: 16px;
  padding: 48px 40px;
  max-width: 440px;
  width: 100%;
  text-align: center;
  box-shadow: 0 8px 40px rgba(0,0,0,.3);
}
.success-icon { font-size: 3rem; margin-bottom: 16px; }
.success-title {
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--navy);
  margin-bottom: 8px;
}
.success-sub { color: var(--muted); font-size: .9rem; line-height: 1.6; }

/* ── Audit page ───────────────────────────────────────────────────────────── */
.audit-table { width: 100%; border-collapse: collapse; font-size: .85rem; }
.audit-table th {
  text-align: left; padding: 8px 12px;
  font-size: .72rem; text-transform: uppercase;
  letter-spacing: .06em; color: var(--muted);
  border-bottom: 1px solid var(--border);
}
.audit-table td { padding: 9px 12px; border-bottom: 1px solid var(--border); }

/* ── Misc ─────────────────────────────────────────────────────────────────── */
.divider { height: 1px; background: var(--border); margin: 6px 0; }
.spinner {
  display: inline-block;
  width: 16px; height: 16px;
  border: 2px solid rgba(255,255,255,.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin .6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.toast {
  position: fixed;
  bottom: 24px; right: 24px;
  background: var(--navy);
  color: #fff;
  padding: 12px 18px;
  border-radius: 10px;
  font-size: .875rem;
  box-shadow: 0 4px 20px rgba(0,0,0,.25);
  z-index: 999;
  opacity: 0;
  transform: translateY(8px);
  transition: all .25s;
  pointer-events: none;
}
.toast.show { opacity: 1; transform: none; }
.toast.error { background: var(--red); }

@media (max-width: 768px) {
  .prepare-layout { grid-template-columns: 1fr; }
  .prepare-sidebar { height: auto; border-right: none; border-bottom: 1px solid var(--border); }
  .sign-body { grid-template-columns: 1fr; }
  .sign-sidebar { display: none; }
}

/* ── Auth pages ───────────────────────────────────────────────────────────── */
.auth-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--navy);
  padding: 24px;
}
.auth-card {
  background: #fff;
  border-radius: 16px;
  padding: 40px 36px;
  width: 100%;
  max-width: 400px;
  box-shadow: 0 8px 40px rgba(0,0,0,.3);
}
.auth-logo {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -.03em;
  color: var(--navy);
  margin-bottom: 4px;
}
.auth-logo span { color: var(--amber); }
.auth-sub { color: var(--muted); font-size: .875rem; margin-bottom: 24px; }
.auth-row { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.auth-link { font-size: .82rem; color: var(--amber); }
.auth-footer { text-align: center; font-size: .82rem; color: var(--muted); margin-top: 20px; }
.auth-footnote { text-align: center; font-size: .75rem; color: #bbb; margin-top: 10px; }
.btn-full { width: 100%; justify-content: center; }
.btn-google {
  background: #fff;
  border: 1.5px solid var(--border);
  color: var(--text);
  gap: 8px;
  margin-bottom: 10px;
  justify-content: center;
}
.btn-google:hover { background: #f9fafb; border-color: #aaa; }
.auth-divider {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--muted);
  font-size: .8rem;
  margin: 16px 0;
}
.auth-divider::before,.auth-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}
.success-banner {
  background: #dcfce7;
  border: 1px solid #86efac;
  color: var(--green);
  padding: 10px 14px;
  border-radius: 8px;
  font-size: .85rem;
  margin-bottom: 16px;
}
.checkbox-label { display: flex; align-items: center; gap: 8px; font-size: .875rem; color: var(--text); cursor: pointer; }
.checkbox-label input { width: auto; }

/* ── Top nav ──────────────────────────────────────────────────────────────── */
.header-nav { display: flex; gap: 4px; margin-left: 24px; }
.header-nav-link {
  color: rgba(255,255,255,.65);
  font-size: .875rem;
  font-weight: 500;
  padding: 6px 12px;
  border-radius: 6px;
  text-decoration: none;
  transition: all .15s;
  cursor: pointer;
  background: none;
  border: none;
  font-family: inherit;
}
.header-nav-link:hover { color: #fff; background: rgba(255,255,255,.1); text-decoration: none; }
.header-nav-link.active { color: #fff; background: rgba(255,255,255,.15); }
.header-nav-coming { opacity: .35; cursor: default; font-size: .875rem; }

/* Header icon button */
.header-icon-btn {
  position: relative;
  background: none; border: none; color: rgba(255,255,255,.7);
  cursor: pointer; width: 36px; height: 36px;
  border-radius: 8px; display: flex; align-items: center; justify-content: center;
  transition: background .15s;
}
.header-icon-btn:hover { background: rgba(255,255,255,.1); color: #fff; }

/* Notification bell */
.header-bell { position: relative; }
.bell-badge {
  position: absolute; top: 2px; right: 2px;
  background: var(--red); color: #fff;
  font-size: .6rem; font-weight: 700;
  min-width: 16px; height: 16px; border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  padding: 0 3px;
}
.bell-dropdown {
  position: absolute; right: 0; top: calc(100% + 8px);
  background: var(--card); border: 1px solid var(--border);
  border-radius: 12px; box-shadow: 0 8px 32px rgba(0,0,0,.16);
  width: 320px; z-index: 200;
  display: none; flex-direction: column; overflow: hidden;
}
.bell-dropdown.open { display: flex; }
.bell-dropdown-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 14px; border-bottom: 1px solid var(--border);
}
.bell-item {
  display: block; padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  text-decoration: none; color: var(--text);
  transition: background .1s;
}
.bell-item:last-child { border-bottom: none; }
.bell-item:hover { background: var(--bg-soft); text-decoration: none; }
.bell-item.unread { background: var(--bg-soft); }
.bell-item-msg { font-size: .85rem; line-height: 1.4; }
.bell-item-time { font-size: .75rem; color: var(--muted); margin-top: 3px; }
.bell-empty { padding: 24px 14px; text-align: center; font-size: .875rem; color: var(--muted); }

/* User menu */
.header-user-menu { position: relative; }
.header-user-btn {
  display: flex; align-items: center; gap: 8px;
  background: none; border: none; color: rgba(255,255,255,.85);
  cursor: pointer; padding: 6px 10px; border-radius: 8px;
  font-size: .875rem; font-family: inherit;
}
.header-user-btn:hover { background: rgba(255,255,255,.1); }
.header-user-name { max-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.header-chevron { font-size: .7rem; opacity: .7; }
.user-avatar-sm {
  width: 28px; height: 28px; border-radius: 50%;
  object-fit: cover; flex-shrink: 0;
}
.user-avatar-initials {
  background: var(--amber); color: #fff;
  font-size: .8rem; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
}
.user-dropdown {
  position: absolute; right: 0; top: calc(100% + 6px);
  background: var(--card); border: 1px solid var(--border);
  border-radius: 12px; box-shadow: 0 8px 32px rgba(0,0,0,.16);
  width: 220px; z-index: 200;
  display: none; flex-direction: column; overflow: hidden;
}
.user-dropdown.open { display: flex; }
@media (max-width: 768px) {
  .user-dropdown {
    right: 0; left: auto;
    max-width: calc(100vw - 16px);
    width: 220px;
  }
  .header-user-menu { position: static; }
  .header-user-menu .user-dropdown { position: fixed; top: 60px; right: 8px; left: auto; }
}
.dropdown-header { padding: 14px 16px; border-bottom: 1px solid var(--border); }
.dropdown-name { font-weight: 600; font-size: .9rem; color: var(--text); }
.dropdown-email { font-size: .78rem; color: var(--muted); margin-top: 2px; }
.dropdown-divider { height: 1px; background: var(--border); }
.dropdown-item {
  padding: 10px 16px; font-size: .875rem; color: var(--text);
  text-decoration: none; transition: background .1s;
  display: block;
}
.dropdown-item:hover { background: var(--bg-soft); text-decoration: none; }
.dropdown-item-danger { color: var(--red) !important; }
.plan-badge {
  display: inline-block; padding: 2px 8px; border-radius: 10px;
  font-size: .7rem; font-weight: 700; text-transform: uppercase; letter-spacing: .06em;
}
.plan-free         { background: #f3f4f6; color: #6b7280; }
.plan-pro          { background: #dbeafe; color: #1d4ed8; }
.plan-business_pro { background: #dbeafe; color: #1d4ed8; }
.plan-agency       { background: #ede9fe; color: #7c3aed; }
.plan-realtor      { background: #dcfce7; color: #15803d; }
.plan-enterprise   { background: #0f1e3c; color: #fff; }

/* Flash messages */
.flash-container { position: fixed; top: 64px; right: 16px; z-index: 300; display: flex; flex-direction: column; gap: 8px; }
.flash {
  background: var(--navy); color: #fff;
  padding: 12px 16px 12px 14px;
  border-radius: 10px; font-size: .875rem;
  box-shadow: 0 4px 16px rgba(0,0,0,.2);
  display: flex; align-items: center; gap: 12px;
  max-width: 380px;
}
.flash-success { background: var(--green); }
.flash-error   { background: var(--red); }
.flash-warning { background: #d97706; }
.flash-close { background: none; border: none; color: rgba(255,255,255,.7); cursor: pointer; font-size: 1rem; padding: 0; line-height: 1; }
.flash-close:hover { color: #fff; }

/* ── Dashboard styles ──────────────────────────────────────────────────────── */
.dash-overview-strip {
  display: grid; grid-template-columns: repeat(4, 1fr);
  gap: 12px; margin-bottom: 16px;
}
@media (max-width: 700px) { .dash-overview-strip { grid-template-columns: repeat(2, 1fr); } }
.dash-stat-card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px 16px; text-align: center;
}
.dash-stat-card.dash-stat-alert { border-color: var(--amber); }
.dash-stat-val { font-size: 1.75rem; font-weight: 700; line-height: 1; }
.dash-stat-label { font-size: .75rem; color: var(--muted); margin-top: 4px; }
.dash-quick-actions {
  display: flex; gap: 10px; margin-bottom: 16px; flex-wrap: wrap;
}
.dash-quick-btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 14px; background: var(--card);
  border: 1px solid var(--border); border-radius: var(--radius);
  font-size: .85rem; color: var(--text); text-decoration: none;
  transition: all .15s; font-weight: 500;
}
.dash-quick-btn:hover { border-color: var(--navy); color: var(--navy); text-decoration: none; }
.dash-card {}
.dash-card-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px; border-bottom: 1px solid var(--border);
}
.dash-card-title { font-weight: 700; font-size: .9rem; }
.dash-card-badge {
  background: var(--amber); color: #fff;
  font-size: .72rem; font-weight: 700;
  padding: 2px 8px; border-radius: 10px;
}
.dash-card-link { font-size: .8rem; color: var(--amber); }
.dash-card-body { padding: 8px 0; }
.task-row {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 18px; text-decoration: none; color: var(--text);
  border-bottom: 1px solid var(--border); transition: background .1s;
}
.task-row:last-child { border-bottom: none; }
.task-row:hover { background: var(--bg-soft); text-decoration: none; }
.task-icon { font-size: 1.2rem; flex-shrink: 0; }
.task-info { flex: 1; }
.task-title { font-weight: 600; font-size: .875rem; }
.task-meta { font-size: .78rem; color: var(--muted); margin-top: 2px; }
.task-cta { font-size: .82rem; color: var(--amber); font-weight: 600; white-space: nowrap; }
.activity-row {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 10px 18px; border-bottom: 1px solid var(--border);
}
.activity-row:last-child { border-bottom: none; }
.activity-icon { font-size: 1rem; flex-shrink: 0; margin-top: 2px; }
.activity-info { flex: 1; }
.activity-desc { font-size: .85rem; color: var(--text); }
.activity-desc a { color: var(--navy); }
.activity-time { font-size: .75rem; color: var(--muted); margin-top: 2px; }
.overview-stat { padding: 12px 0; border-bottom: 1px solid var(--border); }
.overview-stat:last-child { border-bottom: none; }
.overview-val { font-size: 1.8rem; font-weight: 700; letter-spacing: -.03em; }
.overview-label { font-size: .78rem; color: var(--muted); margin-top: 2px; }
.usage-bar {
  width: 100%; height: 8px;
  background: var(--border); border-radius: 4px; overflow: hidden;
}
.usage-fill { height: 100%; background: var(--amber); border-radius: 4px; transition: width .3s; }
.usage-full { background: var(--red) !important; }
.quick-action-btn {
  display: block; padding: 10px 12px; font-size: .85rem; color: var(--text);
  text-decoration: none; border-radius: 8px; transition: background .1s;
}
.quick-action-btn:hover { background: var(--bg); text-decoration: none; }

/* ── Page layout helpers ──────────────────────────────────────────────────── */
.page-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 24px; flex-wrap: wrap; gap: 12px;
}
.pagination {
  display: flex; align-items: center; justify-content: center; gap: 16px;
  padding: 14px; border-top: 1px solid var(--border);
}
.page-btn {
  font-size: .875rem; color: var(--navy); text-decoration: none;
  padding: 6px 12px; border: 1.5px solid var(--border); border-radius: 6px;
}
.page-btn:hover { background: var(--bg); }
.page-info { font-size: .875rem; color: var(--muted); }

/* Actions dropdown */
.actions-menu-wrap { position: relative; display: inline-block; }
.actions-dropdown {
  position: absolute; right: 0; top: calc(100% + 4px);
  background: var(--card); border: 1px solid var(--border);
  border-radius: 10px; box-shadow: 0 8px 24px rgba(0,0,0,.12);
  min-width: 160px; z-index: 100; display: none; flex-direction: column;
  overflow: hidden;
}
.actions-dropdown.open { display: flex; }
.actions-dropdown a,
.actions-dropdown button {
  display: block; padding: 9px 14px; font-size: .875rem;
  color: var(--text); text-decoration: none; background: none;
  border: none; text-align: left; cursor: pointer; font-family: inherit;
  width: 100%;
}
.actions-dropdown a:hover,
.actions-dropdown button:hover { background: var(--bg-soft); }

/* ── Upload zone ──────────────────────────────────────────────────────────── */
.upload-zone {
  border: 2px dashed var(--border);
  border-radius: 12px;
  padding: 48px 32px;
  text-align: center;
  cursor: pointer;
  transition: all .15s;
  background: var(--bg-soft);
}
.upload-zone:hover,.upload-zone.drag-over { border-color: var(--amber); background: #fff8f3; }
.upload-zone.has-file { border-color: var(--green); background: #f0fdf4; }
.upload-icon { font-size: 2.5rem; margin-bottom: 12px; }
.upload-label { font-size: 1rem; font-weight: 600; color: var(--text); margin-bottom: 6px; }
.upload-sub { font-size: .875rem; color: var(--muted); }
.upload-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 24px; }

/* Step indicator */
.step-indicator {
  display: flex; align-items: center; margin-top: 32px; padding: 0 20px;
}
.step { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.step-num {
  width: 32px; height: 32px; border-radius: 50%;
  border: 2px solid var(--border); background: var(--card);
  color: var(--muted); font-size: .85rem; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
}
.step.active .step-num { border-color: var(--amber); background: var(--amber); color: #fff; }
.step-label { font-size: .75rem; color: var(--muted); white-space: nowrap; }
.step.active .step-label { color: var(--text); font-weight: 600; }
.step-line { flex: 1; height: 2px; background: var(--border); margin: 0 8px; margin-bottom: 20px; }

/* ── Signing page improvements ───────────────────────────────────────────── */
.signed-by-bracket {
  border-left: 3px solid #2563eb;
  padding: 4px 10px;
  margin-bottom: 4px;
  font-size: .7rem;
  color: #2563eb;
  font-weight: 600;
}
.witness-notice {
  background: #fef3c7;
  border: 1px solid #fcd34d;
  color: #92400e;
  padding: 10px 14px;
  border-radius: 8px;
  font-size: .875rem;
  margin-bottom: 12px;
  text-align: center;
}

/* ── Contacts ─────────────────────────────────────────────────────────────── */
.passkey-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 0; border-bottom: 1px solid var(--border); font-size: .875rem;
}
.passkey-row:last-child { border-bottom: none; }

/* ── Settings ─────────────────────────────────────────────────────────────── */
.settings-section { padding: 24px; margin-bottom: 16px; }
.settings-section-title { font-size: .75rem; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin-bottom: 18px; }
.settings-subsection { margin-top: 20px; padding-top: 20px; border-top: 1px solid var(--border); }
.settings-subsection-title { font-size: .85rem; font-weight: 600; margin-bottom: 14px; }
.settings-row { display: flex; gap: 24px; align-items: flex-start; margin-bottom: 16px; }
.settings-avatar { width: 72px; height: 72px; border-radius: 50%; object-fit: cover; }
.settings-avatar-wrap { display: flex; flex-direction: column; align-items: center; }
.settings-avatar-initials {
  width: 72px; height: 72px; border-radius: 50%;
  background: var(--amber); color: #fff;
  font-size: 1.4rem; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
}
.settings-toggles { display: flex; flex-direction: column; gap: 12px; }
.toggle-row {
  display: flex; align-items: center; justify-content: space-between;
  font-size: .875rem; padding: 8px 0; border-bottom: 1px solid #f3f4f6; cursor: pointer;
}
.toggle-row:last-child { border-bottom: none; }

/* ── Agency / stats ───────────────────────────────────────────────────────── */
.stats-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 16px; margin-bottom: 24px;
}
.stat-card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 20px 24px;
  box-shadow: var(--shadow);
}
.stat-val { font-size: 2rem; font-weight: 700; letter-spacing: -.03em; color: var(--text); }
.stat-label { font-size: .78rem; color: var(--muted); margin-top: 4px; }
.approval-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 20px; border-bottom: 1px solid var(--border); gap: 16px; flex-wrap: wrap;
}
.approval-row:last-child { border-bottom: none; }

/* ── Pricing ──────────────────────────────────────────────────────────────── */
.billing-toggle {
  display: inline-flex; border: 1.5px solid var(--border);
  border-radius: 10px; overflow: hidden; margin-top: 20px;
}
.billing-btn {
  padding: 8px 20px; background: none; border: none;
  font-size: .875rem; font-weight: 600; color: var(--muted); cursor: pointer;
  font-family: inherit;
}
.billing-btn.active { background: var(--navy); color: #fff; }
.save-badge {
  background: #dcfce7; color: #15803d;
  font-size: .65rem; padding: 1px 6px; border-radius: 6px; margin-left: 4px;
}
.pricing-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 20px;
}
.pricing-card {
  background: var(--card); border: 1.5px solid var(--border);
  border-radius: 16px; padding: 28px 24px; position: relative;
}
.pricing-featured { border-color: var(--amber); box-shadow: 0 0 0 3px rgba(212,115,42,.12); }
.pricing-badge {
  position: absolute; top: -12px; left: 50%; transform: translateX(-50%);
  background: var(--amber); color: #fff;
  font-size: .7rem; font-weight: 700; padding: 3px 12px; border-radius: 10px;
}
.pricing-plan { font-size: .75rem; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin-bottom: 8px; }
.pricing-price { margin-bottom: 6px; }
.pricing-amount { font-size: 2.2rem; font-weight: 700; letter-spacing: -.03em; }
.pricing-cycle { font-size: .875rem; color: var(--muted); }
.pricing-desc { font-size: .82rem; color: var(--muted); margin-bottom: 20px; }
.pricing-features { list-style: none; margin-bottom: 24px; font-size: .875rem; }
.pricing-features li { padding: 5px 0; color: var(--text); }
.pricing-features li:not(:last-child) { border-bottom: 1px solid var(--border); }

/* ── Field type: locked overlay ──────────────────────────────────────────── */
.field-tool-locked {
  opacity: .5; cursor: not-allowed; position: relative;
  color: var(--muted);
}

/* ── New sign field types ─────────────────────────────────────────────────── */
.sign-field-overlay.checkbox-field { border-style: solid; background: rgba(37,99,235,.04); }
.field-checkbox-box {
  width: 20px; height: 20px; border: 2px solid var(--border);
  border-radius: 4px; background: var(--card); cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  margin: auto;
}
.field-checkbox-box.checked { background: var(--navy); border-color: var(--navy); color: #fff; }

/* toast success */
.toast.success { background: var(--green); }

/* ── Contact autocomplete ─────────────────────────────────────────────────── */
.contact-suggestions {
  position: fixed;
  background: var(--card); border: 1.5px solid var(--border);
  border-radius: 8px; z-index: 9999;
  box-shadow: 0 8px 24px rgba(0,0,0,.12); max-height: 220px; overflow-y: auto;
}
.contact-suggestion-item {
  padding: 9px 12px; cursor: pointer; font-size: .84rem;
  border-bottom: 1px solid var(--border);
  transition: background .1s;
}
.contact-suggestion-item:last-child { border-bottom: none; }
.contact-suggestion-item:hover { background: var(--bg-soft); }
#add-signer-form { position: relative; }

/* ── Comparison table ─────────────────────────────────────────────────────── */
.comparison-table {
  width: 100%; border-collapse: collapse; font-size: .86rem;
  border: 1.5px solid var(--border); border-radius: 12px; overflow: hidden;
}
.comparison-table thead tr { background: var(--navy); color: #fff; }
.comparison-table thead th {
  padding: 13px 14px; font-weight: 600; font-size: .8rem;
  text-transform: uppercase; letter-spacing: .04em;
}
.comparison-table tbody tr:nth-child(even) { background: var(--bg-soft); }
.comparison-table tbody tr:hover { background: var(--bg-soft); }
.comparison-table td { padding: 11px 14px; border-bottom: 1px solid var(--border); }
.comparison-table tbody tr:last-child td { border-bottom: none; }
.pricing-popular-badge {
  position: absolute; top: -12px; left: 50%; transform: translateX(-50%);
  background: var(--amber); color: #fff; font-size: .72rem; font-weight: 700;
  padding: 4px 14px; border-radius: 20px; white-space: nowrap;
  letter-spacing: .04em; text-transform: uppercase;
}
.pricing-card { position: relative; }

/* ── PDF drag-from-sidebar ────────────────────────────────────────────────── */
.pdf-page-wrap.drag-target { outline: 3px dashed var(--amber); outline-offset: -3px; }


/* ── Documents list with folder sidebar ───────────────────────────────────── */
.docs-layout {
  display: flex; gap: 24px; align-items: flex-start;
  max-width: 1280px; margin: 0 auto; padding: 24px 20px;
}
.folder-sidebar {
  width: 220px; flex-shrink: 0;
  background: var(--card); border: 1.5px solid var(--border);
  border-radius: 12px; padding: 12px 0 8px;
  position: sticky; top: 80px;
}
.folder-header {
  font-size: .7rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: .07em; color: var(--muted); padding: 0 16px 8px;
}
.folder-list { display: flex; flex-direction: column; gap: 1px; }
.folder-item {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 16px; font-size: .875rem; color: var(--text);
  text-decoration: none; border-radius: 0;
  transition: background .12s; cursor: pointer;
}
.folder-item:hover { background: var(--bg-soft); }
.folder-item.active { background: var(--bg-soft); color: var(--navy); font-weight: 600; }
.folder-item.drag-over { background: #dbeafe; }
.folder-item-system .folder-name { color: var(--muted); }
.folder-item-system.active .folder-name { color: var(--navy); }
.folder-lock { color: var(--muted); opacity: .5; flex-shrink: 0; display: flex; align-items: center; margin-right: 2px; }
.folder-icon { font-size: .95rem; flex-shrink: 0; }
.folder-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.folder-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.folder-badge {
  font-size: .7rem; background: var(--border); color: var(--muted);
  border-radius: 20px; padding: 1px 7px; flex-shrink: 0;
}
.folder-divider { height: 1px; background: var(--border); margin: 6px 12px; }
.folder-item-wrap { display: flex; align-items: center; position: relative; }
.folder-item-wrap .folder-item { flex: 1; }
.folder-menu-btn {
  background: none; border: none; color: var(--muted); cursor: pointer;
  padding: 4px 8px; font-size: 1rem; opacity: 0;
  transition: opacity .12s;
}
.folder-item-wrap:hover .folder-menu-btn { opacity: 1; }
.new-folder-btn {
  width: 100%; text-align: left; background: none; border: none;
  color: var(--muted); font-size: .82rem; padding: 8px 16px;
  cursor: pointer; border-top: 1px solid var(--border); margin-top: 6px;
}
.new-folder-btn:hover { color: var(--navy); }
.docs-main { flex: 1; min-width: 0; }
.docs-main .page-wrap { padding: 0; }
.ctx-menu-item {
  display: block; width: 100%; text-align: left; padding: 8px 16px;
  background: none; border: none; font-size: .875rem; cursor: pointer;
  color: var(--text); font-family: inherit;
}
.ctx-menu-item:hover { background: var(--bg-soft); }
.ctx-menu-danger { color: var(--red); }
.doc-row.dragging { opacity: .5; }

/* ── Settings sidebar layout ──────────────────────────────────────────────── */
.settings-layout {
  display: flex; gap: 32px; align-items: flex-start;
  max-width: 1100px; margin: 0 auto; padding: 24px 20px;
}
.settings-nav {
  width: 220px; flex-shrink: 0;
  background: var(--card); border: 1.5px solid var(--border);
  border-radius: 12px; overflow: hidden;
  position: sticky; top: 80px;
}
.settings-nav-section {
  font-size: .68rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: .07em; color: var(--muted); padding: 12px 16px 4px;
}
.settings-nav-link {
  display: block; padding: 8px 16px; font-size: .875rem;
  color: var(--text); text-decoration: none;
  transition: background .12s;
}
.settings-nav-link:hover { background: var(--bg-soft); }
.settings-nav-link.active { background: var(--bg-soft); color: var(--navy); font-weight: 600; }
.settings-nav-divider { height: 1px; background: var(--border); margin: 6px 0; }
.settings-content { flex: 1; min-width: 0; }
.settings-panel { display: none; }
.settings-panel.active { display: block; }
.settings-panel-title {
  font-size: 1.25rem; font-weight: 700; color: var(--text);
  margin: 0 0 20px;
}
.settings-section-desc {
  font-size: .85rem; color: var(--muted); margin: -12px 0 16px;
}
.settings-toggle-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 12px 0; border-bottom: 1px solid var(--border);
}
.settings-toggle-row:last-child { border-bottom: none; }
.settings-toggle-label { font-size: .9rem; color: var(--text); }
.settings-toggle-desc { font-size: .78rem; color: var(--muted); margin-top: 2px; }
.toggle-switch {
  position: relative; width: 44px; height: 24px; cursor: pointer;
  flex-shrink: 0;
}
.toggle-switch input { opacity: 0; width: 0; height: 0; }
.toggle-slider {
  position: absolute; inset: 0; background: var(--border);
  border-radius: 24px; transition: background .2s;
}
.toggle-slider::before {
  content: ''; position: absolute; height: 18px; width: 18px;
  left: 3px; top: 3px; background: var(--card); border-radius: 50%;
  transition: transform .2s; box-shadow: 0 1px 4px rgba(0,0,0,.2);
}
.toggle-switch input:checked + .toggle-slider { background: var(--navy); }
.toggle-switch input:checked + .toggle-slider::before { transform: translateX(20px); }
.account-id-display {
  font-family: monospace; font-size: .9rem; background: var(--bg-soft);
  border: 1.5px solid var(--border); border-radius: 8px;
  padding: 8px 14px; color: var(--text); letter-spacing: .05em;
  display: inline-flex; align-items: center; gap: 10px;
}
.delete-account-btn {
  background: none; border: 1.5px solid #dc2626; color: #dc2626;
  border-radius: 8px; padding: 8px 16px; font-size: .875rem;
  font-weight: 600; cursor: pointer; font-family: inherit;
  margin-top: 24px; display: block;
}
.delete-account-btn:hover { background: #fef2f2; }
.branding-preview {
  border: 1.5px solid var(--border); border-radius: 12px;
  overflow: hidden; margin-top: 16px;
}
.branding-preview-header {
  background: var(--navy); color: #fff;
  padding: 12px 20px; font-weight: 700; font-size: .95rem;
}
.plan-usage-bar {
  background: var(--border); border-radius: 4px; height: 8px;
  margin-top: 6px; overflow: hidden;
}
.plan-usage-fill {
  height: 100%; border-radius: 4px;
  background: linear-gradient(90deg, var(--navy), var(--amber));
  transition: width .5s;
}

/* ── Page transitions ─────────────────────────────────────────────────────── */
body { opacity: 0; background: var(--bg); transition: opacity .05s ease; }
body.page-ready { opacity: 1; }

/* ── Global footer ────────────────────────────────────────────────────────── */
.app-footer {
  border-top: 1px solid var(--border); background: #fff;
  padding: 14px 24px; display: flex; align-items: center;
  justify-content: space-between;
  font-size: .8rem; color: var(--muted);
  margin-top: 48px; flex-shrink: 0;
}
.footer-left { color: var(--muted); }
.footer-center { color: var(--muted); }
.footer-links { display: flex; gap: 14px; align-items: center; }
.footer-links a { color: var(--muted); text-decoration: none; }
.footer-links a:hover { color: var(--navy); }
.coming-soon-tooltip {
  position: relative; cursor: default;
}
.coming-soon-tooltip::after {
  content: 'Coming Soon'; position: absolute; bottom: 110%; left: 50%;
  transform: translateX(-50%); background: #1e293b; color: #fff;
  font-size: .7rem; padding: 3px 8px; border-radius: 6px;
  white-space: nowrap; opacity: 0; pointer-events: none;
  transition: opacity .15s;
}
.coming-soon-tooltip:hover::after { opacity: 1; }

/* ── 404/500 error pages ──────────────────────────────────────────────────── */
.error-page {
  display: flex; flex-direction: column; align-items: center;
  justify-content: center; min-height: 60vh; text-align: center;
  padding: 48px 24px;
}
.error-code {
  font-size: 6rem; font-weight: 900; color: var(--navy);
  line-height: 1; opacity: .12; margin-bottom: 8px;
}
.error-title {
  font-size: 1.5rem; font-weight: 700; color: var(--navy); margin-bottom: 8px;
}
.error-msg {
  color: var(--muted); font-size: 1rem; margin-bottom: 28px; max-width: 420px;
}
.countdown-text { font-size: .82rem; color: var(--muted); margin-top: 12px; }

/* ── Comparison table additions ───────────────────────────────────────────── */
.comparison-table .yes { text-align:center;color:#16a34a;font-size:1rem;font-weight:600 }
.comparison-table .no  { text-align:center;color:#d1d5db;font-size:1rem }
.comparison-table .col-pro { background: rgba(245,158,11,.05); }
.comparison-table thead .col-pro { background: rgba(245,158,11,.15); }
.comparison-group-row td {
  background: var(--bg-soft); font-weight: 700; font-size: .75rem;
  text-transform: uppercase; letter-spacing: .06em; color: var(--muted);
  padding: 8px 14px; border-bottom: 1px solid var(--border);
}
.btn-spinner {
  display: inline-block; width: 14px; height: 14px;
  border: 2px solid rgba(255,255,255,.4);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin .6s linear infinite;
  vertical-align: middle;
  margin-right: 4px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Auth pages don't use base.html so force body visible */
.auth-wrap ~ script, .auth-wrap { opacity: 1; }
body:has(.auth-wrap) { opacity: 1 !important; }

@keyframes session-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: .45; }
}

/* ═══════════════════════════════════════════════════════════════════════════
   MOBILE RESPONSIVENESS — 768px tablet, 480px mobile
   ═══════════════════════════════════════════════════════════════════════════ */

/* ── Global touch targets & form inputs ──────────────────────────────────── */
@media (max-width: 768px) {
  .btn { min-height: 44px; display: inline-flex; align-items: center; justify-content: center; }
  .btn-sm { min-height: 36px; }
  input[type="text"], input[type="email"], input[type="password"],
  input[type="tel"], input[type="number"], input[type="search"],
  input[type="date"], textarea, select {
    font-size: 16px !important; /* prevents iOS zoom */
  }
}

/* ── Hamburger button ─────────────────────────────────────────────────────── */
.hamburger-btn {
  display: none;
  background: none; border: none;
  color: rgba(255,255,255,.85); cursor: pointer;
  padding: 6px; margin-left: 4px;
  flex-shrink: 0;
}
@media (max-width: 768px) {
  .hamburger-btn { display: flex; align-items: center; }
}

/* ── Mobile nav drawer ────────────────────────────────────────────────────── */
.mobile-nav-drawer {
  position: fixed; top: 0; left: 0;
  width: 280px; height: 100vh;
  background: var(--navy); z-index: 500;
  transform: translateX(-100%);
  transition: transform .28s cubic-bezier(.22,1,.36,1);
  display: flex; flex-direction: column;
}
.mobile-nav-drawer.open { transform: translateX(0); }
.mobile-nav-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 20px; border-bottom: 1px solid rgba(255,255,255,.1);
}
.mobile-nav-links { padding: 12px 0; overflow-y: auto; flex: 1; }
.mobile-nav-link {
  display: block; padding: 13px 20px;
  color: rgba(255,255,255,.85); text-decoration: none;
  font-size: .95rem; font-weight: 500;
  transition: background .12s;
}
.mobile-nav-link:hover { background: rgba(255,255,255,.08); color: #fff; }

/* ── Header: hide elements on mobile ─────────────────────────────────────── */
@media (max-width: 768px) {
  .header-nav { display: none; }
  .plan-badge { display: none; }
  #session-timer-wrap { display: none !important; }
  .header-user-name { display: none; }
  .header-chevron { display: none; }
  /* Keep bell + avatar visible */
}

/* ── Footer ───────────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .app-footer {
    flex-direction: column; gap: 8px;
    text-align: center; padding: 20px 16px;
  }
  .footer-links { gap: 12px; flex-wrap: wrap; justify-content: center; }
}

/* ── Dashboard stat cards ─────────────────────────────────────────────────── */
@media (max-width: 900px) {
  .stats-grid { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 480px) {
  .stats-grid { grid-template-columns: 1fr; }
  .page-wrap { padding: 16px; }
  .page-header { flex-direction: column; align-items: flex-start; gap: 12px; }
  .page-header .btn { width: 100%; }
}

/* ── Documents list ───────────────────────────────────────────────────────── */
@media (max-width: 900px) {
  .docs-layout { flex-direction: column; }
  .folder-sidebar {
    width: 100%; height: auto;
    border-right: none; border-bottom: 1px solid var(--border);
    overflow-x: auto; overflow-y: hidden;
  }
  .folder-header { display: none; }
  .folder-list {
    display: flex; flex-direction: row;
    gap: 4px; padding: 8px 12px;
    white-space: nowrap;
    scrollbar-width: none;
  }
  .folder-list::-webkit-scrollbar { display: none; }
  .folder-item {
    padding: 6px 12px; border-radius: 20px;
    border: 1.5px solid var(--border);
    flex-shrink: 0; font-size: .8rem;
  }
  .folder-item.active {
    background: var(--navy); color: #fff; border-color: var(--navy);
  }
  .folder-divider { width: 1px; height: 24px; background: var(--border); margin: auto 4px; align-self: center; }
  .folder-item-wrap { flex-shrink: 0; }
  .folder-item-wrap .folder-item { border-radius: 20px; }
  .new-folder-btn { display: none; }
  #new-folder-input { display: none !important; }
}
@media (max-width: 768px) {
  .docs-table thead th:nth-child(3),
  .docs-table tbody td:nth-child(3) { display: none; } /* Signers */
  .docs-table thead th:nth-child(4),
  .docs-table tbody td:nth-child(4) { display: none; } /* Created */
  .doc-meta { display: none; }
}
@media (max-width: 480px) {
  .filter-tabs { overflow-x: auto; scrollbar-width: none; }
  .filter-tabs::-webkit-scrollbar { display: none; }
}

/* ── Prepare page ─────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .prepare-layout { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .prepare-sidebar {
    height: auto; max-height: 50vh;
    border-right: none; border-bottom: 1px solid var(--border);
    overflow-y: auto;
  }
  .prepare-main { min-height: 60vh; }
  .field-tools { grid-template-columns: repeat(3, 1fr); }
  .field-tool-btn { min-height: 44px; padding: 8px 4px; }
  .signer-chip { min-height: 44px; }
  .signer-remove { min-width: 44px; min-height: 44px; display: flex; align-items: center; justify-content: center; }
  .add-signer-form input { min-height: 44px; }
  .sidebar-section button.btn { min-height: 44px; }
}
@media (max-width: 480px) {
  .field-tools { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 390px) {
  .prepare-sidebar { max-height: 45vh; padding: 12px; gap: 12px; }
  .field-tools { grid-template-columns: repeat(2, 1fr); gap: 6px; }
  .field-tool-btn { font-size: .72rem; min-height: 44px; }
  .sidebar-title { font-size: .82rem; }
}

/* ── Sign page ─────────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .sign-body { grid-template-columns: 1fr; }
  .sign-sidebar { display: none; }
  .sign-pdf-area { width: 100%; max-width: 100vw; }
  .sign-footer { padding: 10px 12px; gap: 8px; }
  .sign-footer .sign-progress { flex: 1; min-width: 0; }
  #sig-canvas { max-width: 100%; }
  /* Mobile sign sidebar bottom sheet */
  .sign-sidebar-mobile-sheet {
    display: block; position: fixed; bottom: 0; left: 0; right: 0;
    background: #fff; border-top: 2px solid var(--border);
    border-radius: 16px 16px 0 0; z-index: 400;
    max-height: 70vh; overflow-y: auto;
    transform: translateY(100%); transition: transform .3s cubic-bezier(.22,1,.36,1);
    box-shadow: 0 -4px 24px rgba(0,0,0,.12);
  }
  .sign-sidebar-mobile-sheet.open { transform: translateY(0); }
  .sign-sidebar-sheet-handle {
    width: 36px; height: 4px; background: #ddd; border-radius: 2px;
    margin: 10px auto 0;
  }
  .sign-mobile-fab {
    display: flex; position: fixed; bottom: 80px; right: 16px;
    background: var(--navy); color: #fff; border: none; border-radius: 50%;
    width: 52px; height: 52px; align-items: center; justify-content: center;
    box-shadow: 0 4px 16px rgba(0,0,0,.25); cursor: pointer; z-index: 300;
    font-size: 1.2rem;
  }
}
@media (min-width: 769px) {
  .sign-sidebar-mobile-sheet { display: none; }
  .sign-mobile-fab { display: none; }
}
@media (max-width: 480px) {
  .sign-header { padding: 0 12px; }
  .sign-doc-title { font-size: .8rem; max-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .sign-footer button { min-height: 44px; }
}
@media (max-width: 390px) {
  .sign-footer { flex-wrap: wrap; }
  .sign-footer button { flex: 1; min-width: 120px; }
}

/* ── Settings ─────────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .settings-layout { flex-direction: column; padding: 16px; gap: 16px; }
  .settings-nav {
    width: 100%; position: static;
    /* Collapse to a horizontal scroll row */
    display: flex; flex-direction: row;
    overflow-x: auto; scrollbar-width: none;
    border-radius: 8px; background: #fff;
    border: 1.5px solid var(--border);
  }
  .settings-nav::-webkit-scrollbar { display: none; }
  .settings-nav-section { display: none; }
  .settings-nav-divider { display: none; }
  .settings-nav-link {
    padding: 10px 14px; white-space: nowrap;
    flex-shrink: 0; font-size: .82rem;
    border-right: 1px solid var(--border);
  }
  .settings-nav-link:last-child { border-right: none; }
  .settings-nav-link.active {
    background: var(--navy); color: #fff; border-radius: 0;
  }
}

/* ── Pricing page ─────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .pricing-grid { grid-template-columns: 1fr !important; max-width: 400px; margin: 0 auto; }
  .pricing-tabs { flex-wrap: wrap; justify-content: center; }
  .comparison-table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .comparison-table { min-width: 600px; }
}
@media (max-width: 480px) {
  .pricing-hero h1 { font-size: 1.6rem; }
}

/* ── Audit drawer: full width on mobile ───────────────────────────────────── */
@media (max-width: 480px) {
  #audit-drawer { width: 100vw !important; }
}

/* ── Modals: bottom sheet on mobile ──────────────────────────────────────── */
@media (max-width: 480px) {
  .ss-modal-overlay {
    align-items: flex-end;
    padding: 0;
  }
  .ss-modal {
    border-radius: 20px 20px 0 0;
    max-width: 100%;
    width: 100%;
    animation: ssModalBottomIn .22s cubic-bezier(.22,1,.36,1);
  }
  @keyframes ssModalBottomIn {
    from { transform: translateY(100%); opacity: 1; }
    to   { transform: translateY(0);    opacity: 1; }
  }
}

/* ── Auth pages on small screens ─────────────────────────────────────────── */
@media (max-width: 480px) {
  .auth-card { padding: 28px 20px; border-radius: 0; min-height: 100vh; justify-content: center; display: flex; flex-direction: column; }
  .auth-wrap { padding: 0; align-items: flex-start; }
}

/* ── General card / page-wrap on mobile ───────────────────────────────────── */
@media (max-width: 768px) {
  .dash-grid { grid-template-columns: 1fr; }
  .card { border-radius: 8px; }
}

/* ── Touch targets: 44px minimum ─────────────────────────────────────────── */
@media (max-width: 768px) {
  .btn, button:not(.field-overlay-delete):not(.field-overlay-resize):not(.modal-close) {
    min-height: 44px;
  }
  .signer-remove, .folder-menu-btn { min-height: 36px; min-width: 36px; }
}

/* ── Inputs: 16px font-size prevents iOS auto-zoom ───────────────────────── */
@media (max-width: 768px) {
  input[type="text"],
  input[type="email"],
  input[type="password"],
  input[type="search"],
  input[type="url"],
  input[type="number"],
  input[type="tel"],
  textarea,
  select {
    font-size: 16px !important;
  }
}

/* ── Modals: bottom sheet on mobile (standard modal class) ───────────────── */
@media (max-width: 480px) {
  .modal-overlay {
    align-items: flex-end !important;
    padding: 0 !important;
  }
  .modal {
    border-radius: 20px 20px 0 0 !important;
    max-width: 100% !important;
    width: 100% !important;
    max-height: 90vh;
    overflow-y: auto;
  }
}


/* ═══════════════════════════════════════════════════════════════
   BRIEF 11 — COMPREHENSIVE MOBILE OPTIMIZATION
   Targets: 375px, 390px, 428px (and all widths ≤ 768px)
   ═══════════════════════════════════════════════════════════════ */

/* ── Dashboard: stack all cards on mobile ───────────────────────────── */
@media (max-width: 768px) {
  .dash-overview-strip {
    grid-template-columns: repeat(2, 1fr);
  }
  .dash-quick-actions {
    flex-wrap: wrap;
    gap: 8px;
  }
  .dash-quick-btn {
    flex: 1 1 calc(50% - 8px);
    min-width: 120px;
    justify-content: center;
  }
}
@media (max-width: 480px) {
  .dash-overview-strip {
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
  }
  .dash-stat-card {
    padding: 12px;
  }
  .dash-stat-val {
    font-size: 1.5rem;
  }
  .dash-quick-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }
  .dash-quick-btn {
    flex: none;
    width: 100%;
    font-size: .8rem;
    padding: 10px;
    justify-content: center;
  }
  .usage-bar {
    height: 6px;
  }
}
@media (max-width: 375px) {
  .dash-overview-strip {
    grid-template-columns: 1fr 1fr;
  }
}

/* ── Documents list: table scrolls horizontally ─────────────────────── */
@media (max-width: 768px) {
  .docs-table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  .docs-table {
    min-width: 600px;
  }
  /* Doc title column stays visible */
  .docs-table td:first-child,
  .docs-table th:first-child {
    min-width: 140px;
  }
}
@media (max-width: 480px) {
  /* Convert document rows to card-like view */
  .docs-table,
  .docs-table thead,
  .docs-table tbody,
  .docs-table tr,
  .docs-table td,
  .docs-table th {
    display: block;
    width: 100%;
  }
  .docs-table thead { display: none; }
  .docs-table tr {
    border: 1px solid var(--border);
    border-radius: 8px;
    margin-bottom: 8px;
    padding: 10px 12px;
    background: #fff;
  }
  .docs-table td {
    padding: 3px 0;
    border: none;
    font-size: .82rem;
  }
  .docs-table td[data-label]::before {
    content: attr(data-label) ': ';
    font-size: .72rem;
    font-weight: 700;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: .04em;
  }
}

/* ── Contacts: table scroll on mobile ───────────────────────────────── */
@media (max-width: 768px) {
  .contacts-table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  .contacts-table {
    min-width: 500px;
  }
}

/* ── Templates: stack cards single column ───────────────────────────── */
@media (max-width: 600px) {
  .template-grid {
    grid-template-columns: 1fr !important;
    max-width: 100%;
  }
}

/* ── Prepare page: better sidebar behavior ──────────────────────────── */
@media (max-width: 768px) {
  .prepare-layout {
    flex-direction: column;
  }
  .prepare-sidebar {
    width: 100%;
    max-height: none;
    position: relative;
  }
  #pdf-canvas-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
}

/* ── Settings: sidebar on mobile is a scroll-nav ─────────────────────── */
@media (max-width: 768px) {
  .settings-layout {
    flex-direction: column;
  }
  .settings-nav {
    width: 100%;
    flex-direction: row;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    white-space: nowrap;
    display: flex;
    border-bottom: 1.5px solid var(--border);
    border-right: none;
    background: #fff;
    border-radius: 8px 8px 0 0;
    padding: 0;
  }
  .settings-nav-section,
  .settings-nav-divider { display: none; }
  .settings-nav-link {
    padding: 10px 16px;
    white-space: nowrap;
    flex-shrink: 0;
    font-size: .82rem;
    border-right: 1px solid var(--border);
    border-bottom: none;
  }
  .settings-nav-link:last-child { border-right: none; }
  .settings-nav-link.active {
    background: var(--navy);
    color: #fff;
    border-radius: 0;
  }
  .settings-content {
    border-radius: 0 0 8px 8px;
  }
}

/* ── Pricing: single column on small screens ─────────────────────────── */
@media (max-width: 600px) {
  .pricing-cards.three-col,
  .pricing-cards.two-col {
    grid-template-columns: 1fr;
    max-width: 400px;
    margin: 0 auto;
  }
  .billing-toggle-pill .btoggle-btn {
    padding: 9px 16px;
    font-size: .82rem;
  }
}

/* ── Superadmin: tables scroll horizontally ─────────────────────────── */
@media (max-width: 900px) {
  .sa-sidebar { display: none; }
  .sa-content { padding: 16px; }
}
@media (max-width: 768px) {
  .sa-stats-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
  }
  .sa-table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  .sa-table { min-width: 520px; }
}
@media (max-width: 480px) {
  .sa-stats-grid { grid-template-columns: 1fr 1fr; }
}

/* ── Activity rows: compact on small screens ─────────────────────────── */
@media (max-width: 480px) {
  .activity-row {
    flex-wrap: wrap;
    gap: 6px;
  }
  .activity-row .badge {
    margin-left: auto;
  }
  .task-row {
    flex-wrap: wrap;
  }
  .task-cta {
    display: none;
  }
}

/* ── Page header: stack on mobile ────────────────────────────────────── */
@media (max-width: 480px) {
  .page-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
  }
  .page-header .btn {
    width: 100%;
    text-align: center;
    justify-content: center;
  }
}

/* ── Onboarding card ─────────────────────────────────────────────────── */
@media (max-width: 480px) {
  .onboarding-card {
    border-radius: 8px;
  }
}

/* ── General overflow prevention ─────────────────────────────────────── */
@media (max-width: 428px) {
  .page-wrap {
    padding-left: 12px;
    padding-right: 12px;
  }
  body {
    overflow-x: hidden;
  }
}
@media (max-width: 390px) {
  .page-wrap {
    padding-left: 10px;
    padding-right: 10px;
  }
}
@media (max-width: 375px) {
  .plan-badge { font-size: .62rem; padding: 2px 5px; }
  .btn { font-size: .82rem; }
}

/* ── Cards on mobile get smaller padding ─────────────────────────────── */
@media (max-width: 480px) {
  .card {
    padding: 14px;
  }
  .dash-card-header {
    padding: 12px 14px 8px;
  }
  .dash-card-body {
    padding: 0 14px 14px;
  }
}

/* ── Header plan badge hides on very small screens ───────────────────── */
@media (max-width: 390px) {
  .header-user-name { display: none; }
  .plan-badge:not(.dropdown-header .plan-badge) { display: none; }
}

/* B3: signer drag handle and drag-over state */
.signer-drag-handle {
  display: flex;
  align-items: center;
  color: var(--muted);
  cursor: grab;
  flex-shrink: 0;
  padding: 0 2px;
  touch-action: none;
}
.signer-drag-handle:active { cursor: grabbing; }
.signer-chip.drag-over {
  border-color: var(--blue);
  background: var(--bg-soft);
}

/* ===================================================================
   MOBILE UI FIXES  (scoped to <=768px only; desktop is untouched)
   =================================================================== */
@media (max-width: 768px) {
  /* 1. App header: drop the Upgrade button (it lives in the drawer as
        "Upgrade Plan"); lighten the dark-mode toggle's visual weight. */
  .header-upgrade-btn { display: none !important; }
  .dark-mode-btn { padding: 4px; color: rgba(255,255,255,.45); }
  .dark-mode-btn svg { width: 16px; height: 16px; }

  /* 2. Nav drawer: 80% of screen width, and lift the drawer + overlay
        above the sticky warning banners so they no longer bleed through. */
  .mobile-nav-drawer { width: 80%; max-width: 360px; z-index: 10001; }
  #mobile-nav-overlay { z-index: 10000 !important; }

  /* 3. Documents toolbar: stack so the search matches the filter row width;
        make the filter tabs scroll with a right-edge fade indicator. */
  .dash-toolbar { flex-direction: column; align-items: stretch; gap: 10px; }
  .filter-tabs {
    position: relative;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .filter-tabs::-webkit-scrollbar { display: none; }
  .filter-tabs::after {
    content: '';
    position: sticky;
    right: 0;
    flex: 0 0 28px;
    align-self: stretch;
    margin-left: -28px;
    pointer-events: none;
    background: linear-gradient(to right, rgba(255,255,255,0), var(--card));
  }
  .dash-search { width: 100%; max-width: none; }

  /* 4. Contacts: stop the sideways page scroll and let the table fit. */
  .contacts-page { overflow-x: hidden; }
  .contacts-page .docs-table { min-width: 0; }

  /* 5. Plan & Billing cards: full width in light and dark mode. */
  .settings-section { width: 100%; max-width: 100%; }

  /* 6. Settings tab bar: right-edge fade to signal more tabs, and split the
        secondary links ("View Pricing" etc.) off from the real tabs with a
        clear divider so they no longer read as tabs. */
  .settings-nav { position: relative; }
  .settings-nav::after {
    content: '';
    position: sticky;
    right: 0;
    flex: 0 0 28px;
    align-self: stretch;
    margin-left: -28px;
    pointer-events: none;
    z-index: 1;
    background: linear-gradient(to right, rgba(255,255,255,0), #fff);
  }
  .settings-nav-extra {
    margin-top: 0 !important;
    padding: 0 4px 0 14px !important;
    border-top: none !important;
    border-left: 2px solid var(--border) !important;
    display: flex !important;
    align-items: center;
    flex-shrink: 0;
  }
  .settings-nav-extra a {
    display: inline-block !important;
    padding: 8px 10px !important;
    white-space: nowrap;
  }

  /* 7. 2FA option cards: stack vertically full width, raise subtitle contrast. */
  .tfa-pick-grid, .tfa-method-grid { grid-template-columns: 1fr !important; }
  .tfa-pick-sub { color: var(--muted) !important; }
  .tfa-method-card p { color: var(--muted) !important; }

  /* 9. Global: kill horizontal overflow (removes the grey edge scroll handle). */
  html, body { overflow-x: hidden; }
}

/* ── Dark mode: privacy page ──────────────────────────────────────────────── */
body.dark .privacy-page h2,
body.dark .privacy-page h1 { color: var(--text) !important; }
body.dark .privacy-page .toc a { color: var(--amber) !important; }
body.dark .privacy-page .toc-title { color: var(--muted) !important; }

/* ── Dark mode: pricing page ──────────────────────────────────────────────── */
body.dark .btoggle-btn { background: var(--card); color: var(--muted); border-color: var(--border); }
body.dark .btoggle-btn.active { background: var(--navy2); color: #fff; border-color: var(--navy2); }
body.dark .plan-price-main { color: var(--text); }
body.dark .plan-features li.feat-head { color: var(--text); }
body.dark .plan-cta-outline { color: var(--text); border-color: var(--border); }
body.dark .plan-cta-outline:hover { background: var(--bg-soft); color: var(--text); }
body.dark .comparison-wrap h2 { color: var(--text); }
body.dark .comparison-table tr:nth-child(even) td,
body.dark .comparison-table tr:nth-child(even) td:first-child { background: var(--bg-soft); }
body.dark .comparison-table .cat-row td { background: var(--bg-soft) !important; color: var(--text); }
body.dark .comparison-table td:first-child { background: var(--card); }
body.dark .agency-quantity label { color: var(--text); }
body.dark .qty-btn { background: var(--bg-soft); color: var(--text); }
body.dark .qty-display { color: var(--text); }
body.dark .qty-total strong { color: var(--text); }
body.dark .pricing-hero h1 { color: var(--text); }
body.dark .pricing-tab-btn.active { color: var(--text); }
