/* Shared primitives for public, account, and workspace surfaces. */
:root {
  color-scheme: dark;
  --bg: var(--color-canvas); --paper: var(--color-canvas); --surface: var(--color-surface);
  --ink: var(--color-ink); --muted: var(--color-muted); --line: var(--color-line);
  --brand: var(--color-brand); --accent: var(--color-accent); --soft: var(--color-surface-subtle);
  --body: var(--color-body, var(--color-ink));
  --serif: var(--font-serif); --radius: var(--radius-lg);
}
*, *::before, *::after { box-sizing: border-box; }
/* Turbo restores history scroll positions immediately. */
html { scroll-behavior: auto; scroll-padding-top: 32px; }
body { margin: 0; background: var(--bg); color: var(--ink); font: var(--text-body)/1.65 var(--font-sans); -webkit-font-smoothing: antialiased; overflow-wrap: anywhere; }
h1, h2, h3, p { margin-top: 0; }
h1, h2, h3 { line-height: 1.2; font-weight: 650; text-wrap: balance; }
h1 { font-size: clamp(32px, 4vw, 48px); letter-spacing: -1.8px; }
h2 { font-size: 24px; letter-spacing: -.6px; }
h3 { font-size: 18px; letter-spacing: -.3px; }
p { color: var(--body); }
a { color: var(--brand); text-underline-offset: 4px; }
button, input, select, textarea { font: inherit; }
a, button, input, select, textarea, summary { touch-action: manipulation; }
button, .button, input[type=submit] { transition: background var(--motion-fast), border-color var(--motion-fast), box-shadow var(--motion-fast); }
img, svg { max-width: 100%; }
::selection { background: var(--color-highlight); color: var(--color-on-highlight); }
:focus-visible { outline: 3px solid var(--color-focus); outline-offset: 4px; }
main:focus { outline: none; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }
.skip-link { position: fixed; top: -100px; left: 16px; z-index: 100; background: var(--brand); color: var(--color-on-brand); padding: 12px 20px; border-radius: var(--radius-sm); }
.skip-link:focus { top: 12px; }
.eyebrow { color: var(--accent); font-size: var(--text-meta); line-height: 1.5; letter-spacing: .8px; font-weight: 650; text-transform: uppercase; margin-bottom: 16px; }
.serif-word { font-family: var(--serif); font-style: italic; font-weight: 400; }
.muted { color: var(--muted); }
.small { font-size: var(--text-meta); }
.button, input[type=submit], button.primary { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: var(--size-control); padding: 11px 20px; border: 1px solid var(--brand); border-radius: var(--radius-md); background: var(--brand); color: var(--color-on-brand); text-decoration: none; font-size: var(--text-control); line-height: 1.5; font-weight: 650; cursor: pointer; text-align: center; }
.button:hover, input[type=submit]:hover, button.primary:hover { background: var(--color-brand-hover); border-color: var(--color-brand-hover); box-shadow: var(--shadow-sm); }
.button.secondary { background: var(--surface); color: var(--brand); border-color: var(--line); }
.button.secondary:hover { background: var(--soft); border-color: var(--color-line-strong); }
.quiet-button { min-height: 44px; width: 100%; border: 0; border-radius: var(--radius-sm); background: transparent; color: var(--body); padding: 10px 12px; font-size: 15px; text-align: left; cursor: pointer; }
.quiet-button:hover { background: var(--soft); color: var(--brand); }
/* Disclosure buttons inherit the button contract; their indicator matches selects. */
.button.dropdown-trigger { justify-content: space-between; gap: 12px; list-style: none; white-space: nowrap; }
.button.dropdown-trigger::-webkit-details-marker { display: none; }
.button.dropdown-trigger::after { content: ""; position: static; flex: 0 0 8px; width: 8px; height: 8px; margin: -4px 3px 0 auto; border-right: 1.5px solid currentColor; border-bottom: 1.5px solid currentColor; transform: rotate(45deg); color: var(--muted); }
details[open] > .button.dropdown-trigger::after { margin-top: 4px; transform: rotate(225deg); }
.button.danger { color: var(--color-danger); background: var(--surface); border-color: var(--color-danger-line); }
.button.danger:hover { background: var(--color-danger-bg); border-color: var(--color-danger); }
.button-light { background: var(--color-highlight); border-color: var(--color-highlight); color: var(--color-on-highlight); }
.button-light:hover { background: var(--color-brand-hover); border-color: var(--color-brand-hover); }
button:disabled, input:disabled, .button[aria-disabled=true] { cursor: not-allowed; opacity: .65; box-shadow: none; }
button:disabled:hover, input[type=submit]:disabled:hover { background: var(--brand); border-color: var(--brand); }
.text-link { display: inline-flex; align-items: center; gap: 8px; min-height: 44px; font-size: 14px; font-weight: 600; text-decoration: none; }
.text-link:hover { text-decoration: underline; }
.actions { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; margin-top: 24px; }
.actions form { margin: 0; }
.badge, .status { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border: 1px solid var(--line); border-radius: var(--radius-sm); font-size: var(--text-meta); line-height: 1.5; color: var(--body); }
.status { background: var(--soft); color: var(--brand); }
.status-dot { width: 6px; height: 6px; display: inline-block; border-radius: 50%; background: currentColor; flex-shrink: 0; }
.panel { border: 1px solid var(--line); border-radius: var(--radius-lg); padding: 28px; background: var(--surface); margin-bottom: 24px; box-shadow: var(--shadow-sm); min-width: 0; }
.panel-head { display: flex; justify-content: space-between; align-items: center; gap: 16px; margin-bottom: 24px; }
.panel-head h2 { margin: 0; }
.highlight { background: var(--surface); border-color: var(--line); color: var(--ink); }
.highlight p, .highlight .small { color: var(--muted); }
.highlight .status { color: var(--brand); }
.highlight a { color: var(--ink); }
.highlight .eyebrow { color: var(--color-highlight); }
.highlight .button { background: var(--color-highlight); border-color: var(--color-highlight); color: var(--color-on-highlight); }
.highlight .button:hover { background: var(--color-brand-hover); }
.highlight .button:disabled:hover { background: var(--color-highlight); border-color: var(--color-highlight); }
.flash, .errors, .notice { padding: 16px 20px; border-radius: var(--radius-md); margin-bottom: 24px; background: var(--color-success-bg); color: var(--color-success); border: 1px solid var(--color-success-line); font-size: 14px; }
.flash.alert, .errors { background: var(--color-danger-bg); color: var(--color-danger); border-color: var(--color-danger-line); }
.notice.warning { background: var(--color-warning-bg); color: var(--color-warning); border-color: var(--color-warning-line); }
.flash p, .errors p, .notice p { color: inherit; margin-bottom: 6px; }
.errors ul { margin: 8px 0 0; padding-left: 20px; }
.errors a { color: inherit; }
.errors:focus { outline: 3px solid var(--color-focus); outline-offset: 3px; }
label { display: block; font-size: 14px; font-weight: 600; margin-bottom: 7px; }
input:not([type=checkbox]):not([type=submit]):not([type=hidden]), select, textarea { display: block; width: 100%; min-height: var(--size-control); padding: 11px 13px; border: 1px solid var(--color-line-strong); border-radius: var(--radius-md); background: var(--surface); color: var(--ink); font-size: 16px; line-height: 1.5; transition: border-color var(--motion-fast), box-shadow var(--motion-fast); }
input::placeholder, textarea::placeholder { color: var(--muted); opacity: 1; }
input:not([type=submit]):focus, select:focus, textarea:focus { border-color: var(--brand); }
input[aria-invalid=true], textarea[aria-invalid=true], select[aria-invalid=true] { border-color: var(--color-danger); background: var(--color-danger-bg); }
select:disabled { cursor: not-allowed; opacity: .65; }

