/* ============================================================
   Balance Commodities — Nomination System
   Design tokens + shared component styles

   Responsive scale (shell breakpoints):
     1024px — sidebar collapses to overlay, topbar reflows
      640px — single-column / phone layout
   Module CSS may add content-driven breakpoints (see console.css)
   but should reuse these two for layout-level changes.
   ============================================================ */

:root {
  /* Brand */
  --accent-h: 155;
  --accent: oklch(0.55 0.12 var(--accent-h));
  --accent-hover: oklch(0.50 0.13 var(--accent-h));
  --accent-soft: oklch(0.96 0.03 var(--accent-h));
  --accent-border: oklch(0.88 0.06 var(--accent-h));
  --accent-text: oklch(0.40 0.10 var(--accent-h));

  /* Neutrals (cool graphite) */
  --bg: #fafaf9;
  --bg-elev: #ffffff;
  --bg-sunken: #f4f4f2;
  --bg-hover: #f0efed;
  --border: #e7e5e0;
  --border-strong: #d6d3cc;
  --text: #18181b;
  --text-2: #52525b;
  --text-3: #8a8a8f;
  --text-inv: #ffffff;

  /* Semantic */
  --ok: oklch(0.58 0.14 150);
  --ok-soft: oklch(0.95 0.04 150);
  --warn: oklch(0.70 0.14 75);
  --warn-soft: oklch(0.96 0.05 80);
  --err: oklch(0.56 0.18 25);
  --err-soft: oklch(0.96 0.03 25);
  --info: oklch(0.58 0.12 240);
  --info-soft: oklch(0.96 0.03 240);
  --neutral-dot: oklch(0.58 0.03 255);

  /* Chart series */
  --s-db: oklch(0.55 0.15 280);        /* purple — Database */
  --s-nom: oklch(0.55 0.14 155);       /* green — Nominated */
  --s-settled: oklch(0.60 0.17 30);    /* red/orange — Settled */
  --s-counter: oklch(0.58 0.14 235);   /* blue — Counterparty */

  /* Geometry */
  --r-sm: 4px;
  --r: 6px;
  --r-md: 8px;
  --r-lg: 10px;
  --r-pill: 999px;
  --row-h: 36px;

  /* Type scale (px) — use instead of hardcoded font sizes */
  --fs-2xs: 10px;
  --fs-xs: 11px;
  --fs-sm: 12px;
  --fs-md: 13px;
  --fs-lg: 14px;
  --shadow-1: 0 1px 0 rgba(24, 24, 27, 0.04), 0 1px 2px rgba(24, 24, 27, 0.05);
  --shadow-2: 0 2px 4px rgba(24, 24, 27, 0.04), 0 8px 24px rgba(24, 24, 27, 0.06);
  /* Button elevation (resting / hover) — theme-aware so buttons read as raised */
  --btn-shadow: 0 1px 2px rgba(24, 24, 27, 0.10), 0 2px 5px rgba(24, 24, 27, 0.08);
  --btn-shadow-hover: 0 2px 4px rgba(24, 24, 27, 0.12), 0 8px 18px rgba(24, 24, 27, 0.16);

  /* Type */
  --font-sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;

  /* Layout */
  --sidebar-w: 220px;
  --sidebar-w-collapsed: 64px;
  --topbar-h: 52px;
  --sidebar-top: calc(var(--topbar-h) * 2);
}

