/* styles.css — Kinso design tokens, ported from Kinso-App `apps/web/src/styles/globals.css`
 * (direction "Brief") the same way KinsoCF's packages/app/src/styles/tokens.css does it.
 *
 * PARITY, NOT INVENTION. Every value below is Kinso-App's. The identity-carrying decision
 * is the first one: the page is a WARM off-white, not white and not a cool grey. Green is
 * RATIONED — primary action, status chips, focus rings, active states, nowhere else.
 */

:root {
  color-scheme: light;

  --background: hsl(45 33% 97.5%);
  --foreground: hsl(60 6% 18%);
  --card: hsl(0 0% 100%);
  --muted: hsl(60 6% 94%);
  --muted-foreground: hsl(60 4% 42%);

  --primary: hsl(165 50% 32%);
  --primary-foreground: hsl(0 0% 100%);
  --primary-deep: hsl(165 30% 24%);
  --primary-hover: hsl(165 50% 25%);
  --primary-tint: hsl(165 35% 92%);
  --primary-tint-foreground: hsl(165 30% 24%);

  --secondary: hsl(60 8% 95%);
  --secondary-hover: hsl(60 8% 88%);
  --border: hsl(45 10% 88%);
  --input: hsl(45 10% 88%);
  --ring: hsl(165 50% 32%);

  --destructive: hsl(12 70% 50%);
  --button-destructive: hsl(12 60% 95%);
  --button-destructive-foreground: hsl(12 65% 35%);
  --success: hsl(155 45% 42%);
  --warning: hsl(75 65% 55%);
  --warning-foreground: hsl(60 30% 15%);
  --danger: hsl(25 75% 50%);

  --radius: 0.5rem;
  --shadow-1: 0 1px 0 hsl(60 6% 88% / 0.6);
  --shadow-2: 0 1px 2px hsl(60 6% 18% / 0.04), 0 8px 24px -12px hsl(60 6% 18% / 0.08);
  --shadow-3: 0 4px 12px hsl(60 6% 18% / 0.08), 0 24px 48px -16px hsl(60 6% 18% / 0.16);

  /* WP-0.4 type roles — the COMPACT (lawyer workspace) values. 13px is the floor. */
  --type-title-page: 1.5rem;
  --type-title-section: 0.9375rem;
  --type-body: 0.875rem;
  --type-meta: 0.8125rem;
  --type-caption: 0.8125rem;
  --touch-target: 2.25rem;

  --font-sans: Inter, system-ui, -apple-system, sans-serif;
  --font-serif: "Source Serif 4", Georgia, "Times New Roman", serif;
  --font-mono: "JetBrains Mono", ui-monospace, SFMono-Regular, monospace;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--background);
  color: var(--foreground);
  font-family: var(--font-sans);
  font-size: var(--type-body);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--ring); outline-offset: 2px; border-radius: 3px; }

/* ── app shell ─────────────────────────────────────────────────────────────── */

.app { display: grid; grid-template-rows: auto 1fr; height: 100vh; }

.topbar {
  display: flex; align-items: center; gap: 16px;
  padding: 0 16px; height: 52px;
  background: var(--background);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: baseline; gap: 8px; font-weight: 650; letter-spacing: -0.01em; }
.brand .mark { color: var(--primary); }
.brand .sub { color: var(--muted-foreground); font-weight: 450; font-size: var(--type-meta); }
.doc-title {
  font-size: var(--type-body); font-weight: 550;
  border: 1px solid transparent; background: transparent;
  padding: 5px 8px; border-radius: 6px; min-width: 220px;
}
.doc-title:hover { border-color: var(--border); background: var(--card); }
.spacer { flex: 1; }

.panes {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  min-height: 0;
}
.pane { min-height: 0; display: flex; flex-direction: column; overflow: hidden; }
.pane + .pane { border-left: 1px solid var(--border); }

