/* ─── LegalFrame design tokens ─── */
:root {
  /* Type */
  --font-display: "Source Serif 4", "Source Serif Pro", "Iowan Old Style", Georgia, serif;
  --font-ui: "Inter", ui-sans-serif, -apple-system, system-ui, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, monospace;

  /* Light surfaces (paper) */
  --paper:        oklch(0.985 0.004 90);     /* page */
  --paper-2:      oklch(0.975 0.005 90);     /* panel surface */
  --paper-3:      oklch(0.965 0.006 90);     /* recessed */
  --paper-edge:   oklch(0.92 0.008 90);      /* hairline */

  --ink:          oklch(0.18 0.012 250);     /* primary text */
  --ink-2:        oklch(0.32 0.012 250);     /* secondary */
  --ink-3:        oklch(0.52 0.010 250);     /* tertiary */
  --ink-4:        oklch(0.72 0.008 250);     /* placeholder */

  /* Accent — deep ink-blue */
  --accent:       #0F2A4A;
  --accent-soft:  color-mix(in oklab, var(--accent) 12%, transparent);
  --accent-line:  color-mix(in oklab, var(--accent) 30%, transparent);
  --accent-text:  color-mix(in oklab, var(--accent) 88%, var(--ink));

  /* Semantic */
  --ok:           oklch(0.55 0.08 145);
  --warn:         oklch(0.65 0.12 70);
  --danger:       oklch(0.55 0.15 25);

  /* Field highlight in document (placeholders) */
  --field-fill:    color-mix(in oklab, var(--accent) 8%, transparent);
  --field-line:    color-mix(in oklab, var(--accent) 35%, transparent);
  --field-active:  color-mix(in oklab, var(--accent) 18%, transparent);

  /* Shadows */
  --shadow-1: 0 1px 0 rgba(255,255,255,.6) inset, 0 1px 2px rgba(15,30,50,.04), 0 1px 1px rgba(15,30,50,.03);
  --shadow-2: 0 1px 0 rgba(255,255,255,.5) inset, 0 8px 24px -12px rgba(15,30,50,.18), 0 2px 6px rgba(15,30,50,.06);
  --shadow-doc: 0 1px 0 rgba(255,255,255,.6) inset, 0 24px 56px -28px rgba(15,30,50,.24), 0 6px 16px -8px rgba(15,30,50,.10);

  /* Radii */
  --r-1: 6px;
  --r-2: 10px;
  --r-3: 14px;
  --r-4: 20px;

  /* Spacing scale (4px base) */
  --s-1: 4px; --s-2: 8px; --s-3: 12px; --s-4: 16px; --s-5: 20px;
  --s-6: 24px; --s-7: 32px; --s-8: 40px; --s-9: 56px; --s-10: 72px;
}

/* Arabic / Devanagari / multilingual stacks (customized-form pages set .legal-frame-i18n on <html>) */
html.legal-frame-i18n {
  --font-ui: "Inter", "Noto Naskh Arabic", "Noto Sans Devanagari", "Noto Sans", ui-sans-serif, system-ui, sans-serif;
  --font-display: "Source Serif 4", "Noto Serif Arabic", "Noto Serif Devanagari", Georgia, serif;
}

/* Dark — "private chambers" */
:root[data-theme="dark"] {
  --paper:        oklch(0.16 0.008 250);
  --paper-2:      oklch(0.20 0.010 250);
  --paper-3:      oklch(0.235 0.012 250);
  --paper-edge:   oklch(0.30 0.012 250);

  --ink:          oklch(0.96 0.005 90);
  --ink-2:        oklch(0.82 0.008 90);
  --ink-3:        oklch(0.66 0.010 90);
  --ink-4:        oklch(0.46 0.012 90);

  --accent-soft:  color-mix(in oklab, var(--accent) 22%, transparent);
  --accent-line:  color-mix(in oklab, var(--accent) 50%, transparent);
  --accent-text:  color-mix(in oklab, var(--accent) 70%, var(--ink));

  --field-fill:    color-mix(in oklab, var(--accent) 22%, transparent);
  --field-line:    color-mix(in oklab, var(--accent) 55%, transparent);
  --field-active:  color-mix(in oklab, var(--accent) 35%, transparent);

  --shadow-1: 0 1px 0 rgba(255,255,255,.04) inset, 0 1px 2px rgba(0,0,0,.4);
  --shadow-2: 0 1px 0 rgba(255,255,255,.04) inset, 0 8px 24px -12px rgba(0,0,0,.5), 0 2px 6px rgba(0,0,0,.25);
  --shadow-doc: 0 1px 0 rgba(255,255,255,.04) inset, 0 24px 56px -28px rgba(0,0,0,.65), 0 6px 16px -8px rgba(0,0,0,.4);
}

