/* The shared base and component set for every web app on Bunyad (D-247), drawn from the 2026 design (D-246).
   Link after fonts.css and tokens.css. It holds no app shell: each app adds its own (the Panel its sidebar, a
   dashboard its brand bar). Every page carries no style attribute, so every look a page needs is a class here or in
   the app's shell stylesheet. */

/* ─── reset ──────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }
/* The hidden attribute always wins, so anything marked hidden stays hidden whatever its class sets. */
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  background: var(--canvas);
  color: var(--ink-1);
  font-family: var(--ui);
  font-size: 13px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}
img, svg { display: block; max-width: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
table { border-collapse: collapse; }

/* ─── typography ─────────────────────────────────────────────────────────── */
h1, h2, h3, h4 { margin: 0 0 .4em; line-height: 1.2; color: var(--ink-1); }
h1 { font-size: 20px; font-weight: 700; font-stretch: 106%; letter-spacing: -.015em; }
h2 { font-size: 15px; font-weight: 700; }
h3 { font-size: 13.5px; font-weight: 700; }
h4 { font-size: 12.5px; font-weight: 600; }
p { margin: 0 0 .8em; }
small, .muted { color: var(--ink-3); }
small { font-size: 11.5px; }
strong, b { font-weight: 600; }
code, kbd, samp, pre { font-family: var(--mono); font-size: 12px; }
code {
  padding: 1px 5px; border-radius: var(--r-sm);
  background: var(--sunken); border: 1px solid var(--line);
}
hr { border: 0; border-top: 1px solid var(--line); margin: 14px 0; }

/* Figures line up in columns: tabular numerals everywhere a number is compared with the one above it. */
.num { font-variant-numeric: tabular-nums; font-feature-settings: "tnum" 1; }
.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; font-feature-settings: "tnum" 1; }

/* small caps label, used sparingly where a column or group needs naming */
.lbl {
  font-size: 9.5px; font-weight: 600; letter-spacing: .09em;
  text-transform: uppercase; color: var(--ink-3);
}

/* ─── links ──────────────────────────────────────────────────────────────── */
a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-strong); text-decoration: underline; text-underline-offset: 2px; }

/* ─── buttons ────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 31px; padding: 0 13px; border-radius: var(--r-md);
  border: 1px solid var(--line-strong); background: var(--raised); color: var(--ink-1);
  font-size: 12.5px; font-weight: 600; white-space: nowrap; text-decoration: none;
  transition: background .12s, border-color .12s, color .12s, box-shadow .12s, transform .06s;
}
.btn:hover:not(:disabled) {
  background: var(--canvas); border-color: var(--ink-4); box-shadow: var(--shadow-sm);
  color: var(--ink-1); text-decoration: none;
}
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: .42; cursor: not-allowed; }

.btn.primary { background: var(--accent); border-color: var(--accent-strong); color: var(--on-accent); }
.btn.primary:hover:not(:disabled) { background: var(--accent-strong); border-color: var(--accent-strong); color: var(--on-accent); }

.btn.secondary { background: var(--accent-wash); border-color: var(--accent-line); color: var(--accent-strong); }
.btn.secondary:hover:not(:disabled) {
  background: color-mix(in srgb, var(--accent-wash) 70%, var(--accent) 12%);
  border-color: var(--accent); color: var(--accent-strong);
}

.btn.danger { background: var(--danger-bg); border-color: var(--danger-line); color: var(--danger); }
.btn.danger:hover:not(:disabled) { background: var(--danger); border-color: var(--danger); color: var(--raised); }

.btn.quiet { background: transparent; border-color: transparent; color: var(--ink-2); }
.btn.quiet:hover:not(:disabled) { background: var(--sunken); border-color: transparent; box-shadow: none; color: var(--ink-1); }

.actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 12px; }

/* ─── form fields ────────────────────────────────────────────────────────── */
.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; margin-bottom: 10px; }
label, .field > label { font-size: 11.5px; font-weight: 500; color: var(--ink-3); }
input:not([type="checkbox"], [type="radio"], [type="submit"], [type="button"], [type="hidden"]),
select,
textarea {
  width: 100%; min-height: 31px; padding: 0 9px; border-radius: var(--r-sm);
  border: 1px solid var(--line-strong); background: var(--raised); color: var(--ink-1);
  font-size: 12.5px; transition: border-color .12s, box-shadow .12s;
}
textarea { padding: 7px 9px; min-height: 72px; resize: vertical; }
input:hover:not(:disabled), select:hover:not(:disabled), textarea:hover:not(:disabled) { border-color: var(--accent-line); }
input:focus, select:focus, textarea:focus {
  outline: 0; border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 20%, transparent);
}
input:disabled, select:disabled, textarea:disabled { background: var(--sunken); color: var(--ink-3); cursor: not-allowed; }
input.mono { font-family: var(--mono); font-size: 12px; }
input[type="checkbox"], input[type="radio"] { accent-color: var(--accent); width: 15px; height: 15px; margin: 0; }
.check { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--ink-2); }
.field .hint { font-size: 11.5px; color: var(--ink-3); }
.field .error, .field-error { font-size: 11.5px; font-weight: 500; color: var(--danger); }
.field.invalid input, .field.invalid select, .field.invalid textarea { border-color: var(--danger); }

