/* Colours, in both themes, are aliases onto brand/tokens.css: that file
   already carries the full light/dark/unstamped contract (bare :root,
   prefers-color-scheme, [data-theme]), so admin.css never needs its own
   copy of that contract, it only needs to name which token backs which
   local role. tokens.css and chrome.css must be linked before this file. */
:root {
  --ink:          var(--text-1);
  --body:         var(--text-1);
  --muted:        var(--text-2);
  --muted-soft:   var(--text-3);
  --canvas:       var(--bg);
  --app-bg:       var(--bg);
  --card:         var(--surface);
  --hairline:     var(--border);
  --hairline-soft: var(--border-subtle);
  --soft:         var(--surface-hover);
  --primary:      var(--text-1);
  --primary-hover: var(--text-2);
  --ok:           var(--success);
  --warn:         var(--warning);
  --danger:       var(--alert);
  /* No blue in the brand palette: --pos keeps its own value rather than
     borrowing the olive --accent, which would collapse the income chart's
     pos/neg/accrued legend down to two hues instead of three. */
  --pos:          #4f8cff;
  --accrued:      var(--emerald);
  --shadow: 0 1px 2px rgba(0,0,0,.4);
  --r-full: 999px;
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --pos: #2563eb;
    --shadow: 0 1px 2px rgba(0,0,0,.05);
  }
}

[data-theme="light"] {
  --pos: #2563eb;
  --shadow: 0 1px 2px rgba(0,0,0,.05);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; -webkit-font-smoothing: antialiased; }
body { font-family: var(--font-sans); color: var(--body); background: var(--app-bg); line-height: 1.5; }
a { color: var(--ink); text-decoration: none; }
img { max-width: 100%; display: block; }
button { cursor: pointer; font-family: inherit; border: none; background: none; }
input, select, textarea { font-family: inherit; }
::selection { background: var(--accent-glow); color: var(--ink); }

.display-sm { font-size: 28px; font-weight: 600; line-height: 1.2; letter-spacing: -0.5px; color: var(--ink); }
.title-md { font-size: 18px; font-weight: 600; line-height: 1.4; letter-spacing: 0; color: var(--ink); }
.title-sm { font-size: 16px; font-weight: 600; line-height: 1.4; letter-spacing: 0; color: var(--ink); }
.body-md { font-size: 16px; font-weight: 400; line-height: 1.5; letter-spacing: 0; }
.body-sm { font-size: 14px; font-weight: 400; line-height: 1.5; color: var(--muted); }
.muted { color: var(--muted); }

.admin { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }

.sidebar { background: var(--canvas); border-left: 1px solid var(--hairline); display: flex; flex-direction: column; padding: 24px 16px; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.sidebar .ab-brand, .sidebar .abLockup { margin-bottom: 32px; padding: 0 8px; }
.brand-logo { width: 32px; height: 32px; border-radius: var(--radius-md); object-fit: contain; flex-shrink: 0; }
.brand-logo-light { display: none; }
:root[data-theme="light"] .brand-logo-dark { display: none; }
:root[data-theme="light"] .brand-logo-light { display: block; }
.nav { display: flex; flex-direction: column; gap: 4px; flex: 1; }
.nav-item { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 10px; color: var(--muted); font-weight: 500; font-size: 14px; transition: background-color .15s ease, color .15s ease; position: relative; }
.nav-item:hover { background: var(--soft); color: var(--ink); }
.nav-item.active { background: var(--soft); color: var(--ink); }
.nav-item.active::before { content: ''; position: absolute; inset-inline-start: 0; top: 50%; transform: translateY(-50%); width: 3px; height: 20px; background: var(--alert); border-radius: 0 3px 3px 0; }
.ic { width: 18px; height: 18px; stroke: currentColor; stroke-width: 1.8; fill: none; }

.main-wrap { display: flex; flex-direction: column; min-height: 100vh; }
.topbar { background: var(--canvas); border-bottom: 1px solid var(--hairline); padding: 16px 28px; display: flex; align-items: center; justify-content: space-between; position: sticky; top: 0; z-index: 10; }
.page-title { font-size: 22px; font-weight: 600; letter-spacing: -0.3px; color: var(--ink); }
.topbar-right { display: flex; align-items: center; gap: 16px; }
.today { font-size: 14px; color: var(--muted); font-weight: 500; }
.icon-btn { width: 38px; height: 38px; border-radius: 10px; border: 1px solid var(--hairline); background: transparent; display: grid; place-items: center; position: relative; color: var(--muted); transition: background-color .15s ease, color .15s ease; cursor: pointer; list-style: none; }
.icon-btn::-webkit-details-marker { display: none; }
.icon-btn:hover { background: var(--soft); color: var(--ink); border-color: var(--hairline); }
.icon-btn svg { width: 18px; height: 18px; stroke: currentColor; stroke-width: 1.8; fill: none; }
.dot { position: absolute; top: 8px; right: 8px; width: 8px; height: 8px; background: var(--alert); border-radius: 50%; border: 2px solid var(--canvas); }
.notif { position: relative; }
.notif-panel {
  position: absolute; right: 0; top: calc(100% + 8px); min-width: 220px;
  background: var(--card); border: 1px solid var(--hairline); border-radius: 12px;
  box-shadow: var(--shadow); padding: 8px; z-index: 30;
}
.notif-panel a {
  display: block; padding: 10px 12px; border-radius: 8px; color: var(--ink);
  text-decoration: none; font-size: 13px; font-weight: 500;
}
.notif-panel a:hover { background: var(--soft); }
.content { max-width: 1120px; width: 100%; padding: 28px; margin: 0 auto; }


.card { background: var(--card); border: 1px solid var(--hairline); border-radius: 14px; box-shadow: var(--shadow); overflow: hidden; }
.card-head { padding: 20px 24px 16px; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--hairline-soft); }
.card-body { padding: 24px; }
.card-action { font-size: 13px; font-weight: 500; color: var(--muted); text-decoration: none; transition: color 0.15s ease; }
.card-action:hover { color: var(--ink); }

.table { width: 100%; border-collapse: collapse; }
.table th { text-align: left; font-size: 12px; font-weight: 500; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; padding: 12px 16px; border-bottom: 1px solid var(--hairline); }
.table td { padding: 14px 16px; border-bottom: 1px solid var(--hairline-soft); vertical-align: middle; font-size: 14px; color: var(--body); }
.table tr:last-child td { border-bottom: none; }
.table tr:hover td { background: var(--soft); }
.table .mono { font-variant-numeric: tabular-nums; }

.pill { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: var(--r-full); font-size: 12px; font-weight: 500; line-height: 1.2; }
.pill-ok { background: color-mix(in srgb, var(--ok) 20%, var(--card)); color: var(--ok); }
.pill-pending { background: color-mix(in srgb, var(--warn) 20%, var(--card)); color: var(--warn); }
.pill-cancelled { background: color-mix(in srgb, var(--danger) 20%, var(--card)); color: var(--danger); }

/* .btn/.btn-ghost/.btn-danger/.field retired: every template now wears the
   shared ab-btn/ab-field family from chrome.css instead (brand/phase2). */
.ab-field { margin-bottom: 16px; }

.empty { text-align: center; padding: 48px 24px; color: var(--muted); }

.row { display: flex; align-items: center; gap: 12px; }
.between { display: flex; align-items: center; justify-content: space-between; }
.gap-sm { gap: 8px; }
.gap-md { gap: 16px; }
.mb-md { margin-bottom: 16px; }
.mb-lg { margin-bottom: 24px; }
.text-right { text-align: right; }
.fw-600 { font-weight: 600; }

@media (max-width: 720px) {
  /* Form fields carry inline min-width for desktop columns; let them shrink below it on phones */
  .row .ab-field { min-width: 0 !important; }

  /* Forms / dashboard: stack multi-column rows and full-width controls */

  .content .row { flex-wrap: wrap; }
  .content .row.between { align-items: flex-start; gap: 10px; }
  .content .row.gap-md > .ab-field,
  .content .row.gap-sm > .ab-field { flex: 1 1 100%; min-width: 0; }
  .content form .row { flex-direction: column; align-items: stretch; }
  .content form .row > input,
  .content form .row > select,
  .content form .row > button,
  .content form .row > a.ab-btn { width: 100%; max-width: 100%; }

  .ab-field { margin-bottom: 12px; }
  .card-body form .row { gap: 10px; }

  .topbar { flex-wrap: wrap; gap: 8px; }
  .page-title { font-size: 18px; }
  .today { display: none; }
}