/* Keep native labels, validation, keyboard controls and form values. Older
   browsers retain their native picker; multi-selects/listboxes are unchanged. */
@supports (appearance: base-select) and selector(::picker(select)) {
  select:not([multiple]):is(:not([size]), [size="1"]) { appearance: base-select; display: flex; min-width: 0; align-items: center; justify-content: space-between; gap: 12px; cursor: pointer; }
  select:not([multiple]):is(:not([size]), [size="1"])::picker(select) {
    appearance: base-select;
    width: anchor-size(width);
    max-width: calc(100vw - 24px);
    max-height: min(360px, 50dvh);
    margin-block: 8px;
    padding: 6px;
    border: 1px solid var(--color-line-strong);
    border-radius: var(--radius-md);
    background: var(--surface);
    color: var(--ink);
    box-shadow: var(--shadow-md);
    font: inherit;
    overflow-y: auto;
    overscroll-behavior: contain;
    scrollbar-color: var(--color-line-strong) var(--surface);
  }
  select:not([multiple]):is(:not([size]), [size="1"])::picker-icon { content: ""; flex: 0 0 8px; width: 8px; height: 8px; margin: -4px 3px 0 auto; border-right: 1.5px solid currentColor; border-bottom: 1.5px solid currentColor; transform: rotate(45deg); color: var(--muted); }
  select:not([multiple]):is(:not([size]), [size="1"]):open { border-color: var(--brand); }
  select:not([multiple]):is(:not([size]), [size="1"])[aria-invalid=true] { border-color: var(--color-danger); }
  select:not([multiple]):is(:not([size]), [size="1"]):disabled { cursor: not-allowed; }
  select:not([multiple]):is(:not([size]), [size="1"]):open::picker-icon { margin-top: 4px; transform: rotate(225deg); }
  select:not([multiple]):is(:not([size]), [size="1"]) option { display: flex; align-items: center; gap: 12px; min-height: 44px; padding: 10px 12px; border: 0; border-radius: var(--radius-sm); background: var(--surface); color: var(--ink); font: inherit; white-space: normal; overflow-wrap: anywhere; cursor: pointer; }
  select:not([multiple]):is(:not([size]), [size="1"]) option:checked { background: var(--color-surface-accent); font-weight: 650; }
  select:not([multiple]):is(:not([size]), [size="1"]) option:hover, select:not([multiple]):is(:not([size]), [size="1"]) option:focus-visible { background: var(--soft); outline: 2px solid var(--color-focus); outline-offset: -2px; }
  select:not([multiple]):is(:not([size]), [size="1"]) option::checkmark { order: 1; margin-left: auto; color: var(--brand); }
  select:not([multiple]):is(:not([size]), [size="1"]) option:disabled { color: var(--muted); opacity: .65; cursor: not-allowed; }
  select:not([multiple]):is(:not([size]), [size="1"]) optgroup { color: var(--muted); font: inherit; font-weight: 650; }
}
textarea { resize: vertical; }
input[type=checkbox] { width: 20px; height: 20px; accent-color: var(--brand); flex-shrink: 0; }
.field { margin-bottom: 22px; }
.field small { display: block; color: var(--muted); font-size: var(--text-meta); margin-top: 7px; line-height: 1.6; }
.field-error { display: block; color: var(--color-danger); font-size: var(--text-meta); margin-top: 6px; }
.field_with_errors { display: contents; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; column-gap: 24px; }
.check { display: flex; align-items: center; gap: 12px; min-height: 44px; font-weight: 400; }
fieldset { min-width: 0; margin: 0; padding: 0; border: 0; }
.section { border-bottom: 1px solid var(--line); padding: 4px 0 24px; margin-bottom: 28px; }
.section legend { font-size: 18px; font-weight: 650; padding-bottom: 20px; letter-spacing: -.3px; }
.empty { padding: 40px 24px; text-align: center; background: var(--bg); border: 1px dashed var(--color-line-strong); border-radius: var(--radius-md); }
.empty p { max-width: 460px; margin: 0 auto; }
.empty .actions { justify-content: center; }
.empty-icon { display: grid; place-items: center; width: 48px; height: 48px; margin: 0 auto 18px; border-radius: var(--radius-md); background: var(--color-surface-accent); color: var(--brand); }
.ui-icon { display: block; width: 20px; height: 20px; flex-shrink: 0; }
code { font: var(--text-meta)/1.7 var(--font-mono); overflow-wrap: anywhere; padding: 3px 6px; background: var(--soft); border-radius: 5px; }
.token { overflow-wrap: anywhere; padding: 18px; border: 1px solid var(--line); background: var(--soft); border-radius: var(--radius-md); font: var(--text-meta)/1.8 var(--font-mono); }
.token-actions { display: flex; align-items: center; gap: 12px; margin-top: 12px; }
.copy-status { font-size: var(--text-meta); color: var(--brand); }
.form-status { font-size: var(--text-meta); color: var(--body); margin: 12px 0 0; }
.confirm-dialog { width: min(440px, calc(100% - 32px)); padding: 28px; border: 1px solid var(--line); border-radius: var(--radius-lg); color: var(--ink); background: var(--surface); box-shadow: var(--shadow-lg); }
.confirm-dialog::backdrop { background: rgb(0 0 0 / 60%); }
.confirm-dialog h2 { font-size: 24px; }
.confirm-dialog .actions { justify-content: flex-end; }

