/* Trust Diff design system. Tokens first, then base, layout, components. */
:root {
  /* Color: surface */
  --background: #f6f7fb;
  --surface: #ffffff;
  --card: #ffffff;
  --subtle: #f2f4f8;
  --foreground: #0f1729;
  --muted-foreground: #5d667a;
  --border: #e3e6ee;
  --border-strong: #cdd2de;
  /* Color: brand and status */
  --primary: #4338ca;
  --primary-hover: #3730a3;
  --primary-soft: #eef0ff;
  --primary-foreground: #ffffff;
  --success: #166534;
  --success-soft: #e8f7ee;
  --warning: #92400e;
  --warning-soft: #fff4e0;
  --danger: #b42318;
  --danger-soft: #fdecea;
  /* Type */
  --font: ui-sans-serif, -apple-system, "SF Pro Text", "Segoe UI", Inter, system-ui, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, monospace;
  --text-xs: 0.75rem;
  --text-sm: 0.875rem;
  --text-base: 1rem;
  --text-lg: 1.0625rem;
  --text-2xl: 1.375rem;
  /* Space, radius, elevation */
  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.25rem;
  --space-6: 1.5rem;
  --radius-sm: 0.5rem;
  --radius: 0.75rem;
  --radius-pill: 999px;
  --shadow-sm: 0 1px 2px rgb(16 24 40 / 0.06), 0 1px 3px rgb(16 24 40 / 0.04);
  --shadow-md: 0 4px 12px rgb(16 24 40 / 0.08), 0 1px 3px rgb(16 24 40 / 0.05);
  --ring: 0 0 0 3px rgb(67 56 202 / 0.25);
}
@media (prefers-color-scheme: dark) {
  :root {
    --background: #0b0e17;
    --surface: #131826;
    --card: #131826;
    --subtle: #1a2033;
    --foreground: #eef0f6;
    --muted-foreground: #9aa3b8;
    --border: #262d42;
    --border-strong: #38405a;
    --primary: #8b93ff;
    --primary-hover: #a3a9ff;
    --primary-soft: #1d2142;
    --primary-foreground: #0b0e17;
    --success: #6fd08c;
    --success-soft: #11291c;
    --warning: #f0b44c;
    --warning-soft: #2e2210;
    --danger: #ff8a80;
    --danger-soft: #331715;
    --ring: 0 0 0 3px rgb(139 147 255 / 0.35);
  }
}

/* Base */
* { box-sizing: border-box; }
body { margin: 0; font: var(--text-base) / 1.5 var(--font); -webkit-font-smoothing: antialiased; }
h1, h2, h3, p { margin: 0; }
input, button, select { font: inherit; border-radius: var(--radius-sm); }
button { border: 0; cursor: pointer; transition: background 0.15s, box-shadow 0.15s, transform 0.05s, border-color 0.15s; }
button:active:not(:disabled) { transform: translateY(1px); }
button:disabled { opacity: 0.5; cursor: not-allowed; }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; box-shadow: var(--ring); }
[hidden] { display: none !important; }

/* Utilities (the markup uses these names) */
.bg-background { background: var(--background); }
.bg-card { background: var(--card); }
.bg-primary { background: var(--primary); }
.text-foreground { color: var(--foreground); }
.text-primary { color: var(--primary); }
.text-primary-foreground { color: var(--primary-foreground); }
.text-muted-foreground { color: var(--muted-foreground); }
.border { border: 1px solid var(--border); }
.border-b { border-bottom: 1px solid var(--border); }
.border-border { border-color: var(--border); }
.text-sm { font-size: var(--text-sm); }
.text-lg { font-size: var(--text-lg); font-weight: 650; letter-spacing: -0.01em; }
.text-2xl { font-size: var(--text-2xl); font-weight: 700; letter-spacing: -0.02em; }
.p-2 { padding: var(--space-2) var(--space-3); }
.p-4 { padding: var(--space-5); }
.p-6 { padding: var(--space-6); }
.stack { display: grid; gap: var(--space-3); max-width: 44rem; }
.card { border-radius: var(--radius); box-shadow: var(--shadow-sm); }
.outline { background: var(--surface); }