/* Reset-ish */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  font-family: var(--font-ui);
  font-size: 14px;
  line-height: 1.45;
  color: var(--ink);
  background: var(--paper);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  font-feature-settings: "ss01", "cv11";
}
button { font: inherit; color: inherit; }
input, textarea, select { font: inherit; color: inherit; }
::selection { background: var(--accent-soft); color: var(--accent-text); }

/* ─── App shell ─── */
.app {
  display: grid;
  grid-template-rows: auto 1fr;
  height: 100vh;
  width: 100vw;
  background: var(--paper);
}

/* Wraps topbar + optional document-text strip (customized forms). */
.topbar-stack {
  position: relative;
  z-index: 5;
  min-width: 0;
  border-bottom: 1px solid var(--paper-edge);
  background: var(--paper);
}
.topbar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  padding: 0 var(--s-5);
  border-bottom: none;
  background: var(--paper);
  min-width: 0;
  min-height: 52px;
}
.topbar-sub.doc-text-strip {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 6px var(--s-5) 8px;
  border-top: 1px solid var(--paper-edge);
  background: var(--paper-2);
  font-family: var(--font-ui);
}
.doc-text-strip .dts-drag {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  font-weight: 600;
  color: var(--accent-text);
  padding: 7px 12px;
  border: 1px dashed var(--accent-line);
  border-radius: 8px;
  cursor: grab;
  user-select: none;
}
.doc-text-strip .dts-drag:active {
  cursor: grabbing;
}
.doc-text-strip .dts-drag svg {
  flex-shrink: 0;
}
.topbar-left { display:flex; align-items:center; gap: var(--s-4); min-width: 0; overflow: hidden; }
.topbar-form-title {
  font-family: var(--font-display);
  font-size: 16px;
  font-weight: 600;
  color: var(--ink);
  letter-spacing: -0.02em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}
.topbar-right { display:flex; align-items:center; gap: var(--s-3); justify-content:flex-end; min-width: 0; }

.brand {
  display:flex; align-items:center; gap: var(--s-2);
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 18px;
  letter-spacing: -0.01em;
  color: var(--ink);
  white-space: nowrap;
  flex-shrink: 0;
}
.brand-mark {
  width: 22px; height: 22px;
  display:grid; place-items:center;
  background: var(--accent);
  color: #fff;
  border-radius: 5px;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 13px;
  line-height: 1;
}
.brand small {
  font-family: var(--font-ui);
  font-size: 11px;
  color: var(--ink-3);
  font-weight: 500;
  letter-spacing: 0.02em;
  margin-left: 4px;
  border-left: 1px solid var(--paper-edge);
  padding-left: var(--s-3);
  white-space: nowrap;
}
@media (max-width: 1100px) {
  .brand small { display: none; }
}