.list-results { display: block; min-width: 0; }

/* Lists start with search; secondary choices live in one optional disclosure. */
.list-tools { position: relative; display: flex; align-items: center; gap: 8px; width: 100%; max-width: 760px; margin: 20px 0; }
.list-search { position: relative; flex: 1; min-width: 0; }
.list-tools .list-search input[type=search] { display: block; width: 100%; min-width: 0; height: 44px; min-height: 44px; margin: 0; padding: 8px 48px 8px 12px; }
.list-search-submit { position: absolute; inset: 0 0 0 auto; display: inline-flex; align-items: center; justify-content: center; width: 44px; min-width: 44px; height: 44px; padding: 10px; border-radius: var(--radius-md); }
.list-filter-menu { flex: none; }
.list-filter-count { font-variant-numeric: tabular-nums; }
.list-filter-panel { position: absolute; z-index: 20; top: calc(100% + 8px); right: 0; width: 320px; max-width: 100%; max-height: min(480px, 60dvh); overflow-y: auto; padding: 20px; border: 1px solid var(--color-line-strong); border-radius: var(--radius-md); background: var(--surface); box-shadow: var(--shadow-md); }
.list-tools .list-filter-panel .field { min-width: 0; margin: 0 0 16px; }
.list-tools .list-filter-panel select { width: 100%; min-width: 0; margin: 0; }
.list-tools .list-filter-panel .field:last-child { margin-bottom: 0; }
.list-search-error { flex-basis: 100%; margin: 0; color: var(--ink); font-size: var(--text-meta); }
.list-tools:has(.list-search-error:not([hidden])) { flex-wrap: wrap; }
.list-filter-note { margin: 0 0 16px; overflow-wrap: anywhere; }
.list-filter-note:last-child { margin-bottom: 0; }
.list-reset { flex: none; justify-content: center; min-width: 44px; }
@media (max-width: 420px) {
  .list-tools:has(.list-filter-menu):has(.list-reset:not([hidden])) { flex-wrap: wrap; }
  .list-tools:has(.list-filter-menu):has(.list-reset:not([hidden])) .list-search { flex-basis: 100%; }
  .list-tools:has(.list-filter-menu) .list-reset { margin-left: auto; }
}
/* Shared hierarchy for workspace pages, lists and task handoffs. */
.page-header { display: flex; align-items: flex-start; justify-content: space-between; flex-wrap: wrap; gap: 20px; margin-bottom: 28px; min-width: 0; }
.page-header > div:first-child { flex: 1 1 360px; min-width: 0; }
.page-header h1 { margin: 0 0 8px; font-size: var(--text-heading); line-height: 1.25; letter-spacing: -.025em; }
.page-description, .page-header > div > p { max-width: 68ch; margin: 0; color: var(--body); font-size: var(--text-body); }
.page-actions { display: flex; align-items: center; flex-wrap: wrap; gap: 12px; margin: 0; }
.page-actions form { margin: 0; }
.record-row { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; min-width: 0; padding: 20px 0; border-bottom: 1px solid var(--line); }
.record-row:last-child { border-bottom: 0; }
.record-row-main { flex: 1; min-width: 0; }
.record-row-main > strong, .record-row-main > a { font-size: var(--text-title); font-weight: 600; }
.record-row-main > p { margin: 8px 0; max-width: 70ch; }
.record-row-meta { display: flex; align-items: center; flex-wrap: wrap; gap: 8px 16px; margin-top: 8px; color: var(--muted); font-size: var(--text-meta); }
.record-row-meta > span, .record-row-meta > time { overflow-wrap: anywhere; }
.record-row-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; flex-shrink: 0; }
.record-row-actions form { margin: 0; }
a.record-row { min-height: 64px; color: var(--ink); text-decoration: none; border-radius: var(--radius-sm); }
a.record-row:hover { background: var(--soft); }
a.record-row:hover strong { text-decoration: underline; text-underline-offset: 4px; }
.record-list .record-row { list-style: none; }
.request-details { margin-top: 16px; }
.request-details > summary { display: flex; align-items: center; min-height: 44px; font-size: var(--text-meta); cursor: pointer; }
.request-details[open] > summary { margin-bottom: 12px; }
@media (max-width: 640px) {
  .form-grid { grid-template-columns: 1fr; }
  .panel { padding: 22px; }
  .panel-head { flex-wrap: wrap; align-items: flex-start; }
  .actions { gap: 10px; }
  .empty { padding: 30px 20px; }
  .page-header { gap: 16px; margin-bottom: 24px; }
  .page-header h1 { font-size: 28px; }
  .page-actions { width: 100%; }
  .record-row { flex-wrap: wrap; }
  .record-row-actions { width: 100%; }
}
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
@media (forced-colors: active) {
  .button, input, select, textarea { border: 1px solid ButtonText; }
  select:not([multiple]):is(:not([size]), [size="1"]), select:not([multiple]):is(:not([size]), [size="1"])::picker(select) { appearance: auto; }
}

