/* =========================================================
   Clearpath Intake — design tokens
   A freelance studio's intake tool. Ink + pine palette, a
   serif display face paired with a plain system sans, and a
   ledger-tab motif on status cards (a nod to paper intake forms).
   ========================================================= */

:root {
  --paper: #FBFAF7;
  --surface: #FFFFFF;
  --ink: #1B1E1B;
  --ink-soft: #5B6058;
  --line: #E3E0D6;
  --line-strong: #CFCBBE;

  --brand: #2D5C4F;
  --brand-ink: #1E3F36;
  --brand-soft: #E7EFEA;

  --accent: #C8743A;
  --accent-soft: #F6E6D8;

  --amber: #9C6B00;
  --amber-soft: #FBEFD2;
  --blue: #2854A6;
  --blue-soft: #E4ECFB;
  --green: #2D6A4F;
  --green-soft: #E1F0E7;
  --red: #A33A2C;
  --red-soft: #FBE5DF;
  --gray-soft: #ECEAE3;

  --font-display: Georgia, 'Iowan Old Style', 'Palatino Linotype', serif;
  --font-body: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 1px 2px rgba(27, 30, 27, 0.04), 0 6px 16px rgba(27, 30, 27, 0.06);
  --sidebar-w: 232px;
}

[data-theme="dark"] {
  --paper: #15171A;
  --surface: #1C1F22;
  --ink: #ECEAE3;
  --ink-soft: #9CA39B;
  --line: #2B2F33;
  --line-strong: #3A3F44;

  --brand: #5AA98E;
  --brand-ink: #BFE6D5;
  --brand-soft: #1E2B26;

  --accent: #E0935B;
  --accent-soft: #2E2520;

  --amber: #D7A93D;
  --amber-soft: #2E2710;
  --blue: #7FA6E6;
  --blue-soft: #1B2433;
  --green: #6FBE96;
  --green-soft: #16261D;
  --red: #E0796A;
  --red-soft: #2E1B17;
  --gray-soft: #24262A;

  --shadow: 0 1px 2px rgba(0,0,0,0.3), 0 8px 20px rgba(0,0,0,0.35);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }

body {
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 14.5px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

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

h1, h2, h3, h4 {
  font-family: var(--font-display);
  font-weight: 600;
  letter-spacing: 0.1px;
  margin: 0 0 4px;
  color: var(--ink);
}

h1 { font-size: 26px; }
h2 { font-size: 20px; }
h3 { font-size: 16px; }

p { margin: 0 0 12px; }
small, .muted { color: var(--ink-soft); }

code, .mono { font-family: var(--font-mono); font-size: 0.92em; }

:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
}

/* ---------- App shell ---------- */

.app-shell {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--line);
  padding: 20px 14px;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.brand-mark {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 8px 20px;
}

.brand-mark .swatch {
  width: 26px; height: 26px;
  border-radius: 7px;
  background: linear-gradient(155deg, var(--brand), var(--accent));
  flex-shrink: 0;
}

.brand-mark .name {
  font-family: var(--font-display);
  font-size: 16.5px;
  font-weight: 700;
  color: var(--ink);
}

.nav-group { margin-bottom: 18px; }
.nav-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink-soft);
  padding: 0 10px;
  margin-bottom: 6px;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: var(--radius-sm);
  color: var(--ink);
  font-size: 14px;
  font-weight: 500;
}
.nav-link:hover { background: var(--gray-soft); text-decoration: none; }
.nav-link.active { background: var(--brand-soft); color: var(--brand-ink); }
.nav-link .ico { width: 18px; text-align: center; opacity: 0.85; }

.sidebar-foot { margin-top: auto; padding-top: 14px; border-top: 1px solid var(--line); }

.main-col { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 28px;
  border-bottom: 1px solid var(--line);
  background: var(--paper);
  position: sticky;
  top: 0;
  z-index: 5;
}

.search-box {
  flex: 1;
  max-width: 420px;
}
.search-box input {
  width: 100%;
}

.topbar-actions { display: flex; align-items: center; gap: 10px; }

.theme-toggle {
  width: 34px; height: 34px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--surface);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  font-size: 15px;
}

.content {
  padding: 28px;
  max-width: 1180px;
  width: 100%;
}

.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

