/* ------------------------------------------------------------------ *
 *  Systematic Utility — admin UI stylesheet (base rules + components).
 *
 *  Design tokens (colors/typography/radii/spacing) are NOT here: they live
 *  in static/ui/themes/<theme>.css, generated from themes/manifest_*.py by
 *  `codegen.py -f css` and linked directly from templates/base.html. Theme is
 *  driven by the `data-theme` attribute on <html>.
 * ------------------------------------------------------------------ */

/* ----------------------------- base ----------------------------- */
* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  background: var(--background);
  color: var(--on-background);
  font-family: Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

code, .mono, .id { font-family: "JetBrains Mono", ui-monospace, monospace; }

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

h1 { font-size: 24px; font-weight: 600; letter-spacing: -0.02em; margin: 0 0 .25rem; }
h2 { font-size: 20px; font-weight: 600; letter-spacing: -0.01em; margin: 0 0 .25rem; }
h3 { font-size: 16px; font-weight: 600; margin: 0; }

.label {
  text-transform: uppercase;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--on-surface-variant);
}
.muted { color: var(--on-surface-variant); }

/* --------------------------- app shell -------------------------- */
.app { display: flex; min-height: 100vh; }

.sidebar {
  width: 240px;
  flex-shrink: 0;
  background: var(--surface-container-low);
  border-right: 1px solid var(--outline-variant);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow: hidden;            /* brand fixed, nav scrolls, account pinned */
  transition: width .15s ease;
}

/* ---- Collapsed sidebar: an icon-only rail. Toggled by the topbar button
   (toggleSidebar in base.html) and remembered in localStorage. ---- */
body.sidebar-collapsed .sidebar { width: 64px; }
body.sidebar-collapsed .sidebar .brand { justify-content: center; padding-left: 0; padding-right: 0; }
body.sidebar-collapsed .sidebar .brand > span,
body.sidebar-collapsed .sidebar .brand .help-icon,
body.sidebar-collapsed .nav-section,
body.sidebar-collapsed .nav-link > span,
body.sidebar-collapsed .nav-group .twirl,
body.sidebar-collapsed .nav-group-row > .twirl,
body.sidebar-collapsed .nav-group-row .help-icon,
body.sidebar-collapsed .nav-children,
body.sidebar-collapsed .account-name { display: none !important; }
body.sidebar-collapsed .nav-link,
body.sidebar-collapsed .nav-group-row { justify-content: center; }
body.sidebar-collapsed .nav-link { padding-left: .5rem; padding-right: .5rem; }
body.sidebar-collapsed .account-user { padding-left: 0; padding-right: 0; }
body.sidebar-collapsed .account-user h2 { justify-content: center; }
body.sidebar-collapsed .sidebar-account { align-items: center; }
.sidebar .brand {
  display: flex; align-items: center; gap: .6rem;
  padding: 1rem 1.25rem;
  font-weight: 600;
  border-bottom: 1px solid var(--outline-variant);
  flex-shrink: 0;
}

/* Manifest help link — a muted question-mark icon shown next to an element
   (project brand, and later schema/table/column headers). Brightens on hover;
   pushed to the trailing edge when it sits in the brand row. */
.help-icon {
  display: inline-flex; align-items: center; justify-content: center;
  vertical-align: middle;      /* aligns the icon when it trails an <h1> text run */
  margin-left: .3rem;          /* small gap after the label it annotates */
  color: var(--on-surface-variant); opacity: .6;
  text-decoration: none; flex-shrink: 0;
}
.help-icon:hover { opacity: 1; color: var(--primary); }
.help-icon i { width: 16px; height: 16px; }
/* lucide icon inherited onto a form section header (column-group ui_icon) — sized
   down to sit inline with the small uppercase heading text. */
.section-icon { width: 14px; height: 14px; vertical-align: middle; }
/* lucide icon (column ``ui_icon``) rendered before a column's label in grid
   headers / form field labels / filter labels. Inherits the label colour. */
.col-icon { width: 14px; height: 14px; vertical-align: middle; margin-right: .3rem; }
/* table ``ui_icon`` before the grid's <h1> title — sized to the 24px heading. */
.grid-title-icon { width: 1.25rem; height: 1.25rem; vertical-align: middle; margin-right: .4rem; }
.sidebar .brand .help-icon { margin-left: auto; }
/* the menu is the only scrolling region; brand + account stay put */
.sidebar nav { padding: .5rem; display: flex; flex-direction: column; gap: 2px; flex: 1 1 auto; overflow-y: auto; min-height: 0; }

/* Account block pinned to the sidebar bottom */
.sidebar-account {
  flex-shrink: 0;
  border-top: 1px solid var(--outline-variant);
  padding: .5rem;
  display: flex; flex-direction: column; gap: 2px;
}
.account-user {
  padding: .6rem .75rem; min-width: 0;
}
/* the markup wraps avatar + name in an <h2>; reset its heading defaults and make
   it a left-aligned row so the avatar comes first with the username inline beside
   it, both on the same level (vertically centred) */
