/* ============================================================
   Drafting Board — styling
   Design system borrowed from Louis (HAQQ Legal AI):
   warm cream comfort-UI, muted gold accent, Inter + EB Garamond.
   ============================================================ */

:root {
  /* Louis brand palette */
  --cream:        #FBF8F2;   /* app background */
  --cream-soft:   #F5F0E5;   /* panels / muted fills */
  --sidebar:      #F7F3EA;   /* rail background */
  --card:         #FFFFFF;   /* node / card surfaces */
  --ink:          #1F2937;   /* primary text */
  --ink-soft:     #4B5563;   /* secondary text */
  --ink-faint:    #8A8578;   /* tertiary / meta text */
  --gold:         #C9A961;   /* accent */
  --gold-soft:    #E6D2A2;   /* hover / glow */
  --gold-deep:    #A8863C;   /* accent text on cream */
  --rule:         #E7E2D6;   /* borders on cream */
  --rule-strong:  #D8D0BD;   /* stronger borders */

  /* status */
  --success:   #2E7D32;
  --success-bg:rgba(46,125,50,0.12);
  --warning:   #B45309;
  --warning-bg:rgba(180,83,9,0.12);
  --danger:    #C2410C;
  --danger-bg: rgba(194,65,12,0.12);
  --info:      #1F6F8B;
  --info-bg:   rgba(31,111,139,0.12);

  /* node accents */
  --n-contract:  #A8863C;
  --n-precedent: #1F6F8B;
  --n-termsheet: #A44D1F;
  --n-redline:   #C2410C;
  --n-client:    #5A4A8A;
  --n-memo:      #2E7D32;

  --radius:    10px;
  --radius-sm: 6px;
  --radius-lg: 14px;

  --font-sans:  'Inter', ui-sans-serif, system-ui, -apple-system, sans-serif;
  --font-serif: 'EB Garamond', ui-serif, Georgia, 'Times New Roman', serif;

  --shadow-sm: 0 1px 2px rgba(31,41,55,0.06), 0 1px 3px rgba(31,41,55,0.08);
  --shadow-md: 0 4px 12px rgba(31,41,55,0.10);
  --shadow-lg: 0 12px 32px rgba(31,41,55,0.16);
}

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

html, body {
  height: 100%;
}
body {
  font-family: var(--font-sans);
  background: var(--cream);
  color: var(--ink);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}
button { cursor: pointer; font-family: inherit; }
::selection { background: var(--gold-soft); }

#app { height: 100vh; display: flex; flex-direction: column; }

/* ---------- generic icon ---------- */
.icon { width: 16px; height: 16px; flex-shrink: 0; stroke: currentColor;
  fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.icon-sm { width: 13px; height: 13px; }
.icon-lg { width: 20px; height: 20px; }
.icon.solid { fill: currentColor; stroke: none; }

/* ============================================================
   TOP BAR
   ============================================================ */
.topbar {
  display: flex; align-items: center; gap: 14px;
  padding: 0 16px; height: 56px; flex-shrink: 0;
  background: var(--cream);
  border-bottom: 1px solid var(--rule);
}
.brand { display: flex; align-items: center; gap: 9px; }
.brand-mark {
  width: 30px; height: 30px; border-radius: 8px;
  background: var(--ink); color: var(--cream);
  display: flex; align-items: center; justify-content: center;
}
.brand-mark .icon { stroke: var(--gold); }
.brand-name { font-weight: 700; font-size: 15px; letter-spacing: -0.01em; }
.brand-sub  { font-size: 11px; color: var(--ink-faint); margin-top: -2px; }

.topbar-divider { width: 1px; height: 26px; background: var(--rule); }

.matter-crumb { display: flex; flex-direction: column; gap: 1px; min-width: 0;
  cursor: pointer; border-radius: var(--radius-sm); padding: 4px 8px; margin: 0 -4px;
  transition: background .14s; }
.matter-crumb:hover { background: var(--cream-soft); }
.matter-title { font-weight: 600; font-size: 13.5px; white-space: nowrap; }
.matter-sub   { font-size: 11.5px; color: var(--ink-faint); white-space: nowrap; }

.spacer { flex: 1; }

.mode-badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 4px 9px; border-radius: 999px;
  font-size: 11px; font-weight: 600;
  border: 1px solid var(--rule-strong);
  background: var(--cream-soft); color: var(--ink-soft);
}
.mode-badge.live { background: var(--success-bg); color: var(--success);
  border-color: rgba(46,125,50,0.3); }