/* a row of fields that wraps on a narrow window */
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 0 12px; }
.form-grid .wide { grid-column: 1 / -1; }

/* ─── tables ─────────────────────────────────────────────────────────────── */
.table-wrap {
  overflow-x: auto; background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-lg); box-shadow: var(--shadow-md);
}
table.grid { width: 100%; border-collapse: separate; border-spacing: 0; }
table.grid th {
  background: var(--sunken); color: var(--ink-2);
  font-size: 9.5px; font-weight: 700; letter-spacing: .085em; text-transform: uppercase;
  text-align: left; padding: 8px 9px; white-space: nowrap;
  border-bottom: 1px solid var(--line-strong);
}
table.grid td {
  height: var(--row-h); padding: 0 9px; font-size: 12.5px;
  border-bottom: 1px solid var(--line); white-space: nowrap;
}
table.grid tbody tr { background: var(--surface); transition: background .1s; }
table.grid tbody tr:nth-child(even) { background: var(--row-alt); }
table.grid tbody tr:hover { background: var(--row-hover); }
table.grid tbody tr[aria-selected="true"] { background: var(--row-sel); }
table.grid tbody tr:last-child td { border-bottom: 0; }
/* Figures are right-aligned in mono so their digits line up down the column. */
table.grid th.num, table.grid td.num { text-align: right; }
table.grid td.num { font-family: var(--mono); font-size: 12px; font-variant-numeric: tabular-nums; }
table.grid td.mono { font-size: 12px; }
table.grid td.muted { color: var(--ink-3); }
table.grid td .sub { display: block; font-size: 10.5px; color: var(--ink-3); line-height: 1.2; }
table.grid td.wrap { white-space: normal; }

/* ─── status pills ───────────────────────────────────────────────────────── */
.pill {
  display: inline-flex; align-items: center; gap: 5px; height: 20px; padding: 0 8px;
  border-radius: 999px; font-size: 10.5px; font-weight: 600; white-space: nowrap;
  border: 1px solid var(--line); background: var(--sunken); color: var(--ink-2);
}
.pill.ok      { background: var(--green-bg);    border-color: var(--green-line);  color: var(--green); }
.pill.warn    { background: var(--amber-bg);    border-color: var(--amber-line);  color: var(--amber); }
.pill.bad     { background: var(--danger-bg);   border-color: var(--danger-line); color: var(--danger); }
.pill.brand   { background: var(--accent-wash); border-color: var(--accent-line); color: var(--accent-strong); }
.pill.neutral { background: var(--sunken);      border-color: var(--line);        color: var(--ink-2); }

/* ─── stat tiles ─────────────────────────────────────────────────────────── */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 10px; margin-bottom: 12px; }
.stat {
  display: block; min-width: 0; padding: 10px 13px; border-radius: var(--r-lg);
  background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow-sm);
  color: var(--ink-1); text-decoration: none;
}
a.stat:hover { border-color: var(--accent-line); color: var(--ink-1); text-decoration: none; }
.stat .cap { font-size: 9.5px; font-weight: 600; letter-spacing: .09em; text-transform: uppercase; color: var(--ink-3); }
.stat .value {
  margin-top: 3px; font-size: 20px; font-weight: 700; font-stretch: 106%; letter-spacing: -.015em;
  font-variant-numeric: tabular-nums; font-feature-settings: "tnum" 1;
}
.stat .value.mono { font-family: var(--mono); font-weight: 600; letter-spacing: 0; }
.stat .sub { margin-top: 1px; font-size: 11px; color: var(--ink-3); }
.stat.warn .value { color: var(--amber); }
.stat.bad .value { color: var(--danger); }