[data-theme="dark"] {
  --bg: #0b0b0c;
  --bg-elev: #141416;
  --bg-sunken: #0e0e10;
  --bg-hover: #1b1b1e;
  --border: #26262a;
  --border-strong: #34343a;
  --text: #f5f5f5;
  --text-2: #a1a1aa;
  --text-3: #71717a;

  --accent-soft: color-mix(in oklch, var(--accent) 18%, #0b0b0c);
  --accent-border: color-mix(in oklch, var(--accent) 40%, #0b0b0c);
  --accent-text: oklch(0.75 0.11 var(--accent-h));

  --ok-soft: color-mix(in oklch, var(--ok) 18%, #0b0b0c);
  --warn-soft: color-mix(in oklch, var(--warn) 18%, #0b0b0c);
  --err-soft: color-mix(in oklch, var(--err) 18%, #0b0b0c);
  --info-soft: color-mix(in oklch, var(--info) 18%, #0b0b0c);

  --shadow-1: 0 1px 0 rgba(0, 0, 0, 0.6), 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-2: 0 2px 4px rgba(0, 0, 0, 0.3), 0 8px 24px rgba(0, 0, 0, 0.4);
  --btn-shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 2px 5px rgba(0, 0, 0, 0.35);
  --btn-shadow-hover: 0 3px 6px rgba(0, 0, 0, 0.5), 0 10px 22px rgba(0, 0, 0, 0.55);
}

* { box-sizing: border-box; }

:where(button, a[href], input, select, textarea):focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: var(--fs-md);
  line-height: 1.45;
  font-feature-settings: "cv11", "ss01";
  -webkit-font-smoothing: antialiased;
}

.mono { font-family: var(--font-mono); font-feature-settings: "zero", "ss01"; }
.num  { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }

/* ---------- App shell ---------- */
.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  grid-template-rows: var(--topbar-h) 1fr;
  grid-template-areas: "brand topbar" "sidebar main";
  height: 100vh;
  min-height: 0;
}
.app[data-sidebar="collapsed"] { grid-template-columns: var(--sidebar-w-collapsed) 1fr; }

.brand {
  grid-area: brand;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 16px;
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  background: var(--bg-elev);
}
.brand-mark {
  width: 26px; height: 26px;
  border-radius: 7px;
  background: linear-gradient(135deg, var(--accent), oklch(0.65 0.16 170));
  display: grid; place-items: center;
  color: white;
  font-weight: 700;
  font-size: var(--fs-md);
  letter-spacing: -0.02em;
  flex-shrink: 0;
}
.brand-name {
  font-weight: 600;
  font-size: var(--fs-md);
  letter-spacing: -0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.brand-sub {
  font-size: var(--fs-xs);
  color: var(--text-3);
  margin-top: 1px;
  letter-spacing: 0.02em;
}
.app[data-sidebar="collapsed"] .brand-text { display: none; }
.app[data-sidebar="collapsed"] .brand {
  justify-content: center;
  padding-left: 8px;
  padding-right: 8px;
  gap: 0;
}
.app[data-sidebar="collapsed"] .brand-mark {
  display: none;
}
.app[data-sidebar="collapsed"] .brand [data-action="toggle-sidebar"] {
  margin-left: 0 !important;
}

.topbar {
  grid-area: topbar;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 16px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-elev);
}
.crumb {
  display: flex; align-items: center; gap: 8px;
  font-size: var(--fs-md);
  color: var(--text-2);
}
.crumb b { color: var(--text); font-weight: 600; }
.crumb .sep { color: var(--text-3); }

.topbar-spacer { flex: 1; }
.topbar > .row:last-child { min-width: 0; }

.pill-btn {
  display: inline-flex; align-items: center; gap: 6px;
  height: 28px; padding: 0 10px;
  border: 1px solid var(--border);
  background: var(--bg-elev);
  border-radius: var(--r-pill);
  color: var(--text-2);
  font-size: var(--fs-sm); font-family: inherit;
  cursor: pointer;
  transition: background .12s, border-color .12s, color .12s;
}
.pill-btn:hover { background: var(--bg-hover); color: var(--text); }
.pill-btn { text-decoration: none; }
.pill-btn.static {
  cursor: default;
  box-shadow: none;
  transform: none;
}
.pill-btn.static:hover { background: var(--bg-elev); color: var(--text-2); }
.pill-btn.primary {
  background: var(--accent);
  color: white;
  border-color: transparent;
}
.pill-btn.primary:hover { background: var(--accent-hover); color: white; }

.icon-btn {
  width: 28px; height: 28px;
  display: grid; place-items: center;
  border: 1px solid var(--border);
  background: var(--bg-elev);
  border-radius: var(--r);
  color: var(--text-2);
  cursor: pointer;
  transition: background .12s, color .12s;
}
.icon-btn:hover { background: var(--bg-hover); color: var(--text); }
.icon-btn.ghost { border-color: transparent; background: transparent; }
.icon-btn.ghost:hover { background: var(--bg-hover); }

/* ---------- Shared form & action primitives ----------
   Single source of truth for the action/form components that pages used to
   redefine locally. Page modules keep only page-specific layout. */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: var(--fs-sm);
  padding: 7px 12px;
  cursor: pointer;
}
.btn:hover { background: var(--bg-hover); }
.btn:disabled { cursor: not-allowed; opacity: 0.6; }
.btn.primary { background: var(--accent-soft); color: var(--accent-text); border-color: var(--accent-border); }
.btn.accent { background: var(--accent); color: var(--text-inv); border-color: var(--accent); }
.btn.accent:hover { background: var(--accent-hover); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: var(--bg-hover); border-color: var(--border); }
.btn.sm { padding: 4px 8px; font-size: var(--fs-xs); }

.field { display: grid; gap: 6px; }
.field label {
  font-size: var(--fs-xs);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-3);
}
.field input,
.field select,
.field textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--r);
  background: var(--bg);
  color: var(--text);
  font: inherit;
  padding: 8px 10px;
}
.field textarea {
  min-height: 90px;
  resize: vertical;
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
}