.pane-head {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 14px; border-bottom: 1px solid var(--border);
  background: var(--background);
}
.pane-title {
  font-size: var(--type-caption); font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.07em;
  color: var(--muted-foreground);
}
.pane-body { overflow: auto; flex: 1; min-height: 0; }

/* ── controls ──────────────────────────────────────────────────────────────── */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: var(--touch-target); padding: 0 12px;
  border-radius: var(--radius); border: 1px solid var(--border);
  background: var(--card); cursor: pointer;
  font-size: var(--type-meta); font-weight: 500;
  transition: background-color .12s ease, border-color .12s ease;
}
.btn:hover { background: var(--secondary-hover); }
.btn-primary { background: var(--primary); color: var(--primary-foreground); border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn-sm { height: 28px; padding: 0 9px; font-size: var(--type-caption); }
.btn-quiet { border-color: transparent; background: transparent; }
.btn-quiet:hover { background: var(--secondary); }
.btn-danger { color: var(--button-destructive-foreground); }
.btn-danger:hover { background: var(--button-destructive); }

.search {
  width: 100%; height: 32px; padding: 0 10px;
  border: 1px solid var(--input); border-radius: var(--radius);
  background: var(--card);
}
.search::placeholder { color: var(--muted-foreground); }

textarea.editor {
  width: 100%; min-height: 220px; padding: 10px 12px;
  border: 1px solid var(--input); border-radius: var(--radius);
  background: var(--card); font-family: var(--font-mono);
  font-size: var(--type-meta); line-height: 1.6; resize: vertical;
}

/* ── clause tree ───────────────────────────────────────────────────────────── */

.tree { padding: 6px 0 24px; }
.tree-section > .row { font-weight: 600; }
.row {
  display: flex; align-items: flex-start; gap: 8px;
  padding: 6px 14px; cursor: pointer; font-size: var(--type-meta);
  border-left: 2px solid transparent;
}
.row:hover { background: var(--secondary); }
.row.active { background: var(--primary-tint); border-left-color: var(--primary); color: var(--primary-tint-foreground); }
.row .twist { width: 12px; color: var(--muted-foreground); flex: none; margin-top: 1px; }
.row .label { flex: 1; min-width: 0; }
.row.depth-1 { padding-left: 28px; }
.row.depth-2 { padding-left: 46px; }
.row .count { color: var(--muted-foreground); font-size: var(--type-caption); flex: none; }

.tick {
  width: 15px; height: 15px; flex: none; margin-top: 1px;
  border: 1.5px solid var(--muted-foreground); border-radius: 3px;
  background: var(--card); display: grid; place-items: center;
  color: transparent; font-size: 10px; line-height: 1;
}
.tick.radio { border-radius: 50%; }
.tick.on { background: var(--primary); border-color: var(--primary); color: var(--primary-foreground); }

.group-hint {
  font-size: var(--type-caption); color: var(--muted-foreground);
  padding: 2px 14px 6px 46px;
}

.empty {
  padding: 28px 20px; text-align: center;
  color: var(--muted-foreground); font-size: var(--type-meta);
}
.empty strong { display: block; color: var(--foreground); margin-bottom: 4px; font-weight: 550; }

/* ── document ──────────────────────────────────────────────────────────────── */

.doc-scroll { padding: 24px; display: flex; justify-content: center; }
.sheet {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow-2); width: 100%; max-width: 760px; padding: 44px 56px 64px;
  font-family: var(--font-serif); font-size: 15px; line-height: 1.65;
}
.sheet h1 {
  font-size: 17px; text-transform: uppercase; letter-spacing: 0.06em;
  text-align: center; font-weight: 600; margin: 0 0 28px;
}
.sheet .parties { text-align: center; margin-bottom: 30px; color: var(--foreground); }
.sheet .parties .and { color: var(--muted-foreground); margin: 6px 0; }
.sheet h2 {
  font-family: var(--font-sans); font-size: var(--type-title-section);
  text-transform: uppercase; letter-spacing: 0.06em;
  margin: 30px 0 10px; padding-bottom: 5px; border-bottom: 1px solid var(--border);
}
.sheet h2 .n { color: var(--muted-foreground); margin-right: 8px; }

