/* Redline — contract review for humans and agents.
   Type: Spectral for the contract (it should read as a document),
   IBM Plex Sans for app chrome, IBM Plex Mono for tool payloads. */

:root {
  --paper: #fbfbfa;
  --surface: #f4f4f2;
  --surface-2: #ecece9;
  --ink: #17171b;
  --ink-soft: #4a4a53;
  --ink-mute: #74747f;
  --rule: #e0e0dc;
  --rule-strong: #cfcfc9;

  --agent: #4338ca;
  --agent-bg: #eef0ff;
  --agent-line: #c9cdf6;

  --insert: #067647;
  --insert-bg: #e9f7f0;
  --delete: #b42318;
  --delete-bg: #fdeeed;

  --sev-critical: #a01b12;
  --sev-high: #b54708;
  --sev-medium: #8a6d1f;
  --sev-low: #5d6068;

  --focus: #4338ca;

  --font-doc: "Spectral", Georgia, "Times New Roman", serif;
  --font-ui: "IBM Plex Sans", system-ui, -apple-system, sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, Menlo, monospace;

  --radius: 6px;
  --shadow: 0 1px 2px rgba(23, 23, 27, 0.06), 0 8px 24px rgba(23, 23, 27, 0.06);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #121216;
    --surface: #1a1a20;
    --surface-2: #232329;
    --ink: #e8e8ec;
    --ink-soft: #b4b4bf;
    --ink-mute: #8a8a97;
    --rule: #2c2c34;
    --rule-strong: #3a3a44;

    --agent: #a5a0ff;
    --agent-bg: #1e1c3a;
    --agent-line: #3b3670;

    --insert: #4ade80;
    --insert-bg: #10241a;
    --delete: #fca5a5;
    --delete-bg: #2a1514;

    --sev-critical: #f87171;
    --sev-high: #fbbf24;
    --sev-medium: #d6c47a;
    --sev-low: #9aa0ab;

    --focus: #a5a0ff;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 8px 24px rgba(0, 0, 0, 0.35);
  }
}

:root[data-theme="dark"] {
  --paper: #121216;
  --surface: #1a1a20;
  --surface-2: #232329;
  --ink: #e8e8ec;
  --ink-soft: #b4b4bf;
  --ink-mute: #8a8a97;
  --rule: #2c2c34;
  --rule-strong: #3a3a44;

  --agent: #a5a0ff;
  --agent-bg: #1e1c3a;
  --agent-line: #3b3670;

  --insert: #4ade80;
  --insert-bg: #10241a;
  --delete: #fca5a5;
  --delete-bg: #2a1514;

  --sev-critical: #f87171;
  --sev-high: #fbbf24;
  --sev-medium: #d6c47a;
  --sev-low: #9aa0ab;

  --focus: #a5a0ff;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 8px 24px rgba(0, 0, 0, 0.35);
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -0.012em; text-wrap: balance; }
p { margin: 0; }
a { color: var(--agent); text-underline-offset: 3px; }
code { font-family: var(--font-mono); font-size: 0.88em; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 3px; }

.hint, .card-sub { color: var(--ink-mute); font-size: 12.5px; line-height: 1.5; }
.error { color: var(--delete); font-size: 13px; }

/* ── Wordmark ─────────────────────────────────────────────────────────── */
.wordmark { font-size: 20px; font-weight: 600; letter-spacing: -0.02em; text-decoration: none; color: var(--ink); }
.wordmark.sm { font-size: 16px; }
.wordmark-strike {
  position: relative;
  background-image: linear-gradient(var(--delete), var(--delete));
  background-size: 100% 1.5px;
  background-position: 0 58%;
  background-repeat: no-repeat;
  padding-inline: 1px;
}

/* ── Buttons ──────────────────────────────────────────────────────────── */
.btn {
  font: inherit;
  font-size: 13px;
  font-weight: 500;
  padding: 7px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--rule-strong);
  background: var(--paper);
  color: var(--ink);
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-primary { background: var(--ink); border-color: var(--ink); color: var(--paper); }
.btn-primary:hover { opacity: 0.88; background: var(--ink); }
.btn-lg { font-size: 15px; padding: 11px 22px; }
.btn-accept { border-color: var(--insert); color: var(--insert); }
.btn-accept:hover { background: var(--insert-bg); }
.btn-reject { border-color: var(--rule-strong); color: var(--ink-soft); }