@media (max-width: 900px) {
  .admin { grid-template-columns: 1fr; }
  .table { display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  /* Below 900 px the nav is a drawer (shell.css sets its width, slide and visibility; shell.js opens it). */
  .sidebar { position: fixed; top: 0; left: 0; bottom: 0; height: 100vh; z-index: 50; }
  .topbar { padding: 12px 16px; }
  .content { padding: 16px; }
}
/* ── Alerts / flash ── */
.alert {
  padding: 12px 16px;
  border-radius: 12px;
  border: 1px solid var(--hairline);
  background: var(--card);
  font-size: 14px;
  line-height: 1.45;
}
.alert-ok {
  border-color: color-mix(in srgb, var(--ok) 45%, var(--hairline));
  background: color-mix(in srgb, var(--ok) 14%, var(--card));
  color: var(--ink);
}
/* The error variant was the one the family was missing: tasks/list.html and
   ventures/form.html have always rendered `alert alert-err` for form errors,
   so every validation failure showed as a plain bordered box with no red at
   all. Same shape as its siblings, on --danger. */
.alert-err {
  border-color: color-mix(in srgb, var(--danger) 45%, var(--hairline));
  background: color-mix(in srgb, var(--danger) 14%, var(--card));
  color: var(--ink);
}
.fw-600 { font-weight: 600; }

/* WS2 dashboard pin & drop */
.dash-head { align-items: flex-start; margin-bottom: 20px; }
#dash-grid.editing .dash-widget {
  cursor: grab;
  outline: 2px dashed var(--alert);
  outline-offset: 4px;
  border-radius: 8px;
}
#dash-grid.editing .dash-widget.dragging { opacity: 0.5; cursor: grabbing; }

/* Services drag-to-reorder */
#services-table.svc-editing tbody tr {
  cursor: grab;
  outline: 2px dashed var(--alert);
  outline-offset: -2px;
}
#services-table.svc-editing tbody tr.dragging {
  opacity: 0.5;
  cursor: grabbing;
}

/* Income chart — diverging bars, zero baseline (position = primary encoding) */
.income-chart__head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 12px; }
.income-chart__legend { display: flex; gap: 14px; }
.income-chart__key { display: inline-flex; align-items: center; gap: 5px; color: var(--muted); }
.income-chart__key::before { content: ""; width: 10px; height: 10px; border-radius: 2px; }
.income-chart__key--pos::before { background: var(--pos); }
.income-chart__key--neg::before { background: var(--danger); }
.income-chart__key--accrued::before { background: var(--accrued); }
/* Accrued sits behind cash in the same column: earned money the ledger has not
   seen yet. Validated against --pos/--danger on the dark surface (CVD dE 10.5). */
.income-chart__bar--accrued { background: var(--accrued); opacity: .85; }
.income-chart__stack { width: 100%; display: flex; align-items: flex-end;
                       justify-content: center; gap: 2px; height: 100%; }
.income-chart__stack > .income-chart__bar { align-self: flex-end; }
.income-chart__plot { display: flex; align-items: stretch; gap: 12px; }
.income-chart__col { display: flex; flex-direction: column; align-items: center; flex: 1; min-width: 0; }
.income-chart__half { width: 100%; display: flex; flex-direction: column; align-items: center; height: 56px; }
.income-chart__half--top { justify-content: flex-end; }
.income-chart__half--bottom { justify-content: flex-start; border-top: 1px solid var(--hairline); }
.income-chart__bar { width: 100%; max-width: 34px; min-height: 2px; }
.income-chart__bar--pos { background: var(--pos); border-radius: 3px 3px 0 0; }
.income-chart__bar--neg { background: var(--danger); border-radius: 0 0 3px 3px; }
.income-chart__val { font-size: 11px; line-height: 1.4; color: var(--body); }
.income-chart__val--neg { color: var(--danger); }
.income-chart__label { font-size: 11px; margin-top: 4px; color: var(--muted); }
.stat-section { margin-bottom: 18px; }
.stat-section:last-child { margin-bottom: 0; }
.stat-section__label { text-transform: uppercase; letter-spacing: .06em; font-size: 11px;
                       color: var(--muted-soft); margin-bottom: 8px; }