.mode-badge .pip {
  width: 6px; height: 6px; border-radius: 50%; background: currentColor;
}
.mode-badge.live .pip { animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse { 0%,100%{opacity:.5;transform:scale(1);} 50%{opacity:1;transform:scale(1.35);} }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 12px; border-radius: var(--radius-sm);
  font-size: 12.5px; font-weight: 500;
  border: 1px solid var(--rule-strong);
  background: var(--card); color: var(--ink);
  transition: background .14s, border-color .14s, box-shadow .14s, transform .04s;
}
.btn:hover { background: var(--cream-soft); border-color: var(--gold); }
.btn:active { transform: translateY(0.5px); }
.btn.primary {
  background: var(--ink); color: var(--cream); border-color: var(--ink);
}
.btn.primary:hover { background: #2c3a4d; border-color: #2c3a4d; }
.btn.gold {
  background: var(--gold); color: #2b230d; border-color: var(--gold);
  font-weight: 600;
}
.btn.gold:hover { background: var(--gold-soft); border-color: var(--gold-soft); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: var(--cream-soft); border-color: var(--rule); }
.btn.danger { color: var(--danger); border-color: rgba(194,65,12,0.35); }
.btn.danger:hover { background: var(--danger-bg); border-color: var(--danger); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn.icon-only { padding: 7px; }

/* ============================================================
   BODY LAYOUT
   ============================================================ */
.board-body { flex: 1; display: flex; min-height: 0; }

/* ---------- canvas ---------- */
.canvas-wrap {
  flex: 1; position: relative; overflow: hidden;
  background-color: var(--cream);
  cursor: grab; touch-action: none;
}
.canvas-wrap.panning { cursor: grabbing; }
.canvas {
  position: absolute; left: 0; top: 0;
  width: 3600px; height: 2400px;
  transform-origin: 0 0;
  background:
    radial-gradient(circle, var(--rule-strong) 1.1px, transparent 1.1px);
  background-size: 26px 26px;
  will-change: transform;
}
.links-svg { position: absolute; inset: 0; width: 100%; height: 100%;
  pointer-events: none; overflow: visible; }
.link-line { transition: opacity .2s, stroke-width .2s; }

.canvas-toolbar {
  position: absolute; left: 16px; bottom: 16px; z-index: 50;
  display: flex; align-items: center; gap: 4px;
  background: var(--card); border: 1px solid var(--rule-strong);
  border-radius: var(--radius); padding: 5px; box-shadow: var(--shadow-md);
}
.canvas-tool {
  width: 30px; height: 30px; border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  background: transparent; border: none; color: var(--ink-soft);
}
.canvas-tool:hover { background: var(--cream-soft); color: var(--ink); }
.tool-divider { width: 1px; height: 20px; background: var(--rule); margin: 0 3px; }
.zoom-label { font-size: 11.5px; font-weight: 600; color: var(--ink-soft);
  padding: 0 8px; min-width: 46px; text-align: center; }

/* ============================================================
   NODES
   ============================================================ */
.node {
  position: absolute;
  background: var(--card);
  border: 1px solid var(--rule-strong);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  cursor: grab; user-select: none;
  display: flex; flex-direction: column;
  overflow: hidden;
  transition: box-shadow .15s, border-color .15s;
}
.node::before {
  content: ''; position: absolute; left: 0; top: 0; bottom: 0;
  width: 3px; background: var(--node-accent, var(--gold));
}
.node:hover { box-shadow: var(--shadow-md); border-color: var(--node-accent); }
.node.dragging { box-shadow: var(--shadow-lg); cursor: grabbing; }
.node.selected { border-color: var(--node-accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--node-accent) 18%, transparent), var(--shadow-md); }

.node.running { animation: nodePulse 1.4s ease-in-out infinite; }
@keyframes nodePulse {
  0%,100% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--node-accent) 0%, transparent), var(--shadow-sm); }
  50%     { box-shadow: 0 0 0 5px color-mix(in srgb, var(--node-accent) 22%, transparent), var(--shadow-md); }
}

