/* ──────────────────────────────────────────────────────────────────────────
   Fluency Hub — shared design system.

   One stylesheet for every server-rendered page and the tokens the Svelte apps
   read. Apps add only what is theirs (oracle/_styles.html, assist/_styles.html,
   planner.css); buttons, fields, flashes, tables, tags and panels live here.

   The look: a data desk, not a dashboard template. Cool paper and ink, one
   petrol accent, hairline rules instead of floating cards, tight corners,
   Schibsted Grotesk for words and JetBrains Mono for data, ids and labels.
   ────────────────────────────────────────────────────────────────────────── */

:root {
    color-scheme: light dark;

    --font-sans: "Schibsted Grotesk", "Helvetica Neue", Arial, sans-serif;
    --font-mono: "JetBrains Mono", ui-monospace, "SF Mono", Consolas, monospace;

    /* Surfaces and ink */
    --bg: light-dark(#f2f3ef, #0e1110);
    --card: light-dark(#ffffff, #151917);
    --card-hover: light-dark(#f7f8f5, #1b201d);
    --subtle: light-dark(#e8eae4, #212723);
    --border: light-dark(#d9dcd4, #2b322e);
    --rule-strong: light-dark(#141816, #e6eae4);
    --fg: light-dark(#141816, #e6eae4);
    --muted: light-dark(#5d635e, #9aa29c);

    /* One accent. Dark enough to carry white text in both schemes (the
       planner puts white on it); --link is the readable-as-text variant. */
    --accent: light-dark(#0e6470, #1a7f8c);
    --accent-soft: light-dark(#dcecee, #12343a);
    --link: light-dark(#0e6470, #6cc9d4);
    /* A highlighter, for selection and "you are here" marks only. */
    --signal: light-dark(#d9f25c, #c6e04a);

    --primary: light-dark(#141816, #e6eae4);
    --on-primary: light-dark(#f2f3ef, #0e1110);

    --danger: light-dark(#b42318, #d64538);
    --ok: light-dark(#16714a, #43c08a);
    --warn: light-dark(#8a5a00, #e0a52a);

    /* Verdict and score scale, shared by the Oracle and anything that rates. */
    --v-high: light-dark(#16714a, #5fd39c);
    --v-high-bg: light-dark(#dcefe4, #143224);
    --v-mid: light-dark(#8a5a00, #e8b44a);
    --v-mid-bg: light-dark(#f6ebcf, #3a2d10);
    --v-low: light-dark(#b42318, #ff8a7e);
    --v-low-bg: light-dark(#f7ded9, #3f1d19);
    --v-none: light-dark(#5d635e, #9aa29c);
    --v-none-bg: light-dark(#e8eae4, #212723);

    --radius: 4px;
    --radius-sm: 3px;
    /* Popovers only — content sits on rules, not shadows. */
    --shadow: 0 1px 0 light-dark(rgba(20, 24, 22, 0.04), rgba(0, 0, 0, 0.3)),
        0 14px 36px -12px light-dark(rgba(20, 24, 22, 0.28), rgba(0, 0, 0, 0.7));

    --page: 72rem;
    --gutter: clamp(1rem, 3vw, 2rem);
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }
body {
    margin: 0;
    font-family: var(--font-sans);
    font-size: 15px;
    line-height: 1.55;
    background: var(--bg);
    color: var(--fg);
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
}
/* Tabular figures only where numbers line up — in this face they also make
   commas and full stops fixed-width, which looks wrong in running text. */
.num, .stat-value, code, .mono { font-variant-numeric: tabular-nums; }
::selection { background: var(--signal); color: #141816; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

a { color: var(--link); text-decoration-thickness: 1px; text-underline-offset: 0.18em; }
a:hover { text-decoration-thickness: 2px; }
h1, h2, h3, h4 { line-height: 1.2; letter-spacing: -0.012em; }
code, kbd, samp, .mono { font-family: var(--font-mono); font-size: 0.86em; }
code {
    background: var(--subtle); padding: 0.08rem 0.32rem; border-radius: var(--radius-sm);
}
hr { border: 0; border-top: 1px solid var(--border); margin: 2rem 0; }

main { max-width: var(--page); margin: 0 auto; padding: 2.75rem var(--gutter) 4rem; }
body.wide main { max-width: none; padding: 1rem var(--gutter) 2rem; }

/* ── Top bar ───────────────────────────────────────────────────────────── */

header.site {
    position: sticky; top: 0; z-index: 30;
    display: flex; justify-content: space-between; align-items: center; gap: 1.5rem;
    min-height: 3.5rem;
    padding: 0 max(var(--gutter), calc((100vw - var(--page)) / 2 + var(--gutter)));
    background: color-mix(in srgb, var(--bg) 88%, transparent);
    backdrop-filter: saturate(1.4) blur(10px);
    border-bottom: 1px solid var(--border);
}
body.wide header.site { padding: 0 var(--gutter); }
header.site form { display: inline; margin: 0; }

.nav { display: flex; align-items: center; gap: 2rem; min-width: 0; }
.nav-brand {
    display: inline-flex; align-items: center; gap: 0.55rem;
    color: var(--fg); text-decoration: none; white-space: nowrap;
    font-weight: 700; font-size: 1rem; letter-spacing: -0.02em;
}
/* The mark: a split square — ink over accent. */
.nav-brand::before {
    content: ""; width: 0.95rem; height: 0.95rem; flex: none;
    background: linear-gradient(to bottom, var(--fg) 0 50%, var(--accent) 50% 100%);
    border-radius: 2px;
}
.nav-brand .nav-brand-sub {
    font-family: var(--font-mono); font-weight: 400; font-size: 0.78rem;
    color: var(--muted); letter-spacing: 0;
}

.nav-menus { display: flex; align-items: center; gap: 0.15rem; list-style: none; margin: 0; padding: 0; }
.nav-menu { position: relative; }
.nav-menu > summary {
    list-style: none; cursor: pointer; user-select: none;
    padding: 0.4rem 0.65rem; border-radius: var(--radius-sm);
    font-size: 0.9rem; font-weight: 500; color: var(--muted);
}
.nav-menu > summary::-webkit-details-marker { display: none; }
.nav-menu > summary::after {
    content: ""; display: inline-block; width: 0.38rem; height: 0.38rem; margin-left: 0.45rem;
    border-right: 1.5px solid currentColor; border-bottom: 1.5px solid currentColor;
    transform: translateY(-0.2em) rotate(45deg); opacity: 0.7;
}
.nav-menu > summary:hover, .nav-menu[open] > summary { color: var(--fg); background: var(--subtle); }

.nav-dropdown {
    position: absolute; z-index: 40; top: calc(100% + 0.5rem); left: 0;
    min-width: 18rem; padding: 0.35rem; margin: 0; list-style: none;
    border-radius: var(--radius); border: 1px solid var(--border);
    background: var(--card); box-shadow: var(--shadow);
}
.nav-dropdown a, .nav-dropdown .nav-item-off {
    display: block; padding: 0.55rem 0.65rem; border-radius: var(--radius-sm);
    color: inherit; text-decoration: none;
}
.nav-dropdown a:hover { background: var(--card-hover); }
.nav-dropdown a:hover .nav-item-name { color: var(--link); }
.nav-item-name { display: block; font-size: 0.9rem; font-weight: 600; }
.nav-item-desc { display: block; font-size: 0.8rem; color: var(--muted); margin-top: 0.1rem; }
.nav-item-off { opacity: 0.5; cursor: default; }
.nav-soon {
    font-style: normal; font-family: var(--font-mono); font-size: 0.66rem; font-weight: 400;
    margin-left: 0.45rem; padding: 0.02rem 0.3rem; border-radius: 2px; border: 1px dashed currentColor;
}

.nav-account { display: flex; align-items: center; gap: 0.25rem; white-space: nowrap; }
.nav-account a, .nav-account button {
    display: inline-block; padding: 0.4rem 0.65rem; border-radius: var(--radius-sm);
    color: var(--muted); text-decoration: none; font: inherit; font-size: 0.88rem; font-weight: 500;
    background: none; border: 0; cursor: pointer;
}
.nav-account a:hover, .nav-account button:hover { color: var(--fg); background: var(--subtle); }
.nav-user {
    font-family: var(--font-mono); font-size: 0.75rem; color: var(--muted);
    padding-right: 0.6rem; margin-right: 0.35rem; border-right: 1px solid var(--border);
}

/* ── Page furniture ────────────────────────────────────────────────────── */

.crumb, .eyebrow {
    margin: 0 0 0.9rem; font-family: var(--font-mono); font-size: 0.75rem; color: var(--muted);
    letter-spacing: 0;
}
.crumb a { color: inherit; text-decoration: none; }
.crumb a:hover { color: var(--fg); text-decoration: underline; }
.page-title { font-size: clamp(1.7rem, 3vw, 2.25rem); font-weight: 700; margin: 0; letter-spacing: -0.03em; line-height: 1.1; }
.page-intro { margin: 0.65rem 0 2rem; color: var(--muted); max-width: 44rem; font-size: 1.02rem; }
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 1rem 1.5rem; flex-wrap: wrap; margin-bottom: 2.25rem; }
.page-head .page-intro { margin-bottom: 0; }
/* An intro written after the head (not inside it) takes over the spacing. */
.page-head:has(+ .page-intro) { margin-bottom: 0; }
.actions { display: flex; gap: 0.5rem; flex-wrap: wrap; align-items: center; }
.actions form { display: inline; margin: 0; }
.row { display: flex; gap: 0.6rem; flex-wrap: wrap; align-items: center; }
.row form { display: inline; margin: 0; }

.muted { color: var(--muted); }
.note { color: var(--muted); font-size: 0.86rem; }
.optional { font-weight: 400; color: var(--muted); font-size: 0.78rem; margin-left: 0.35rem; font-family: var(--font-mono); }

.section-label {
    display: flex; align-items: baseline; gap: 0.6rem; margin: 0 0 1rem;
    font-family: var(--font-mono); font-size: 0.75rem; font-weight: 500; color: var(--muted);
}
.section-label::after { content: ""; flex: 1; border-top: 1px solid var(--border); transform: translateY(-0.2em); }

.block { padding: 1.5rem 0 0; margin-top: 2rem; border-top: 1px solid var(--border); }
.block h2 { font-family: var(--font-mono); font-size: 0.75rem; font-weight: 500; color: var(--muted); margin: 0 0 1rem; letter-spacing: 0; }
.block h3 { font-size: 1rem; margin: 1.5rem 0 0.4rem; }
.block p { margin: 0 0 0.85rem; max-width: 46rem; }
.block .note { font-size: 0.86rem; }
.steps, ul.plain { margin: 0; padding-left: 1.25rem; max-width: 46rem; }
.steps li { margin-bottom: 0.6rem; }
ul.plain li { margin-bottom: 0.45rem; }

.facts { display: grid; grid-template-columns: 9rem 1fr; gap: 0.55rem 1.25rem; margin: 0; }
.facts dt { color: var(--muted); font-family: var(--font-mono); font-size: 0.78rem; padding-top: 0.12rem; }
.facts dd { margin: 0; font-size: 0.94rem; }

/* ── Buttons ───────────────────────────────────────────────────────────── */

.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 0.4rem;
    min-height: 2.25rem; padding: 0 0.9rem;
    border: 1px solid var(--border); border-radius: var(--radius-sm);
    background: var(--card); color: var(--fg);
    font: inherit; font-size: 0.88rem; font-weight: 600; line-height: 1;
    text-decoration: none; white-space: nowrap; cursor: pointer;
    transition: border-color 0.12s ease, background-color 0.12s ease, color 0.12s ease;
}
.btn:hover { border-color: var(--rule-strong); }
.btn-primary, .btn.primary { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }
.btn-primary:hover, .btn.primary:hover { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-danger, .btn.danger { color: var(--danger); }
.btn-danger:hover, .btn.danger:hover { border-color: var(--danger); }
.btn-ghost, .btn.ghost { border-color: transparent; background: none; }
.btn-ghost:hover, .btn.ghost:hover { background: var(--subtle); border-color: transparent; }
.btn-sm, .btn.small { min-height: 1.85rem; padding: 0 0.6rem; font-size: 0.8rem; }
.btn:disabled, .btn[aria-disabled="true"] { opacity: 0.45; cursor: default; pointer-events: none; }

/* ── Form fields ───────────────────────────────────────────────────────────
   `div.field` is the wrapper partial (core/_field.html); the planner uses a
   bare `.field` class on inputs, so the wrapper rules stay on the div. */

.input,
div.field input:not([type=checkbox]):not([type=radio]),
div.field select,
div.field textarea {
    width: 100%; min-height: 2.4rem; padding: 0.45rem 0.65rem;
    border: 1px solid var(--border); border-radius: var(--radius-sm);
    background: var(--card); color: var(--fg); font: inherit; font-size: 0.94rem;
    transition: border-color 0.12s ease, box-shadow 0.12s ease;
}
div.field textarea, textarea.input { resize: vertical; line-height: 1.5; }
.input:hover, div.field input:hover, div.field select:hover, div.field textarea:hover { border-color: color-mix(in srgb, var(--rule-strong) 35%, var(--border)); }
.input:focus, div.field input:focus, div.field select:focus, div.field textarea:focus {
    outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft);
}
input[type=checkbox], input[type=radio] { accent-color: var(--accent); width: 1rem; height: 1rem; }

div.field { margin: 0 0 1.1rem; max-width: 32rem; }
div.field > label { display: block; font-size: 0.84rem; font-weight: 600; margin-bottom: 0.35rem; }
div.field > div { display: flex; flex-wrap: wrap; gap: 0.35rem 1rem; }
div.field > div label, .check { display: inline-flex; align-items: center; gap: 0.45rem; font-size: 0.92rem; font-weight: 400; }
div.field .help { font-size: 0.8rem; color: var(--muted); margin: 0.35rem 0 0; }
div.field .help ul { margin: 0.2rem 0 0; padding-left: 1.1rem; }
div.field .errorlist, div.field .errors { list-style: none; padding: 0; color: var(--danger); font-size: 0.84rem; margin: 0.35rem 0 0; }
ul.errorlist.nonfield { list-style: none; padding: 0; color: var(--danger); font-size: 0.9rem; }

.form { display: grid; gap: 0.25rem; max-width: 46rem; margin-top: 1.5rem; }
.form-wide div.field { max-width: none; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 0 1.25rem; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(13rem, 1fr)); gap: 0 1.25rem; max-width: 40rem; }
.grid2 div.field { max-width: none; }

/* ── Messages ──────────────────────────────────────────────────────────── */

.flash { list-style: none; padding: 0; margin: 1.25rem 0; display: grid; gap: 0.5rem; }
.flash li, .flash-msg {
    margin: 0 0 0.5rem; padding: 0.7rem 0.9rem 0.7rem 1rem;
    border: 1px solid var(--border); border-left: 3px solid var(--rule-strong);
    border-radius: var(--radius-sm); background: var(--card); font-size: 0.92rem;
}
.flash li { margin: 0; }
.flash .error, .flash-msg.error { border-left-color: var(--danger); }
.flash .success, .flash-msg.success { border-left-color: var(--ok); }
.flash .warning, .flash-msg.warning { border-left-color: var(--warn); }
.flash .info, .flash-msg.info { border-left-color: var(--accent); }

.callout {
    padding: 1rem 1.2rem; border-radius: var(--radius); border: 1px solid var(--border);
    background: var(--card); border-left: 3px solid var(--accent);
}
.callout.warn { border-left-color: var(--warn); background: var(--v-mid-bg); border-color: transparent; }
.callout h2 { font-size: 0.95rem; margin: 0 0 0.5rem; }
.callout ul { margin: 0; padding-left: 1.2rem; }

.empty {
    padding: 2.5rem 1.5rem; text-align: center; color: var(--muted);
    border: 1px dashed var(--border); border-radius: var(--radius);
}
.empty strong { display: block; color: var(--fg); font-size: 1rem; margin-bottom: 0.3rem; }

/* ── Panels, stats, tabs ───────────────────────────────────────────────── */

.panel { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.25rem 1.4rem; }
.panel + .panel { margin-top: 1rem; }
.panel .facts { grid-template-columns: 9rem 1fr; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(8.5rem, 1fr)); gap: 0 1.5rem; margin: 2rem 0; }
.stat { padding: 0.8rem 0 0.2rem; border-top: 2px solid var(--rule-strong); }
.stat-value { font-size: 2rem; font-weight: 700; letter-spacing: -0.03em; line-height: 1.1; font-variant-numeric: tabular-nums; }
.stat-label { margin-top: 0.3rem; font-family: var(--font-mono); font-size: 0.72rem; color: var(--muted); }

.tabs { display: flex; gap: 0.25rem; margin: 1.5rem 0 0; border-bottom: 1px solid var(--border); }
.tabs a {
    padding: 0.55rem 0.85rem; color: var(--muted); text-decoration: none; font-size: 0.9rem; font-weight: 600;
    border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tabs a:hover { color: var(--fg); }
.tabs a.on { color: var(--fg); border-bottom-color: var(--accent); }
/* The tab rule already separates; the first section under it needs no second line. */
.tabs + .block, .tabs + .flash + .block { border-top: 0; margin-top: 1.5rem; padding-top: 0.5rem; }

/* ── Tables ────────────────────────────────────────────────────────────── */

.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--card); }
table.table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.table th, .table td { text-align: left; padding: 0.7rem 0.85rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table thead th {
    font-family: var(--font-mono); font-size: 0.7rem; font-weight: 500; color: var(--muted);
    white-space: nowrap; background: var(--card-hover); border-bottom-color: var(--border);
}
.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr:hover td { background: var(--card-hover); }
.table a { color: inherit; font-weight: 600; text-decoration: none; }
.table a:hover { color: var(--link); text-decoration: underline; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; font-family: var(--font-mono); font-size: 0.84rem; }
.table tr.off td { opacity: 0.45; }
/* Bare variant: a table sitting on the page rather than in a frame. */
.table-wrap.bare { border: 0; background: none; border-radius: 0; }
.table-wrap.bare thead th { background: none; border-bottom: 1px solid var(--rule-strong); padding-left: 0; }
.table-wrap.bare td { padding-left: 0; }
.table-wrap.bare tbody tr:hover td { background: none; }

/* ── Tags, chips, statuses ─────────────────────────────────────────────── */

.tag, .pill {
    display: inline-block; font-family: var(--font-mono); font-size: 0.7rem; line-height: 1.5;
    padding: 0 0.4rem; margin: 0 0.25rem 0.2rem 0; border-radius: 2px;
    background: var(--subtle); color: var(--fg);
}
.chip {
    display: inline-block; font-family: var(--font-mono); font-size: 0.7rem; font-weight: 500;
    padding: 0.08rem 0.42rem; border-radius: 2px; white-space: nowrap; line-height: 1.5;
}
.chip-high { color: var(--v-high); background: var(--v-high-bg); }
.chip-medium, .chip-conditional { color: var(--v-mid); background: var(--v-mid-bg); }
.chip-medium-high { color: var(--v-high); background: color-mix(in srgb, var(--v-high-bg) 55%, var(--v-mid-bg)); }
.chip-low-medium { color: var(--v-low); background: color-mix(in srgb, var(--v-low-bg) 55%, var(--v-mid-bg)); }
.chip-low { color: var(--v-low); background: var(--v-low-bg); }
.chip-none, .chip- { color: var(--v-none); background: var(--v-none-bg); }

.status {
    font-family: var(--font-mono); font-size: 0.7rem; padding: 0.05rem 0.42rem; border-radius: 2px;
    white-space: nowrap; border: 1px solid currentColor;
}
.status-live { color: var(--ok); }
.status-built-not-deployed { color: var(--warn); }
.status-planned { color: var(--muted); border-style: dashed; }

/* ── Lists of things (agents, chats…) ──────────────────────────────────── */

.list { display: grid; border-top: 1px solid var(--border); }
.list-row {
    display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 0.2rem 1.5rem; align-items: baseline;
    padding: 1.1rem 0.25rem; border-bottom: 1px solid var(--border);
    color: inherit; text-decoration: none;
}
a.list-row:hover { background: linear-gradient(to right, var(--card-hover), transparent); }
a.list-row:hover .list-title { color: var(--link); }
.list-title { font-weight: 650; font-size: 1.05rem; letter-spacing: -0.01em; }
.list-meta { font-family: var(--font-mono); font-size: 0.74rem; color: var(--muted); }
.list-body { grid-column: 1 / -1; margin: 0; color: var(--muted); font-size: 0.94rem; max-width: 52rem; }

/* Agents pages (core) */
.agent-head { display: flex; align-items: center; gap: 0.75rem; flex-wrap: wrap; }

/* ── Sign-in ───────────────────────────────────────────────────────────── */

.auth { max-width: 24rem; margin: 6vh auto 0; }
.auth .eyebrow { margin-bottom: 0.5rem; }
.auth h1 { font-size: 1.9rem; margin: 0 0 1.75rem; letter-spacing: -0.03em; }
.auth .btn { width: 100%; min-height: 2.6rem; margin-top: 0.5rem; }
.auth div.field { max-width: none; }

@media (max-width: 40rem) {
    header.site { gap: 0.75rem; }
    .nav { gap: 0.75rem; }
    .nav-dropdown { min-width: 14rem; }
    .nav-user { display: none; }
    .form-row { grid-template-columns: 1fr; }
    .facts, .panel .facts { grid-template-columns: 1fr; gap: 0.15rem 0; }
    .facts dd { margin-bottom: 0.6rem; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { transition: none !important; animation: none !important; }
}