.dc-p { display: grid; grid-template-columns: 58px 1fr; gap: 8px; margin: 0 0 10px; }
.dc-p.dc-l2 { padding-left: 34px; }
.dc-p.dc-l3 { padding-left: 68px; }
.dc-num { color: var(--muted-foreground); font-family: var(--font-sans); font-size: 12.5px; padding-top: 3px; font-variant-numeric: tabular-nums; }
.dc-blank {
  background: var(--muted); border-bottom: 1px solid var(--muted-foreground);
  padding: 0 3px; border-radius: 2px; cursor: pointer;
  font-family: var(--font-sans); font-size: 13.5px; color: var(--muted-foreground);
}
.dc-blank:hover { background: var(--primary-tint); color: var(--primary-tint-foreground); }
.dc-blank.target { background: var(--primary); color: var(--primary-foreground); border-color: var(--primary); }
.dc-unknown { background: var(--button-destructive); color: var(--button-destructive-foreground); padding: 0 3px; border-radius: 2px; }

.clause-wrap { position: relative; }
.clause-wrap .clause-tools {
  position: absolute; right: -44px; top: 0; display: flex; flex-direction: column; gap: 3px;
  opacity: 0; transition: opacity .12s ease;
}
.clause-wrap:hover .clause-tools { opacity: 1; }
.badge {
  display: inline-block; font-family: var(--font-sans); font-size: 11px; font-weight: 600;
  letter-spacing: 0.04em; text-transform: uppercase;
  padding: 1px 6px; border-radius: 3px; vertical-align: 2px; margin-left: 8px;
}
.badge.edited { background: var(--primary-tint); color: var(--primary-tint-foreground); }
.badge.custom { background: hsl(215 30% 92%); color: hsl(215 30% 32%); }

/* ── right rail ────────────────────────────────────────────────────────────── */

.section-block { border-bottom: 1px solid var(--border); }
.section-block h3 {
  margin: 0; padding: 10px 14px 6px;
  font-size: var(--type-caption); font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.07em; color: var(--muted-foreground);
}
.field-row { display: grid; gap: 4px; padding: 6px 14px 10px; }
.field-row label { font-size: var(--type-caption); color: var(--muted-foreground); }
.field-row input, .field-row select {
  height: 30px; padding: 0 8px; border: 1px solid var(--input);
  border-radius: 6px; background: var(--card); width: 100%;
}
.field-row.done label { color: var(--success); }

.problem {
  display: flex; gap: 8px; padding: 9px 14px; font-size: var(--type-meta);
  border-bottom: 1px solid var(--border);
}
.problem .dot { width: 6px; height: 6px; border-radius: 50%; flex: none; margin-top: 6px; }
.problem.error .dot { background: var(--destructive); }
.problem.warning .dot { background: var(--danger); }
.problem .msg { flex: 1; }
.problem .fix { color: var(--muted-foreground); font-size: var(--type-caption); }

.meter { padding: 10px 14px; border-bottom: 1px solid var(--border); }
.meter .bar { height: 5px; border-radius: 3px; background: var(--muted); overflow: hidden; margin-top: 6px; }
.meter .bar > span { display: block; height: 100%; background: var(--primary); border-radius: 3px; transition: width .2s ease; }
.meter .line { display: flex; justify-content: space-between; font-size: var(--type-caption); color: var(--muted-foreground); }

/* ── commentary ────────────────────────────────────────────────────────────── */

.commentary {
  padding: 12px 14px; font-size: var(--type-meta); line-height: 1.55;
  color: var(--foreground); background: var(--card);
  border-top: 1px solid var(--border); max-height: 42%; overflow: auto;
}
.commentary h4 { margin: 0 0 6px; font-size: var(--type-meta); font-weight: 600; }
.commentary p { margin: 0 0 8px; }
.commentary .src { color: var(--muted-foreground); font-size: var(--type-caption); }