.node-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px; padding: 9px 11px 7px 13px;
}
.node-kind {
  display: flex; align-items: center; gap: 5px;
  font-size: 10px; font-weight: 700; letter-spacing: 0.05em;
  text-transform: uppercase; color: var(--node-accent);
}
.node-meta { font-size: 10.5px; color: var(--ink-faint); white-space: nowrap; }
.node-title {
  font-family: var(--font-serif);
  font-size: 16px; font-weight: 600; line-height: 1.25;
  padding: 0 13px 8px 13px; color: var(--ink);
}
.node-author { font-size: 11px; color: var(--ink-faint); padding: 0 13px 6px; }

/* run controls strip */
.node-run {
  margin-top: auto;
  display: flex; align-items: center; gap: 6px;
  padding: 7px 11px 8px 13px;
  border-top: 1px dashed var(--rule);
  background: var(--cream-soft);
}
.run-status {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 10.5px; font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.04em; color: var(--ink-faint);
}
.run-status .pip { width: 6px; height: 6px; border-radius: 50%;
  background: var(--ink-faint); }
.run-status.running { color: var(--info); }
.run-status.running .pip { background: var(--info); animation: pulse 1.2s infinite; }
.run-status.done { color: var(--success); }
.run-status.done .pip { background: var(--success); }
.run-status.needs_approval { color: var(--warning); }
.run-status.needs_approval .pip { background: var(--warning); animation: pulse 1.2s infinite; }
.run-btn {
  margin-left: auto;
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 11px; font-weight: 600;
  padding: 4px 9px; border-radius: 999px;
  border: 1px solid var(--node-accent);
  color: var(--node-accent); background: var(--card);
}
.run-btn:hover { background: var(--node-accent); color: #fff; }
.run-btn:disabled { opacity: .45; cursor: not-allowed; }
.run-btn:disabled:hover { background: var(--card); color: var(--node-accent); }

/* ---- contract node ---- */
.node.contract { z-index: 5; }
.contract-sections {
  flex: 1; overflow-y: auto; padding: 2px 8px 8px;
}
.c-section {
  display: flex; align-items: center; gap: 7px;
  padding: 5px 7px; border-radius: var(--radius-sm);
  font-size: 12.5px;
}
.c-section + .c-section { margin-top: 1px; }
.c-section:hover { background: var(--cream-soft); }
.c-section-n {
  font-weight: 700; color: var(--ink-faint);
  font-size: 11px; min-width: 24px;
}
.c-section-title { flex: 1; color: var(--ink-soft); }
.c-section.ok .c-section-title { color: var(--ink); }
.c-pill {
  font-size: 9px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.04em; padding: 2px 6px; border-radius: 999px;
  white-space: nowrap;
}
.c-pill.edited  { background: var(--success-bg); color: var(--success); }
.c-pill.pending { background: var(--warning-bg); color: var(--warning); }
.c-pill.flagged { background: var(--danger-bg);  color: var(--danger); }
.c-pill.comment { background: var(--info-bg);    color: var(--info); }
.c-section.flagged { background: rgba(194,65,12,0.05); }
.c-section.pending { background: rgba(180,83,9,0.05); }
.c-section.edited::before {
  content: ''; width: 0;
}
.c-open-hint {
  display: flex; align-items: center; gap: 5px;
  margin-top: 4px; padding: 6px 7px; border-radius: var(--radius-sm);
  font-size: 11px; font-weight: 500; color: var(--gold-deep);
  background: var(--cream-soft); border: 1px dashed var(--rule-strong);
  cursor: pointer;
}
.c-open-hint:hover { border-color: var(--gold); background: var(--card); }

/* ---- term sheet ---- */
.ts-points { padding: 0 11px 4px; display: flex; flex-direction: column; gap: 3px; }
.ts-row {
  display: flex; justify-content: space-between; gap: 8px;
  font-size: 12px; padding: 4px 7px; border-radius: var(--radius-sm);
  background: var(--cream-soft);
}
.ts-row.open { background: var(--warning-bg); }
.ts-label { color: var(--ink-soft); }
.ts-val { font-weight: 600; color: var(--ink); text-align: right; }
.ts-row.open .ts-val { color: var(--warning); }

/* ---- redline ---- */
.rl-changes { padding: 0 11px 4px; display: flex; flex-direction: column; gap: 3px;
  overflow-y: auto; }
.rl-row {
  display: flex; align-items: center; gap: 6px;
  font-size: 11.5px; padding: 4px 6px; border-radius: var(--radius-sm);
}
.rl-row:hover { background: var(--cream-soft); }
.rl-sec { font-weight: 700; color: var(--ink-faint); min-width: 30px; }
.rl-type {
  font-size: 9px; font-weight: 700; text-transform: uppercase;
  padding: 1px 5px; border-radius: 3px;
}
.rl-type.edit   { background: var(--info-bg);    color: var(--info); }
.rl-type.insert { background: var(--success-bg); color: var(--success); }
.rl-type.delete { background: var(--danger-bg);  color: var(--danger); }
.rl-note { flex: 1; color: var(--ink-soft); }

/* ---- client comments ---- */
.cc-list { padding: 0 11px 4px; display: flex; flex-direction: column; gap: 6px;
  overflow-y: auto; }
.cc-item {
  padding: 7px 9px; border-radius: var(--radius-sm);
  background: var(--cream-soft); border-left: 2px solid var(--n-client);
}
.cc-item.resolved { opacity: 0.55; border-left-color: var(--success); }
.cc-head { display: flex; gap: 6px; font-size: 11px; margin-bottom: 2px; }
.cc-who { font-weight: 700; color: var(--ink); }
.cc-sec { color: var(--ink-faint); font-weight: 600; }
.cc-text { font-size: 12px; color: var(--ink-soft); line-height: 1.4; }

/* ---- jurisdiction memo ---- */
.memo-flags { padding: 0 13px 6px; list-style: none; }
.memo-flags li {
  font-size: 12px; color: var(--ink-soft); line-height: 1.45;
  padding: 4px 0 4px 16px; position: relative;
}
.memo-flags li::before {
  content: ''; position: absolute; left: 2px; top: 10px;
  width: 5px; height: 5px; border-radius: 50%; background: var(--n-memo);
}
.memo-flags li + li { border-top: 1px solid var(--rule); }

/* ---- precedent ---- */
.node.precedent .node-title { font-size: 14px; }

/* ============================================================
   RIGHT RAIL — timeline
   ============================================================ */
.rail {
  width: 372px; flex-shrink: 0;
  display: flex; flex-direction: column;
  background: var(--sidebar);
  border-left: 1px solid var(--rule);
}
.rail-scroll { flex: 1; overflow-y: auto; }

/* ---- approval gate ---- */
.gate {
  margin: 12px 12px 4px;
  border: 1.5px solid var(--warning);
  border-radius: var(--radius);
  background: var(--card);
  box-shadow: 0 0 0 4px var(--warning-bg), var(--shadow-md);
  overflow: hidden;
}
.gate-head {
  display: flex; align-items: center; gap: 7px;
  padding: 9px 12px; background: var(--warning-bg);
  font-size: 11.5px; font-weight: 700; color: var(--warning);
}
.gate-head .gate-time { margin-left: auto; font-weight: 600; opacity: .8; }
.gate-body { padding: 11px 13px 13px; }
.gate-action { font-size: 13px; font-weight: 600; color: var(--ink);
  line-height: 1.4; }
.gate-target {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 11.5px; font-weight: 600; color: var(--gold-deep);
  margin: 6px 0 8px;
}
.gate-preview {
  font-family: var(--font-serif); font-style: italic;
  font-size: 13px; line-height: 1.55; color: var(--ink-soft);
  border-left: 2px solid var(--gold); padding: 4px 0 4px 12px;
  margin-bottom: 10px;
}
.gate-preview-edit {
  width: 100%; font-family: var(--font-serif); font-size: 13px;
  line-height: 1.55; color: var(--ink); padding: 8px 10px;
  border: 1px solid var(--rule-strong); border-radius: var(--radius-sm);
  background: var(--cream); resize: vertical; min-height: 90px;
  margin-bottom: 10px; outline: none;
}
.gate-preview-edit:focus { border-color: var(--gold); }
.gate-sources { margin-bottom: 10px; }
.gate-sources-label {
  font-size: 10px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.05em; color: var(--ink-faint); margin-bottom: 4px;
}
.gate-source {
  display: flex; align-items: center; gap: 6px;
  font-size: 11.5px; color: var(--ink-soft);
  padding: 3px 0;
}
.gate-source .icon { color: var(--gold-deep); }
.gate-meta { display: flex; flex-wrap: wrap; gap: 5px; margin-bottom: 11px; }
.gate-tag {
  font-size: 10px; font-weight: 600; padding: 3px 7px; border-radius: 999px;
  background: var(--cream-soft); color: var(--ink-soft);
  border: 1px solid var(--rule);
}
.gate-tag.ok   { background: var(--success-bg); color: var(--success);
  border-color: rgba(46,125,50,0.25); }
.gate-tag.warn { background: var(--warning-bg); color: var(--warning);
  border-color: rgba(180,83,9,0.25); }
.gate-actions { display: flex; gap: 6px; }
.gate-actions .btn { flex: 1; justify-content: center; padding: 7px 8px; }

/* ---- timeline ---- */
.rail-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 14px 8px;
}
.rail-title { font-size: 12px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.06em; color: var(--ink-faint); }
.rail-tabs { display: flex; gap: 2px; background: var(--cream-soft);
  padding: 2px; border-radius: 999px; }
