/* CiteVibe UI. Built to cognitive-accessibility principles:
   one task per screen, plain words, predictable layout, nothing moves unless asked,
   every control reachable by keyboard with a visible focus ring, and user-set
   comfort settings (calm theme, larger text, wider spacing) that persist. */

:root {
  --ink: #0B0B0E;
  --surface: #15151B;
  --surface-2: #1E1E27;
  --line: #2E2E3A;
  --text: #F5F5F7;
  --text-2: #B8B8C4;
  --purple: #7C3AED;
  --magenta: #D946EF;
  --amber: #F5A524;
  --focus: #F5A524;
  --ok: #34D399;
  --warn: #F5A524;
  --bad: #F87171;
  --radius: 12px;
  --size: 17px;
  --leading: 1.6;
  --space: 1;
  --measure: 62ch;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, Inter, sans-serif;
}

/* Calm theme: light, lower contrast, less visual noise. Chosen by the person, remembered. */
:root[data-theme="calm"] {
  --ink: #F6F3EE;
  --surface: #FFFFFF;
  --surface-2: #F0ECE4;
  --line: #D9D3C7;
  --text: #1F1B2E;
  --text-2: #5C5670;
  --focus: #7C3AED;
}
:root[data-text="large"] { --size: 20px; }
:root[data-spacing="wide"] { --leading: 1.9; --space: 1.4; letter-spacing: 0.02em; word-spacing: 0.08em; }

* { box-sizing: border-box; }
html { font-size: var(--size); }
body {
  margin: 0; background: var(--ink); color: var(--text);
  font-family: var(--font); line-height: var(--leading);
}
/* Nothing animates unless the person has not asked for reduced motion, and even then only briefly. */
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }

/* Keyboard focus is always visible and high contrast. */
:focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; border-radius: 6px; }
.skip { position: absolute; left: -999px; top: 8px; background: var(--amber); color: #000; padding: 8px 12px; border-radius: 8px; z-index: 10; }
.skip:focus { left: 8px; }

.wrap { max-width: 72rem; margin: 0 auto; padding: calc(16px * var(--space)) 16px; }
.narrow { max-width: var(--measure); }
header.top { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 12px 0; }
.brand { display: inline-flex; align-items: center; gap: 10px; font-weight: 700; text-decoration: none; color: var(--text); }
.brand img { width: 40px; height: 40px; }
[data-chip] svg { width: 100%; height: 100%; display: block; }
.brand .vibe { color: var(--magenta); }

h1, h2 { line-height: 1.2; margin: 0 0 calc(12px * var(--space)); }
h1 { font-size: 1.9rem; } h2 { font-size: 1.3rem; }
p { margin: 0 0 calc(14px * var(--space)); max-width: var(--measure); }
.muted { color: var(--text-2); }

label { display: block; font-weight: 600; margin-bottom: 6px; }
input, textarea, select, button { font: inherit; }
input, textarea, select {
  width: 100%; padding: 12px 14px; border-radius: var(--radius);
  border: 2px solid var(--line); background: var(--surface); color: var(--text);
}
input:hover, textarea:hover { border-color: var(--text-2); }
textarea { min-height: 6rem; resize: vertical; }
.hint { color: var(--text-2); font-size: 0.92rem; margin-top: 4px; }

button, .btn {
  display: inline-flex; align-items: center; gap: 8px; min-height: 48px; padding: 10px 20px;
  border-radius: var(--radius); border: 2px solid transparent; cursor: pointer; font-weight: 600;
  background: var(--purple); color: #fff; text-decoration: none;
}
button:hover, .btn:hover { filter: brightness(1.12); }
button.quiet { background: var(--surface-2); color: var(--text); border-color: var(--line); }
button:disabled { opacity: 0.55; cursor: not-allowed; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: calc(20px * var(--space)); }
.stack > * + * { margin-top: calc(16px * var(--space)); }
.row { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; }

/* Status messages are announced to screen readers and never rely on colour alone. */
.notice { border-left: 5px solid var(--purple); padding: 12px 14px; background: var(--surface-2); border-radius: 8px; }
.notice.ok { border-color: var(--ok); } .notice.warn { border-color: var(--warn); } .notice.bad { border-color: var(--bad); }

/* Budget meter: a labelled bar plus the number, so it works without colour and at a glance. */
.meter { height: 12px; background: var(--surface-2); border-radius: 999px; overflow: hidden; border: 1px solid var(--line); }
.meter > span { display: block; height: 100%; background: var(--purple); }
.meter.warn > span { background: var(--warn); } .meter.bad > span { background: var(--bad); }

/* Studio: two panes on wide screens, stacked on phones. The chat is always first in reading order. */
.studio { display: grid; gap: 16px; grid-template-columns: 1fr; }
@media (min-width: 900px) { .studio { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); } }
.chat { display: flex; flex-direction: column; min-height: 60vh; }
.messages { flex: 1; overflow: auto; display: flex; flex-direction: column; gap: 12px; padding-bottom: 8px; }
.msg { padding: 12px 14px; border-radius: 14px; max-width: 95%; white-space: pre-wrap; }
.msg.me { background: var(--surface-2); align-self: flex-end; }
.msg.chip { background: var(--surface); border: 1px solid var(--line); align-self: flex-start; }
.msg.chip::before { content: "Chip"; display: block; font-weight: 700; color: var(--magenta); font-size: 0.85rem; margin-bottom: 4px; }
.preview { background: #fff; border-radius: 16px; min-height: 60vh; border: 1px solid var(--line); overflow: hidden; }
.preview iframe { width: 100%; height: 100%; min-height: 60vh; border: 0; }

/* Comfort settings panel */
details.comfort summary { cursor: pointer; font-weight: 600; min-height: 44px; display: flex; align-items: center; }
fieldset { border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 16px; margin: 0; }
legend { padding: 0 6px; font-weight: 600; }
.choice { display: flex; gap: 10px; align-items: center; min-height: 44px; }
.choice input { width: 22px; height: 22px; }

/* Admin tables: plain rows, generous padding, scroll sideways on phones rather than squashing. */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 12px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
thead th { color: var(--text-2); font-weight: 600; font-size: 0.92rem; }
tbody th { font-weight: 600; }

.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