/* ---------- Buttons & form controls ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line-strong);
  background: var(--surface);
  color: var(--ink);
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  line-height: 1.2;
}
.btn:hover { background: var(--gray-soft); text-decoration: none; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-ink); }
.btn-danger { background: var(--red); border-color: var(--red); color: #fff; }
.btn-danger:hover { filter: brightness(0.92); }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-ghost:hover { background: var(--gray-soft); }
.btn-sm { padding: 6px 11px; font-size: 12.5px; }
.btn-block { width: 100%; justify-content: center; }
.btn[disabled] { opacity: 0.55; cursor: not-allowed; }

input, select, textarea {
  font-family: inherit;
  font-size: 14px;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  padding: 9px 11px;
  width: 100%;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--brand);
}
textarea { resize: vertical; min-height: 80px; }

label { font-size: 13px; font-weight: 600; margin-bottom: 6px; display: block; }
.field { margin-bottom: 16px; }
.field .hint { font-size: 12px; color: var(--ink-soft); margin-top: 4px; }
.field .error { font-size: 12px; color: var(--red); margin-top: 4px; }
.required-mark { color: var(--red); margin-left: 2px; }

.checkbox-row { display: flex; align-items: center; gap: 8px; }
.checkbox-row input { width: auto; }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px 20px; }
@media (max-width: 720px) { .form-grid { grid-template-columns: 1fr; } }

/* ---------- Cards / tables / badges ---------- */

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.card-pad { padding: 20px 22px; }
.card-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px; border-bottom: 1px solid var(--line);
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
.stat-card {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px 18px 16px;
  overflow: hidden;
}
.stat-card::before {
  content: "";
  position: absolute; top: 0; left: 0; right: 0; height: 4px;
  background: var(--tab-color, var(--brand));
}
.stat-card .label { font-size: 12px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--ink-soft); }
.stat-card .value { font-family: var(--font-display); font-size: 32px; margin-top: 6px; }

table { width: 100%; border-collapse: collapse; }
thead th {
  text-align: left;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--ink-soft);
  font-weight: 600;
  padding: 10px 16px;
  border-bottom: 1px solid var(--line);
}
tbody td { padding: 13px 16px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tbody tr:hover { background: var(--gray-soft); }
tbody tr:last-child td { border-bottom: none; }
.table-wrap { overflow-x: auto; }

.badge {
  display: inline-flex; align-items: center;
  font-size: 11.5px; font-weight: 700;
  padding: 3px 9px; border-radius: 999px;
  text-transform: uppercase; letter-spacing: 0.03em;
}
.badge-gray { background: var(--gray-soft); color: var(--ink-soft); }
.badge-amber { background: var(--amber-soft); color: var(--amber); }
.badge-blue { background: var(--blue-soft); color: var(--blue); }
.badge-green { background: var(--green-soft); color: var(--green); }
.badge-red { background: var(--red-soft); color: var(--red); }

.empty-state {
  text-align: center; padding: 50px 20px; color: var(--ink-soft);
}
.empty-state h3 { color: var(--ink); margin-bottom: 6px; }

/* ---------- Flash messages ---------- */

.flash-stack { position: fixed; top: 16px; right: 16px; z-index: 50; display: flex; flex-direction: column; gap: 8px; max-width: 340px; }
.flash {
  padding: 12px 14px; border-radius: var(--radius-sm); font-size: 13.5px;
  box-shadow: var(--shadow); border: 1px solid var(--line);
  background: var(--surface);
}
.flash-success { border-color: var(--green); color: var(--green); }
.flash-error { border-color: var(--red); color: var(--red); }

/* ---------- Pagination ---------- */

.pagination { display: flex; gap: 6px; align-items: center; margin-top: 16px; }
.pagination a, .pagination span {
  padding: 6px 11px; border-radius: var(--radius-sm); border: 1px solid var(--line);
  font-size: 13px; color: var(--ink);
}
.pagination .current { background: var(--brand); border-color: var(--brand); color: #fff; }

/* ---------- Modal (confirm dialogs) ---------- */

.modal-overlay {
  position: fixed; inset: 0; background: rgba(20, 22, 19, 0.45);
  display: none; align-items: center; justify-content: center; z-index: 100; padding: 20px;
}
.modal-overlay.open { display: flex; }
.modal-box {
  background: var(--surface); border-radius: var(--radius); padding: 22px;
  max-width: 380px; width: 100%; box-shadow: var(--shadow);
}
.modal-box .actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 18px; }

/* ---------- Template builder ---------- */

.builder-layout { display: grid; grid-template-columns: 1fr 260px; gap: 20px; align-items: start; }
@media (max-width: 900px) { .builder-layout { grid-template-columns: 1fr; } }

.section-card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  margin-bottom: 14px; cursor: grab;
}
.section-card.dragging { opacity: 0.5; }
.section-card-head {
  display: flex; align-items: center; gap: 10px; padding: 12px 16px;
  border-bottom: 1px solid var(--line); background: var(--brand-soft);
  border-radius: var(--radius) var(--radius) 0 0;
}
.drag-handle { cursor: grab; color: var(--ink-soft); font-size: 16px; user-select: none; }
.section-card-head input { background: transparent; border: none; font-weight: 700; font-size: 15px; padding: 4px 6px; }
.section-card-head input:focus { background: var(--surface); border: 1px solid var(--line-strong); }
.section-body { padding: 12px 16px; }

