/* AIvisible - design system for the web app.
   Tokens first; components below use only tokens. Dark mode follows the OS unless the
   viewer picks a theme (data-theme on <html>). Chart colours (--s1..--s8) match the
   validated dashboard palette and are only used for data. */

:root {
  color-scheme: light;
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f9fafb;
  --border: #e5e7eb;
  --border-strong: #d1d5db;
  --text: #0f172a;
  --text2: #475569;
  --muted: #64748b;
  --brand: #4338ca;
  --brand-hover: #3730a3;
  --brand-soft: #eef2ff;
  --brand-line: #c7d2fe;
  --brand-ink: #ffffff;
  --up: #15803d;
  --up-soft: #ecfdf3;
  --down: #b91c1c;
  --down-soft: #fef2f2;
  --warn: #b45309;
  --warn-soft: #fffbeb;
  --warn-line: #fcd34d;
  --infobg: var(--brand-soft);
  --infobd: var(--brand-line);
  --warnbg: var(--warn-soft);
  --warnbd: var(--warn-line);
  --grid: #eef0f3;
  --other: #a9a8a2;
  --heat: 42, 120, 214;
  --s1: #2a78d6; --s2: #eb6834; --s3: #1baf7a; --s4: #eda100;
  --s5: #e87ba4; --s6: #008300; --s7: #4a3aa7; --s8: #e34948;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, .05);
  --shadow: 0 1px 3px rgba(15, 23, 42, .08), 0 1px 2px rgba(15, 23, 42, .04);
  --shadow-lg: 0 12px 32px rgba(15, 23, 42, .10);
  --font: "Inter", "InterVariable", system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Code", Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0b1020; --surface: #111827; --surface-2: #0f172a; --border: #1f2937; --border-strong: #374151;
    --text: #e5e7eb; --text2: #a3adbd; --muted: #8b95a5;
    --brand: #818cf8; --brand-hover: #a5b4fc; --brand-soft: #1e1b4b; --brand-line: #3730a3; --brand-ink: #0b1020;
    --up: #4ade80; --up-soft: #052e16; --down: #f87171; --down-soft: #450a0a;
    --warn: #fbbf24; --warn-soft: #2a1f05; --warn-line: #78350f;
    --grid: #1f2937; --other: #6b6a64; --heat: 57, 135, 229;
    --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500; --s5: #d55181; --s6: #008300; --s7: #9085e9; --s8: #e66767;
    --shadow-sm: none; --shadow: 0 1px 2px rgba(0, 0, 0, .4); --shadow-lg: 0 12px 32px rgba(0, 0, 0, .5);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0b1020; --surface: #111827; --surface-2: #0f172a; --border: #1f2937; --border-strong: #374151;
  --text: #e5e7eb; --text2: #a3adbd; --muted: #8b95a5;
  --brand: #818cf8; --brand-hover: #a5b4fc; --brand-soft: #1e1b4b; --brand-line: #3730a3; --brand-ink: #0b1020;
  --up: #4ade80; --up-soft: #052e16; --down: #f87171; --down-soft: #450a0a;
  --warn: #fbbf24; --warn-soft: #2a1f05; --warn-line: #78350f;
  --grid: #1f2937; --other: #6b6a64; --heat: 57, 135, 229;
  --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500; --s5: #d55181; --s6: #008300; --s7: #9085e9; --s8: #e66767;
  --shadow-sm: none; --shadow: 0 1px 2px rgba(0, 0, 0, .4); --shadow-lg: 0 12px 32px rgba(0, 0, 0, .5);
}