/* Shared inline quiet action and chart primitives. Legend selection is local visibility. */
.quiet-button.inline { display: inline-flex; width: auto; align-items: center; gap: 8px; max-width: 100%; overflow-wrap: anywhere; }
.quiet-button.inline[aria-pressed=false] { opacity: .5; text-decoration: line-through; }
.chart-swatch { flex: 0 0 24px; }
.chart-graphic { display: block; width: 100%; max-width: 100%; }
.chart-graphic text { fill: var(--ink); font: var(--text-meta) var(--font-sans); }
.chart-tooltip { position: absolute; z-index: 5; max-width: 100%; padding: 12px; background: var(--surface); color: var(--ink); border: 1px solid var(--color-line-strong); border-radius: var(--radius-md); box-shadow: var(--shadow-md); pointer-events: none; font-size: var(--text-meta); }
.chart-tooltip strong { display: block; margin-bottom: 8px; }
.chart-tooltip-row { display: flex; justify-content: space-between; align-items: baseline; gap: 16px; margin-top: 8px; }
.chart-tooltip-row > span { min-width: 0; overflow-wrap: anywhere; }
.chart-tooltip-row > span:first-child { flex: 1; }
.chart-tooltip-row > span:last-child { flex: 0 1 auto; max-width: 45%; font-variant-numeric: tabular-nums; }
.chart-tooltip-row small { display: block; font-size: inherit; color: var(--muted); }

.knowledge-table[data-overflow=true][data-scroll-end=false],
.table-scroll[data-overflow=true][data-scroll-end=false] { box-shadow: inset -12px 0 12px -12px var(--muted); }

.knowledge-table[data-overflow=true][data-scroll-start=false],
.table-scroll[data-overflow=true][data-scroll-start=false] { box-shadow: inset 12px 0 12px -12px var(--muted); }
.knowledge-table[data-overflow=true][data-scroll-start=false][data-scroll-end=false],
.table-scroll[data-overflow=true][data-scroll-start=false][data-scroll-end=false] { box-shadow: inset 12px 0 12px -12px var(--muted), inset -12px 0 12px -12px var(--muted); }