/* App bar */
header.border-b { position: sticky; top: 0; z-index: 5; background: var(--surface); padding: var(--space-4) var(--space-6) 0; }
header h1 { display: flex; align-items: center; gap: var(--space-3); }
header h1::before { content: ""; width: 1.75rem; height: 1.75rem; border-radius: 0.5rem; background: linear-gradient(135deg, var(--primary), #7c6cf6); box-shadow: inset 0 0 0 2px rgb(255 255 255 / 0.35); }
.tabs { display: flex; gap: var(--space-5); margin-top: var(--space-3); }
.tabs [role="tab"] { background: none; color: var(--muted-foreground); padding: var(--space-2) 0 var(--space-3); font-weight: 600; font-size: var(--text-sm); border-radius: 0; }
.tabs [role="tab"]:hover { color: var(--foreground); }
.tabs [aria-selected="true"] { color: var(--primary); box-shadow: inset 0 -2px var(--primary); }
main.p-4 { padding: var(--space-6); }

/* Layout */
.wide { display: grid; gap: var(--space-5); max-width: 72rem; margin: 0 auto; }
.wide .stack { max-width: none; }
#context { max-width: 44rem; margin: 0 auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-sm); padding: var(--space-6); }
#context h2 { margin-top: var(--space-3); }
.layout { display: grid; gap: var(--space-5); grid-template-columns: 3fr 2fr; align-items: start; }
.col { display: grid; gap: var(--space-5); min-width: 0; }
.controls { display: flex; flex-wrap: wrap; gap: var(--space-3); align-items: flex-end; }
.field { display: grid; gap: var(--space-1); }
.field label { font-weight: 600; color: var(--muted-foreground); font-size: var(--text-xs); text-transform: uppercase; letter-spacing: 0.04em; }
.actions { display: flex; flex-wrap: wrap; gap: var(--space-2); }
.plain { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--space-1); }

/* Cards */
.card.bg-card { background: var(--surface); border-color: var(--border); }
.card h2.text-lg { margin-bottom: var(--space-1); }
.note { display: flex; gap: var(--space-2); align-items: center; background: var(--primary-soft); color: var(--foreground); border: 1px solid transparent; border-radius: var(--radius-sm); padding: var(--space-2) var(--space-3); }
.note::before { content: "Demo"; font-size: var(--text-xs); font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; color: var(--primary); background: var(--surface); border-radius: var(--radius-pill); padding: 0.1rem 0.55rem; flex: none; }
.footer { border-top: 1px solid var(--border); }

/* Form controls */
select.border { background: var(--surface); color: var(--foreground); border-color: var(--border-strong); min-width: 14rem; padding: var(--space-2) var(--space-3); box-shadow: var(--shadow-sm); }
select.border:hover { border-color: var(--primary); }
button.bg-primary { background: var(--primary); color: var(--primary-foreground); font-weight: 600; padding: var(--space-2) var(--space-4); box-shadow: var(--shadow-sm); }
button.bg-primary:hover:not(:disabled) { background: var(--primary-hover); }
button.outline { color: var(--foreground); border: 1px solid var(--border-strong); font-weight: 600; padding: var(--space-2) var(--space-4); box-shadow: var(--shadow-sm); }
button.outline:hover:not(:disabled) { background: var(--subtle); }

/* Plan steps */
.step { display: block; border: 1px solid var(--border); border-radius: var(--radius-sm); padding: var(--space-3) var(--space-4); background: var(--surface); box-shadow: var(--shadow-sm); transition: border-color 0.15s, box-shadow 0.15s, background 0.15s; }
.step:hover { border-color: var(--border-strong); box-shadow: var(--shadow-md); }
.step label { display: flex; gap: var(--space-3); align-items: flex-start; cursor: pointer; }
.step input { margin-top: 0.3rem; width: 1.1rem; height: 1.1rem; flex: none; accent-color: var(--primary); }
.badge { display: inline-block; width: fit-content; font-size: var(--text-xs); font-weight: 700; letter-spacing: 0.02em; border-radius: var(--radius-pill); padding: 0.1rem 0.6rem; margin-bottom: var(--space-1); }
.match .badge { color: var(--success); background: var(--success-soft); }
.extra .badge { color: var(--warning); background: var(--warning-soft); }
.danger .badge { color: var(--danger); background: var(--danger-soft); }
.tag, .why { font-size: var(--text-sm); color: var(--muted-foreground); display: block; }
.step.picked { background: var(--primary-soft); border-color: var(--primary); box-shadow: 0 0 0 1px var(--primary), var(--shadow-sm); outline: none; }

/* Chat */
.chat { display: grid; gap: var(--space-3); padding-right: var(--space-1); }
.msg { display: flex; gap: var(--space-3); align-items: flex-start; }
.msg.me { flex-direction: row-reverse; }
.avatar { flex: none; width: 2rem; height: 2rem; border-radius: 50%; display: grid; place-items: center; background: var(--surface); border: 1px solid var(--border); color: var(--foreground); box-shadow: var(--shadow-sm); }
.avatar svg { width: 1.1rem; height: 1.1rem; }
.me .avatar { background: var(--primary); border-color: var(--primary); color: var(--primary-foreground); font-size: var(--text-xs); font-weight: 700; }
.bubble { min-width: 0; flex: 0 1 100%; max-width: 100%; border: 1px solid var(--border); border-radius: var(--radius); background: var(--subtle); padding: var(--space-3) var(--space-4); display: grid; gap: var(--space-2); }
.me .bubble { background: var(--primary); border-color: var(--primary); color: var(--primary-foreground); flex: 0 1 auto; border-bottom-right-radius: 0.25rem; box-shadow: var(--shadow-sm); }
.meta { font-size: var(--text-xs); color: var(--muted-foreground); }
.me .meta { color: var(--primary-foreground); opacity: 0.8; }
.notice { border: 1px solid var(--border); background: var(--surface); border-radius: var(--radius-sm); padding: var(--space-2) var(--space-3); font-size: var(--text-sm); color: var(--foreground); }
.notice::before { content: "System notice: "; font-weight: 700; }
.notice.warn { border-color: var(--warning); background: var(--warning-soft); }
.notice.ok { border-color: var(--success); background: var(--success-soft); }
.dots { display: inline-flex; gap: 0.25rem; align-items: center; }
.dots i { width: 0.5rem; height: 0.5rem; border-radius: 50%; background: var(--muted-foreground); animation: blink 1s infinite; }
.dots i:nth-child(2) { animation-delay: 0.2s; }
.dots i:nth-child(3) { animation-delay: 0.4s; }
@keyframes blink { 0%, 100% { opacity: 0.25; } 50% { opacity: 1; } }
.enter { animation: slide-in 0.35s ease-out; }
@keyframes slide-in { from { opacity: 0; transform: translateY(0.5rem); } to { opacity: 1; transform: none; } }
.pulse { animation: pulse 0.7s ease-out; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 var(--primary); } 100% { box-shadow: 0 0 0 0.6rem transparent; } }

