/* Beaconsuite: plain, dense internal tool. Tokens first; components only use tokens. */
:root {
  --bg: #f4f6f7;
  --surface: #ffffff;
  --fg: #1c2429;
  --muted: #5a6870;
  --rule: #d5dde1;
  --accent: #0b6874;
  --accent-fg: #ffffff;
  --accent-soft: #e2f0f2;
  --stripe: #e9eef0;   /* every other row of a result table */
  --ok: #1e7a3c;      --ok-soft: #e2f3e7;
  --warn: #8a5a00;    --warn-soft: #fbefd6;
  --bad: #a3271f;     --bad-soft: #fbe4e1;
  --body: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  color-scheme: light;
}
/* Dark follows the system's setting unless a theme is chosen in the top bar
   (data-theme on <html>, static/js/theme.js). The two dark blocks must match. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #12181b; --surface: #192125; --fg: #e2e8eb; --muted: #97a6ae; --rule: #2b373d;
    --accent: #5bc2cd; --accent-fg: #0d1416; --accent-soft: #173336; --stripe: #1e282c;
    --ok: #7fd49a; --ok-soft: #173023; --warn: #f0c070; --warn-soft: #33290f;
    --bad: #f39a90; --bad-soft: #3a1c19;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #12181b; --surface: #192125; --fg: #e2e8eb; --muted: #97a6ae; --rule: #2b373d;
  --accent: #5bc2cd; --accent-fg: #0d1416; --accent-soft: #173336; --stripe: #1e282c;
  --ok: #7fd49a; --ok-soft: #173023; --warn: #f0c070; --warn-soft: #33290f;
  --bad: #f39a90; --bad-soft: #3a1c19;
  color-scheme: dark;
}

* { box-sizing: border-box; }
/* Components set display (flex, grid); keep the hidden attribute winning over them. */
[hidden] { display: none !important; }
body { margin: 0; background: var(--bg); color: var(--fg); font: 15px/1.5 var(--body); }
a { color: var(--accent); }
h1 { font-size: 1.6rem; margin: 0 0 .25rem; }
h2 { font-size: 1.1rem; margin: 0 0 .75rem; }
.lead { color: var(--muted); max-width: 70ch; margin: 0 0 1.25rem; }
.muted { color: var(--muted); }
.mono { font-family: var(--mono); font-size: .9em; }

.topbar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 24px; padding: 10px max(16px, 3vw);
          background: var(--surface); border-bottom: 1px solid var(--rule); }
.topbar .brand { font-weight: 700; color: var(--fg); text-decoration: none; }
.topbar nav { display: flex; gap: 16px; flex: 1; }
.topbar nav a { text-decoration: none; }
.signout { display: flex; gap: 8px; align-items: center; color: var(--muted); }
.theme-select { padding: 3px 8px; font-size: .85rem; color: var(--muted); }
.page { max-width: 1200px; margin: 0 auto; padding: 24px max(16px, 3vw) 48px; display: flex; flex-direction: column; gap: 24px; }
.crumbs { margin: 0; color: var(--muted); font-size: .9rem; }
.kind { font-size: .8rem; font-weight: 500; color: var(--muted); border: 1px solid var(--rule); border-radius: 999px; padding: 2px 10px; vertical-align: middle; }