/* ---- base ---------------------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.55 var(--font);
  font-feature-settings: "cv11", "ss01"; -webkit-font-smoothing: antialiased; }
a { color: var(--brand); text-decoration: none; }
a:hover { color: var(--brand-hover); text-decoration: underline; text-underline-offset: 3px; }
h1 { font-size: 26px; line-height: 1.25; letter-spacing: -.02em; font-weight: 700; margin: 0 0 6px; }
h2 { font-size: 17px; letter-spacing: -.01em; font-weight: 650; margin: 36px 0 12px; }
h3 { font-size: 14px; font-weight: 600; margin: 0 0 10px; color: var(--text); }
p { margin: 0 0 10px; }
code { font: 13px var(--mono); background: var(--surface-2); border: 1px solid var(--border); padding: 1px 5px; border-radius: 5px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.hidden { display: none; }
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }

/* ---- app shell ----------------------------------------------------------------- */
.app-header { position: sticky; top: 0; z-index: 20; background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: saturate(180%) blur(8px); border-bottom: 1px solid var(--border); }
.app-header .inner { max-width: 1160px; margin: 0 auto; padding: 0 20px; height: 60px; display: flex; align-items: center; gap: 28px; }
.logo { display: inline-flex; align-items: center; gap: 9px; color: var(--text); }
.logo:hover { text-decoration: none; color: var(--text); }
.logo .wordmark { font-size: 20px; font-weight: 650; letter-spacing: -.035em; line-height: 1; }
.logo .ai { color: var(--brand); }
.logo .mark { flex: none; }
.mk-bg { fill: #4338ca; } .mk-dot { fill: #fff; }
.mk-arc, .mk-arc2 { fill: none; stroke-width: 2.4; stroke-linecap: round; } .mk-arc { stroke: #fff; } .mk-arc2 { stroke: #a5b4fc; }
.nav-links { display: flex; gap: 4px; flex: 1; }
.nav-links a { color: var(--text2); font-size: 14px; font-weight: 500; padding: 6px 10px; border-radius: var(--radius-sm); }
.nav-links a:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.nav-links a.on { color: var(--text); background: var(--surface-2); }
.user-menu { display: flex; align-items: center; gap: 12px; font-size: 13px; color: var(--muted); }
.user-menu form { margin: 0; }
.container { max-width: 1160px; margin: 0 auto; padding: 32px 20px 72px; }
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; margin-bottom: 8px; }
.page-head p { color: var(--text2); margin: 0; }
.crumb { font-size: 13px; margin-bottom: 10px; display: inline-block; color: var(--muted); }
.app-footer { max-width: 1160px; margin: 0 auto; padding: 24px 20px 40px; border-top: 1px solid var(--border);
  font-size: 13px; color: var(--muted); display: flex; gap: 16px; flex-wrap: wrap; }
.app-footer a { color: var(--muted); }

/* ---- buttons ------------------------------------------------------------------- */
button, .btn { font: 500 14px/1 var(--font); display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 38px; padding: 0 14px; border-radius: var(--radius-sm); border: 1px solid var(--border-strong);
  background: var(--surface); color: var(--text); cursor: pointer; text-decoration: none; white-space: nowrap;
  box-shadow: var(--shadow-sm); transition: background .12s, border-color .12s, box-shadow .12s; }
button:hover, .btn:hover { background: var(--surface-2); border-color: var(--muted); text-decoration: none; color: var(--text); }
button.primary, .btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); font-weight: 600; }
button.primary:hover, .btn.primary:hover { background: var(--brand-hover); border-color: var(--brand-hover); color: var(--brand-ink); }
button.ghost, .btn.ghost { background: transparent; border-color: transparent; box-shadow: none; color: var(--text2); }
button.ghost:hover, .btn.ghost:hover { background: var(--surface-2); }
button.sm, .btn.sm { height: 30px; padding: 0 10px; font-size: 13px; }
button.lg, .btn.lg { height: 44px; padding: 0 20px; font-size: 15px; }
button:disabled, .btn[aria-disabled="true"] { opacity: .45; cursor: not-allowed; box-shadow: none; }

/* ---- forms --------------------------------------------------------------------- */
input, select, textarea { font: 14px var(--font); color: var(--text); background: var(--surface);
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm); padding: 8px 10px; min-height: 38px;
  transition: border-color .12s, box-shadow .12s; max-width: 100%; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