.account-user h2 {
  margin: 0; font: inherit;
  display: flex; align-items: center; gap: .6rem;
  min-width: 0;
}
.account-avatar {
  width: 32px; height: 32px; border-radius: 50%;
  object-fit: cover; flex-shrink: 0;
  background: var(--surface-container);
}
.account-avatar-fallback {
  display: inline-flex; align-items: center; justify-content: center;
  color: var(--on-surface-variant);
}
.account-avatar-fallback svg { width: 18px; height: 18px; }
.account-name {
  font-weight: 600; min-width: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.nav-link {
  display: flex; align-items: center; gap: .6rem;
  padding: .55rem .75rem;
  border-radius: .375rem;
  color: var(--on-surface);
  font-weight: 500;
}
.nav-link:hover { background: var(--surface-container); text-decoration: none; }
.nav-link.active { background: var(--primary); color: var(--on-primary); }
.nav-section { padding: .75rem .75rem .25rem; }

/* expandable nav groups */
[x-cloak] { display: none !important; }
.nav-group {
  width: 100%; border: none; background: transparent; cursor: pointer;
  font: inherit; font-weight: 500; text-align: left; color: var(--on-surface);
}
.nav-group .twirl { margin-left: auto; display: inline-flex; transition: transform .15s ease; }
.nav-group .twirl.open { transform: rotate(90deg); }
/* Group header row: the toggle button grows to fill, the help ? and the expand
   twirl trail it (twirl lives outside the button so the help link — an <a> —
   isn't nested inside a <button>, which is invalid). */
.nav-group-row { display: flex; align-items: center; }
.nav-group-row .nav-group { flex: 1 1 auto; width: auto; }
.nav-group-row > .twirl {
  display: inline-flex; align-items: center; cursor: pointer;
  transition: transform .15s ease; color: var(--on-surface-variant);
}
.nav-group-row > .twirl.open { transform: rotate(90deg); }
.nav-children { display: flex; flex-direction: column; gap: 2px; padding-left: .85rem; }
.nav-children .nav-link { font-weight: 400; }

.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 1rem;
  padding: .75rem 1.5rem;
  border-bottom: 1px solid var(--outline-variant);
  background: var(--surface-container-lowest);
  position: sticky; top: 0; z-index: 20;
}
.content { padding: 1.5rem; flex: 1; }
/* CMS pages render their own full-bleed sections (backgrounds span the whole
   width; inner content is centered/padded by base.css's .cms-section__inner), so
   drop the admin content padding when a CMS page is shown inside the shell. */
.app:has(.cms-page) .content { padding: 0; }

/* ---------------------------- cards ----------------------------- */
.card {
  background: var(--surface-container-lowest);
  border: 1px solid var(--outline-variant);
  border-radius: .5rem;
  box-shadow: var(--shadow);
}
.card-header {
  display: flex; align-items: center; justify-content: space-between;
  gap: 1rem;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--outline-variant);
}
.card-body { padding: 1.25rem; }
/* ACE code editor (JSON / code fields). ACE auto-sizes via min/maxLines; the
   container just supplies the frame and rounded corners. */
.ace-editor {
  width: 100%;
  min-height: 9rem;
  border: 1px solid var(--outline-variant);
  border-radius: .5rem;
  font-size: 13px;
  line-height: 1.4;
}
.card-footer {
  display: flex; align-items: center; justify-content: flex-end;
  gap: .5rem;
  padding: 1rem 1.25rem;
  border-top: 1px solid var(--outline-variant);
}

/* --------------------------- buttons ---------------------------- */
.btn {
  display: inline-flex; align-items: center; gap: .4rem;
  padding: .5rem .9rem;
  border-radius: .25rem;
  border: 1px solid transparent;
  font: inherit; font-weight: 600; font-size: 13px;
  cursor: pointer;
  background: var(--primary); color: var(--on-primary);
  transition: filter .12s ease, background .12s ease;
}
.btn:hover { filter: brightness(1.08); text-decoration: none; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-ghost { background: transparent; color: var(--on-surface); border-color: var(--outline-variant); }
.btn-ghost:hover { background: var(--surface-container); filter: none; }
.btn-danger { background: var(--error); color: var(--on-error); }
.btn-sm { padding: .3rem .6rem; font-size: 12px; }
.btn-icon { padding: .4rem; background: transparent; color: var(--on-surface-variant); border-color: transparent; }
.btn-icon:hover { background: var(--surface-container); color: var(--on-surface); }
/* empty slot for a per-row-hidden action — keeps same-type icons aligned across
   rows (see _action_ph.html). Occupies a real btn-icon's space, but invisible. */
.btn-icon-ph { visibility: hidden; pointer-events: none; }
.btn-icon-ph:hover { background: transparent; }

/* ---------------------------- forms ----------------------------- */
.field { display: flex; flex-direction: column; gap: .3rem; margin-bottom: 1rem; }
.field > label { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--on-surface-variant); }
.input, .select, .textarea {
  width: 100%;
  padding: .5rem .65rem;
  background: var(--surface-container-lowest);
  border: 1px solid var(--outline-variant);
  border-radius: .25rem;
  color: var(--on-surface);
  font: inherit; font-size: 14px;
}
/* Dropdown options: pair background and text explicitly so the popup never
   ends up same-on-same (option styling is honored where the browser allows it;
   color-scheme above covers the rest). */