.rail-tab {
  font-size: 11px; font-weight: 600; padding: 3px 9px;
  border-radius: 999px; border: none; background: transparent;
  color: var(--ink-faint); text-transform: capitalize;
}
.rail-tab.active { background: var(--card); color: var(--ink);
  box-shadow: var(--shadow-sm); }

.timeline { padding: 4px 12px 12px; }
.evt {
  display: flex; gap: 9px; padding: 7px 8px;
  border-radius: var(--radius-sm);
  animation: evtIn .28s ease-out;
}
@keyframes evtIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; } }
.evt:hover { background: var(--cream-soft); }
.evt-rail {
  width: 26px; height: 26px; flex-shrink: 0; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  background: var(--cream-soft); color: var(--ink-soft);
  border: 1px solid var(--rule);
}
.evt.agent .evt-rail   { background: var(--success-bg); color: var(--success);
  border-color: rgba(46,125,50,0.25); }
.evt.gate .evt-rail    { background: var(--warning-bg); color: var(--warning);
  border-color: rgba(180,83,9,0.25); }
.evt-body { flex: 1; min-width: 0; }
.evt-row { display: flex; align-items: baseline; gap: 7px; }
.evt-actor { font-size: 12px; font-weight: 700; }
.evt-actor.agent { color: var(--success); }
.evt-actor.human { color: var(--ink); }
.evt-t { font-size: 10.5px; color: var(--ink-faint); margin-left: auto; }
.evt-text { font-size: 12.5px; color: var(--ink-soft); line-height: 1.45;
  margin-top: 1px; }