.payout-progress { margin-top: 10px; }
.payout-progress__label { display: flex; justify-content: space-between; gap: 8px;
                          color: var(--muted); margin-bottom: 3px; }
.payout-progress__track { height: 6px; border-radius: var(--r-full); background: var(--soft); overflow: hidden; }
.payout-progress__fill { height: 100%; border-radius: var(--r-full); background: var(--accrued); }
.income-chart__ranges { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 14px; }
.income-chart__range { padding: 3px 10px; border-radius: var(--r-full); border: 1px solid transparent; color: var(--muted); text-decoration: none; }
.income-chart__range:hover { background: var(--soft); color: var(--body); }
.income-chart__range.is-active { border-color: var(--hairline); background: var(--soft); color: var(--ink); font-weight: 600; }
/* Daily windows pack ~30 columns into the same width: shed the 12px gutter and
   the bar cap, or the gaps eat the plot and every bar collapses to a sliver. */
.income-chart__plot--dense { gap: 2px; }
.income-chart__plot--dense .income-chart__bar { max-width: none; }
.income-chart__plot--dense .income-chart__label { font-size: 10px; }

/* Motion is an enhancement: with a reduce preference nothing slides, fades or animates. */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; scroll-behavior: auto !important; }
}

/* Focus: one visible ring on every control, also the ones chrome.css styles with box-shadow only. */
:where(.ab-input, .ab-select, .ab-textarea, .ab-btn, .icon-btn, .nav-item, .card-action, .notif-panel a):focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Links inside prose read as links without hover. */
:where(.body-sm, .empty, .alert) a:not(.ab-btn) { text-decoration: underline; text-underline-offset: 3px; text-decoration-color: var(--hairline); }
:where(.body-sm, .empty, .alert) a:not(.ab-btn):hover { text-decoration-color: var(--accent); }

/* ── Mobile layer (owner rule 2026-11-29: every site is fully optimised for phones and tablets) ─────────────────────
   Last section of admin.css, so a page loads no extra stylesheet (a separate file cost 0.15 s of LCP on the simulated phone,
   because the raw sheet crossed the 14.6 KB first flight; the edge compresses it). shell.css, ops.css and stat-card.css load
   after this sheet: every rule that must beat them carries :root. The drawer, the stacked tables and the 44 px bars are
   shell.css and ops.css; this section closes what they leave: grid track, 16 px floor, remaining targets, safe areas.
   Applies on touch screens and on any viewport up to 1100 px. Gate: tests/test_mobile_css.py, docs/mobile.md. */

:root {
  --tap: 44px;              /* touch target floor */
  --tap-gap: 8px;           /* room between two targets */
  --fs-floor: 1rem;         /* smallest text on a touch screen */
  --fs-fine: .9em;          /* inline `font-size: var(--fs-fine, ...)` in templates; the floor replaces it on touch screens */
  --measure: 34em;          /* longest prose line, about 72 characters */
}

/* The grid track grew to the widest table (524 px on a 390 px phone): a track may shrink, the table scrolls in its own box */
.admin { grid-template-columns: 240px minmax(0, 1fr); }
.main-wrap, .content, .card, .card-body { min-width: 0; }
.empty code, .alert code, .ab-card code { overflow-wrap: anywhere; }
@media (max-width: 900px) { .admin { grid-template-columns: minmax(0, 1fr); } }
@media (max-width: 1100px) { .table:not(.table--stack) { display: block; max-width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; } }
/* a stacked table is cards only up to 720 px; a tablet shows the wide table and scrolls it */
@media (min-width: 721px) and (max-width: 1100px) { .table--stack { display: block; max-width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; } }
.card-head { flex-wrap: wrap; row-gap: 8px; }