.select option { background: var(--surface-container-lowest); color: var(--on-surface); }
.input::placeholder, .textarea::placeholder { color: var(--on-surface-variant); opacity: .7; }
.textarea { min-height: 80px; resize: vertical; font-family: "JetBrains Mono", monospace; font-size: 13px; }
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 2px color-mix(in srgb, var(--primary) 25%, transparent); }

/* Clearable search box (templates/_search_form.html, _manifest_grid.html): an
   in-field "x" button that appears only while there's a query (the .has-text
   class is toggled by the input, or rendered server-side) and wipes the search. */
.search-field { position: relative; display: inline-block; }
.search-field .input { padding-right: 1.85rem; }
/* suppress the browser's native search clear so we don't render two x's */
.search-field .input::-webkit-search-cancel-button { -webkit-appearance: none; appearance: none; }
.search-field .search-clear {
  position: absolute; top: 50%; right: .4rem; transform: translateY(-50%);
  display: block; align-items: center; justify-content: center;
  padding: 2px; border: 0; background: transparent; cursor: pointer;
  color: var(--on-surface-variant); line-height: 0;
}
.search-field.has-text .search-clear { display: inline-flex; }
.search-field .search-clear:hover { color: var(--on-surface); }
.search-field .search-clear svg, .search-field .search-clear i { width: 15px; height: 15px; }
.checkbox { width: 16px; height: 16px; accent-color: var(--primary); }
.form-row { display: flex; gap: 1rem; }
.form-row > * { flex: 1; }

/* on/off switch (permission-overview matrix toggles) */
.switch { position: relative; display: inline-block; width: 38px; height: 22px; flex: 0 0 auto;
  border: none; border-radius: 999px; background: var(--outline-variant); cursor: pointer; padding: 0;
  transition: background .15s ease; vertical-align: middle; }
.switch .switch-knob { position: absolute; top: 2px; left: 2px; width: 18px; height: 18px;
  border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,.3); transition: left .15s ease; }
.switch.on { background: var(--primary); }
.switch.on .switch-knob { left: 18px; }
.switch:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
/* labelled switch row (e.g. the admin Settings modal) */
.switch-row { display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: .6rem 0; border-bottom: 1px solid var(--outline-variant); font-size: 14px; }
.switch-row:last-child { border-bottom: none; }
.switch-row svg { width: 16px; height: 16px; color: var(--on-surface-variant); }

/* permission-overview matrix: sticky header row + sticky first column */
.perm-matrix th, .perm-matrix td { white-space: nowrap; }
.perm-matrix thead th { position: sticky; top: 0; z-index: 2; background: var(--surface-container-low, var(--surface-container-lowest)); }
.perm-matrix .sticky-col { position: sticky; left: 0; z-index: 1; background: var(--surface-container-lowest); text-align: left; }
.perm-matrix thead th.sticky-col { z-index: 3; }

/* Tabulator (editable grid modal) — blend the light-only base theme with the
   app's surface/on-surface variables so it works in dark mode too. */
.tabulator { background: var(--surface-container-lowest); border-color: var(--outline-variant); color: var(--on-surface); font-family: inherit; font-size: 13px; }
.tabulator .tabulator-header, .tabulator .tabulator-header .tabulator-col { background: var(--surface-container-low, var(--surface-container-lowest)); color: var(--on-surface); border-color: var(--outline-variant); }
.tabulator .tabulator-row { background: var(--surface-container-lowest); color: var(--on-surface); }
.tabulator .tabulator-row.tabulator-row-even { background: var(--surface-container, var(--surface-container-lowest)); }
.tabulator .tabulator-row .tabulator-cell { border-color: var(--outline-variant); }
/* taller rows (~50% more than Tabulator's default) — more vertical padding so
   the row grows with content rather than being clipped to a fixed height. */
.tabulator .tabulator-row .tabulator-cell { padding-top: 11px; padding-bottom: 11px; }
.tabulator .tabulator-row:hover { background: var(--surface-container-high, var(--surface-container)); }
.tabulator .tabulator-footer { background: var(--surface-container-low, var(--surface-container-lowest)); color: var(--on-surface); border-color: var(--outline-variant); }
.tabulator .tabulator-cell.tabulator-editing input, .tabulator .tabulator-cell.tabulator-editing select { background: var(--surface-container-lowest); color: var(--on-surface); border-color: var(--primary); }
.tabulator-edit-list { background: var(--surface-container-lowest); color: var(--on-surface); border: 1px solid var(--outline-variant); }
.tabulator-edit-list .tabulator-edit-list-item { color: var(--on-surface); }
.tabulator-edit-list .tabulator-edit-list-item.active, .tabulator-edit-list .tabulator-edit-list-item:hover { background: var(--primary); color: var(--on-primary); }