/* ── Landing ──────────────────────────────────────────────────────────── */
.landing { max-width: 780px; margin: 0 auto; padding: 72px 28px 56px; }
.landing-head { display: flex; flex-direction: column; gap: 18px; }
.eyebrow {
  font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.1em;
  color: var(--ink-mute); font-weight: 500; margin-top: 22px;
}
.landing h1 { font-family: var(--font-doc); font-size: 46px; line-height: 1.14; font-weight: 600; }
.lede { font-size: 17px; color: var(--ink-soft); max-width: 62ch; line-height: 1.6; }
.landing-actions { display: flex; flex-direction: column; gap: 10px; align-items: flex-start; margin-top: 8px; }
.how {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 26px; margin: 64px 0 0; padding-top: 34px; border-top: 1px solid var(--rule);
}
.how h2 { font-size: 12px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--agent); margin-bottom: 8px; }
.how p { font-size: 14px; color: var(--ink-soft); line-height: 1.6; }
.landing-foot { margin-top: 56px; padding-top: 22px; border-top: 1px solid var(--rule); font-size: 13px; color: var(--ink-mute); }

/* ── Top bar ──────────────────────────────────────────────────────────── */
.topbar {
  display: flex; align-items: center; gap: 20px; flex-wrap: wrap;
  padding: 12px 24px; border-bottom: 1px solid var(--rule);
  background: var(--paper); position: sticky; top: 0; z-index: 20;
}
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 12px; }

.phase-stepper { display: flex; border: 1px solid var(--rule-strong); border-radius: var(--radius); overflow: hidden; }
.phase {
  font: inherit; font-size: 12.5px; font-weight: 500;
  padding: 6px 14px; border: 0; background: transparent; color: var(--ink-mute); cursor: pointer;
}
.phase + .phase { border-left: 1px solid var(--rule-strong); }
.phase:hover:not(.active) { background: var(--surface-2); color: var(--ink); }
.phase.active { background: var(--ink); color: var(--paper); }

.tool-count { font-family: var(--font-mono); font-size: 12px; color: var(--ink-mute); }
.mcp-pill {
  display: inline-flex; align-items: center; gap: 8px;
  font-family: var(--font-mono); font-size: 11.5px;
  padding: 5px 11px; border-radius: 999px;
  border: 1px solid var(--agent-line); background: var(--agent-bg); color: var(--agent);
}
.mcp-pill .dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.mcp-pill.on .dot { animation: pulse 2.4s ease-in-out infinite; }
.mcp-pill.off { border-color: var(--rule-strong); background: var(--surface); color: var(--ink-mute); }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.25; } }
@media (prefers-reduced-motion: reduce) { .mcp-pill.on .dot { animation: none; } }

/* ── Workspace ────────────────────────────────────────────────────────── */
.workspace {
  display: grid; grid-template-columns: minmax(0, 1fr) 372px;
  gap: 34px; max-width: 1400px; margin: 0 auto; padding: 30px 24px 40px; align-items: start;
}
@media (max-width: 1080px) { .workspace { grid-template-columns: minmax(0, 1fr); } }

.doc-pane { min-width: 0; }
.doc-head { padding-bottom: 20px; margin-bottom: 8px; border-bottom: 1px solid var(--rule); }
.doc-head h1 { font-family: var(--font-doc); font-size: 32px; line-height: 1.16; margin-bottom: 8px; }
.doc-meta { font-size: 13.5px; color: var(--ink-mute); }
.doc-stats { display: flex; gap: 16px; flex-wrap: wrap; margin-top: 14px; font-size: 12.5px; color: var(--ink-mute); }
.doc-stats b { font-variant-numeric: tabular-nums; color: var(--ink); font-weight: 600; }

/* ── Clauses ──────────────────────────────────────────────────────────── */
.clause {
  padding: 22px 0 22px 18px; border-bottom: 1px solid var(--rule);
  border-left: 3px solid transparent; scroll-margin-top: 80px;
}
.clause.sev-critical { border-left-color: var(--sev-critical); }
.clause.sev-high { border-left-color: var(--sev-high); }
.clause.sev-medium { border-left-color: var(--sev-medium); }
.clause.sev-low { border-left-color: var(--sev-low); }
.clause.deleted { opacity: 0.5; }

.clause-head { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; margin-bottom: 8px; }
.clause-num { font-family: var(--font-mono); font-size: 12px; color: var(--ink-mute); }
.clause-heading { font-family: var(--font-doc); font-size: 18px; font-weight: 600; }
.clause-id { font-family: var(--font-mono); font-size: 11px; color: var(--ink-mute); opacity: 0.7; margin-left: auto; }