/* viewport-fit=cover: keep the drawer, the bars and the content out of the notch and the home bar */
@media (max-width: 900px) {
  :root .sidebar { padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-bottom: max(20px, env(safe-area-inset-bottom, 0px)); }
  :root .topbar { padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); }
  :root .content { padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); padding-bottom: max(16px, env(safe-area-inset-bottom, 0px)); }
}
.sidebar { overscroll-behavior: contain; }
:root :where(a, button, input, select, textarea, label, summary) { touch-action: manipulation; }

/* Short landscape phone: a sticky two-row bar was a quarter of 390 px */
@media (max-height: 500px) and (orientation: landscape) {
  :root .topbar { position: static; }
  .main-wrap { min-height: 100dvh; }
}

@media (pointer: coarse), (max-width: 1100px) {

  /* text floor: 16 px. Only the selectors the sheets set below 1rem. */
  :root { --fs-fine: var(--fs-floor); }
  :root .body-sm,
  :root .nav-item,
  :root .today,
  :root .notif-panel a,
  :root .card-action,
  :root .table th,
  :root .table td,
  :root .pill,
  :root .alert,
  :root .income-chart__val,
  :root .income-chart__label,
  :root .stat-section__label,
  :root .income-chart__plot--dense .income-chart__label,
  :root .ai-crumb,
  :root .ov-incident__detail,
  :root .ov-incident__when,
  :root kbd,
  :root .palette__kind,
  :root .palette__hint,
  :root .palette__status,
  :root .palette__foot,
  :root .nav-group-title,
  :root .topbar-search kbd,
  :root .jobs-badge,
  :root .jobs-badge__n,
  :root .chip,
  :root .ops-facts dt,
  :root .ops-argv,
  :root .joblog,
  :root .stat-card__label,
  :root .stat-card__delta,
  :root .ab-brand-name,
  :root .ab-brand-sub,
  :root .ab-nav-link,
  :root .ab-footer-inner,
  :root .ab-btn,
  :root .ab-btn-sm,
  :root .ab-label,
  :root .ab-input,
  :root .ab-textarea,
  :root .ab-select,
  :root .ab-hint,
  :root .ab-error {
    font-size: var(--fs-floor);
  }
  :root .panel-act, :root .stat-grid.kpi6 .stat-card__label, :root .sites-drawer__bar,
  :root .sites-kpis:not(.sites-kpis--host) .stat-card__label {
    font-size: var(--fs-floor);
  }
  :root .chip { padding-block: 2px; }
  :root .abLockup .abLk-sub { font-size: var(--fs-floor); letter-spacing: 0.06em; }
  :root .abLockup { min-height: var(--tap); }
  :root .table th, :root .stat-card__label, :root .stat-section__label, :root .ab-label { letter-spacing: 0.04em; }

  /* tap targets: 44 px both ways, 8 px apart */
  :root a.body-sm, :root .empty a, :root .ab-btn, :root .ab-btn-sm, :root .btn, :root .btn-sm, :root a.status-filter,
  :root .ab-nav-link, :root a.svc-link, :root .page-link, :root .pager a, :root summary.icon-btn {
    display: inline-flex; align-items: center; justify-content: center;
    min-height: var(--tap);
    min-width: var(--tap);
  }
  :root a.svc-link { justify-content: flex-start; }
  :root .income-chart__ranges, :root .status-filters { gap: var(--tap-gap); }
  :root input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]):not([type="range"]), :root select, :root textarea,
  :root .form-control, :root .input {
    font-size: var(--fs-floor);
    min-height: var(--tap);
  }
  :root input { font-size: var(--fs-floor); }
  :root input[type="range"] { min-height: var(--tap); }
  :root input[type="checkbox"], :root input[type="radio"] { inline-size: 1.4rem; block-size: 1.4rem; }
  :root label:has(> input[type="checkbox"]), :root label:has(> input[type="radio"]) { display: inline-flex; align-items: center; gap: 0.6rem; min-height: var(--tap); }
}