/* --------------------------- tables ----------------------------- */
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: 13px; }
table.data thead th {
  position: sticky; top: 0;
  text-align: left;
  text-transform: uppercase;
  font-size: 11px; font-weight: 600; letter-spacing: .03em;
  color: var(--on-surface-variant);
  padding: .55rem .75rem;
  background: var(--surface-container);
  border-bottom: 1px solid var(--outline-variant);
  white-space: nowrap;
}
table.data tbody td { padding: .5rem .75rem; border-bottom: 1px solid var(--outline-variant); vertical-align: top; }
table.data tbody tr:hover { background: var(--surface-container-low); }
table.data .id { font-size: 12px; color: var(--on-surface-variant); }
/* bookmark toggle on list rows: outline when off, filled amber when on */
.bookmark-toggle.on { color: var(--warning); }
.bookmark-toggle.on svg { fill: currentColor; }
/* boolean cells render as icons: check (true) / minus (false) */
table.data .bool-icon { width: 24px; height: 24px; vertical-align: middle; }
table.data tbody tr.clickable { cursor: pointer; }

/* severity-level badges (logs): info=green, warning=amber, error/critical=red */
.sev {
  display: inline-block; padding: .1rem .5rem; border-radius: 999px;
  font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .02em;
  border: 1px solid transparent; white-space: nowrap;
}
.sev-info { color: var(--success); background: color-mix(in srgb, var(--success) 14%, transparent); border-color: color-mix(in srgb, var(--success) 35%, transparent); }
.sev-warning { color: var(--warning); background: color-mix(in srgb, var(--warning) 16%, transparent); border-color: color-mix(in srgb, var(--warning) 38%, transparent); }
.sev-error, .sev-critical { color: var(--error); background: color-mix(in srgb, var(--error) 14%, transparent); border-color: color-mix(in srgb, var(--error) 35%, transparent); }

/* read-only detail view (log rows) */
.detail-value { font-size: 13px; color: var(--on-surface); word-break: break-word; }
.detail-value.id { font-family: var(--font-mono, ui-monospace, monospace); font-size: 12px; color: var(--on-surface-variant); }
.detail-pre {
  margin: 0; padding: .6rem .75rem;
  background: var(--surface-container); border: 1px solid var(--outline-variant);
  border-radius: .375rem; max-height: 320px; overflow: auto;
  font-family: var(--font-mono, ui-monospace, monospace); font-size: 12px; line-height: 1.5;
  white-space: pre-wrap; word-break: break-word; color: var(--on-surface);
}
table.data .bool-icon.on { color: var(--success); }
table.data .bool-icon.off { color: var(--on-surface-variant); }

/* ---------------------------- tree ------------------------------ */
.tree { width: 100%; border-collapse: collapse; font-size: 13px; }
.tree td { padding: .4rem .6rem; border-bottom: 1px solid var(--outline-variant); }
.tree tr:hover { background: var(--surface-container-low); }
.tree .node-cell { display: flex; align-items: center; gap: .4rem; }
.tree .twisty {
  display: inline-flex; align-items: center; justify-content: center;
  width: 28px; height: 28px; border-radius: .25rem;
  cursor: pointer; color: var(--on-surface);
  border: none; background: transparent;
  flex-shrink: 0;
}
.tree .twisty svg { width: 22px; height: 22px; stroke-width: 2.5; flex-shrink: 0; }
.tree .twisty:hover { background: var(--surface-container-high); }
.tree .twisty.leaf { visibility: hidden; }
.tree .node-label { font-weight: 500; }
.tree .htmx-request .twisty svg { animation: spin .8s linear infinite; }
.kind-chip {
  font-size: 10px; text-transform: uppercase; letter-spacing: .04em;
  padding: .1rem .4rem; border-radius: 9999px;
  background: var(--surface-container-high); color: var(--on-surface-variant);
  font-weight: 600;
}
/* hierarchy levels — one tinted hue per level so rows scan at a glance */
.kind-chip.kind-realm      { background: color-mix(in srgb, var(--primary) 20%, transparent); color: var(--primary); }
.kind-chip.kind-domain     { background: color-mix(in srgb, var(--success) 20%, transparent); color: var(--success); }
.kind-chip.kind-rule       { background: color-mix(in srgb, var(--warning) 20%, transparent); color: var(--warning); }
.kind-chip.kind-rule_value { background: color-mix(in srgb, var(--violet)  20%, transparent); color: var(--violet); }

/* --------------------------- chips ------------------------------ */
.chip { display: inline-flex; align-items: center; gap: .3rem; font-size: 11px; padding: .15rem .5rem; border-radius: 9999px; background: var(--surface-container-high); color: var(--on-surface-variant); }
.chip.ok { background: color-mix(in srgb, var(--success) 18%, transparent); color: var(--success); }
.chip.warn { background: color-mix(in srgb, var(--warning) 18%, transparent); color: var(--warning); }
.chip.err { background: color-mix(in srgb, var(--error) 18%, transparent); color: var(--error); }
.chip.info { background: color-mix(in srgb, var(--primary) 18%, transparent); color: var(--primary); }