input[type=checkbox], input[type=radio] { min-height: 0; width: 16px; height: 16px; accent-color: var(--brand); margin: 0; vertical-align: -3px; }
input[type=file] { padding: 6px; background: var(--surface-2); }
textarea { width: 100%; min-height: 96px; line-height: 1.45; resize: vertical; }
label { display: block; font-size: 13px; font-weight: 500; color: var(--text2); margin: 14px 0 6px; }
label:has(> input[type=checkbox]), label:has(> input[type=radio]) { display: inline-flex; align-items: center; gap: 8px; font-weight: 400; color: var(--text); }
.field-help { font-size: 12.5px; color: var(--muted); margin-top: 6px; }
.choice { display: flex; gap: 10px; align-items: flex-start; padding: 12px 14px; border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm); background: var(--surface); cursor: pointer; margin: 0; }
.choice:has(input:checked) { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.chips-input { display: flex; flex-wrap: wrap; gap: 8px; }
.chips-input label { margin: 0; padding: 7px 12px; border: 1px solid var(--border-strong); border-radius: 999px; background: var(--surface); cursor: pointer; font-size: 14px; }
.chips-input label:has(input:checked) { border-color: var(--brand); background: var(--brand-soft); color: var(--text); }

/* ---- surfaces ------------------------------------------------------------------ */
.panel, .card, .tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-sm); }
.panel { padding: 20px; }
.card { padding: 18px 20px; }
a.card:hover { border-color: var(--brand-line); box-shadow: var(--shadow); text-decoration: none; }
.row { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 16px; }
.grid-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(290px, 1fr)); gap: 16px; }
.two { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 16px; }
.actions { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.actions form { margin: 0; }
.stack > * + * { margin-top: 12px; }

/* KPI tiles */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; margin-top: 16px; }
.tile { padding: 18px 20px; }
.tile-label { font-size: 12.5px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.tile-value { font-size: 30px; font-weight: 700; letter-spacing: -.02em; margin: 6px 0 2px; font-variant-numeric: tabular-nums; }
.tile-value small { font-size: 14px; font-weight: 500; color: var(--muted); margin-left: 2px; }
.tile-help { font-size: 13px; color: var(--text2); margin-top: 6px; line-height: 1.5; }

/* Steps on the workspace page */
.step { display: grid; grid-template-columns: 34px 1fr; gap: 0 14px; margin-top: 30px; }
.step-n { width: 30px; height: 30px; border-radius: 50%; background: var(--brand-soft); color: var(--brand);
  font-weight: 700; font-size: 14px; display: grid; place-items: center; border: 1px solid var(--brand-line); margin-top: 2px; }
.step.done .step-n { background: var(--up-soft); color: var(--up); border-color: transparent; }
.step-title { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; font-size: 17px; font-weight: 650; margin: 4px 0 12px; }
.step-body { grid-column: 2; }

/* ---- tables -------------------------------------------------------------------- */
.scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
.rank th, table th { text-align: left; font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase;
  letter-spacing: .04em; padding: 10px 12px; border-bottom: 1px solid var(--border); background: var(--surface-2); }
.rank th.num, table th.num { text-align: right; }
.rank td, table td { padding: 11px 12px; border-bottom: 1px solid var(--grid); vertical-align: middle; }
.rank tbody tr:hover td { background: var(--surface-2); }
.rank tr:last-child td { border-bottom: 0; }
.panel > table, .panel > .scroll > table { margin: -4px 0; }
.table-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow-sm); }
.table-card th:first-child, .table-card td:first-child { padding-left: 18px; }
.table-card th:last-child, .table-card td:last-child { padding-right: 18px; }