.clause-text {
  font-family: var(--font-doc); font-size: 16.5px; line-height: 1.66;
  color: var(--ink); max-width: 66ch;
}
.clause.deleted .clause-text { text-decoration: line-through; text-decoration-color: var(--delete); }

.badge {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 10.5px; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase;
  padding: 2px 7px; border-radius: 3px; border: 1px solid currentColor;
}
.badge.revised { color: var(--insert); }
.badge.sev-critical { color: var(--sev-critical); }
.badge.sev-high { color: var(--sev-high); }
.badge.sev-medium { color: var(--sev-medium); }
.badge.sev-low { color: var(--sev-low); }

.annotations { display: flex; flex-direction: column; gap: 8px; margin-top: 14px; max-width: 66ch; }
.flag, .note {
  display: flex; gap: 10px; padding: 10px 12px; border-radius: var(--radius);
  background: var(--surface); font-size: 13.5px; line-height: 1.5; color: var(--ink-soft);
}
.flag .flag-sev { font-weight: 600; white-space: nowrap; }
.flag.sev-critical .flag-sev { color: var(--sev-critical); }
.flag.sev-high .flag-sev { color: var(--sev-high); }
.flag.sev-medium .flag-sev { color: var(--sev-medium); }
.flag.sev-low .flag-sev { color: var(--sev-low); }
.note-label { color: var(--ink-mute); white-space: nowrap; font-size: 12px; padding-top: 1px; }

/* ── Inline redline ───────────────────────────────────────────────────── */
.redline {
  margin-top: 16px; max-width: 66ch;
  border: 1px solid var(--agent-line); border-radius: var(--radius);
  background: var(--paper); overflow: hidden;
}
.redline-head {
  display: flex; align-items: center; gap: 9px; flex-wrap: wrap;
  padding: 9px 13px; background: var(--agent-bg); border-bottom: 1px solid var(--agent-line);
  font-size: 12px; color: var(--ink-soft);
}
.redline-id { font-family: var(--font-mono); font-size: 11px; color: var(--ink-mute); margin-left: auto; }
.redline-body { padding: 13px; display: flex; flex-direction: column; gap: 10px; }
.diff { font-family: var(--font-doc); font-size: 15px; line-height: 1.6; padding: 9px 12px; border-radius: 4px; }
.diff.out { background: var(--delete-bg); color: var(--ink-soft); text-decoration: line-through; text-decoration-color: var(--delete); text-decoration-thickness: 1px; }
.diff.in { background: var(--insert-bg); color: var(--ink); }
.rationale { font-size: 13.5px; color: var(--ink-soft); line-height: 1.55; }
.rationale b { color: var(--ink); font-weight: 600; }
.redline-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; padding: 0 13px 13px; }
.redline-actions .spacer { flex: 1; }
.resolved-note { font-size: 12.5px; color: var(--ink-mute); }
.reject-form { flex-direction: column; align-items: stretch; gap: 9px; }
.reject-reason {
  width: 100%; resize: vertical; padding: 8px 10px;
  font-family: inherit; font-size: 13.5px; line-height: 1.5;
  color: var(--ink); background: var(--surface); border: 1px solid var(--rule-strong);
  border-radius: 4px;
}
.reject-reason::placeholder { color: var(--ink-mute); }
.reject-reason:focus { outline: none; border-color: var(--ink-soft); }
.reject-buttons { display: flex; gap: 8px; }
.redline.resolved { opacity: 0.68; }
.redline.accepted .redline-head { background: var(--insert-bg); border-color: var(--insert); }
.redline.rejected .redline-head { background: var(--surface-2); }

.tag {
  display: inline-flex; align-items: center; gap: 5px;
  font-family: var(--font-mono); font-size: 10px; font-weight: 500;
  letter-spacing: 0.07em; text-transform: uppercase;
  padding: 2px 7px; border-radius: 3px;
}
.tag.agent { background: var(--agent); color: var(--paper); }
.tag.human { background: var(--surface-2); color: var(--ink-soft); border: 1px solid var(--rule-strong); }

/* ── Rail ─────────────────────────────────────────────────────────────── */
.rail { display: flex; flex-direction: column; gap: 18px; position: sticky; top: 76px; }
@media (max-width: 1080px) { .rail { position: static; } }
.card { border: 1px solid var(--rule); border-radius: 8px; background: var(--surface); padding: 16px 17px; }
.card h2 { font-size: 13px; text-transform: uppercase; letter-spacing: 0.07em; color: var(--ink-soft); }
.card-head-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.card-sub { margin-top: 5px; }
.counter {
  font-family: var(--font-mono); font-size: 12px; font-variant-numeric: tabular-nums;
  background: var(--paper); border: 1px solid var(--rule-strong); border-radius: 999px; padding: 1px 9px;
}