.evt.reasoning .evt-text { font-style: italic; }
.evt.tool .evt-text { font-family: var(--font-serif); font-size: 13px; }

.timeline-empty {
  text-align: center; padding: 30px 16px; color: var(--ink-faint);
  font-size: 12.5px;
}

/* ---- composer ---- */
.composer {
  flex-shrink: 0; padding: 11px 12px 13px;
  border-top: 1px solid var(--rule); background: var(--sidebar);
}
.composer textarea {
  width: 100%; min-height: 58px; max-height: 160px;
  padding: 9px 10px; border-radius: var(--radius-sm);
  border: 1px solid var(--rule-strong); background: var(--card);
  font-family: var(--font-sans); font-size: 12.5px; color: var(--ink);
  resize: none; outline: none; line-height: 1.45;
}
.composer textarea:focus { border-color: var(--gold);
  box-shadow: 0 0 0 3px var(--warning-bg); }
.composer-row { display: flex; align-items: center; gap: 7px; margin-top: 7px; }
.composer-hint { font-size: 10.5px; color: var(--ink-faint); flex: 1; }
.send-btn {
  width: 32px; height: 32px; border-radius: var(--radius-sm);
  background: var(--ink); color: var(--cream); border: none;
  display: flex; align-items: center; justify-content: center;
}
.send-btn:hover { background: var(--gold); color: #2b230d; }
.send-btn:disabled { opacity: .4; cursor: not-allowed; }

/* ============================================================
   MODAL
   ============================================================ */
.modal-overlay {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(31,41,55,0.32);
  display: flex; align-items: center; justify-content: center;
  padding: 24px; animation: fadeIn .15s;
}
@keyframes fadeIn { from { opacity: 0; } }
.modal {
  background: var(--cream); border: 1px solid var(--rule-strong);
  border-radius: var(--radius-lg); box-shadow: var(--shadow-lg);
  width: 100%; max-width: 460px; max-height: 86vh; overflow: auto;
  animation: modalIn .2s ease-out;
}
@keyframes modalIn { from { opacity: 0; transform: translateY(8px) scale(.98); } }
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 18px 12px;
}
.modal-title { font-family: var(--font-serif); font-size: 19px; font-weight: 600; }
.modal-body { padding: 4px 18px 18px; }
.modal-section { margin-bottom: 16px; }
.modal-label {
  display: block; font-size: 11.5px; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.04em;
  color: var(--ink-faint); margin-bottom: 6px;
}
.modal-input, .modal-select {
  width: 100%; padding: 9px 11px; border-radius: var(--radius-sm);
  border: 1px solid var(--rule-strong); background: var(--card);
  font-family: var(--font-sans); font-size: 13px; color: var(--ink);
  outline: none;
}
.modal-input:focus, .modal-select:focus { border-color: var(--gold);
  box-shadow: 0 0 0 3px var(--warning-bg); }