/* bars (brands, citations) */
.hrow, .barcell { display: flex; align-items: center; gap: 10px; }
.hrow { margin: 8px 0; }
.hname { width: 130px; flex: none; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 14px; }
.track { flex: 1; height: 10px; background: var(--grid); border-radius: 5px; overflow: hidden; }
.fill { height: 100%; border-radius: 0 5px 5px 0; min-width: 2px; }
.val { min-width: 52px; text-align: right; font-variant-numeric: tabular-nums; font-size: 14px; }
.sw { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 8px; }

/* ---- badges & messages --------------------------------------------------------- */
.pill { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; font-weight: 600; line-height: 1;
  padding: 5px 9px; border-radius: 999px; background: var(--surface-2); color: var(--text2); border: 1px solid var(--border); }
.pill.st-done { background: var(--up-soft); color: var(--up); border-color: transparent; }
.pill.st-failed { background: var(--down-soft); color: var(--down); border-color: transparent; }
.pill.st-queued, .pill.st-running { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.pill.brand { background: var(--brand-soft); color: var(--brand); border-color: transparent; }
td.st-done { color: var(--up); font-weight: 600; } td.st-failed { color: var(--down); font-weight: 600; }
td.st-queued, td.st-running { color: var(--warn); font-weight: 600; }
.flash { border: 1px solid var(--brand-line); background: var(--brand-soft); color: var(--text); border-radius: var(--radius-sm);
  padding: 11px 14px; margin: 0 0 18px; font-size: 14px; display: flex; gap: 10px; align-items: flex-start; }
.flash.err { border-color: var(--warn-line); background: var(--warn-soft); }
.banner { border: 1px solid var(--brand-line); background: var(--brand-soft); border-radius: var(--radius-sm); padding: 11px 14px; font-size: 14px; }
.spinner { width: 14px; height: 14px; border: 2px solid var(--brand-line); border-top-color: var(--brand); border-radius: 50%;
  animation: spin .8s linear infinite; flex: none; margin-top: 3px; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation: none; } }