/* Live panel */
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-2); }
.stats > * { background: var(--subtle); border-radius: var(--radius-sm); padding: var(--space-2) var(--space-3); font-weight: 600; }
.card h3.text-sm { margin-top: var(--space-2); font-size: var(--text-xs); text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted-foreground); font-weight: 700; }
.state { display: flex; justify-content: space-between; gap: var(--space-2); padding: var(--space-2) var(--space-3); border-radius: var(--radius-sm); background: var(--subtle); }
.state.changed { font-weight: 600; background: var(--primary-soft); box-shadow: inset 3px 0 var(--primary); }
.state.changed span:last-child { color: var(--primary); }
.sign { font-family: var(--mono); font-weight: 700; }
.mono { font-family: var(--mono); font-size: var(--text-xs); white-space: pre-wrap; overflow-wrap: anywhere; margin: 0; background: var(--subtle); border-radius: var(--radius-sm); padding: var(--space-3); }
.live-note { font-weight: 700; }
.logo { width: 1.1rem; height: 1.1rem; vertical-align: -0.2rem; }
.sr-hide { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.line { display: block; margin-bottom: var(--space-2); }
table { border-collapse: collapse; width: 100%; }
caption { text-align: start; padding-bottom: var(--space-2); }
th, td { text-align: start; padding: var(--space-2); border-bottom: 1px solid var(--border); }
tfoot { font-weight: 600; }
ol, ul { padding-left: 1.25rem; }

/* Diagram */
.diagram { width: 100%; max-width: 32rem; height: auto; color: var(--foreground); }
.diagram.wide-d { max-width: 100%; }
.node rect { fill: var(--surface); stroke: var(--border-strong); stroke-width: 1.5; transition: stroke 0.3s, stroke-width 0.3s; }
.node.on rect { stroke: var(--primary); stroke-width: 3; fill: var(--primary-soft); }
.node.done rect { stroke: var(--success); stroke-width: 2.5; fill: var(--success-soft); }
.node text { fill: currentColor; font-size: 12px; text-anchor: middle; }
.link { stroke: currentColor; stroke-width: 1.5; fill: none; opacity: 0.3; transition: opacity 0.3s; }
.link.on { opacity: 1; stroke: var(--primary); stroke-width: 3; }
.stage { min-height: 2.5rem; }
.panels { display: grid; gap: var(--space-4); grid-template-columns: 1fr 1fr; }

@media (max-width: 52rem) { .layout { grid-template-columns: 1fr; } }
@media (max-width: 40rem) { .panels { grid-template-columns: 1fr; } header.border-b, main.p-4 { padding-inline: var(--space-4); } }
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; scroll-behavior: auto !important; }
}