.modal-help { font-size: 11.5px; color: var(--ink-faint); margin-top: 6px;
  line-height: 1.5; }
.modal-help a { color: var(--gold-deep); }

.toggle-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 11px 13px; border-radius: var(--radius);
  background: var(--card); border: 1px solid var(--rule);
}
.toggle-row-text { font-size: 12.5px; }
.toggle-row-text strong { display: block; font-weight: 600; color: var(--ink); }
.toggle-row-text span { color: var(--ink-faint); font-size: 11.5px; }
.switch {
  position: relative; width: 40px; height: 23px; flex-shrink: 0;
  border-radius: 999px; background: var(--rule-strong);
  border: none; transition: background .16s;
}
.switch.on { background: var(--success); }
.switch::after {
  content: ''; position: absolute; left: 2px; top: 2px;
  width: 19px; height: 19px; border-radius: 50%; background: #fff;
  box-shadow: var(--shadow-sm); transition: transform .16s;
}
.switch.on::after { transform: translateX(17px); }

.modal-foot {
  display: flex; gap: 8px; justify-content: flex-end;
  padding: 0 18px 18px;
}

.kbd {
  font-family: var(--font-sans); font-size: 10.5px; font-weight: 600;
  padding: 1px 5px; border-radius: 4px; background: var(--cream-soft);
  border: 1px solid var(--rule-strong); color: var(--ink-soft);
}