.question-row {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 11px 12px; border: 1px solid var(--line); border-radius: var(--radius-sm);
  margin-bottom: 8px; background: var(--paper); cursor: grab;
}
.question-row.dragging { opacity: 0.45; }
.question-row .qbody { flex: 1; min-width: 0; }
.question-row .qtitle { font-weight: 600; }
.question-row .qmeta { font-size: 12px; color: var(--ink-soft); margin-top: 2px; }
.question-row .qactions { display: flex; gap: 4px; flex-shrink: 0; }

.type-pill {
  display: inline-block; font-size: 11px; padding: 1px 7px; border-radius: 999px;
  background: var(--gray-soft); color: var(--ink-soft); margin-left: 6px;
}

.sidebar-help { font-size: 13px; color: var(--ink-soft); }
.sidebar-help li { margin-bottom: 6px; }

/* ---------- Public client form ---------- */

.public-shell { background: var(--paper); min-height: 100vh; }
.public-header {
  border-bottom: 1px solid var(--line); padding: 18px 24px; background: var(--surface);
  display: flex; align-items: center; justify-content: space-between;
}
.public-body {
  display: flex; max-width: 980px; margin: 0 auto; gap: 28px; padding: 28px 20px 80px;
}
.public-nav { width: 220px; flex-shrink: 0; }
.public-nav .step {
  display: block; padding: 9px 10px; border-radius: var(--radius-sm); font-size: 13.5px;
  color: var(--ink-soft); margin-bottom: 2px;
}
.public-nav .step.active { background: var(--brand-soft); color: var(--brand-ink); font-weight: 600; }
.public-nav .step.complete::after { content: " ✓"; color: var(--green); }

.progress-wrap { padding: 14px 0 6px; }
.progress-track {
  height: 8px; border-radius: 999px; background: var(--gray-soft); overflow: hidden;
  background-image: repeating-linear-gradient(45deg, transparent, transparent 6px, rgba(0,0,0,0.03) 6px, rgba(0,0,0,0.03) 12px);
}
.progress-fill { height: 100%; background: linear-gradient(90deg, var(--brand), var(--accent)); border-radius: 999px; transition: width 0.3s ease; }
.progress-label { display: flex; justify-content: space-between; font-size: 12.5px; color: var(--ink-soft); margin-top: 6px; }

.autosave-indicator { font-size: 12px; color: var(--ink-soft); display: flex; align-items: center; gap: 6px; }
.autosave-indicator .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--green); }

.public-section { margin-bottom: 36px; }
.public-section h2 { border-bottom: 1px solid var(--line); padding-bottom: 10px; margin-bottom: 18px; }

.question-block { margin-bottom: 20px; }
.question-block .qlabel { font-weight: 600; margin-bottom: 6px; display: block; }
.option-group { display: flex; flex-direction: column; gap: 8px; }
.option-group label { font-weight: 400; display: flex; align-items: center; gap: 8px; }
.option-group input { width: auto; }

.file-drop {
  border: 1.5px dashed var(--line-strong); border-radius: var(--radius); padding: 18px;
  text-align: center; color: var(--ink-soft); font-size: 13px; background: var(--surface);
}
.file-drop.over { border-color: var(--brand); background: var(--brand-soft); }
.file-list { margin-top: 8px; font-size: 13px; }

.thanks-box, .invalid-box {
  max-width: 480px; margin: 80px auto; text-align: center; padding: 40px 30px;
}

/* ---------- Misc ---------- */

.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 16px; }
.toolbar .spacer { flex: 1; }
.divider { height: 1px; background: var(--line); margin: 20px 0; }
.notes-list { display: flex; flex-direction: column; gap: 10px; }
.note-item { padding: 10px 12px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--paper); font-size: 13.5px; }
.note-item .meta { font-size: 11.5px; color: var(--ink-soft); margin-top: 4px; }

.unsaved-banner {
  display: none; background: var(--amber-soft); color: var(--amber); border: 1px solid var(--amber);
  border-radius: var(--radius-sm); padding: 8px 12px; font-size: 13px; margin-bottom: 14px;
}
.unsaved-banner.show { display: block; }

.copy-row { display: flex; gap: 8px; align-items: center; }
.copy-row input { font-family: var(--font-mono); font-size: 12.5px; }

@media (max-width: 860px) {
  .sidebar { display: none; }
  .content { padding: 18px; }
  .public-body { flex-direction: column; }
  .public-nav { width: 100%; }
}