/* Celery worker online/offline pill (operations queue list header). Mirrors the
   dataflow editor's .df-worker; empty until the first poll resolves. */
.worker-pill:empty { display: none; }
.worker-pill { display: inline-flex; align-items: center; gap: .35rem; font-size: 11px;
  padding: .15rem .55rem; border-radius: 9999px; white-space: nowrap;
  background: var(--surface-container-high); color: var(--on-surface-variant); }
.worker-pill .dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.worker-pill.online { color: var(--success); background: color-mix(in srgb, var(--success) 16%, transparent); }
.worker-pill.offline { color: var(--warning); background: color-mix(in srgb, var(--warning) 18%, transparent); }

/* Colour-graded inline-edit select (e.g. the queue priority dropdown): tints the
   control + its options by the column's value_color_json class, reusing the chip
   palette. The tone class is set on render and refreshed on change (see
   _inline_edit.html). */
.inline-select { font-weight: 600; border-color: transparent; }
.inline-select.ok   { background: color-mix(in srgb, var(--success) 18%, transparent); color: var(--success); }
.inline-select.warn { background: color-mix(in srgb, var(--warning) 18%, transparent); color: var(--warning); }
.inline-select.err  { background: color-mix(in srgb, var(--error)   18%, transparent); color: var(--error); }
.inline-select.info { background: color-mix(in srgb, var(--primary) 18%, transparent); color: var(--primary); }
.inline-select option        { background: var(--surface-container-high); color: var(--on-surface); font-weight: 500; }
.inline-select option.ok     { color: var(--success); }
.inline-select option.warn   { color: var(--warning); }
.inline-select option.err    { color: var(--error); }
.inline-select option.info   { color: var(--primary); }

/* ------------------------- pagination --------------------------- */
.pagination { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; padding: .75rem 1.25rem; border-top: 1px solid var(--outline-variant); }
.pagination .pages { display: flex; gap: 2px; }
.pagination .page-btn { min-width: 32px; text-align: center; padding: .3rem .5rem; border-radius: .25rem; border: 1px solid var(--outline-variant); background: var(--surface-container-lowest); color: var(--on-surface); cursor: pointer; font-size: 12px; }
.pagination .page-btn.active { background: var(--primary); color: var(--on-primary); border-color: var(--primary); }
.pagination .page-btn:hover:not(.active) { background: var(--surface-container); }

/* ---------------------------- modal ----------------------------- */
.modal-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.5); display: flex; align-items: flex-start; justify-content: center; padding: 4rem 1rem; z-index: 50; }
.modal { background: var(--surface-container-lowest); border: 1px solid var(--outline-variant); border-radius: .75rem; width: 100%; max-width: 640px; max-height: 85vh; overflow-y: auto; box-shadow: 0 12px 32px rgba(0,0,0,.35); }
/* Add/Edit forms: freeze the header (title + close) and footer (save) while the
   field area scrolls. The modal becomes a flex column with a non-scrolling
   shell and only the body overflowing. */
.modal-flex { display: flex; flex-direction: column; overflow: hidden; }
.modal-flex > form { display: flex; flex-direction: column; min-height: 0; flex: 1 1 auto; }
.modal-flex .card-header { flex: 0 0 auto; }
.modal-flex .card-footer { flex: 0 0 auto; }
.modal-flex .card-body { flex: 1 1 auto; min-height: 0; overflow-y: auto; }

/* ------------------- maximizable modals ------------------------- */
/* Bookmarks, query builder + entity forms: 60% wide / 80% tall by default;
   .maximized on the backdrop (persisted in localStorage) grows the modal to
   nearly full screen — the backdrop padding shrinks with it. */
.modal-60 { width: 60vw; height: 80vh; max-width: none; max-height: none; }
.modal-pivot { width: 88vw; height: 84vh; max-width: 1500px; max-height: none; }
.modal-backdrop.maximized { padding: 1rem; }
.modal-backdrop.maximized .modal-60 { width: 100%; height: calc(100vh - 2rem); }
.modal-backdrop.maximized .modal-pivot { width: 100%; max-width: none; height: calc(100vh - 2rem); }

/* ------------------------- chart tooltips ----------------------- */
/* ApexCharts' light/dark tooltip can leave dark text on a dark slice/bg.
   Force the app's surface/on-surface pair (they flip with the theme), so the
   text is always readable — dark-on-light in light mode, light-on-dark in dark. */
.apexcharts-tooltip {
  background: var(--surface-container-lowest) !important;
  color: var(--on-surface) !important;
  border: 1px solid var(--outline-variant) !important;
  box-shadow: 0 4px 16px rgba(0,0,0,.25) !important;
}
.apexcharts-tooltip-title {
  background: var(--surface-container-lowest) !important;
  color: var(--on-surface) !important;
  border-bottom: 1px solid var(--outline-variant) !important;
  font-weight: 600;
}
/* every text node inside the tooltip (labels + values), overriding inline colors */
.apexcharts-tooltip * { color: var(--on-surface) !important; }