.panel { background: var(--surface); border: 1px solid var(--rule); border-radius: 8px; padding: 16px 20px; }
.run-form { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
select, input[type=search], input[type=email], input[type=password] { font: inherit; color: var(--fg); background: var(--surface); border: 1px solid var(--rule); border-radius: 6px; padding: 7px 10px; min-width: 0; }
input[type=search] { flex: 1 1 320px; }
button { font: inherit; border: 1px solid var(--accent); background: var(--accent); color: var(--accent-fg); border-radius: 6px; padding: 7px 16px; cursor: pointer; }
button.secondary { background: transparent; color: var(--accent); }
button.link { border: 0; background: none; color: var(--accent); padding: 0; }
button.small { padding: 2px 10px; font-size: .85rem; }
button.danger { background: transparent; color: var(--bad); border-color: var(--bad); }
.row-actions { display: inline-flex; gap: 8px; align-items: center; }
a.button { display: inline-block; border: 1px solid var(--accent); border-radius: 6px; color: var(--accent); padding: 7px 16px; text-decoration: none; transition: background-color .12s; }
a.button.small { padding: 2px 10px; font-size: .85rem; }
a.button:hover { background: var(--accent-soft); }
/* A square button holding an icon, as tall as a button with text: a line plus its padding and border. */
.icon-button { display: inline-flex; align-items: center; justify-content: center; box-sizing: border-box; width: calc(1lh + 16px); height: calc(1lh + 16px); border: 1px solid var(--accent); border-radius: 6px; color: var(--accent); transition: background-color .12s; }
.icon-button:hover { background: var(--accent-soft); }
.icon-button svg { width: 1.15em; height: 1.15em; }
.form-actions { justify-content: flex-end; }
button { transition: background-color .12s, border-color .12s, color .12s, filter .12s; }
button:hover:not(:disabled) { filter: brightness(1.1); }
button.secondary:hover:not(:disabled) { background: var(--accent-soft); filter: none; }
button.danger:hover:not(:disabled) { background: var(--bad-soft); filter: none; }
button.link:hover:not(:disabled) { text-decoration: underline; filter: none; }
button:active:not(:disabled) { transform: translateY(1px); }
button:disabled { opacity: .5; cursor: not-allowed; }
button:focus-visible, a:focus-visible, select:focus-visible, input:focus-visible, summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

.table-scroll { overflow-x: auto; }
table.list { width: 100%; border-collapse: collapse; font-size: .92rem; }
table.list th, table.list td { text-align: left; padding: 6px 10px; border-bottom: 1px solid var(--rule); white-space: nowrap; }
table.list th { font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; }
.num { text-align: right !important; font-variant-numeric: tabular-nums; }

#tables { display: flex; flex-direction: column; gap: 6px; }
details { background: var(--surface); border: 1px solid var(--rule); border-radius: 6px; }
details[open] { border-color: var(--accent); }
summary { cursor: pointer; padding: 8px 12px; display: flex; gap: 10px; align-items: baseline; }
summary .count { color: var(--muted); font-size: .85rem; font-variant-numeric: tabular-nums; }
details .table-scroll { border-top: 1px solid var(--rule); }

.pill { display: inline-block; font-size: .78rem; font-weight: 600; padding: 1px 9px; border-radius: 999px; }
.pill.succeeded { background: var(--ok-soft); color: var(--ok); }
.pill.running, .pill.queued { background: var(--warn-soft); color: var(--warn); }
.pill.cancelled { background: var(--rule); color: var(--muted); }
.pill.failed { background: var(--bad-soft); color: var(--bad); }
pre.error { background: var(--bad-soft); color: var(--bad); padding: 10px 12px; border-radius: 6px; white-space: pre-wrap; overflow-wrap: anywhere; }

/* A highlighted note above a page's content, e.g. a partial feature */
.notice { background: var(--warn-soft); color: var(--fg); border-left: 3px solid var(--warn); padding: 8px 12px; border-radius: 6px; margin: 0; max-width: 90ch; }

/* Sign in */
.sign-in { width: 100%; max-width: 400px; margin: 8vh auto 0; }
.stacked-form { display: flex; flex-direction: column; gap: 6px; margin-top: 1rem; }
.stacked-form label { font-weight: 500; margin-top: 6px; }
.stacked-form button { margin-top: 14px; align-self: flex-start; }
.form-error { background: var(--bad-soft); color: var(--bad); padding: 8px 12px; border-radius: 6px; margin: .75rem 0 0; }

/* Database Viewer */
.small { font-size: .85rem; }
.source-list { margin: 0; padding-left: 20px; display: flex; flex-direction: column; gap: 4px; }
.viewer { display: grid; grid-template-columns: minmax(200px, 260px) minmax(0, 1fr); gap: 20px; align-items: start; }
@media (max-width: 760px) { .viewer { grid-template-columns: 1fr; } }
.table-list { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.table-list input[type=search] { flex: none; width: 100%; }
.table-list ul { list-style: none; margin: 0; padding: 0; max-height: 70vh; overflow-y: auto; border: 1px solid var(--rule); border-radius: 6px; background: var(--surface); }
.table-list li { display: flex; justify-content: space-between; gap: 8px; padding: 4px 10px; border-bottom: 1px solid var(--rule); }
.table-list li:last-child { border-bottom: 0; }
.table-list li a { font-family: var(--mono); font-size: .85rem; text-decoration: none; overflow-wrap: anywhere; }
.table-list li a[aria-current] { font-weight: 700; }
.table-list .count { color: var(--muted); font-size: .8rem; font-variant-numeric: tabular-nums; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--rule); margin: 4px 0 14px; }
.tabs a { padding: 6px 14px; text-decoration: none; border: 1px solid transparent; border-bottom: 0; border-radius: 6px 6px 0 0; margin-bottom: -1px; }
.tabs a[aria-current] { border-color: var(--rule); background: var(--surface); font-weight: 600; }
.table-main { display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.entity-title { font-family: var(--mono); margin: 0; }
.placeholder { padding: 24px 0; }
.conditions { display: flex; flex-direction: column; gap: 8px; background: var(--surface); border: 1px solid var(--rule); border-radius: 8px; padding: 12px; }
.ask-form { display: flex; flex-direction: column; gap: 10px; }
.ask-form textarea { font: inherit; color: var(--fg); background: var(--surface); border: 1px solid var(--rule); border-radius: 6px; padding: 8px 10px; width: 100%; resize: vertical; }
.ask-turn { display: flex; flex-direction: column; gap: 8px; padding-bottom: 16px; border-bottom: 1px solid var(--rule); }
.ask-turn .ask-question { font-size: 1.25rem; margin: 0; }
.ask-turn > p { margin: 0; }
.ask-steps > summary { cursor: pointer; color: var(--muted); }
.ask-step { border-top: 1px solid var(--rule); padding: 8px 0; }
.ai-client { display: flex; flex-direction: column; gap: 12px; }
.ai-service { display: flex; flex-direction: column; gap: 8px; border-top: 1px solid var(--rule); padding-top: 12px; }
.ai-service h3 { margin: 0; font-size: 1rem; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.ai-service input[type=text], .ai-service input[type=url], .ai-service input[type=password], .ai-service select, .ai-service textarea { font: inherit; color: var(--fg); background: var(--surface); border: 1px solid var(--rule); border-radius: 6px; padding: 6px 10px; max-width: 520px; width: 100%; }
.ai-service .helptext { display: block; color: var(--muted); font-size: .85rem; }
.ai-add > summary { cursor: pointer; color: var(--accent); }
.ask-step summary { cursor: pointer; }
.answer-text > :first-child { margin-top: 0; }
.answer-text p, .answer-text ul, .answer-text ol { margin: 0 0 .6rem; }
.answer-text table { border-collapse: collapse; margin: 0 0 .6rem; }
.answer-text th, .answer-text td { border: 1px solid var(--rule); padding: 4px 10px; text-align: left; }
.answer-text th { background: var(--accent-soft); }
.answer-text code { font-family: var(--mono); font-size: .9em; }
.condition-group { display: flex; flex-direction: column; gap: 8px; }
.condition-group .condition-group { border: 1px solid var(--rule); border-radius: 8px; padding: 10px; background: var(--bg); }
.condition-group .condition-group .condition-group { background: var(--surface); }
.group-items { display: flex; flex-direction: column; gap: 6px; }
.group-items:empty { display: none; }
.group-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
select.connector { align-self: flex-start; font-size: .85rem; }
.condition input[type=text][readonly] { background: var(--bg); color: var(--muted); }
.condition.invalid input:not([readonly]), .condition-group.invalid { border-color: var(--bad); }
.condition-error, .group-error { flex-basis: 100%; margin: 0; color: var(--bad); font-size: .8rem; }
.combo-count { float: right; margin-left: 12px; color: var(--muted); font-family: var(--body); }
.condition { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.condition input[type=text] { font: inherit; color: var(--fg); background: var(--surface); border: 1px solid var(--rule); border-radius: 6px; padding: 7px 10px; flex: 1 1 160px; min-width: 0; }
.condition select { max-width: 100%; }
.condition-actions { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.filter-text { margin: 0; font-size: .85rem; overflow-wrap: anywhere; }
.grid-bar { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 8px; }
.pager { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.loading { color: var(--muted); }
.htmx-indicator { display: none; }
.htmx-request.htmx-indicator, .htmx-request .htmx-indicator { display: block; }
.table-area { display: flex; flex-direction: column; gap: 8px; }
/* Result tables (common/_table.html) wrap: at spaces, or inside text with none, at most 32 characters wide. Numbers stay on one line. */
.table-area table.list th, .table-area table.list td { white-space: normal; vertical-align: top; }
.table-area table.list td.num { white-space: nowrap; }
.table-area .cell { max-width: 32ch; overflow-wrap: break-word; }
/* Every other row a shade apart, so a wide row is easy to follow across. */
.table-area table.list { background: var(--surface); }
.table-area table.list tbody tr:nth-child(even) { background: var(--stripe); }
/* The table scrolls in its own box, so its header row stays at the top (a line
   drawn by a shadow, as a sticky cell's border stays behind) and pinned columns
   at the left (static/js/tables.js sets how far from it). */
.table-area .table-scroll { overflow: auto; max-height: 75vh; }
.table-area table.list thead th { position: sticky; top: 0; z-index: 2; background: var(--surface); border-bottom: 0; box-shadow: inset 0 -1px var(--rule); }
.table-area table.list .pinned { position: sticky; z-index: 1; background: var(--surface); }
.table-area table.list tbody tr:nth-child(even) .pinned { background: var(--stripe); }
.table-area table.list thead th.pinned { z-index: 3; }
.table-area table.list td.pinned-last { box-shadow: inset -1px 0 var(--rule); }
.table-area table.list th.pinned-last { box-shadow: inset 0 -1px var(--rule), inset -1px 0 var(--rule); }
/* A header's pin sits in its top right corner, whatever the header's length
   (a number column's header is right-aligned against it). */
.table-area table.list th .cell { display: flex; align-items: flex-start; gap: 6px; }
.table-area table.list th.num .cell { justify-content: flex-end; }
th .pin { display: inline-flex; flex: none; margin-left: auto; color: var(--muted); opacity: .35; }
th.num .pin { margin-left: 0; }
th .pin svg { width: 1.2em; height: 1.2em; }
th:hover .pin, th .pin:focus-visible { opacity: 1; }
th .pin.pinned { opacity: 1; color: var(--accent); }
th .pin.pinned svg { fill: currentColor; }
.page.popout { max-width: none; padding-top: 16px; gap: 16px; }
.popout-title { font-size: 1.2rem; margin: 0; }
th a.sort { color: inherit; text-decoration: none; user-select: none; }  /* shift-click sorts, rather than selecting text */
.sort-place { font-size: .75em; margin-left: 1px; }
/* A result table's saved filters (saved_filters/_menu.html): a dropdown in its summary bar. */
.saved-filters { position: relative; }
.saved-filters > summary { cursor: pointer; color: var(--accent); }
.saved-filters-panel { position: absolute; right: 0; top: calc(100% + 6px); z-index: 20; width: min(380px, calc(100vw - 32px)); display: flex; flex-direction: column; gap: 10px; background: var(--surface); border: 1px solid var(--rule); border-radius: 8px; padding: 12px; box-shadow: 0 6px 20px rgb(0 0 0 / .15); }
.saved-filters-panel ul { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.saved-filters-panel li { display: flex; flex-wrap: wrap; gap: 6px 10px; align-items: center; overflow-wrap: anywhere; }
.saved-filters-panel p { margin: 0; }
.saved-filter-actions { display: inline-flex; gap: 10px; margin-left: auto; }
.saved-filter-actions form { display: inline; }
.save-filter { display: flex; flex-direction: column; gap: 6px; border-top: 1px solid var(--rule); padding-top: 10px; }
th a.sort:hover { text-decoration: underline; }

/* Fuzzy combobox */
.combo { position: relative; flex: 1 1 220px; min-width: 0; }
.combo input { width: 100%; font: inherit; font-family: var(--mono); font-size: .9rem; color: var(--fg); background: var(--surface); border: 1px solid var(--rule); border-radius: 6px; padding: 7px 10px; }
.combo-list { position: absolute; z-index: 10; top: calc(100% + 2px); left: 0; right: 0; max-height: 260px; overflow-y: auto; margin: 0; padding: 4px 0; list-style: none; background: var(--surface); border: 1px solid var(--rule); border-radius: 6px; box-shadow: 0 6px 18px rgb(0 0 0 / .12); }
.combo-list li { padding: 4px 10px; font-family: var(--mono); font-size: .85rem; cursor: pointer; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.combo-list li[aria-selected=true] { background: var(--accent-soft); }
.combo-list mark { background: none; color: var(--accent); font-weight: 700; }
.combo-list .combo-empty { color: var(--muted); cursor: default; font-family: var(--body); }

/* Completion Audit */
a.button { display: inline-block; border: 1px solid var(--accent); background: var(--accent); color: var(--accent-fg); border-radius: 6px; padding: 7px 16px; text-decoration: none; margin-right: 12px; }
table.mapping td { vertical-align: middle; }
table.mapping .parents { display: flex; flex-wrap: wrap; gap: 8px; }
table.mapping .parent { display: inline-flex; align-items: center; gap: 4px; }
.options { margin-top: 1rem; }
.missing-list { columns: 3 14rem; margin: .5rem 0 1rem; padding-left: 1.2rem; font-size: .85rem; }

/* Doctor */
.check-panel p { margin: 0 0 .5rem; }
.check-panel p:last-child { margin-bottom: 0; }

/* Search */
.search-form fieldset.values { border: 1px solid var(--rule); border-radius: 6px; padding: 8px 12px 12px; margin: 12px 0; }
.search-form fieldset.values p { margin: 0 0 8px; }
#value-rows { display: flex; flex-direction: column; gap: 6px; margin-bottom: 8px; max-width: 40rem; }
.value-row { display: flex; gap: 8px; align-items: center; }
.value-row input { flex: 1; font: inherit; font-family: var(--mono); color: var(--fg); background: var(--surface); border: 1px solid var(--rule); border-radius: 6px; padding: 7px 10px; min-width: 0; }
.search-form label.block { display: block; margin-top: 12px; }
.legend-actions { display: inline-flex; gap: 6px; margin-left: 10px; vertical-align: middle; }
.search-form fieldset.sets { border: 1px solid var(--rule); border-radius: 6px; padding: 8px 12px; margin: 0 0 12px; display: flex; flex-wrap: wrap; gap: 6px 16px; }

/* Messages after an action */
.messages { list-style: none; margin: 0 0 1rem; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.messages li { padding: 8px 12px; border-radius: 6px; background: var(--ok-soft); color: var(--ok); }
.messages li.error { background: var(--bad-soft); color: var(--bad); }

/* Data Control */
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 10px 16px; align-items: start; }
.form-grid > div { display: flex; flex-direction: column; gap: 4px; }
.form-grid label { font-weight: 500; }
.form-grid .wide { grid-column: 1 / -1; }
.form-grid .helptext { font-size: .8rem; color: var(--muted); }
details.cannot-replace { margin-top: .5rem; padding: 0; }
details.field-list { margin-top: 10px; }
details.field-list > summary { cursor: pointer; display: flex; gap: 12px; align-items: baseline; }
.field-columns { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 16px; }
.field-columns ul { margin: 0; padding-left: 1.25rem; columns: 2 14rem; }
.field-columns h3 { margin: 12px 0 6px; }
.cannot-heading { margin-top: 2.5rem; padding-top: 1.25rem; border-top: 1px solid var(--rule); }
.cannot-reasons { margin: .25rem 0 0; padding-left: 1.25rem; columns: 2 22rem; }
.cannot-reasons li { break-inside: avoid; }
details.cannot-replace > summary { padding: 8px 12px; cursor: pointer; }
.comment-cell { max-width: 28ch; overflow: hidden; text-overflow: ellipsis; }
.reserve-rows td { vertical-align: top; white-space: normal; }
.reserve-rows input[type=text], .reserve-rows input[type=number] { font: inherit; color: var(--fg); background: var(--surface); border: 1px solid var(--rule); border-radius: 6px; padding: 5px 8px; width: 100%; min-width: 7em; }
.reserve-rows input.narrow { min-width: 4em; max-width: 6em; }
.reserve-rows .helptext, .reserve-rows .form-error { display: block; font-size: .8rem; margin-top: 4px; }
.reserve-rows .helptext { color: var(--muted); }
.pill.ok, .pill.approved { background: var(--ok-soft); color: var(--ok); }
.pill.warn, .pill.reserved { background: var(--warn-soft); color: var(--warn); }
.pill.bad, .pill.never_reuse { background: var(--bad-soft); color: var(--bad); }
.tools { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; }
.tools .panel h3 { margin-top: 0; }
.inline { display: inline; }

/* Documents */
.nowrap { white-space: nowrap; }
/* A table cell whose text may wrap (e.g. a list of report names), so the table fits the page. */
table.list td.wrap { white-space: normal; min-width: 18ch; max-width: 40ch; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.toolbar a[aria-current="page"] { font-weight: 600; text-decoration: none; color: var(--fg); }
.chip { display: inline-block; background: var(--accent-soft); border-radius: 999px; padding: 0 4px 0 10px; margin: 1px 0; font-size: .85rem; white-space: nowrap; }
.chip button.link { padding: 0 4px; }
table.list tr.highlight td { background: var(--warn-soft); }
/* The Documents table page: the list box beside the table */
.documents-viewer { grid-template-columns: minmax(220px, 300px) minmax(0, 1fr); }
.list-box { display: flex; flex-direction: column; gap: 8px; min-width: 0; border: 1px solid var(--rule); border-radius: 6px; background: var(--surface); padding: 10px 12px; position: sticky; top: 12px; }
.list-box h2 { margin: 0; font-size: 1rem; display: flex; justify-content: space-between; align-items: baseline; }
.list-box .count { color: var(--muted); font-size: .8rem; font-weight: 400; font-variant-numeric: tabular-nums; }
.list-box form { display: flex; flex-direction: column; gap: 8px; }
.list-items { list-style: none; margin: 0; padding: 0; max-height: 60vh; overflow-y: auto; border-top: 1px solid var(--rule); }
.list-items li { display: flex; flex-direction: column; gap: 2px; padding: 6px 2px; border-bottom: 1px solid var(--rule); }
.list-items li .mono { font-size: .85rem; overflow-wrap: anywhere; }
.list-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