.crumbs {
  display: flex; align-items: center; gap: var(--s-2);
  font-size: 13px;
  color: var(--ink-3);
  white-space: nowrap;
  min-width: 0;
  overflow: hidden;
}
.crumbs > span { white-space: nowrap; }
.crumbs .doc-name {
  color: var(--ink);
  font-family: var(--font-display);
  font-size: 15px;
  font-weight: 500;
  white-space: nowrap;
}
.crumbs .sep { color: var(--ink-4); }
.crumbs .status {
  margin-left: var(--s-3);
  display:inline-flex; align-items:center; gap: 6px;
  padding: 3px 8px;
  background: var(--paper-3);
  border: 1px solid var(--paper-edge);
  border-radius: 999px;
  font-size: 11px;
  color: var(--ink-2);
  white-space: nowrap;
  flex-shrink: 0;
}
@media (max-width: 1280px) {
  .crumbs > span:not(.doc-name):not(.status):not(.sep) { display: none; }
  .crumbs > .sep { display: none; }
}
@media (max-width: 1080px) {
  .crumbs { display: none; }
}
.crumbs .status .dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--ok);
}

/* Stage tabs (admin / client / done) */
.stage-tabs {
  display: flex;
  background: var(--paper-3);
  padding: 3px;
  border-radius: 999px;
  border: 1px solid var(--paper-edge);
  font-size: 12px;
  position: relative;
}
.stage-tabs button {
  appearance: none;
  border: 0;
  background: transparent;
  padding: 5px 14px;
  border-radius: 999px;
  cursor: pointer;
  color: var(--ink-3);
  font-weight: 500;
  display: inline-flex; align-items: center; gap: 6px;
  transition: color .15s;
}
.stage-tabs button[data-active="1"] {
  background: var(--paper);
  color: var(--ink);
  box-shadow: var(--shadow-1);
}
.stage-tabs .num {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--ink-4);
}
.stage-tabs button[data-active="1"] .num { color: var(--accent); }

/* Buttons */
.btn {
  appearance: none; border: 0; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
  gap: 6px;
  height: 32px; padding: 0 14px;
  font-size: 13px; font-weight: 500;
  border-radius: 8px;
  transition: background .15s, transform .1s, box-shadow .15s;
  white-space: nowrap;
}
.btn:active { transform: translateY(0.5px); }
.btn-primary {
  background: var(--accent);
  color: #fff;
  box-shadow: var(--shadow-1), 0 1px 0 color-mix(in oklab, var(--accent) 80%, black) inset 0 -1px;
}
.btn-primary:hover { background: color-mix(in oklab, var(--accent) 88%, black); }
.btn-secondary {
  background: var(--paper-2);
  color: var(--ink);
  box-shadow: var(--shadow-1);
  border: 1px solid var(--paper-edge);
}
.btn-secondary:hover { background: var(--paper-3); }
.btn-ghost {
  background: transparent; color: var(--ink-2);
}
.btn-ghost:hover { background: var(--paper-3); color: var(--ink); }

.btn-sm { height: 26px; padding: 0 10px; font-size: 12px; border-radius: 6px; }
.btn-lg { height: 40px; padding: 0 18px; font-size: 14px; border-radius: 10px; }

.icon { width: 14px; height: 14px; flex: 0 0 auto; }
.icon-sm { width: 12px; height: 12px; }
.icon-lg { width: 16px; height: 16px; }

/* ─── Stage container ─── */
.stage {
  position: relative;
  overflow: hidden;
  background: var(--paper);
  /* Let the 1fr row in #root shrink so descendants get a real height (iframe / nested grid). */
  min-height: 0;
}
.stage > section {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  min-height: 0;
  opacity: 0;
  pointer-events: none;
  transition: opacity .35s ease;
}
.stage > section[data-active="1"] {
  opacity: 1;
  pointer-events: auto;
}

/* Soft scrollbars */
.scroll {
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--paper-edge) transparent;
}
.scroll::-webkit-scrollbar { width: 10px; }
.scroll::-webkit-scrollbar-track { background: transparent; }
.scroll::-webkit-scrollbar-thumb {
  background: var(--paper-edge);
  border-radius: 5px;
  border: 2px solid transparent;
  background-clip: content-box;
}
.scroll::-webkit-scrollbar-thumb:hover {
  background: color-mix(in oklab, var(--paper-edge) 70%, var(--ink-3));
  background-clip: content-box;
  border: 2px solid transparent;
}

/* Section labels */
.eyebrow {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-3);
}