.ctx-group { margin-top: 12px; }
.ctx-label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.07em; color: var(--ink-mute); margin-bottom: 5px; }
.ctx-list { margin: 0; padding-left: 17px; font-size: 13px; color: var(--ink-soft); line-height: 1.55; }
.ctx-list li { margin-bottom: 3px; }
.ctx-list.hard li { color: var(--delete); }

.queue-item {
  display: flex; flex-direction: column; gap: 5px; padding: 11px 0;
  border-top: 1px solid var(--rule); font-size: 13px;
}
.queue-item:first-child { border-top: 0; }
.queue-top { display: flex; align-items: center; gap: 8px; }
.queue-target { font-weight: 500; }
.queue-why { color: var(--ink-mute); font-size: 12.5px; line-height: 1.45; }
.queue-jump { font: inherit; font-size: 12px; background: none; border: 0; color: var(--agent); cursor: pointer; padding: 0; text-align: left; }
.empty { font-size: 13px; color: var(--ink-mute); padding: 12px 0 2px; }

.activity { display: flex; flex-direction: column; gap: 9px; margin-top: 12px; max-height: 320px; overflow-y: auto; }
.act { display: flex; gap: 9px; font-size: 12.5px; line-height: 1.45; color: var(--ink-soft); }
.act .tag { flex: none; height: fit-content; margin-top: 1px; }
.act b { color: var(--ink); font-weight: 600; }
.act time { display: block; color: var(--ink-mute); font-size: 11px; margin-top: 2px; font-variant-numeric: tabular-nums; }

/* ── Tools ────────────────────────────────────────────────────────────── */
.tools-section { border-top: 1px solid var(--rule); background: var(--surface); }
.tools-toggle {
  display: flex; align-items: center; gap: 13px; width: 100%; flex-wrap: wrap;
  max-width: 1400px; margin: 0 auto; padding: 16px 24px;
  font: inherit; background: none; border: 0; cursor: pointer; color: inherit; text-align: left;
}
.tools-title { font-size: 15px; font-weight: 600; }
.tools-badge {
  font-family: var(--font-mono); font-size: 11px;
  background: var(--agent); color: var(--paper); padding: 2px 8px; border-radius: 3px;
}
.tools-hint { font-size: 12.5px; color: var(--ink-mute); flex: 1; min-width: 200px; }
.chev { color: var(--ink-mute); transition: transform 0.2s; }
.tools-section.open .chev { transform: rotate(180deg); }
@media (prefers-reduced-motion: reduce) { .chev { transition: none; } }

.tools-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(330px, 1fr)); gap: 14px;
  max-width: 1400px; margin: 0 auto; padding: 0 24px 30px;
}
.tool {
  border: 1px solid var(--rule); border-radius: 8px; background: var(--paper);
  padding: 14px 15px; display: flex; flex-direction: column; gap: 9px;
}
.tool-name { font-family: var(--font-mono); font-size: 13px; font-weight: 500; color: var(--agent); overflow-wrap: anywhere; }
.tool-desc { font-size: 12.5px; color: var(--ink-mute); line-height: 1.5; }
.tool textarea {
  font-family: var(--font-mono); font-size: 12px; line-height: 1.5;
  width: 100%; min-height: 62px; resize: vertical; padding: 9px 10px;
  border: 1px solid var(--rule-strong); border-radius: var(--radius);
  background: var(--surface); color: var(--ink);
}
.tool-run-row { display: flex; align-items: center; gap: 9px; }
.tool-out {
  font-family: var(--font-mono); font-size: 11.5px; line-height: 1.55;
  white-space: pre-wrap; overflow-wrap: anywhere; margin: 0;
  max-height: 200px; overflow: auto; padding: 10px 11px;
  border-radius: var(--radius); background: var(--surface-2); color: var(--ink-soft);
}
.tool-out.err { color: var(--delete); }

/* ── Toast ────────────────────────────────────────────────────────────── */
.toast {
  position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%);
  background: var(--ink); color: var(--paper);
  padding: 10px 18px; border-radius: 999px; font-size: 13.5px;
  box-shadow: var(--shadow); z-index: 50; max-width: 90vw;
}
.toast.err { background: var(--delete); }