.checks { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.checks label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: var(--fs-sm);
  color: var(--text-2);
}

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

.status, .api-status, .status-box {
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 8px 10px;
  background: var(--bg);
  font-size: var(--fs-sm);
  color: var(--text-2);
}
.status.ok, .api-status.success, .status-box.good { border-color: color-mix(in oklch, var(--ok) 45%, var(--border)); }
.status.err, .api-status.error, .status-box.bad { border-color: color-mix(in oklch, var(--err) 45%, var(--border)); }

pre.json, .json-box {
  margin: 0;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--bg);
  padding: 10px;
  max-height: 280px;
  overflow: auto;
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  line-height: 1.45;
  white-space: pre-wrap;
}

.hint { font-size: var(--fs-xs); color: var(--text-3); }
.muted { color: var(--text-3); font-size: var(--fs-xs); }
.status-text { font-size: var(--fs-sm); color: var(--text-2); }

/* ---------- Button elevation ----------
   Resting drop shadow so buttons read as raised, clickable objects; lift on
   hover, press on active. Applies app-wide in both normal and glass mode
   (glass.css layers a glossier float on top when glass is enabled). Ghost and
   icon buttons stay flat at rest and pop on hover, to avoid shadow noise in
   toolbars and table rows. */
.btn:not(.ghost),
.pill-btn,
.tool-btn {
  box-shadow: var(--btn-shadow);
  transition: box-shadow .14s ease, transform .14s ease, background .12s, border-color .12s, color .12s;
}
.btn:not(.ghost):hover,
.pill-btn:hover,
.tool-btn:hover {
  box-shadow: var(--btn-shadow-hover);
  transform: translateY(-1px);
}
.btn:not(.ghost):active,
.pill-btn:active,
.tool-btn:active {
  box-shadow: var(--btn-shadow);
  transform: translateY(0);
}
.btn:not(.ghost):disabled,
.pill-btn:disabled,
.tool-btn:disabled {
  box-shadow: none;
  transform: none;
}
.btn.ghost:hover,
.icon-btn:hover {
  box-shadow: var(--btn-shadow);
}

.user-menu {
  position: relative;
}

.user-trigger {
  height: 30px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 2px 8px 2px 2px;
  border: 1px solid var(--border);
  border-radius: var(--r-pill);
  background: var(--bg-elev);
  color: var(--text-2);
  cursor: pointer;
}

.user-trigger:hover {
  background: var(--bg-hover);
  color: var(--text);
}

.user-avatar {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  overflow: hidden;
  background: var(--bg-sunken);
  display: grid;
  place-items: center;
  position: relative;
  flex-shrink: 0;
}