/* ---------------------------- misc ------------------------------ */
.flash { padding: .6rem .9rem; border-radius: .375rem; margin-bottom: 1rem; font-size: 13px; }
.flash.error { background: var(--error-container); color: var(--on-error-container); }
.flash.success { background: color-mix(in srgb, var(--success) 18%, transparent); color: var(--success); }
.center-screen { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 1.5rem; background: var(--background); }
.auth-card { width: 100%; max-width: 400px; }
/* will-change promotes the spinner to its own compositor layer so the rotate
   animation keeps running on the GPU/compositor thread even while the main thread
   is blocked by heavy synchronous work (big JSON.parse, chart/pivot render) —
   otherwise the spinner visibly freezes exactly when it's needed most. */
.spinner { display: inline-block; width: 16px; height: 16px; border: 2px solid var(--outline-variant); border-top-color: var(--primary); border-radius: 50%; animation: spin .7s linear infinite; will-change: transform; }
@keyframes spin { to { transform: rotate(360deg); } }
.toolbar { display: flex; align-items: center; gap: .75rem; flex-wrap: wrap; margin-bottom: 1rem; }

/* ---- Frozen list layout: the heading, toolbar and column titles stay put,
   only the table body scrolls. Scoped to pages that contain a list table. ---- */
.app:has(#admin-table), .app:has(#log-table) { height: 100vh; overflow: hidden; }
.app:has(#admin-table) .content,
.app:has(#log-table) .content { min-height: 0; display: flex; flex-direction: column; overflow: hidden; }
.app:has(#admin-table) .toolbar,
.app:has(#log-table) .toolbar { flex: 0 0 auto; }
.app:has(#admin-table) .card,
.app:has(#log-table) .card { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; overflow: hidden; }
#admin-table, #log-table { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; overflow: hidden; }
#admin-table > .table-wrap, #log-table > .table-wrap { flex: 1 1 auto; min-height: 0; overflow: auto; }
#admin-table > .pagination, #log-table > .pagination { flex: 0 0 auto; }
.grow { flex: 1; }
.htmx-indicator { opacity: 0; transition: opacity .2s; }
.htmx-request .htmx-indicator, .htmx-request.htmx-indicator { opacity: 1; }

/* flag images */
.flag-img { width: 22px; height: 16px; object-fit: cover; border-radius: 2px; border: 1px solid var(--outline-variant); vertical-align: middle; flex-shrink: 0; }
/* in data-table listings, match the 24px lucide action icons; width follows
   the image's natural aspect */
table.data .flag-img { height: 24px; width: auto; object-fit: contain; }
/* align-self keeps the natural aspect inside .field (a column flexbox would
   otherwise stretch the img to full width while the height stays fixed) */
.flag-img-lg { height: 64px; width: auto; max-width: 100%; object-fit: contain; align-self: flex-start; border-radius: 3px; border: 1px solid var(--outline-variant); display: block; margin-bottom: .5rem; }

/* drag-and-drop image/file upload (see templates/_image_drop.html) */
.image-drop {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: .625rem; min-height: 7rem; padding: 1rem;
  border: 1.5px dashed var(--outline-variant); border-radius: .375rem;
  background: var(--surface-container-lowest);
  transition: border-color .15s ease, background .15s ease;
}
.image-drop.dragover { border-color: var(--primary); background: color-mix(in srgb, var(--primary) 8%, transparent); }
/* native picker is hidden; the styled "Choose file" button proxies to it */
.image-drop-input { display: none; }
/* edit-box preview: never taller than 200px, aspect ratio preserved */
.image-drop-preview { max-height: 200px; max-width: 100%; width: auto; height: auto; object-fit: contain; border-radius: .25rem; border: 1px solid var(--outline-variant); }
.image-drop-prompt { display: flex; flex-direction: column; align-items: center; gap: .375rem; color: var(--on-surface-variant); font-size: 13px; text-align: center; }
.image-drop-prompt svg { width: 30px; height: 30px; stroke-width: 1.5; opacity: .85; }
.image-drop-file { display: inline-flex; align-items: center; gap: .4rem; font-size: 13px; color: var(--on-surface); }
.image-drop-file svg { width: 16px; height: 16px; }
.image-drop-actions { display: flex; gap: .5rem; flex-wrap: wrap; justify-content: center; }
.image-drop-actions svg { width: 15px; height: 15px; }

/* flag-aware select widget */
.flag-select { position: relative; }
.flag-select-btn { display: flex; align-items: center; gap: .5rem; width: 100%; text-align: left; cursor: pointer; }
.flag-select-panel {
  position: absolute; z-index: 40; top: calc(100% + 4px); left: 0; right: 0;
  background: var(--surface-container-lowest); border: 1px solid var(--outline-variant);
  border-radius: .375rem; box-shadow: 0 8px 24px rgba(0,0,0,.25); padding: .4rem; max-height: 280px; display: flex; flex-direction: column; gap: .35rem;
}
/* HTMX autocomplete result panels carry this class but hold no markup until a
   search swaps results in (and are cleared again on blur/outside-click) — keep
   the empty container from rendering as a stray bordered box. */
.flag-select-panel:empty { display: none; }
.flag-select-list { overflow-y: auto; }
.flag-opt-row { display: flex; align-items: center; gap: .5rem; padding: .4rem .5rem; border-radius: .25rem; cursor: pointer; }
.flag-opt-row:hover { background: var(--surface-container); }

/* FontAwesome icon picker (iconPicker in base.html) */
.icon-select { position: relative; }
.icon-select-btn { display: flex; align-items: center; gap: .5rem; width: 100%; text-align: left; cursor: pointer; }
.icon-select-clear { display: inline-flex; cursor: pointer; color: var(--on-surface-variant); }
.icon-select-clear:hover { color: var(--on-surface); }
.icon-select-panel {
  /* full width of the field — the 5-column grid stretches to fill it */
  position: absolute; z-index: 40; top: calc(100% + 4px); left: 0; right: 0;
  background: var(--surface-container-lowest); border: 1px solid var(--outline-variant);
  border-radius: .375rem; box-shadow: 0 8px 24px rgba(0,0,0,.25); padding: .4rem;
  display: flex; flex-direction: column; gap: .35rem;
}
.icon-select-grid {
  /* a fixed row height keeps "5 rows tall" deterministic even when the panel is
     wider than its min-width; beyond 5 rows the grid scrolls. */
  overflow-y: auto; display: grid; gap: .25rem;
  grid-template-columns: repeat(auto-fill, minmax(64px, 1fr)); grid-auto-rows: 64px;
  max-height: calc(64px * 5 + .25rem * 4);
}
.icon-opt {
  display: flex; align-items: center; justify-content: center;
  border: 1px solid transparent; border-radius: .3rem; background: transparent;
  color: var(--on-surface); cursor: pointer; font-size: 32px;
}
.icon-opt:hover { background: var(--surface-container); border-color: var(--outline-variant); }
.icon-opt.on { background: var(--primary); color: var(--on-primary); }
/* picker footer: icon count on the left, prev/next pager on the right */
.icon-select-foot { display: flex; align-items: center; justify-content: space-between; gap: .5rem; padding: .1rem .25rem; }
.icon-select-pager { display: flex; align-items: center; gap: .15rem; }
.icon-select-pager .btn-icon:disabled { opacity: .35; cursor: default; }
/* Lucide picker cells render an injected <svg> (not a font glyph), so size the
   svg rather than font-size. */
.icon-opt-lucide svg { width: 28px; height: 28px; }
/* FontAwesome icon shown in a list cell — twice the surrounding text size */
table.data .list-icon { font-size: 2em; vertical-align: middle; }
/* Lucide icon shown in a list cell — an injected <svg>, sized explicitly */
table.data .list-icon-lucide { width: 1.6em; height: 1.6em; vertical-align: middle; }
/* JSON cell: a "braces" icon in the grid whose formatted value pops up
   underneath on hover. The popover (#json-hover-popover) is a single element
   appended to <body> by the handler in base.html so it escapes the table's
   overflow clipping; styles below cover both the trigger and that element. */
.json-cell { display: inline-flex; align-items: center; cursor: help; color: var(--on-surface-variant); }
.json-cell:hover, .json-cell:focus-visible { color: var(--primary); outline: none; }
.json-cell .json-icon { width: 18px; height: 18px; }
#json-hover-popover {
  position: fixed; z-index: 1000; display: none; pointer-events: none;
  margin: 0; max-width: 480px; max-height: 360px; overflow: hidden;
  padding: .6rem .75rem; border-radius: .5rem;
  background: var(--surface-container-high); color: var(--on-surface);
  border: 1px solid var(--outline-variant); box-shadow: 0 8px 24px rgba(0,0,0,.35);
  font-family: 'JetBrains Mono', ui-monospace, monospace; font-size: 12px; line-height: 1.45;
  white-space: pre; tab-size: 2;
}
/* Failed-status chip: the chip becomes a hover trigger revealing the row's
   error_text in the body-level #status-hover-popover (wired in base.html). */
.status-pop { cursor: help; }
#status-hover-popover {
  position: fixed; z-index: 1000; display: none; pointer-events: none;
  margin: 0; max-width: 420px; max-height: 320px; overflow: hidden;
  padding: .55rem .7rem; border-radius: .5rem;
  background: var(--surface-container-high); color: var(--on-surface);
  border: 1px solid var(--outline-variant); box-shadow: 0 8px 24px rgba(0,0,0,.35);
  font-size: 12px; line-height: 1.45; white-space: pre-wrap; word-break: break-word;
}
/* thumbnail image shown in a list cell (e.g. pickup-order photo) */
table.data .list-img { height: 44px; width: auto; max-width: 80px; object-fit: cover;
  border-radius: 4px; border: 1px solid var(--outline-variant); vertical-align: middle; }

/* --------------------------------------------------------------------------
   PivotTable.js — themed to match the app (scoped to #pivot-output, so the
   ID selectors win over the library's default class rules in either theme).
   -------------------------------------------------------------------------- */
#pivot-output { font-size: 13px; color: var(--on-surface); }
#pivot-output table.pvtUi { color: var(--on-surface); border-collapse: separate; border-spacing: 8px; }
#pivot-output table.pvtUi > tbody > tr > td { padding: 0; vertical-align: top; }

/* drop zones (unused / rows / cols / vals) */
#pivot-output .pvtAxisContainer,
#pivot-output td.pvtVals {
  background: var(--surface-container-low);
  border: 1px solid var(--outline-variant);
  border-radius: .5rem;
  padding: .4rem;
}
#pivot-output .pvtAxisContainer.pvtHorizList li,
#pivot-output .pvtAxisContainer.pvtVertList li { margin: .15rem; }

/* draggable attribute pills (look like the app's chips) */
#pivot-output .pvtAxisContainer li span.pvtAttr {
  background: var(--surface-container-highest);
  border: 1px solid var(--outline-variant);
  color: var(--on-surface);
  border-radius: 999px;
  padding: .2rem .55rem;
  font-size: 12px;
  white-space: nowrap;
  box-shadow: var(--shadow);
}
#pivot-output .pvtAxisContainer li.pvtPlaceholder {
  border: 1px dashed var(--primary);
  border-radius: 999px;
}
#pivot-output .pvtTriangle { color: var(--on-surface-variant); cursor: pointer; }

/* renderer / aggregator selectors + native selects */
#pivot-output .pvtRenderers,
#pivot-output .pvtVals { line-height: 1.8; }
#pivot-output select.pvtRenderer,
#pivot-output select.pvtAggregator,
#pivot-output select.pvtAttrDropdown,
#pivot-output .pvtVals select {
  border: 1px solid var(--outline-variant);
  border-radius: .375rem;
  background: var(--surface-container-lowest);
  color: var(--on-surface);
  padding: .25rem .45rem;
  font-size: 12px;
}
#pivot-output a.pvtRowOrder,
#pivot-output a.pvtColOrder { color: var(--on-surface-variant); text-decoration: none; }

/* the result table */
#pivot-output table.pvtTable { border-collapse: collapse; font-size: 13px; box-shadow: var(--shadow); border-radius: .5rem; overflow: hidden; }
#pivot-output table.pvtTable thead tr th,
#pivot-output table.pvtTable tbody tr th {
  background: var(--surface-container);
  color: var(--on-surface-variant);
  border: 1px solid var(--outline-variant);
  font-weight: 600;
  padding: .45rem .65rem;
  text-align: left;
}
#pivot-output table.pvtTable tbody tr td {
  background: var(--surface-container-lowest);
  color: var(--on-surface);
  border: 1px solid var(--outline-variant);
  padding: .4rem .65rem;
  text-align: right;
}
#pivot-output table.pvtTable .pvtTotalLabel,
#pivot-output table.pvtTable .pvtTotal,
#pivot-output table.pvtTable .pvtGrandTotal {
  background: var(--surface-container-high);
  color: var(--on-surface);
  font-weight: 600;
}
#pivot-output table.pvtTable tbody tr td:hover { background: var(--surface-container-low); }