/* ============================================================
   TOASTS
   ============================================================ */
#toast-host {
  position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%);
  z-index: 300; display: flex; flex-direction: column; gap: 8px;
  align-items: center;
}
.toast {
  display: flex; align-items: center; gap: 8px;
  padding: 9px 14px; border-radius: 999px;
  background: var(--ink); color: var(--cream);
  font-size: 12.5px; font-weight: 500; box-shadow: var(--shadow-lg);
  animation: toastIn .22s ease-out;
}
.toast .icon { stroke: var(--gold); }
.toast.fade { animation: toastOut .3s ease-in forwards; }
@keyframes toastIn { from { opacity: 0; transform: translateY(10px); } }
@keyframes toastOut { to { opacity: 0; transform: translateY(8px); } }

/* ============================================================
   EMPTY / MISC
   ============================================================ */
.run-board-progress {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 11.5px; color: var(--info); font-weight: 600;
}

/* ---------- gate flash (when an action is blocked by an open gate) ---------- */
.gate.flash { animation: gateFlash 0.9s ease-out 2; }
@keyframes gateFlash {
  0%, 100% { box-shadow: 0 0 0 4px var(--warning-bg), var(--shadow-md); }
  50%      { box-shadow: 0 0 0 7px rgba(180,83,9,0.35), var(--shadow-lg);
             border-color: var(--danger); }
}

/* ============================================================
   FORMS — node / contract editors
   ============================================================ */
.modal.wide { max-width: 600px; }
.form-row { margin-bottom: 13px; }
.form-row:last-child { margin-bottom: 0; }
.form-grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.form-grid-3 { display: grid; grid-template-columns: 64px 1fr 120px; gap: 8px; }

/* list editor — repeating rows of inputs */
.list-editor {
  border: 1px solid var(--rule); border-radius: var(--radius);
  background: var(--card); padding: 8px; max-height: 260px; overflow-y: auto;
}
.le-row {
  display: flex; align-items: center; gap: 6px; margin-bottom: 6px;
}
.le-row:last-child { margin-bottom: 0; }
.le-row input, .le-row select, .le-row textarea,
.doc-section-head input, .doc-section-head select {
  padding: 6px 8px; border-radius: var(--radius-sm);
  border: 1px solid var(--rule-strong); background: var(--cream);
  font-family: var(--font-sans); font-size: 12.5px; color: var(--ink);
  outline: none; min-width: 0;
}
.le-row input:focus, .le-row select:focus, .le-row textarea:focus,
.doc-section-head input:focus, .doc-section-head select:focus {
  border-color: var(--gold); background: var(--card);
}
.le-row .le-grow { flex: 1; }
.le-row .le-n { width: 46px; text-align: center; font-weight: 600; }
.le-row .le-sm { width: 90px; }
.le-del {
  width: 26px; height: 26px; flex-shrink: 0; border-radius: var(--radius-sm);
  border: 1px solid transparent; background: transparent; color: var(--ink-faint);
  display: flex; align-items: center; justify-content: center;
}
.le-del:hover { background: var(--danger-bg); color: var(--danger); }
.le-add {
  display: inline-flex; align-items: center; gap: 5px; margin-top: 8px;
  font-size: 12px; font-weight: 600; color: var(--gold-deep);
  background: transparent; border: 1px dashed var(--rule-strong);
  border-radius: var(--radius-sm); padding: 6px 11px; width: 100%;
  justify-content: center;
}
.le-add:hover { border-color: var(--gold); background: var(--cream-soft); }
.le-cc-row { flex-wrap: wrap; }
.le-cc-row .le-cc-text { flex-basis: 100%; }

/* add-node picker grid */
.kind-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; }
.kind-card {
  display: flex; align-items: center; gap: 10px; text-align: left;
  padding: 12px; border-radius: var(--radius);
  border: 1px solid var(--rule-strong); background: var(--card);
}
.kind-card:hover { border-color: var(--kc-accent, var(--gold));
  background: var(--cream-soft); }