.user-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.user-avatar-fallback {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: var(--fs-2xs);
  font-weight: 600;
  color: var(--text-2);
  pointer-events: none;
}

.user-mini {
  align-items: flex-start;
  min-width: 0;
}

.user-mini-name {
  max-width: 130px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  line-height: 1.1;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--text);
}

.user-mini-email {
  max-width: 130px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  line-height: 1.1;
  font-size: var(--fs-2xs);
  color: var(--text-3);
}

.user-dropdown {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  min-width: 220px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-2);
  z-index: 120;
  display: none;
  overflow: hidden;
}

.user-menu.open .user-dropdown {
  display: block;
}

.user-dropdown-head {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-sunken);
}

.user-dropdown-name {
  font-size: var(--fs-sm);
  font-weight: 600;
}

.user-dropdown-email {
  font-size: var(--fs-xs);
  color: var(--text-3);
  margin-top: 2px;
}

.user-link {
  width: 100%;
  display: block;
  padding: 9px 12px;
  text-align: left;
  font: inherit;
  font-size: var(--fs-sm);
  color: var(--text-2);
  text-decoration: none;
  border: 0;
  border-top: 1px solid var(--border);
  background: var(--bg-elev);
  cursor: pointer;
}

.user-link:hover {
  background: var(--bg-hover);
  color: var(--text);
}

.user-link.danger {
  color: var(--err);
}

/* ---------- Sidebar ---------- */
.sidebar {
  grid-area: sidebar;
  border-right: 1px solid var(--border);
  background: var(--bg-elev);
  padding: 10px 10px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.nav-section {
  font-size: var(--fs-2xs);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-3);
  padding: 14px 10px 6px;
  font-weight: 600;
}
.app[data-sidebar="collapsed"] .nav-section { display: none; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 10px;
  border-radius: var(--r);
  color: var(--text-2);
  cursor: pointer;
  text-decoration: none;
  font-size: var(--fs-md);
  transition: background .12s, color .12s;
  white-space: nowrap;
  position: relative;
}
.nav-item:hover { background: var(--bg-hover); color: var(--text); }
.nav-item.active {
  background: var(--accent-soft);
  color: var(--accent-text);
  font-weight: 500;
}
.nav-item.active::before {
  content: ""; position: absolute; left: 0; top: 6px; bottom: 6px;
  width: 2px; background: var(--accent); border-radius: 0 2px 2px 0;
}
.nav-item .ico { width: 16px; height: 16px; flex-shrink: 0; }
.nav-button {
  width: 100%;
  border: 0;
  background: transparent;
  font: inherit;
  text-align: left;
}
.nav-item .badge {
  margin-left: auto;
  font-size: var(--fs-2xs);
  padding: 1px 6px;
  border-radius: var(--r-pill);
  background: var(--bg-sunken);
  color: var(--text-2);
  font-variant-numeric: tabular-nums;
}
.nav-item.active .badge { background: color-mix(in oklch, var(--accent) 18%, transparent); color: var(--accent-text); }
.nav-sub {
  padding-left: 20px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.app[data-sidebar="collapsed"] .nav-sub { display: none; }
.app[data-sidebar="collapsed"] .nav-label { display: none; }
.app[data-sidebar="collapsed"] .nav-item .badge { display: none; }
.app[data-sidebar="collapsed"] .nav-item { justify-content: center; }

.nav-item .ico {
  overflow: visible;
}

.app[data-sidebar="collapsed"] .sidebar {
  padding-left: 8px;
  padding-right: 8px;
}

.sidebar-backdrop { display: none; }

.app[data-sidebar="collapsed"] .nav-item {
  padding-left: 0;
  padding-right: 0;
  min-height: 34px;
}
.app[data-sidebar="collapsed"] .nav-item.active::before {
  left: 3px;
}

/* ---------- Main ---------- */
.main {
  grid-area: main;
  overflow: hidden;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg);
}