/* ── modal ─────────────────────────────────────────────────────────────────── */

.scrim {
  position: fixed; inset: 0; background: hsl(60 6% 18% / 0.32);
  display: grid; place-items: center; padding: 24px; z-index: 40;
}
.modal {
  background: var(--card); border-radius: 10px; box-shadow: var(--shadow-3);
  width: min(860px, 100%); max-height: 88vh; display: flex; flex-direction: column;
  border: 1px solid var(--border);
}
.modal header {
  padding: 14px 18px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 12px;
}
.modal header h2 { margin: 0; font-size: var(--type-title-section); font-weight: 600; }
.modal .body { padding: 16px 18px; overflow: auto; display: grid; gap: 14px; }
.modal footer {
  padding: 12px 18px; border-top: 1px solid var(--border);
  display: flex; align-items: center; gap: 10px;
}
.hint { font-size: var(--type-caption); color: var(--muted-foreground); }
.hint code {
  font-family: var(--font-mono); background: var(--muted);
  padding: 1px 4px; border-radius: 3px; font-size: 11.5px;
}
.chips { display: flex; flex-wrap: wrap; gap: 5px; }
.chip {
  font-family: var(--font-mono); font-size: 11.5px;
  background: var(--muted); border: 1px solid var(--border);
  padding: 2px 6px; border-radius: 4px; cursor: pointer;
}
.chip:hover { background: var(--primary-tint); border-color: var(--primary); }
.validation { display: grid; gap: 5px; }
.validation .err {
  font-size: var(--type-caption); color: var(--button-destructive-foreground);
  background: var(--button-destructive); padding: 6px 9px; border-radius: 5px;
}
.validation .ok { font-size: var(--type-caption); color: var(--success); }
.tabs { display: flex; gap: 2px; }
.tab {
  padding: 5px 11px; border-radius: 6px; cursor: pointer;
  font-size: var(--type-meta); color: var(--muted-foreground);
}
.tab.on { background: var(--primary-tint); color: var(--primary-tint-foreground); font-weight: 550; }

/* A clause the drafter could unblock, shown rather than hidden. */
.row.blocked { cursor: default; }
.row.blocked .label { color: var(--muted-foreground); }
.row.blocked .tick { opacity: 0.4; }
.row .gate {
  display: block; font-size: var(--type-caption);
  color: var(--muted-foreground); margin-top: 1px;
}

/* ── boot, auth wall, account ───────────────────────────────────────────────── */

.boot {
  display: grid; place-items: center; height: 100vh;
  color: var(--muted-foreground); font-size: var(--type-meta);
}
.boot-error { gap: 6px; padding: 24px; text-align: center; max-width: 46ch; margin: 0 auto; }
.boot-error strong { color: var(--foreground); font-size: var(--type-title-section); }

.wall { display: grid; place-items: center; height: 100vh; padding: 24px; }
.wall-card {
  background: var(--card); border: 1px solid var(--border); border-radius: 10px;
  box-shadow: var(--shadow-2); padding: 36px 40px; text-align: center;
  max-width: 400px; display: grid; gap: 10px; justify-items: center;
}
.wall-card h1 { margin: 6px 0 0; font-size: var(--type-title-page); font-weight: 600; }
.wall-card p { margin: 0; color: var(--muted-foreground); font-size: var(--type-meta); }
.wall-card .btn { margin-top: 8px; min-width: 160px; }
.wall-note { font-size: var(--type-caption) !important; }