.kind-card .kc-ico {
  width: 34px; height: 34px; flex-shrink: 0; border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  background: var(--cream-soft); color: var(--kc-accent, var(--gold-deep));
  border: 1px solid var(--rule);
}
.kc-text strong { display: block; font-size: 13px; font-weight: 600; }
.kc-text span { font-size: 11.5px; color: var(--ink-faint); }

/* export / import options */
.opt-row {
  display: flex; align-items: center; gap: 11px; width: 100%;
  padding: 12px 13px; border-radius: var(--radius);
  border: 1px solid var(--rule-strong); background: var(--card);
  text-align: left; margin-bottom: 9px;
}
.opt-row:last-child { margin-bottom: 0; }
.opt-row:hover { border-color: var(--gold); background: var(--cream-soft); }
.opt-row .opt-ico {
  width: 32px; height: 32px; flex-shrink: 0; border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  background: var(--cream-soft); color: var(--gold-deep);
  border: 1px solid var(--rule);
}
.opt-text strong { display: block; font-size: 13px; font-weight: 600; }
.opt-text span { font-size: 11.5px; color: var(--ink-faint); }

/* danger zone separator inside modals */
.modal-divider { height: 1px; background: var(--rule); margin: 4px 0 14px; }

/* ============================================================
   DOCUMENT VIEW — the contract as a real, editable document
   ============================================================ */
.modal.doc { max-width: 720px; }
.doc-sub { font-size: 11.5px; color: var(--ink-faint); margin-top: 3px; }
#doc-sections { display: flex; flex-direction: column; gap: 10px; margin-bottom: 10px; }
.doc-section {
  border: 1px solid var(--rule); border-radius: var(--radius);
  background: var(--card); padding: 10px;
}
.doc-section-head {
  display: flex; align-items: center; gap: 6px; margin-bottom: 8px;
}
.doc-section-head .ds-n { width: 50px; text-align: center; font-weight: 600; }
.doc-section-head .ds-title { flex: 1; }
.doc-section-head .ds-state { width: 96px; }
.ds-body {
  width: 100%; min-height: 76px;
  font-family: var(--font-serif); font-size: 14.5px; line-height: 1.55;
  padding: 9px 12px; border-radius: var(--radius-sm);
  border: 1px solid var(--rule-strong); background: var(--cream);
  color: var(--ink); resize: vertical; outline: none;
}
.ds-body:focus { border-color: var(--gold); background: var(--card);
  box-shadow: 0 0 0 3px var(--warning-bg); }
.doc-hist-wrap {
  margin-top: 8px; padding-top: 8px; border-top: 1px dashed var(--rule);
  display: flex; flex-direction: column; gap: 5px;
}
.doc-hist { font-size: 11.5px; color: var(--ink-soft); }
.doc-hist-t { font-weight: 700; color: var(--ink-faint); margin-right: 6px; }
.doc-hist-edit .doc-hist-x { color: var(--success); font-weight: 500; }
.doc-hist-note .doc-hist-x {
  font-family: var(--font-serif); font-size: 13px; color: var(--info);
  font-style: italic;
}
.doc-prev { margin-top: 5px; }
.doc-prev summary {
  cursor: pointer; font-size: 10.5px; font-weight: 600; color: var(--gold-deep);
  list-style: none;
}
.doc-prev summary::-webkit-details-marker { display: none; }
.doc-prev summary::before { content: "▸ "; }
.doc-prev[open] summary::before { content: "▾ "; }
.doc-prev > div {
  margin-top: 5px; padding: 7px 10px; border-radius: var(--radius-sm);
  background: var(--danger-bg); color: var(--danger);
  text-decoration: line-through; font-family: var(--font-serif);
  font-size: 13px; line-height: 1.5;
}

@media (max-width: 880px) {
  .rail { width: 320px; }
  .matter-crumb { display: none; }
}