.page-head {
  padding: 16px 24px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-elev);
  display: flex;
  align-items: center;
  gap: 16px;
}
.page-head h1 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  letter-spacing: -0.01em;
}
.page-head .meta {
  font-size: var(--fs-sm);
  color: var(--text-3);
}

.page-body {
  flex: 1;
  overflow: auto;
  padding: 20px 24px;
}

/* ---------- Cards ---------- */
.card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  overflow: hidden;
}
.card-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  font-size: var(--fs-sm);
  color: var(--text-2);
  font-weight: 500;
}
.card-head h2 {
  margin: 0;
  font-size: var(--fs-md);
  font-weight: 600;
  color: var(--text);
}
.card-body { padding: 14px; }

/* ---------- Status pills ---------- */
.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 2px 8px 2px 7px;
  border-radius: var(--r-pill);
  font-size: var(--fs-xs);
  font-weight: 500;
  letter-spacing: 0.01em;
  border: 1px solid transparent;
  line-height: 18px;
  white-space: nowrap;
}
.pill .dot {
  width: 6px; height: 6px; border-radius: 50%;
  flex-shrink: 0;
}
.pill.ok { background: var(--ok-soft); color: var(--ok); border-color: color-mix(in oklch, var(--ok) 20%, transparent); }
.pill.ok .dot { background: var(--ok); }
.pill.warn { background: var(--warn-soft); color: oklch(0.45 0.12 75); border-color: color-mix(in oklch, var(--warn) 30%, transparent); }
.pill.warn .dot { background: var(--warn); }
.pill.err { background: var(--err-soft); color: var(--err); border-color: color-mix(in oklch, var(--err) 25%, transparent); }
.pill.err .dot { background: var(--err); }
.pill.info { background: var(--info-soft); color: var(--info); border-color: color-mix(in oklch, var(--info) 25%, transparent); }
.pill.info .dot { background: var(--info); }
.pill.neutral { background: var(--bg-sunken); color: var(--text-2); border-color: var(--border); }
.pill.neutral .dot { background: var(--neutral-dot); }

[data-theme="dark"] .pill.warn { color: oklch(0.82 0.14 75); }

/* ---------- Tables ---------- */
.tbl {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 12.5px;
}
.tbl thead th {
  text-align: left;
  font-weight: 500;
  color: var(--text-3);
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  font-size: var(--fs-xs);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  background: var(--bg-elev);
  position: sticky; top: 0;
  z-index: 1;
}
.tbl tbody td {
  padding: 9px 12px;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  vertical-align: middle;
  height: var(--row-h);
}
.tbl tbody tr { transition: background .1s; }
.tbl tbody tr:hover { background: var(--bg-sunken); }
.tbl tbody tr.selected { background: var(--accent-soft); }
.tbl tbody tr.selected:hover { background: color-mix(in oklch, var(--accent) 10%, var(--bg-elev)); }
.tbl .num { text-align: right; font-variant-numeric: tabular-nums; }
.tbl .muted { color: var(--text-3); }
.tbl .neg { color: var(--err); }
.tbl .pos { color: var(--ok); }

.tbl.compact tbody td { padding: 6px 12px; height: 30px; }

/* column dividers on hover */
.tbl thead th + th, .tbl tbody td + td { border-left: 1px solid transparent; }

/* ---------- Segmented control ---------- */
.seg {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: var(--r);
  background: var(--bg-elev);
  padding: 2px;
  gap: 2px;
}
.seg button {
  border: none;
  background: transparent;
  padding: 4px 10px;
  font: inherit;
  font-size: var(--fs-sm);
  color: var(--text-2);
  cursor: pointer;
  border-radius: var(--r-sm);
  transition: background .12s, color .12s;
}
.seg button:hover { color: var(--text); }
.seg button.active {
  background: var(--bg-sunken);
  color: var(--text);
  font-weight: 500;
  box-shadow: var(--shadow-1);
}