/* ─── cards ──────────────────────────────────────────────────────────────── */
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg);
  box-shadow: var(--shadow-sm); padding: 13px 15px; margin-bottom: 12px;
}
.card > h2, .card > h3 { display: flex; align-items: center; gap: 8px; }
.card .hint { margin: 0 0 10px; font-size: 11.5px; color: var(--ink-3); }
.card.danger { border-color: var(--danger-line); }
.card.danger > h2, .card.danger > h3 { color: var(--danger); }

/* ─── alerts ─────────────────────────────────────────────────────────────── */
.alert {
  display: flex; align-items: flex-start; gap: 8px; padding: 8px 12px; margin-bottom: 12px;
  border-radius: var(--r-md); border: 1px solid var(--line); font-size: 12.5px; font-weight: 500;
}
.alert.notice { background: var(--accent-wash); border-color: var(--accent-line); color: var(--accent-strong); }
.alert.error  { background: var(--danger-bg);   border-color: var(--danger-line); color: var(--danger); }
.alert.warn   { background: var(--amber-bg);    border-color: var(--amber-line);  color: var(--amber); }
.alert.ok     { background: var(--green-bg);    border-color: var(--green-line);  color: var(--green); }

/* ─── empty state ────────────────────────────────────────────────────────── */
.empty {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
  padding: 36px 16px; text-align: center; color: var(--ink-3);
}
.empty svg { width: 34px; height: 34px; color: var(--ink-4); }
.empty strong, .empty b { font-size: 14px; font-weight: 600; color: var(--ink-2); }
.empty p { margin: 0; font-size: 12px; }

/* ─── pager ──────────────────────────────────────────────────────────────── */
.pager {
  display: flex; align-items: center; justify-content: flex-end; gap: 6px; flex-wrap: wrap;
  padding: 8px 0; font-size: 11.5px; color: var(--ink-3);
}
.pager .count { margin-right: auto; font-variant-numeric: tabular-nums; }
.pager a, .pager span.current {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 29px; height: 27px; padding: 0 9px; border-radius: var(--r-sm);
  border: 1px solid var(--line-strong); background: var(--raised); color: var(--ink-2);
  font-weight: 600; font-variant-numeric: tabular-nums; text-decoration: none;
}
.pager a:hover { border-color: var(--accent-line); background: var(--accent-wash); color: var(--accent); text-decoration: none; }
.pager span.current { background: var(--accent-wash); border-color: var(--accent-line); color: var(--accent-strong); }
.pager [aria-disabled="true"] { opacity: .42; pointer-events: none; }

/* ─── facts list ─────────────────────────────────────────────────────────── */
dl.facts { display: grid; grid-template-columns: minmax(120px, max-content) 1fr; gap: 0 16px; margin: 0; }
dl.facts dt, dl.facts dd { padding: 5px 0; border-bottom: 1px solid var(--line); font-size: 12.5px; }
dl.facts dt { color: var(--ink-3); white-space: nowrap; }
dl.facts dd { margin: 0; font-weight: 500; min-width: 0; overflow-wrap: anywhere; }
dl.facts dd.mono { font-family: var(--mono); font-size: 12px; }
dl.facts dt:last-of-type, dl.facts dd:last-of-type { border-bottom: 0; }

/* ─── keyboard focus ─────────────────────────────────────────────────────── */
/* Only for the keyboard: a mouse click draws no ring, a Tab always does. */
:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; border-radius: 3px; }
input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 0; }

.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;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; scroll-behavior: auto !important; }
}

/* Narrow windows: a table scrolls inside its frame so the page itself never scrolls sideways. */
@media (max-width: 720px) {
  table.grid { min-width: 640px; }
  dl.facts { grid-template-columns: 1fr; }
  dl.facts dt { border-bottom: 0; padding-bottom: 0; }
}