/* ---- auth / onboarding --------------------------------------------------------- */
.auth { min-height: 100vh; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
.auth-brand { background: radial-gradient(1200px 600px at -10% -20%, #6366f1 0%, #4338ca 45%, #1e1b4b 100%);
  color: #eef2ff; padding: 48px 56px; display: flex; flex-direction: column; justify-content: space-between; }
.auth-brand .logo { color: #fff; }
.auth-brand .logo .ai { color: #c7d2fe; }
.auth-brand .mk-bg { fill: #fff; } .auth-brand .mk-dot { fill: #4338ca; }
.auth-brand .mk-arc { stroke: #4338ca; } .auth-brand .mk-arc2 { stroke: #818cf8; }
.auth-brand h2 { font-size: 30px; line-height: 1.2; letter-spacing: -.02em; color: #fff; margin: 0 0 16px; max-width: 460px; }
.auth-brand ul { list-style: none; padding: 0; margin: 24px 0 0; display: grid; gap: 12px; max-width: 440px; }
.auth-brand li { display: flex; gap: 10px; color: #c7d2fe; }
.auth-brand li::before { content: ""; width: 18px; height: 18px; flex: none; margin-top: 3px; border-radius: 50%;
  background: rgba(255, 255, 255, .15) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M4 8.5l2.5 2.5L12 5.5' fill='none' stroke='white' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center/12px no-repeat; }
.auth-brand .fine { font-size: 13px; color: #a5b4fc; }
.auth-form { display: flex; align-items: center; justify-content: center; padding: 48px 24px; }
.auth-form .box { width: 100%; max-width: 400px; }
.auth-form h1 { font-size: 24px; }
.auth-form input[type=email] { width: 100%; height: 44px; font-size: 15px; }
.onboard { max-width: 820px; margin: 0 auto; }
.stepper { display: flex; gap: 8px; margin-bottom: 24px; flex-wrap: wrap; }
.stepper span { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 500; color: var(--muted); }
.stepper span::before { content: attr(data-n); width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center;
  font-size: 12px; font-weight: 700; background: var(--surface); border: 1px solid var(--border-strong); color: var(--muted); }
.stepper span.on { color: var(--text); }
.stepper span.on::before { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.stepper span.done::before { background: var(--up-soft); border-color: transparent; color: var(--up); }
.stepper i { flex: 0 0 28px; height: 1px; background: var(--border-strong); align-self: center; }
.estimate { background: linear-gradient(180deg, var(--brand-soft), var(--surface)); border: 1px solid var(--brand-line);
  border-radius: var(--radius); padding: 20px; margin-top: 20px; }

/* workspace status line on the workspace list */
.ws-status { display: flex; align-items: center; gap: 8px; font-size: 13.5px; font-weight: 500; color: var(--text2); }
.ws-status .spinner { margin-top: 0; }
.ws-status .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); flex: none; }
.ws-status.busy { color: var(--brand); }
.ws-status.action { color: var(--warn); } .ws-status.action .dot { background: var(--warn); }
.ws-status.ok .dot { background: var(--up); }
.ws-status.error { color: var(--down); } .ws-status.error .dot { background: var(--down); }

/* ---- empty states & misc --------------------------------------------------------- */
.empty { text-align: center; padding: 40px 20px; color: var(--muted); }
.empty h3 { color: var(--text); font-size: 16px; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; font-size: 14px; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; }
#tip { position: fixed; pointer-events: none; background: var(--text); color: var(--bg); font-size: 12px; padding: 5px 8px;
  border-radius: 6px; opacity: 0; transition: opacity .1s; z-index: 30; max-width: 260px; }

@media (max-width: 860px) {
  .auth { grid-template-columns: 1fr; }
  .auth-brand { padding: 32px 24px; }
  .auth-brand ul, .auth-brand .fine { display: none; }
  .app-header .inner { gap: 14px; }
  .user-menu .email { display: none; }
  .step { grid-template-columns: 1fr; }
  .step-n { display: none; }
  .step-body { grid-column: 1; }
}
@media (max-width: 600px) {
  .container { padding: 22px 16px 56px; }
  /* Two rows: logo + log out on top, section links below (scrollable if needed). */
  .app-header .inner { flex-wrap: wrap; height: auto; padding: 10px 16px 6px; gap: 6px 12px; }
  .user-menu { margin-left: auto; }
  .nav-links { order: 3; flex-basis: 100%; overflow-x: auto; margin: 0 -6px; }
  .nav-links a { padding: 6px 8px; flex: none; }
  h1 { font-size: 22px; }
  .tile-value { font-size: 26px; }
}

/* ---- admin tabs ------------------------------------------------------------------ */
.tabs { display: flex; gap: 4px; flex-wrap: wrap; border-bottom: 1px solid var(--border); margin: 8px 0 24px; }
.tabs a { padding: 9px 14px; color: var(--text2); text-decoration: none; font-weight: 600; font-size: 14px;
  border-bottom: 2px solid transparent; margin-bottom: -1px; display: inline-flex; gap: 6px; align-items: center; }
.tabs a:hover { color: var(--text); }
.tabs a.on { color: var(--brand); border-bottom-color: var(--brand); }
.alerts { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; }
.alerts li { padding: 10px 14px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface); font-size: 14px; }
.alerts li.error { border-color: transparent; background: var(--down-soft); }
.alerts li.warn { border-color: transparent; background: var(--warn-soft); }
.alerts a { color: inherit; }

/* Two-option choice with an explanation under each (Settings: how we check AI answers) */
.choices { display: grid; gap: 8px; }
.choice-row { display: flex; gap: 10px; align-items: flex-start; margin: 0; padding: 10px 12px; border: 1px solid var(--border-strong);
  border-radius: 10px; background: var(--surface); cursor: pointer; font-weight: 400; }
.choice-row input { margin-top: 3px; }
.choice-row:has(input:checked) { border-color: var(--brand); background: var(--brand-soft); }