/* ---------- Tweaks panel ---------- */
.tweaks {
  position: fixed;
  right: 20px;
  bottom: 20px;
  width: 260px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-2);
  z-index: 100;
  font-size: var(--fs-sm);
  display: none;
  overflow: hidden;
}
.tweaks.show { display: block; }
.tweaks-head {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  display: flex; align-items: center; gap: 8px;
}
.tweaks-head .ico { width: 14px; height: 14px; color: var(--accent); }
.tweaks-body { padding: 12px 14px; display: grid; gap: 12px; }
.tweak-row { display: grid; gap: 6px; }
.tweak-row label {
  font-size: var(--fs-xs);
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.swatches { display: flex; gap: 6px; }
.swatch {
  width: 22px; height: 22px; border-radius: var(--r);
  cursor: pointer;
  border: 2px solid transparent;
  transition: transform .1s;
  padding: 0;
  background-clip: padding-box;
}
.swatch:hover { transform: scale(1.1); }
.swatch.active { border-color: var(--text); }

.toggle-row {
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px; font-size: var(--fs-sm);
}
.toggle {
  width: 32px; height: 18px; border-radius: var(--r-pill);
  background: var(--border-strong);
  position: relative;
  cursor: pointer;
  transition: background .2s;
  border: 0;
  padding: 0;
}
.toggle::after {
  content: ""; position: absolute;
  top: 2px; left: 2px;
  width: 14px; height: 14px;
  background: white;
  border-radius: 50%;
  transition: left .2s;
  box-shadow: 0 1px 2px rgba(0,0,0,0.2);
}
.toggle.on { background: var(--accent); }
.toggle.on::after { left: 16px; }

/* ---------- Charts ---------- */
.legend {
  display: flex; flex-wrap: wrap; gap: 14px;
  font-size: 11.5px;
  color: var(--text-2);
}
.legend-item { display: flex; align-items: center; gap: 6px; }
.legend-swatch { width: 10px; height: 2px; border-radius: 1px; }

/* ---------- Tree ---------- */
.tree-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-radius: var(--r);
  cursor: pointer;
  font-size: 12.5px;
  transition: background .1s;
}
.tree-row:hover { background: var(--bg-sunken); }
.tree-row .chev {
  width: 12px; height: 12px;
  color: var(--text-3);
  transition: transform .12s;
}
.tree-row.open .chev { transform: rotate(90deg); }