/* attribute filter popup */
#pivot-output .pvtFilterBox {
  background: var(--surface-container-lowest);
  border: 1px solid var(--outline-variant);
  border-radius: .5rem;
  box-shadow: 0 12px 32px rgba(0,0,0,.25);
  color: var(--on-surface);
}
#pivot-output .pvtFilterBox h4 { color: var(--on-surface); }
#pivot-output .pvtFilterBox p { color: var(--on-surface-variant); }
#pivot-output .pvtFilterBox input[type="text"],
#pivot-output .pvtFilterBox .pvtSearch {
  border: 1px solid var(--outline-variant);
  border-radius: .375rem;
  background: var(--surface-container-lowest);
  color: var(--on-surface);
  padding: .35rem .5rem;
}
#pivot-output .pvtFilterBox .pvtCheckContainer p { border-radius: .25rem; }
#pivot-output .pvtFilterBox .pvtCheckContainer p:hover { background: var(--surface-container-low); }
#pivot-output .pvtFilterBox .pvtCheckContainer p.selected { background: var(--secondary-container); color: var(--on-secondary-container); }
#pivot-output .pvtButton {
  border: 1px solid var(--outline-variant);
  border-radius: .25rem;
  background: var(--surface-container);
  color: var(--on-surface);
  padding: .25rem .6rem;
  font-size: 12px;
  cursor: pointer;
}
#pivot-output .pvtButton:hover { background: var(--surface-container-high); }