.account { display: flex; align-items: center; gap: 8px; }
.account img { border-radius: 50%; display: block; }
.account .who { font-size: var(--type-caption); color: var(--muted-foreground); max-width: 22ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip-dev {
  font-family: var(--font-mono); font-size: 10.5px; letter-spacing: .06em;
  background: var(--muted); color: var(--muted-foreground);
  padding: 2px 7px; border-radius: 4px; border: 1px solid var(--border);
}

/* ── export menu ────────────────────────────────────────────────────────────── */

.menu { position: relative; }
.menu-pop {
  position: absolute; right: 0; top: calc(100% + 5px); z-index: 20;
  background: var(--card); border: 1px solid var(--border); border-radius: 8px;
  box-shadow: var(--shadow-3); padding: 4px; min-width: 170px; display: grid; gap: 1px;
}
.menu-pop[hidden] { display: none; }
.menu-pop button {
  text-align: left; padding: 7px 10px; border: 0; background: transparent;
  border-radius: 5px; cursor: pointer; font-size: var(--type-meta);
}
.menu-pop button:hover { background: var(--secondary); }

/* The app itself is never printed: Export -> PDF composes its own document. */
@media print { body { visibility: hidden; } }

/* Clerk mounts its OWN card. Nesting it inside ours produced a card in a card with two
 * borders and two shadows, so where Clerk is mounted our wrapper drops its chrome and
 * becomes plain layout.
 *
 * The modifier is set by the renderer, NOT by `:has(.clerk-mount)` — Clerk overwrites the
 * className of the node it mounts into, so the class the selector looked for stops
 * existing the moment Clerk renders and the rule silently never applies. */
.clerk-mount { width: 100%; display: grid; place-items: center; }
.wall-card-bare {
  background: transparent; border: 0; box-shadow: none;
  padding: 0; max-width: none; width: auto; gap: 4px;
}
.wall-card-bare h1 { margin-bottom: 2px; }
.wall-card-bare > p { margin-bottom: 14px; }
.wall-card-bare .wall-note { margin-top: 12px; }

/* ── details drawer ─────────────────────────────────────────────────────────────
 * The checks, the role matrix and the blank inputs used to be a permanent third
 * column. They are reference and repair, not the work — the document is the work —
 * so they live in a drawer and the sheet gets the room instead. What stays on the
 * chrome is the SIGNAL: how many blanks remain, and whether anything is unresolved.
 */

.progress-chip {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 3px 9px; border-radius: 999px;
  background: var(--secondary); border: 1px solid var(--border);
  font-size: var(--type-caption); color: var(--muted-foreground);
}
.progress-bar {
  display: block; width: 46px; height: 4px; border-radius: 2px;
  background: var(--muted); overflow: hidden;
}
.progress-bar > span {
  display: block; height: 100%; background: var(--primary);
  border-radius: 2px; transition: width .2s ease;
}
.progress-text { font-variant-numeric: tabular-nums; }

.btn-on { background: var(--primary-tint); border-color: var(--primary); color: var(--primary-tint-foreground); }
.dot-badge {
  display: inline-block; width: 6px; height: 6px; border-radius: 50%;
  margin-left: 6px; vertical-align: 1px;
}
.dot-badge.is-error { background: var(--destructive); }
.dot-badge.is-warning { background: var(--danger); }

.drawer-scrim {
  position: fixed; inset: 0; z-index: 30;
  background: hsl(60 6% 18% / 0.18);
  display: flex; justify-content: flex-end;
}
.drawer {
  width: min(360px, 100%); height: 100%;
  background: var(--background); border-left: 1px solid var(--border);
  box-shadow: var(--shadow-3);
  display: flex; flex-direction: column; min-height: 0;
  animation: drawer-in .16s ease-out;
}
@keyframes drawer-in { from { transform: translateX(12px); opacity: .6 } to { transform: none; opacity: 1 } }
@media (prefers-reduced-motion: reduce) { .drawer { animation: none } }

.drawer-head {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 14px; border-bottom: 1px solid var(--border);
  height: 52px; flex: none;
}
.drawer-body { overflow: auto; flex: 1; min-height: 0; }