.flag {
  width: 16px; height: 12px;
  border-radius: 1px;
  overflow: hidden;
  flex-shrink: 0;
  display: inline-block;
  box-shadow: 0 0 0 1px rgba(0,0,0,0.08);
}
.flag.nl { background: linear-gradient(to bottom, #ae1c28 33%, #fff 33%, #fff 66%, #21468b 66%); }
.flag.de { background: linear-gradient(to bottom, #000 33%, #dd0000 33%, #dd0000 66%, #ffce00 66%); }
.flag.be { background: linear-gradient(to right, #000 33%, #fae042 33%, #fae042 66%, #ed2939 66%); }

/* ---------- Empty state ---------- */
.empty {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 48px 24px;
  color: var(--text-3);
  font-size: var(--fs-md);
  text-align: center;
}

/* ---------- Utility ---------- */
.row { display: flex; align-items: center; gap: 8px; }
.flex-1 { flex: 1; }
.col { display: flex; flex-direction: column; }
.grow { flex: 1; }
.hsep { width: 1px; background: var(--border); align-self: stretch; }
.mb-8 { margin-bottom: 8px; } .mb-12 { margin-bottom: 12px; } .mb-16 { margin-bottom: 16px; }

/* scrollbars */
.page-body::-webkit-scrollbar, .sidebar::-webkit-scrollbar, .tbl-wrap::-webkit-scrollbar { width: 10px; height: 10px; }
.page-body::-webkit-scrollbar-thumb, .sidebar::-webkit-scrollbar-thumb, .tbl-wrap::-webkit-scrollbar-thumb {
  background: var(--border-strong); border-radius: var(--r-pill); border: 2px solid var(--bg);
}
.tbl-wrap { overflow: auto; }

/* ---------- Responsive ---------- */
@media (max-width: 1024px) {
  :root {
    --topbar-h: 48px;
  }

  .app,
  .app[data-sidebar="collapsed"],
  .app[data-sidebar="expanded"] {
    grid-template-columns: 1fr;
    grid-template-rows: var(--topbar-h) auto 1fr;
    grid-template-areas:
      "brand"
      "topbar"
      "main";
    height: 100dvh;
    min-height: 0;
    position: relative;
  }

  .brand,
  .topbar {
    border-right: 0;
    padding-left: 12px;
    padding-right: 12px;
  }

  .brand {
    border-bottom: 0;
    min-height: var(--topbar-h);
  }

  .app[data-sidebar="collapsed"] .brand,
  .app[data-sidebar="expanded"] .brand {
    justify-content: flex-start;
    padding-left: 8px;
    padding-right: 12px;
    gap: 8px;
  }

  .app[data-sidebar="collapsed"] .brand-mark,
  .app[data-sidebar="expanded"] .brand-mark {
    display: grid;
  }

  .app[data-sidebar="collapsed"] .brand-text,
  .app[data-sidebar="expanded"] .brand-text {
    display: flex;
    min-width: 0;
  }

  .app[data-sidebar="collapsed"] .brand [data-action="toggle-sidebar"],
  .app[data-sidebar="expanded"] .brand [data-action="toggle-sidebar"] {
    margin-left: 0;
  }

  .brand-name { max-width: min(58vw, 260px); }
  .brand-sub { display: none; }

  .tweak-sidebar-row {
    display: none;
  }

  .topbar {
    min-height: var(--topbar-h);
    height: auto;
    padding-top: 8px;
    padding-bottom: 8px;
    flex-wrap: wrap;
    gap: 8px;
    border-top: 1px solid var(--border);
  }

  .crumb {
    flex: 1 1 100%;
    font-size: var(--fs-sm);
  }

  .topbar .hsep,
  .topbar-spacer {
    display: none;
  }

  .user-mini {
    display: none;
  }

  .sidebar {
    position: fixed;
    left: 0;
    top: var(--sidebar-top);
    bottom: 0;
    width: min(84vw, 320px);
    z-index: 90;
    border-right: 1px solid var(--border);
    box-shadow: var(--shadow-2);
    transform: translateX(-105%);
    transition: transform 0.18s ease;
  }

  .app[data-sidebar="expanded"] .sidebar {
    transform: translateX(0);
  }

  .sidebar-backdrop {
    position: fixed;
    inset: var(--sidebar-top) 0 0;
    z-index: 80;
    border: 0;
    background: rgba(10, 10, 12, 0.38);
    backdrop-filter: blur(1px);
    cursor: pointer;
  }

  .app[data-sidebar="expanded"] .sidebar-backdrop {
    display: block;
  }

  .app[data-sidebar="collapsed"] .nav-item,
  .app[data-sidebar="expanded"] .nav-item {
    min-height: 44px;
  }

  .main {
    min-width: 0;
  }

  .page-head {
    padding: 12px 14px 10px;
    flex-wrap: wrap;
    gap: 8px;
  }

  .page-body {
    padding: 14px;
  }

  .tweaks {
    right: 10px;
    left: 10px;
    bottom: 10px;
    width: auto;
    max-height: 70dvh;
    overflow: auto;
  }
}

@media (max-width: 640px) {
  .pill-btn:not(.static),
  .icon-btn,
  .btn,
  .quick-link,
  .tool-btn,
  .page-btn,
  .workspace-tab,
  .date-shift-btn,
  button.tab {
    min-height: 44px;
  }

  .main button {
    min-width: 44px;
    min-height: 44px;
  }

  .icon-btn {
    width: 44px;
    height: 44px;
  }

  .shell-date {
    min-height: 40px;
  }

  .user-trigger {
    padding-right: 6px;
    min-width: 44px;
    min-height: 44px;
  }

  .topbar {
    padding-left: 10px;
    padding-right: 10px;
  }

  .topbar > .row:last-child {
    gap: 2px !important;
  }

  .topbar .user-dropdown {
    position: fixed;
    right: 10px;
    left: 10px;
    top: var(--sidebar-top);
    min-width: 0;
  }

  .main :where(input:not([type="checkbox"]):not([type="radio"]):not([type="file"]), select, textarea),
  .auth-shell :where(input:not([type="checkbox"]):not([type="radio"]):not([type="file"]), select, textarea) {
    min-height: 44px;
    font-size: 16px;
  }

  .actions-row,
  .form-actions {
    align-items: stretch;
  }

  .form-actions .link-inline {
    min-height: 44px;
    display: inline-flex;
    align-items: center;
  }

  .tbl {
    font-size: var(--fs-sm);
  }

  .tbl thead th {
    font-size: var(--fs-2xs);
  }

}

/* ---------- Account ---------- */
.auth-shell {
  min-height: 100dvh;
  background:
    radial-gradient(1200px 500px at 8% -10%, color-mix(in oklch, var(--accent) 12%, transparent), transparent 70%),
    radial-gradient(800px 440px at 95% 115%, color-mix(in oklch, var(--accent) 8%, transparent), transparent 68%),
    var(--bg);
  display: grid;
  place-items: center;
  padding: 24px;
}

.auth-card {
  width: min(460px, 100%);
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow-2);
  overflow: hidden;
}

.auth-card-head {
  padding: 18px 20px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-sunken);
}

.auth-card-head h1 {
  margin: 0;
  font-size: 18px;
  letter-spacing: -0.01em;
}

.auth-card-head p {
  margin: 6px 0 0;
  color: var(--text-2);
  font-size: 12.5px;
}

.auth-body {
  padding: 18px 20px 20px;
}

.form-stack {
  display: grid;
  gap: 12px;
}

.form-row {
  display: grid;
  gap: 6px;
}

.form-row label {
  font-size: var(--fs-sm);
  color: var(--text-2);
}

.field-input {
  width: 100%;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  border-radius: var(--r-md);
  padding: 9px 10px;
  font: inherit;
  font-size: 12.5px;
  outline: none;
}

.field-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.form-help {
  margin: 2px 0 0;
  color: var(--text-3);
  font-size: var(--fs-xs);
}

.form-errors {
  margin: 0;
  padding: 8px 10px;
  list-style: none;
  border: 1px solid color-mix(in oklch, var(--err) 30%, transparent);
  background: var(--err-soft);
  border-radius: var(--r-md);
  color: var(--err);
  font-size: var(--fs-sm);
}

.form-success {
  margin: 0;
  padding: 8px 10px;
  border: 1px solid color-mix(in oklch, var(--ok) 30%, transparent);
  background: var(--ok-soft);
  border-radius: var(--r-md);
  color: var(--ok);
  font-size: var(--fs-sm);
}

.form-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 4px;
}

.link-inline {
  color: var(--accent-text);
  text-decoration: none;
  font-size: var(--fs-sm);
}

.link-inline:hover {
  text-decoration: underline;
}

.profile-layout {
  max-width: 720px;
  margin: 20px auto;
}

.profile-card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
}

.profile-card-head {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-sunken);
}

.profile-card-head h2 {
  margin: 0;
  font-size: 15px;
}

.profile-card-body {
  padding: 18px;
}

.profile-avatar-preview {
  width: 58px;
  height: 58px;
  border-radius: 50%;
  overflow: hidden;
  border: 1px solid var(--border);
  background: var(--bg-sunken);
}

.profile-avatar-preview img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

@media (max-width: 640px) {
  .auth-shell { padding: 12px; }

  .auth-card-head,
  .auth-body {
    padding-left: 16px;
    padding-right: 16px;
  }

  .profile-layout { margin: 10px auto; }
  .profile-card-body { padding: 14px; }

  .main label:has(> input[type="checkbox"]),
  .main label:has(> input[type="radio"]) {
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
  }

  .main input[type="file"] {
    min-height: 44px;
  }
}
