/* =====================================================================
   Tractor ERP — Design system (mobile-first)
   Base rules target phones; min-width queries add tablet and desktop
   layout. All colours are tokens. Brand colours are overridden at
   runtime from Settings (config.branding) so a re-brand never touches
   this file.
   Breakpoints: 640 (large phone / small tablet) · 720 (tables) ·
                1024 (desktop shell) · 1200 (wide grids)
   ===================================================================== */

:root {
  color-scheme: light;
  /* Brand — sampled from the logo */
  --brand: #367c2b;
  --brand-strong: #2a6121;
  --brand-soft: #e8f2e5;
  --on-brand: #ffffff;
  --accent: #ffde00;
  --accent-soft: #fff8cc;

  --page: #f4f6f2;
  --surface: #ffffff;
  --surface-2: #f8faf7;
  --surface-3: #eef1ec;
  --border: #e0e5dc;
  --border-strong: #c7cec1;

  --text: #141a13;
  --text-2: #4a5447;
  --text-3: #7a8576;

  --good: #0f8a3c;   --good-soft: #e4f5ea;
  --warn: #a86f00;   --warn-soft: #fff4d9;
  --bad: #c62f2f;    --bad-soft: #fde8e8;
  --info: #2a67c7;   --info-soft: #e7effc;
  --muted-soft: #eef0ec;

  /* Premium textured green — used by the sidebar, page header, tour.
     --brand-base stays the logo green in both themes (Settings can override it). */
  --brand-base: #367c2b;
  --gold: #ffde00;
  --gold-deep: #e9bd00;
  --tex-noise: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.8' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 .07 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  --tex-furrow: repeating-linear-gradient(118deg, rgba(255,255,255,.028) 0 1px, transparent 1px 8px);
  --green-hi: color-mix(in srgb, var(--brand-base) 92%, #fff);
  --green-mid: color-mix(in srgb, var(--brand-base) 62%, #06140a);
  --green-lo: color-mix(in srgb, var(--brand-base) 30%, #030a04);
  --tex-green:
    var(--tex-noise),
    var(--tex-furrow),
    radial-gradient(120% 90% at 0% 0%, rgba(255, 222, 0, .13), transparent 52%),
    radial-gradient(90% 80% at 100% 100%, rgba(0, 0, 0, .38), transparent 60%),
    linear-gradient(155deg, var(--green-hi) 0%, var(--green-mid) 48%, var(--green-lo) 100%);

  /* Navigation surface (sidebar / menu drawer) */
  --nav-bg: var(--green-mid);
  --nav-text: rgba(255, 255, 255, .78);
  --nav-text-3: rgba(255, 255, 255, .5);
  --nav-hover: rgba(255, 255, 255, .08);
  --nav-line: rgba(255, 255, 255, .12);

  /* chart palette (validated reference order) */
  --s1: #2a78d6; --s2: #eb6834; --s3: #1baf7a; --s4: #eda100;
  --s5: #e87ba4; --s6: #008300; --s7: #4a3aa7; --s8: #e34948;
  --grid: #e1e0d9; --axis: #c3c2b7;

  --radius: 14px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(16, 24, 16, .05), 0 1px 3px rgba(16, 24, 16, .06);
  --shadow-lg: 0 16px 48px rgba(16, 24, 16, .2);
  --sidebar-w: 260px;
  --topbar-h: 56px;
  --bottomnav-h: 64px;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --tap: 44px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --brand: #6cbf5a; --brand-strong: #86cf75; --brand-soft: #1a2e16; --on-brand: #0b1a08;
    --accent: #f5d20a; --accent-soft: #3a3408;
    --page: #0e120d; --surface: #161b15; --surface-2: #1b2119; --surface-3: #232a21;
    --border: #2a3228; --border-strong: #3a4437;
    --text: #eef2ed; --text-2: #b8c2b4; --text-3: #849080;
    --good: #3cc46a; --good-soft: #13301e; --warn: #f0b429; --warn-soft: #362a0b;
    --bad: #f06a6a; --bad-soft: #3a1717; --info: #6aa4f5; --info-soft: #15253d; --muted-soft: #232a21;
    --nav-bg: #0f1a0d;
    --green-hi: color-mix(in srgb, var(--brand-base) 70%, #06140a);
    --green-mid: color-mix(in srgb, var(--brand-base) 38%, #050d04);
    --green-lo: #040903;
    --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500; --s5: #d55181; --s6: #008300; --s7: #9085e9; --s8: #e66767;
    --grid: #2c2c2a; --axis: #383835;
    --shadow: 0 1px 2px rgba(0,0,0,.4); --shadow-lg: 0 16px 48px rgba(0,0,0,.6);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --brand: #6cbf5a; --brand-strong: #86cf75; --brand-soft: #1a2e16; --on-brand: #0b1a08;
  --accent: #f5d20a; --accent-soft: #3a3408;
  --page: #0e120d; --surface: #161b15; --surface-2: #1b2119; --surface-3: #232a21;
  --border: #2a3228; --border-strong: #3a4437;
  --text: #eef2ed; --text-2: #b8c2b4; --text-3: #849080;
  --good: #3cc46a; --good-soft: #13301e; --warn: #f0b429; --warn-soft: #362a0b;
  --bad: #f06a6a; --bad-soft: #3a1717; --info: #6aa4f5; --info-soft: #15253d; --muted-soft: #232a21;
  --nav-bg: #0f1a0d;
  --green-hi: color-mix(in srgb, var(--brand-base) 70%, #06140a);
  --green-mid: color-mix(in srgb, var(--brand-base) 38%, #050d04);
  --green-lo: #040903;
  --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500; --s5: #d55181; --s6: #008300; --s7: #9085e9; --s8: #e66767;
  --grid: #2c2c2a; --axis: #383835;
  --shadow: 0 1px 2px rgba(0,0,0,.4); --shadow-lg: 0 16px 48px rgba(0,0,0,.6);
}

/* ---------- Base ---------- */
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font); font-size: 15px; line-height: 1.5;
  background: var(--page); color: var(--text);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}
body.nav-open, body.search-open, body.sheet-open { overflow: hidden; }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0; line-height: 1.25; font-weight: 650; }
h1 { font-size: 21px; letter-spacing: -.2px; } h2 { font-size: 16px; } h3 { font-size: 15px; } h4 { font-size: 13px; }
p { margin: 0 0 10px; }
code, .mono { font-family: var(--mono); font-size: 12.5px; }
hr { border: 0; border-top: 1px solid var(--border); margin: 16px 0; }
img { max-width: 100%; }
.num, td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.muted { color: var(--text-3); }
.small { font-size: 12.5px; }
.nowrap { white-space: nowrap; }
.hidden { display: none !important; }
.desktop-only { display: none !important; }

/* ---------- Shell: phone ---------- */
.shell { display: flex; min-height: 100vh; min-height: 100dvh; }

/* Sidebar = slide-in menu on phones/tablets, fixed rail on desktop */
#sidebar {
  position: fixed; left: 0; top: 0; bottom: 0; z-index: 60;
  width: min(86vw, 320px);
  background: var(--tex-noise), var(--tex-furrow),
    radial-gradient(140% 50% at 0% 0%, rgba(255, 222, 0, .10), transparent 60%),
    linear-gradient(180deg, var(--green-mid) 0%, var(--green-lo) 100%);
  background-color: var(--nav-bg);
  color: var(--nav-text);
  overflow-y: auto; overscroll-behavior: contain;
  display: flex; flex-direction: column;
  transform: translateX(-102%); transition: transform .22s cubic-bezier(.2,.8,.2,1);
  padding-top: var(--safe-t); padding-bottom: var(--safe-b);
  box-shadow: var(--shadow-lg);
}
body.nav-open #sidebar { transform: none; }
.nav-backdrop {
  position: fixed; inset: 0; z-index: 55; background: rgba(6, 12, 5, .5);
  opacity: 0; pointer-events: none; transition: opacity .2s;
}
body.nav-open .nav-backdrop { opacity: 1; pointer-events: auto; }

.brand-block { display: flex; align-items: center; gap: 12px; padding: 18px 16px 16px; border-bottom: 1px solid var(--nav-line); position: relative; }
.brand-block::after { content: ""; position: absolute; left: 16px; right: 16px; bottom: -1px; height: 1px; background: linear-gradient(90deg, var(--gold), transparent 70%); opacity: .55; }
.brand-logo { width: 44px; height: auto; flex: 0 0 44px; display: block; filter: drop-shadow(0 1px 2px rgba(0,0,0,.25)); }
.brand-text { flex: 1; min-width: 0; }
.brand-name { font-weight: 750; font-size: 16px; letter-spacing: .2px; color: #fff; }
.brand-sub { font-size: 12px; color: var(--nav-text-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand-block .nav-close { color: #fff; }
.brand-block .nav-close:hover { background: var(--nav-hover); }

.nav { padding: 6px 10px 16px; flex: 1; }
.nav-group { margin-top: 14px; }
.nav-group-title { font-size: 10.5px; text-transform: uppercase; letter-spacing: 1px; color: var(--nav-text-3); padding: 4px 12px; font-weight: 700; }
.nav a {
  display: flex; align-items: center; gap: 12px; min-height: var(--tap); padding: 8px 12px; border-radius: 10px;
  color: var(--nav-text); font-weight: 500; font-size: 14.5px; text-decoration: none; position: relative;
}
.nav a:hover { background: var(--nav-hover); color: #fff; }
.nav a.active { background: rgba(255, 222, 0, .14); color: var(--accent); font-weight: 650; }
.nav a.active::before { content: ""; position: absolute; left: 0; top: 10px; bottom: 10px; width: 3px; border-radius: 0 3px 3px 0; background: var(--accent); }
.nav a svg { width: 19px; height: 19px; flex: 0 0 19px; opacity: .9; }
.nav a .phase-tag { margin-left: auto; font-size: 10px; padding: 1px 7px; border-radius: 10px; background: var(--nav-hover); color: var(--nav-text-3); }
.nav a:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }

.sidebar-prefs { padding: 14px 16px; border-top: 1px solid var(--nav-line); display: flex; flex-direction: column; gap: 10px; }
.sidebar-prefs label { font-size: 11px; text-transform: uppercase; letter-spacing: .8px; color: var(--nav-text-3); font-weight: 700; display: flex; flex-direction: column; gap: 6px; }
.sidebar-prefs select { background: rgba(255,255,255,.08); color: #fff; border-color: var(--nav-line); }
.sidebar-prefs select option { color: #000; }
.sidebar-prefs .btn { background: rgba(255,255,255,.08); color: #fff; border-color: var(--nav-line); justify-content: flex-start; }
.sidebar-prefs .btn:hover { background: rgba(255,255,255,.14); }
.sidebar-foot { padding: 12px 16px 16px; border-top: 1px solid var(--nav-line); font-size: 11.5px; color: var(--nav-text-3); }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

/* Top bar */
#topbar {
  min-height: calc(var(--topbar-h) + var(--safe-t)); padding: var(--safe-t) 12px 0;
  display: flex; align-items: center; gap: 8px;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  -webkit-backdrop-filter: saturate(1.4) blur(12px); backdrop-filter: saturate(1.4) blur(12px);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 20;
}
.topbar-logo { display: flex; align-items: center; flex: 0 0 auto; padding: 4px; margin-left: -4px; border-radius: 8px; }
.topbar-logo img { width: 34px; height: auto; display: block; }
.crumbs { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.2; }
.crumbs .crumb-group { font-size: 11px; color: var(--text-3); font-weight: 600; text-transform: uppercase; letter-spacing: .6px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.crumbs b { color: var(--text); font-weight: 700; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-spacer { display: none; }
.menu-btn { display: none; }
#bellBtn, .env-pill, #topbar .role-sel { display: none; }
.sync-text { display: none; }

/* Global search: full-screen sheet on phones, inline on desktop */
.global-search { display: none; }
/* the sticky, blurred top bar is a stacking context and containing block — lift it while the sheet is open */
body.search-open #topbar { z-index: 150; -webkit-backdrop-filter: none; backdrop-filter: none; }
body.search-open .global-search {
  display: flex; flex-wrap: wrap; align-content: flex-start; gap: 10px;
  position: fixed; inset: 0; z-index: 150; background: var(--page);
  padding: calc(var(--safe-t) + 10px) 12px calc(var(--safe-b) + 12px);
  animation: fade .12s ease-out;
}
.global-search .gs-field { position: relative; flex: 1; min-width: 0; }
.global-search .gs-field svg { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); width: 18px; height: 18px; color: var(--text-3); pointer-events: none; }
.global-search input { padding-left: 40px; }
.global-search .search-cancel { flex: 0 0 auto; }
.search-results {
  flex: 1 1 100%; max-height: calc(100dvh - 90px); overflow: auto;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 6px;
}
.search-results a { display: block; padding: 10px 12px; border-radius: 8px; color: var(--text); }
.search-results a:hover, .search-results a:focus { background: var(--surface-3); text-decoration: none; }
.search-results .sr-type { font-size: 11px; color: var(--text-3); text-transform: uppercase; letter-spacing: .5px; }
.search-hint { flex: 1 1 100%; font-size: 13px; color: var(--text-3); padding: 4px 4px 0; }

.env-pill { font-size: 11px; font-weight: 700; padding: 3px 10px; border-radius: 20px; background: var(--accent-soft); color: var(--text); border: 1px solid var(--accent); letter-spacing: .4px; }
.sync-pill { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-2); padding: 8px; }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; background: var(--text-3); }
.dot.good { background: var(--good); } .dot.warn { background: var(--warn); } .dot.bad { background: var(--bad); }
.dot.pulse { animation: pulse 1.6s infinite; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--good) 60%, transparent); } 70% { box-shadow: 0 0 0 7px transparent; } 100% { box-shadow: 0 0 0 0 transparent; } }
.count-badge { position: absolute; top: 2px; right: calc(50% - 20px); min-width: 18px; height: 18px; border-radius: 9px; background: var(--bad); color: #fff; font-size: 10.5px; font-weight: 700; display: grid; place-items: center; padding: 0 4px; border: 2px solid var(--surface); line-height: 1; }

/* Bottom tab bar (phones & tablets) */
#bottomnav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
  display: grid; grid-auto-flow: column; grid-auto-columns: 1fr;
  height: calc(var(--bottomnav-h) + var(--safe-b)); padding-bottom: var(--safe-b);
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  -webkit-backdrop-filter: saturate(1.4) blur(12px); backdrop-filter: saturate(1.4) blur(12px);
  border-top: 1px solid var(--border);
}
#bottomnav .bn-item {
  position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  background: none; border: 0; font: inherit; font-size: 11px; font-weight: 600; color: var(--text-3);
  text-decoration: none; cursor: pointer; padding: 6px 2px; min-width: 0;
}
#bottomnav .bn-item .bn-icon { display: grid; place-items: center; width: 56px; height: 30px; border-radius: 15px; transition: background .15s; }
#bottomnav .bn-item svg { width: 22px; height: 22px; }
#bottomnav .bn-item.active { color: var(--brand); }
#bottomnav .bn-item.active .bn-icon { background: var(--brand-soft); }
#bottomnav .bn-item:active .bn-icon { background: var(--surface-3); }
#bottomnav .bn-item:hover { text-decoration: none; color: var(--text); }
#bottomnav .bn-item.active:hover { color: var(--brand); }
#bottomnav .bn-item:focus-visible { outline: 2px solid var(--brand); outline-offset: -4px; border-radius: 12px; }

#view { padding: 16px 16px calc(var(--bottomnav-h) + var(--safe-b) + 28px); width: 100%; max-width: 1560px; }
.page-head {
  display: flex; flex-direction: column; gap: 14px; margin: 0 0 16px; padding: 20px 18px;
  border-radius: 18px; position: relative; overflow: hidden; isolation: isolate;
  background: var(--tex-green); color: #fff;
  box-shadow: 0 10px 30px -12px rgba(12, 40, 8, .55), inset 0 1px 0 rgba(255,255,255,.08);
}
.page-head::after { content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: 3px; background: linear-gradient(90deg, var(--gold) 0%, var(--gold-deep) 30%, transparent 85%); z-index: -1; }
.page-head::before { content: ""; position: absolute; right: -60px; top: -80px; width: 260px; height: 260px; border-radius: 50%; background: radial-gradient(circle, rgba(255,222,0,.10), transparent 65%); z-index: -1; }
.page-head .titles { flex: 1; min-width: 0; }
.page-head h1 { color: #fff; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.page-head p { color: rgba(255,255,255,.82); margin: 8px 0 0; max-width: 820px; font-size: 14px; }
.page-head p b, .page-head p strong { color: #fff; }
.page-head a:not(.btn) { color: var(--gold); }
.ph-eyebrow { font-size: 11px; font-weight: 700; letter-spacing: 1.2px; text-transform: uppercase; color: var(--gold); margin-bottom: 6px; }
.page-head .btn { background: rgba(255,255,255,.1); border-color: rgba(255,255,255,.22); color: #fff; box-shadow: none; -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px); }
.page-head .btn:hover { background: rgba(255,255,255,.18); }
.page-head .btn.primary { background: linear-gradient(180deg, #ffe84d 0%, var(--gold) 45%, var(--gold-deep) 100%); border-color: var(--gold-deep); color: #16300f; box-shadow: inset 0 1px 0 rgba(255,255,255,.5), 0 2px 8px rgba(0,0,0,.25); }
.page-head .btn.primary:hover { filter: brightness(1.04); }
.page-head select { background-color: rgba(255,255,255,.1); color: #fff; border-color: rgba(255,255,255,.25); }
.page-head select option { color: #000; }
.page-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.page-actions > .btn { flex: 1 1 auto; }

/* ---------- Cards & layout ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-head { display: flex; align-items: center; gap: 8px 10px; padding: 14px 16px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.card-head h2, .card-head h3 { flex: 1; min-width: 60%; }
.card-head .sub { font-size: 12px; color: var(--text-3); font-weight: 400; }
.card-body { padding: 16px; }
.card-body.flush { padding: 0; }
/* safety net: a raw table dropped straight into a card scrolls instead of widening the page */
.card-body:has(> table.tbl) { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.grid { display: grid; gap: 14px; grid-template-columns: minmax(0, 1fr); }
.grid > * { min-width: 0; }
.stack { display: flex; flex-direction: column; gap: 14px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.mt { margin-top: 16px; } .mt-s { margin-top: 8px; } .mb { margin-bottom: 14px; }

/* KPI tiles */
.kpis { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin-bottom: 16px; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; box-shadow: var(--shadow); position: relative; min-width: 0; }
.kpi .k-label { font-size: 12px; color: var(--text-2); font-weight: 600; display: flex; align-items: flex-start; gap: 6px; line-height: 1.3; }
.kpi .k-label svg { flex: 0 0 auto; width: 26px !important; height: 26px !important; padding: 5px; margin: -3px 2px 0 -2px; border-radius: 8px; color: var(--brand); background: var(--brand-soft); }
.kpi::before { content: ""; position: absolute; left: 14px; right: 14px; top: 0; height: 2px; border-radius: 0 0 2px 2px; background: linear-gradient(90deg, var(--brand), var(--gold)); opacity: 0; transition: opacity .15s; }
.kpi.link:hover::before { opacity: 1; }
.kpi .k-value { font-size: 22px; font-weight: 750; margin-top: 6px; letter-spacing: -.4px; overflow-wrap: anywhere; line-height: 1.15; }
.kpi .k-foot { font-size: 11.5px; color: var(--text-3); margin-top: 4px; line-height: 1.35; }
.kpi .k-foot.good { color: var(--good); } .kpi .k-foot.bad { color: var(--bad); } .kpi .k-foot.warn { color: var(--warn); }
.kpi.link { cursor: pointer; transition: border-color .12s, transform .12s; }
.kpi.link:hover { border-color: var(--brand); }
.kpi.link:active { transform: scale(.98); }

/* ---------- Buttons & inputs ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 7px; justify-content: center;
  min-height: 42px; padding: 0 16px; border-radius: 10px; border: 1px solid var(--border-strong);
  background: var(--surface); color: var(--text); font: inherit; font-weight: 600; font-size: 14px;
  cursor: pointer; white-space: nowrap; transition: background .12s, border-color .12s, transform .08s;
  touch-action: manipulation;
}
.btn:hover { background: var(--surface-3); text-decoration: none; }
.btn:active:not([disabled]) { transform: scale(.97); }
.btn:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, a:focus-visible, button:focus-visible { outline: 2px solid var(--brand); outline-offset: 1px; }
.btn.primary {
  background: linear-gradient(180deg, color-mix(in srgb, var(--brand) 88%, #fff) 0%, var(--brand) 55%, color-mix(in srgb, var(--brand) 82%, #000) 100%);
  border-color: color-mix(in srgb, var(--brand) 80%, #000); color: var(--on-brand);
  box-shadow: inset 0 1px 0 rgba(255,255,255,.22), 0 1px 2px rgba(10, 30, 8, .25);
}
.btn.primary:hover { background: linear-gradient(180deg, var(--brand) 0%, var(--brand-strong) 100%); border-color: var(--brand-strong); }
.btn.danger { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 40%, var(--border)); }
.btn.danger:hover { background: var(--bad-soft); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--surface-3); }
.btn.sm { min-height: 36px; padding: 0 12px; font-size: 13px; border-radius: 9px; }
.btn.icon { width: var(--tap); min-height: var(--tap); padding: 0; border-radius: 12px; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.btn svg { width: 17px; height: 17px; flex: 0 0 auto; }
.btn.icon svg { width: 21px; height: 21px; }

/* 16px text on inputs stops iOS from zooming the page on focus */
input, select, textarea {
  font: inherit; font-size: 16px; color: var(--text); background: var(--surface);
  border: 1px solid var(--border-strong); border-radius: 10px; min-height: var(--tap); padding: 0 12px; width: 100%;
}
select { padding-right: 32px; appearance: none; -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%237a8576' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 10px center; background-size: 16px; }
select[multiple] { background-image: none; padding: 6px 10px; }
input[type="search"] { -webkit-appearance: none; appearance: none; }
textarea { min-height: 96px; padding: 10px 12px; resize: vertical; }
input[type="checkbox"], input[type="radio"] { width: 20px; height: 20px; min-height: 0; padding: 0; accent-color: var(--brand); flex: 0 0 auto; }
input[type="color"] { padding: 3px; }
input[readonly] { background: var(--surface-3); color: var(--text-2); }
input.invalid, select.invalid, textarea.invalid { border-color: var(--bad); background-color: var(--bad-soft); }
label.field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; font-weight: 600; color: var(--text-2); }
label.field .req { color: var(--bad); }
label.field .help { font-weight: 400; font-size: 12px; color: var(--text-3); }
label.field .err { font-weight: 500; font-size: 12px; color: var(--bad); }
label.field .err:empty { display: none; }
label.check { display: inline-flex; gap: 10px; align-items: center; font-size: 14px; color: var(--text); font-weight: 500; min-height: var(--tap); }
.form-grid { display: grid; grid-template-columns: minmax(0, 1fr); gap: 14px; }
.form-grid .span-2 { grid-column: 1 / -1; }
.form-section { grid-column: 1 / -1; font-size: 11px; text-transform: uppercase; letter-spacing: .8px; color: var(--text-3); font-weight: 700; border-bottom: 1px solid var(--border); padding-bottom: 6px; margin-top: 8px; }

.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; padding: 12px; border-bottom: 1px solid var(--border); }
.toolbar input[type="search"] { flex: 1 1 100%; }
.toolbar select { flex: 1 1 140px; width: auto; min-width: 0; }
.toolbar .spacer { display: none; }
.toolbar > .row { flex: 1 1 auto; }
.toolbar > .btn { flex: 0 0 auto; }

/* ---------- Tables ---------- */
.table-wrap {
  overflow-x: auto; -webkit-overflow-scrolling: touch;
  /* scroll shadows hint at more columns off-screen */
  background:
    linear-gradient(to right, var(--surface) 30%, transparent) left / 24px 100% no-repeat local,
    linear-gradient(to left, var(--surface) 30%, transparent) right / 24px 100% no-repeat local,
    radial-gradient(farthest-side at 0 50%, rgba(0,0,0,.14), transparent) left / 10px 100% no-repeat scroll,
    radial-gradient(farthest-side at 100% 50%, rgba(0,0,0,.14), transparent) right / 10px 100% no-repeat scroll;
}
table.tbl { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.tbl th {
  text-align: left; font-weight: 650; font-size: 11.5px; text-transform: uppercase; letter-spacing: .4px;
  color: var(--text-3); background: var(--surface-2); padding: 10px 12px; border-bottom: 1px solid var(--border);
  white-space: nowrap; position: sticky; top: 0; z-index: 1;
}
.tbl th.sortable { cursor: pointer; user-select: none; }
.tbl th.sortable:hover { color: var(--text); }
.tbl th .sort-ind { opacity: .6; margin-left: 3px; }
.tbl td { padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.tbl tbody tr:hover td { background: var(--surface-2); }
.tbl tbody tr.clickable { cursor: pointer; }
.tbl tbody tr.selected td { background: var(--brand-soft); }
.tbl tfoot td { font-weight: 650; background: var(--surface-2); }
.tbl .row-actions { display: flex; gap: 6px; justify-content: flex-end; flex-wrap: wrap; }
.tbl-foot { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; padding: 10px 14px; font-size: 12.5px; color: var(--text-3); }
.tbl-foot .pager { display: flex; gap: 6px; align-items: center; }
.sort-sel { flex: 1 1 140px; }
.empty { padding: 36px 16px; text-align: center; color: var(--text-3); }
.empty b { display: block; color: var(--text-2); font-size: 15px; margin-bottom: 4px; }

/* Phones: data tables built by UI.table render each row as a card */
@media (max-width: 719.98px) {
  .tbl-cards thead { display: none; }
  .tbl-cards, .tbl-cards tbody, .tbl-cards tfoot, .tbl-cards tr, .tbl-cards td { display: block; width: 100% !important; }
  .tbl-cards tbody tr { padding: 12px 14px; border-bottom: 1px solid var(--border); position: relative; }
  .tbl-cards tbody tr.clickable { padding-right: 34px; }
  .tbl-cards tbody tr.clickable::after {
    content: ""; position: absolute; right: 14px; top: 18px; width: 8px; height: 8px;
    border-right: 2px solid var(--text-3); border-top: 2px solid var(--text-3); transform: rotate(45deg); opacity: .6;
  }
  .tbl-cards tbody tr.clickable:active { background: var(--surface-3); }
  .tbl-cards tbody tr:hover td { background: none; }
  .tbl-cards tbody tr.selected { background: var(--brand-soft); }
  .tbl-cards td { border: 0; padding: 4px 0; text-align: right; overflow-wrap: anywhere; font-size: 14px; }
  .tbl-cards td::after { content: ""; display: table; clear: both; }
  .tbl-cards td[data-label]::before {
    content: attr(data-label); float: left; max-width: 48%; padding-right: 12px; text-align: left;
    color: var(--text-3); font-size: 12.5px; font-weight: 500; line-height: 1.6;
  }
  .tbl-cards td[data-label]:empty { display: none; }
  .tbl-cards tbody td:first-child { text-align: left; font-weight: 650; font-size: 15px; padding-bottom: 8px; }
  .tbl-cards tbody td:first-child::before { display: none; }
  .tbl-cards tbody td:not([data-label]):not(:first-child) { text-align: left; padding-top: 10px; }
  .tbl-cards tbody td:not([data-label]):empty { display: none; }
  .tbl-cards td.num { font-variant-numeric: tabular-nums; }
  .tbl-cards .row-actions { justify-content: flex-start; }
  .tbl-cards .row-actions .btn, .tbl-cards td:not([data-label]):not(:first-child) > .btn { flex: 1 1 auto; }
  .tbl-cards .empty-row td { text-align: center; }
  .tbl-cards tfoot tr { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 4px 12px; padding: 12px 14px; background: var(--surface-2); }
  .tbl-cards tfoot td { width: auto !important; padding: 0; border: 0; background: none; text-align: left; }
  .tbl-cards tfoot td:empty { display: none; }
  .table-wrap:has(.tbl-cards) { background: none; overflow: visible; }
  /* long-form (prose) tables: label above value reads better than side-by-side */
  .prose .tbl-cards td[data-label] { text-align: left; padding: 6px 0; }
  .prose .tbl-cards td[data-label]::before { float: none; display: block; max-width: none; padding: 0; line-height: 1.4; }
}

@media (min-width: 720px) { .sort-sel { display: none; } }

/* key-value */
.kv { display: grid; grid-template-columns: minmax(0, 1fr); gap: 2px 0; font-size: 14px; }
.kv dt { color: var(--text-3); font-size: 12.5px; }
.kv dd { margin: 0 0 8px; font-weight: 550; overflow-wrap: anywhere; }

/* ---------- Badges ---------- */
.badge { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; font-weight: 650; padding: 2px 10px; border-radius: 20px; white-space: nowrap; background: var(--muted-soft); color: var(--text-2); border: 1px solid transparent; vertical-align: middle; }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .9; }
.badge.plain::before { display: none; }
.badge.good { background: var(--good-soft); color: var(--good); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }
.badge.info { background: var(--info-soft); color: var(--info); }
.badge.brand { background: var(--brand-soft); color: var(--brand); }
.chip { display: inline-block; font-size: 12px; padding: 1px 8px; border-radius: 6px; background: var(--surface-3); color: var(--text-2); border: 1px solid var(--border); margin: 1px 2px 1px 0; }

/* ---------- Alerts ---------- */
.alert { display: flex; gap: 10px; padding: 12px 14px; border-radius: 10px; border: 1px solid; font-size: 14px; align-items: flex-start; }
.alert svg { width: 18px; height: 18px; flex: 0 0 18px; margin-top: 1px; }
.alert.info { background: var(--info-soft); border-color: color-mix(in srgb, var(--info) 30%, transparent); color: var(--text); }
.alert.warn { background: var(--warn-soft); border-color: color-mix(in srgb, var(--warn) 35%, transparent); color: var(--text); }
.alert.bad { background: var(--bad-soft); border-color: color-mix(in srgb, var(--bad) 35%, transparent); color: var(--text); }
.alert.good { background: var(--good-soft); border-color: color-mix(in srgb, var(--good) 35%, transparent); color: var(--text); }
.alert .alert-icon { color: var(--info); } .alert.warn .alert-icon { color: var(--warn); } .alert.bad .alert-icon { color: var(--bad); } .alert.good .alert-icon { color: var(--good); }
a.alert:hover { text-decoration: none; filter: brightness(.98); }

/* ---------- Tabs: scrollable pills on phones, underline on desktop ---------- */
.tabs {
  display: flex; gap: 6px; margin: 0 -16px 16px; padding: 2px 16px 6px; overflow-x: auto;
  scroll-snap-type: x proximity; scroll-padding-inline: 16px; scrollbar-width: none; -webkit-overflow-scrolling: touch;
}
.tabs::-webkit-scrollbar { display: none; }
.tabs button {
  flex: 0 0 auto; scroll-snap-align: start; min-height: 38px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 20px; padding: 0 14px;
  font: inherit; font-size: 14px; font-weight: 600; color: var(--text-2); cursor: pointer; white-space: nowrap;
}
.tabs button:hover { color: var(--text); }
.tabs button.active { color: var(--on-brand); background: var(--brand); border-color: var(--brand); }
.tabs button .count { font-size: 11px; background: var(--surface-3); border-radius: 10px; padding: 0 6px; margin-left: 6px; color: var(--text-3); }
.tabs button.active .count { background: rgba(255,255,255,.22); color: var(--on-brand); }

/* ---------- Modal (bottom sheet on phones) & drawer ---------- */
.overlay {
  position: fixed; inset: 0; background: rgba(6, 12, 5, .5); z-index: 100;
  display: flex; align-items: flex-end; justify-content: center; padding: 0;
  animation: fade .15s ease-out;
}
.modal {
  background: var(--surface); width: 100%; max-height: calc(100dvh - var(--safe-t) - 24px);
  display: flex; flex-direction: column; border-radius: 20px 20px 0 0;
  box-shadow: var(--shadow-lg); animation: sheetup .22s cubic-bezier(.2,.8,.2,1);
  padding-bottom: var(--safe-b);
}
.modal::before { content: ""; display: block; width: 40px; height: 5px; border-radius: 3px; background: var(--border-strong); margin: 8px auto 0; flex: 0 0 auto; }
.modal-head { display: flex; align-items: center; gap: 10px; padding: 8px 12px 12px 18px; border-bottom: 1px solid var(--border); }
.modal-head h2 { flex: 1; font-size: 17px; }
.modal-body { padding: 16px 18px; overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; }
.modal-foot {
  display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; padding: 12px 18px;
  border-top: 1px solid var(--border); background: var(--surface-2);
}
.modal > .modal-foot > .btn { flex: 1 1 0; }
.drawer-overlay { justify-content: flex-end; align-items: stretch; }
.drawer {
  background: var(--surface); width: 100%; height: 100%; display: flex; flex-direction: column;
  box-shadow: var(--shadow-lg); animation: slidein .2s cubic-bezier(.2,.8,.2,1);
  padding-top: var(--safe-t); padding-bottom: var(--safe-b);
}
.drawer .modal-head { padding: 12px 12px 12px 18px; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes slidein { from { transform: translateX(40px); opacity: .4; } to { transform: none; opacity: 1; } }
@keyframes sheetup { from { transform: translateY(40px); opacity: .5; } to { transform: none; opacity: 1; } }

/* ---------- Toasts ---------- */
#toasts {
  position: fixed; left: 12px; right: 12px; z-index: 200;
  bottom: calc(var(--bottomnav-h) + var(--safe-b) + 12px);
  display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none;
}
.toast { width: 100%; max-width: 440px; padding: 12px 16px; border-radius: 12px; background: var(--text); color: var(--surface); box-shadow: var(--shadow-lg); font-size: 14px; display: flex; gap: 10px; align-items: flex-start; animation: sheetup .18s ease-out; pointer-events: auto; }
.toast.good { border-left: 4px solid var(--good); } .toast.bad { border-left: 4px solid var(--bad); } .toast.warn { border-left: 4px solid var(--warn); } .toast.info { border-left: 4px solid var(--info); }

/* ---------- Progress, steps, timeline ---------- */
.progress { height: 8px; background: var(--surface-3); border-radius: 6px; overflow: hidden; }
.progress > span { display: block; height: 100%; background: var(--brand); border-radius: 6px; }
.progress.warn > span { background: var(--warn); } .progress.bad > span { background: var(--bad); } .progress.good > span { background: var(--good); }
.steps { display: flex; gap: 0; align-items: flex-start; overflow-x: auto; padding: 4px 0; scrollbar-width: thin; }
.step { flex: 1; min-width: 84px; text-align: center; position: relative; font-size: 11.5px; color: var(--text-3); }
.step::before { content: ""; position: absolute; top: 11px; left: -50%; width: 100%; height: 2px; background: var(--border); z-index: 0; }
.step:first-child::before { display: none; }
.step .s-dot { width: 24px; height: 24px; border-radius: 50%; border: 2px solid var(--border-strong); background: var(--surface); display: grid; place-items: center; margin: 0 auto 6px; position: relative; z-index: 1; font-size: 11px; font-weight: 700; }
.step.done { color: var(--text-2); } .step.done .s-dot { background: var(--brand); border-color: var(--brand); color: var(--on-brand); } .step.done::before { background: var(--brand); }
.step.current { color: var(--text); font-weight: 650; } .step.current .s-dot { border-color: var(--brand); color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); } .step.current::before { background: var(--brand); }
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { position: relative; padding: 0 0 14px 22px; font-size: 14px; }
.timeline li::before { content: ""; position: absolute; left: 5px; top: 6px; width: 8px; height: 8px; border-radius: 50%; background: var(--brand); }
.timeline li::after { content: ""; position: absolute; left: 8.5px; top: 16px; bottom: 0; width: 1px; background: var(--border); }
.timeline li:last-child::after { display: none; }
.timeline .t-time { font-size: 12px; color: var(--text-3); }

/* ---------- Charts ---------- */
.chart { width: 100%; position: relative; touch-action: pan-y; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .axis-label { fill: var(--text-3); font-size: 11px; }
.chart .grid-line { stroke: var(--grid); stroke-width: 1; }
.chart .base-line { stroke: var(--axis); stroke-width: 1; }
.chart .val-label { fill: var(--text-2); font-size: 11px; font-weight: 600; }
.chart-tip { position: absolute; pointer-events: none; background: var(--text); color: var(--surface); font-size: 12.5px; padding: 6px 10px; border-radius: 8px; white-space: nowrap; z-index: 5; transform: translate(-50%, -110%); box-shadow: var(--shadow); }
.legend { display: flex; gap: 6px 14px; flex-wrap: wrap; font-size: 12.5px; color: var(--text-2); margin-top: 10px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }

/* ---------- Flow diagram: vertical on phones, horizontal from tablet ---------- */
.flow { display: flex; flex-direction: column; align-items: stretch; gap: 0; }
.flow-node { flex: 1; min-width: 0; background: var(--surface-2); border: 1px solid var(--border); border-radius: 12px; padding: 10px 14px; font-size: 13px; display: flex; align-items: center; justify-content: space-between; gap: 10px; }
a.flow-node:hover { border-color: var(--brand); text-decoration: none; }
.flow-node b { display: block; font-size: 14px; }
.flow-node .fn-meta { color: var(--text-3); font-size: 12px; }
.flow-node.brand { border-color: var(--brand); background: var(--brand-soft); }
.flow-arrow { flex: 0 0 22px; display: grid; place-items: center; color: var(--text-3); }
.flow-arrow svg { width: 16px; height: 16px; transform: rotate(90deg); }
div.flow-node { display: block; }

/* Live feed (shop floor) */
.feed { font-family: var(--mono); font-size: 12px; max-height: 360px; overflow: auto; }
.feed-row { display: grid; grid-template-columns: 62px 54px minmax(0, 1fr) 48px; gap: 6px; padding: 6px 12px; border-bottom: 1px solid var(--border); }
.feed-row > * { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.feed-row.nok { background: var(--bad-soft); }

/* Docs / blueprint prose */
.prose { max-width: 980px; font-size: 15px; line-height: 1.65; overflow-wrap: break-word; }
.prose section { scroll-margin-top: calc(var(--topbar-h) + 16px); }
.prose h2 { font-size: 19px; margin: 28px 0 10px; padding-top: 6px; }
.prose h3 { font-size: 16px; margin: 20px 0 8px; }
.prose ul, .prose ol { padding-left: 22px; margin: 0 0 12px; }
.prose li { margin-bottom: 4px; }
.prose table.tbl { margin: 10px 0 16px; font-size: 13px; }
.prose .tbl td { vertical-align: top; }
.toc { position: sticky; top: 78px; font-size: 13px; }
.toc a { display: block; padding: 4px 10px; color: var(--text-2); border-left: 2px solid var(--border); }
.toc a:hover { color: var(--brand); border-left-color: var(--brand); text-decoration: none; }

/* =====================================================================
   ≥ 640px — large phones in landscape, small tablets
   ===================================================================== */
@media (min-width: 640px) {
  #view { padding-left: 24px; padding-right: 24px; }
  .page-head { flex-direction: row; align-items: flex-start; flex-wrap: wrap; gap: 16px; padding: 24px 26px; border-radius: 20px; }
  .page-head .titles { min-width: 260px; }
  .page-actions > .btn { flex: 0 0 auto; }
  .grid { gap: 16px; }
  .g2, .g3, .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .form-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px 16px; }
  .kpis { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; margin-bottom: 18px; }
  .kpi { padding: 14px 16px; }
  .kpi .k-value { font-size: 25px; }
  .kv { grid-template-columns: minmax(130px, max-content) 1fr; gap: 8px 18px; }
  .kv dt { font-size: 13px; }
  .kv dd { margin: 0; }
  .toolbar { padding: 12px 16px; }
  .toolbar input[type="search"] { flex: 1 1 220px; max-width: 320px; }
  .toolbar select { flex: 0 1 auto; min-width: 150px; }
  .toolbar .spacer { display: block; flex: 1; }
  .tabs { margin: 0 0 16px; padding: 2px 0 6px; }
  .flow { flex-direction: row; overflow-x: auto; padding-bottom: 4px; }
  .flow-node { display: block; min-width: 118px; }
  .flow-node b { margin-bottom: 2px; }
  .flow-arrow { flex: 0 0 26px; }
  .flow-arrow svg { transform: none; }
  .feed-row { grid-template-columns: 78px 70px minmax(0, 1fr) 70px; gap: 8px; }

  /* centred dialog instead of bottom sheet */
  .overlay { align-items: center; padding: 24px; }
  .modal { max-width: 640px; border-radius: 16px; border: 1px solid var(--border); max-height: calc(100dvh - 48px); animation: pop .16s ease-out; padding-bottom: 0; }
  .modal::before { display: none; }
  .modal-head { padding: 16px 16px 16px 22px; }
  .modal-body { padding: 18px 22px; }
  .modal-foot { padding: 14px 22px; border-radius: 0 0 16px 16px; }
  .modal > .modal-foot > .btn { flex: 0 0 auto; }
  .modal.lg { max-width: 920px; } .modal.xl { max-width: 1180px; } .modal.sm { max-width: 440px; }
  .drawer { max-width: 620px; }
  .drawer-overlay { padding: 0; align-items: stretch; }
}
@keyframes pop { from { transform: scale(.97); opacity: 0; } to { transform: none; opacity: 1; } }

/* =====================================================================
   ≥ 1024px — desktop: fixed sidebar, full top bar, no bottom tabs
   ===================================================================== */
@media (min-width: 1024px) {
  body { font-size: 14px; }
  .desktop-only { display: revert !important; }
  .mobile-only { display: none !important; }

  #sidebar {
    position: sticky; top: 0; height: 100vh; transform: none; transition: none; box-shadow: none;
    width: var(--sidebar-w); flex: 0 0 var(--sidebar-w); z-index: 30; padding: 0;
  }
  .nav-backdrop, .brand-block .nav-close, .sidebar-prefs { display: none; }
  body.nav-open { overflow: auto; }
  .nav a { min-height: 38px; padding: 7px 12px; font-size: 13.5px; }
  .nav a svg { width: 17px; height: 17px; flex-basis: 17px; }

  #topbar { min-height: 60px; padding: 0 24px; gap: 12px; }
  .topbar-logo { display: none; }
  .crumbs { flex: 0 1 auto; flex-direction: row; align-items: baseline; gap: 6px; }
  .crumbs .crumb-group { font-size: 13px; text-transform: none; letter-spacing: 0; font-weight: 500; }
  .crumbs .crumb-group:not(:empty)::after { content: " /"; }
  .crumbs b { font-size: 14px; font-weight: 650; }
  .topbar-spacer { display: block; flex: 1; }
  #bellBtn, .env-pill { display: inline-flex; }
  #topbar .role-sel { display: block; width: auto; max-width: 200px; min-height: 36px; font-size: 13.5px; }
  .sync-text { display: inline; }
  #topbar .btn.icon { width: 38px; min-height: 38px; }
  #topbar .btn.icon svg { width: 19px; height: 19px; }
  .count-badge { top: 1px; right: 1px; }

  .global-search, body.search-open .global-search {
    display: block; position: relative; inset: auto; padding: 0; background: none; animation: none; z-index: auto;
  }
  body.search-open { overflow: auto; }
  .global-search .gs-field svg { left: 10px; width: 15px; height: 15px; }
  .global-search input { width: 280px; padding-left: 32px; min-height: 36px; font-size: 13.5px; }
  .global-search .search-cancel, .search-hint { display: none; }
  .search-results {
    position: absolute; top: 44px; right: 0; width: 400px; max-height: 440px;
    box-shadow: var(--shadow-lg); z-index: 25;
  }

  #bottomnav { display: none; }
  #view { padding: 24px 28px 60px; }
  h1 { font-size: 23px; }
  .page-head { margin-bottom: 20px; padding: 26px 30px; }
  .page-head p { font-size: 14px; }
  #toasts { left: auto; right: 20px; bottom: 20px; align-items: flex-end; }
  .toast { width: auto; min-width: 280px; max-width: 420px; font-size: 13px; }

  .btn { min-height: 36px; padding: 0 14px; font-size: 13.5px; border-radius: 9px; }
  .btn.sm { min-height: 30px; padding: 0 10px; font-size: 12.5px; border-radius: 8px; }
  .btn.icon { width: 36px; min-height: 36px; border-radius: 9px; }
  .btn.icon svg { width: 18px; height: 18px; }
  .btn svg { width: 15px; height: 15px; }
  input, select, textarea { font-size: 14px; min-height: 36px; border-radius: 9px; padding: 0 10px; }
  select { padding-right: 30px; }
  textarea { padding: 8px 10px; min-height: 80px; }
  input[type="checkbox"], input[type="radio"] { width: 16px; height: 16px; }
  label.field { font-size: 12.5px; gap: 5px; }
  label.check { font-size: 13.5px; min-height: 0; }
  table.tbl { font-size: 13px; }
  .tbl td { padding: 9px 12px; }
  .card-head { padding: 14px 18px; }
  .card-body { padding: 18px; }
  .card-head h2, .card-head h3 { min-width: 0; }
  .alert { font-size: 13px; padding: 11px 14px; }
  .badge { font-size: 11.5px; }

  /* underline tabs on desktop */
  .tabs { gap: 2px; border-bottom: 1px solid var(--border); padding: 0; overflow-x: auto; }
  .tabs button { background: none; border: 0; border-bottom: 2px solid transparent; border-radius: 0; padding: 9px 14px; min-height: 0; font-size: 13.5px; margin-bottom: -1px; }
  .tabs button.active { color: var(--brand); background: none; border-bottom-color: var(--brand); }
  .tabs button.active .count { background: var(--brand-soft); color: var(--brand); }
}

/* ≥ 1200px — wide grids */
@media (min-width: 1200px) {
  .g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .g-2-1 { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
  .g-1-2 { grid-template-columns: minmax(0, 1fr) minmax(0, 2fr); }
}

/* ---------- Master data ---------- */
.master-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 12px; margin-bottom: 8px; }
.master-tile {
  display: flex; flex-direction: column; gap: 6px; text-align: left; padding: 14px 16px; border-radius: var(--radius);
  background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow); color: var(--text); font: inherit; cursor: pointer;
  position: relative; transition: border-color .12s, transform .12s;
}
.master-tile:hover { border-color: var(--brand); text-decoration: none; transform: translateY(-1px); }
.master-tile.entity { background: var(--surface-2); }
.master-tile .mt-top { display: flex; align-items: center; justify-content: space-between; }
.master-tile .mt-ic { width: 32px; height: 32px; border-radius: 9px; display: grid; place-items: center; color: var(--brand); background: var(--brand-soft); }
.master-tile .mt-ic svg { width: 18px; height: 18px; }
.master-tile .mt-count { font-size: 22px; font-weight: 750; letter-spacing: -.3px; }
.master-tile .mt-count small { font-size: 12px; color: var(--text-3); font-weight: 600; }
.master-tile b { font-size: 14.5px; }
.master-tile .mt-desc { font-size: 12.5px; color: var(--text-2); line-height: 1.45; }
.master-tile .mt-foot { font-size: 11.5px; color: var(--text-3); margin-top: auto; padding-top: 6px; border-top: 1px dashed var(--border); }
.master-tile.entity .mt-foot { color: var(--brand); font-weight: 600; }
.where-used { list-style: none; margin: 8px 0 0; padding: 0; }
.where-used li { display: flex; justify-content: space-between; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--border); }
.tbl tr.row-inactive td { opacity: .6; }

/* =====================================================================
   Help: "i" icons, tooltips, tab intros, first-visit nudge, guided tour
   ===================================================================== */
.info-i {
  display: inline-grid; place-items: center; flex: 0 0 auto; vertical-align: middle;
  width: 20px; height: 20px; min-height: 0; padding: 0; margin: 0 0 0 4px; border-radius: 50%;
  font: italic 700 12px/1 Georgia, "Times New Roman", serif; letter-spacing: 0;
  color: var(--brand); background: var(--brand-soft); border: 1px solid color-mix(in srgb, var(--brand) 30%, transparent);
  cursor: help; position: relative; transition: transform .12s, background .12s, color .12s;
}
.info-i::after { content: ""; position: absolute; inset: -12px; } /* 44px touch target */
.info-i:hover, .info-i:focus-visible { background: var(--brand); color: var(--on-brand); transform: scale(1.08); }
.info-i.sm { width: 18px; height: 18px; font-size: 11px; }
.card-head h2 .info-i, .card-head h3 .info-i { margin-left: 6px; }
.kpi .k-label .info-i { margin-left: auto; }
.page-head .info-head {
  width: 30px; height: 30px; font-size: 16px; cursor: pointer;
  color: #16300f; background: linear-gradient(180deg, #ffe84d, var(--gold) 50%, var(--gold-deep)); border-color: var(--gold-deep);
  box-shadow: inset 0 1px 0 rgba(255,255,255,.5), 0 2px 8px rgba(0,0,0,.3);
}
.page-head .info-head:hover { background: #fff; color: var(--brand-base); }
.info-head.pulse { animation: ipulse 2s infinite; }
@keyframes ipulse { 0% { box-shadow: 0 0 0 0 rgba(255,222,0,.7); } 70% { box-shadow: 0 0 0 12px rgba(255,222,0,0); } 100% { box-shadow: 0 0 0 0 rgba(255,222,0,0); } }
.tbl th.has-help { text-decoration: underline dotted color-mix(in srgb, var(--text-3) 70%, transparent); text-underline-offset: 3px; cursor: help; }
.nav a[data-help-tip] { cursor: pointer; }

.help-tip {
  position: fixed; z-index: 400; left: 0; top: 0; max-width: 340px; padding: 12px 14px; border-radius: 12px;
  background: linear-gradient(180deg, #1e3d19, #122810); color: #eef5ec; font-size: 13px; line-height: 1.5;
  box-shadow: 0 12px 32px rgba(0,0,0,.28), inset 0 1px 0 rgba(255,255,255,.08); border: 1px solid rgba(255,222,0,.25);
  opacity: 0; visibility: hidden; transform: translateY(4px); transition: opacity .14s, transform .14s, visibility 0s .14s; pointer-events: none;
}
.help-tip.show { opacity: 1; visibility: visible; transform: none; transition: opacity .14s, transform .14s; }
.help-tip.pinned { pointer-events: auto; }
.help-tip::before { content: ""; position: absolute; top: -6px; left: var(--arrow-x, 50%); width: 10px; height: 10px; margin-left: -5px; background: #1e3d19; border-left: 1px solid rgba(255,222,0,.25); border-top: 1px solid rgba(255,222,0,.25); transform: rotate(45deg); }
.help-tip.above::before { top: auto; bottom: -6px; background: #122810; transform: rotate(225deg); }
.help-tip .ht-title { font-weight: 700; color: var(--gold); font-size: 12px; letter-spacing: .3px; margin-bottom: 4px; }
.help-tip .ht-body b { color: #fff; }
.help-tip .ht-foot { margin-top: 8px; padding-top: 8px; border-top: 1px solid rgba(255,255,255,.12); font-size: 12px; color: rgba(255,255,255,.7); }
.help-tip .ht-tour { background: none; border: 0; padding: 0; font: inherit; font-weight: 700; color: var(--gold); cursor: pointer; }

.ti-icon { display: inline-grid; place-items: center; width: 22px; height: 22px; flex: 0 0 22px; border-radius: 50%; font: italic 700 12px/1 Georgia, serif; color: var(--on-brand); background: var(--brand); }
.ti-icon.inline { width: 18px; height: 18px; font-size: 11px; vertical-align: -3px; }
.tab-intro {
  display: flex; gap: 10px; align-items: flex-start; margin: -6px 0 14px; padding: 10px 14px; border-radius: 12px;
  font-size: 13.5px; color: var(--text-2); background: linear-gradient(90deg, var(--brand-soft), color-mix(in srgb, var(--brand-soft) 30%, var(--surface)));
  border: 1px solid color-mix(in srgb, var(--brand) 18%, var(--border)); border-left: 3px solid var(--brand);
}
.tab-intro b { color: var(--text); }
.tour-nudge {
  display: flex; gap: 12px; align-items: center; flex-wrap: wrap; margin: -6px 0 16px; padding: 12px 14px; border-radius: 14px;
  background: var(--accent-soft); border: 1px solid color-mix(in srgb, var(--gold-deep) 60%, transparent); font-size: 14px; color: var(--text);
}
.tour-nudge > div:nth-child(2) { flex: 1 1 220px; }
.tour-nudge .tn-actions { display: flex; gap: 6px; }
.tour-nudge .ti-icon { background: var(--gold-deep); color: #16300f; }

/* Tour */
.tour { position: fixed; inset: 0; z-index: 300; }
.tour-shade { position: absolute; inset: 0; }
.tour-spot {
  position: fixed; border-radius: 14px; pointer-events: none;
  box-shadow: 0 0 0 3px var(--gold), 0 0 0 9999px rgba(5, 14, 4, .62);
  transition: left .3s cubic-bezier(.2,.8,.2,1), top .3s cubic-bezier(.2,.8,.2,1), width .3s, height .3s, opacity .2s;
}
.tour.centered .tour-spot { opacity: 0 !important; }
.tour.centered .tour-shade { background: rgba(5, 14, 4, .62); -webkit-backdrop-filter: blur(3px); backdrop-filter: blur(3px); }
.tour-pop {
  position: fixed; left: 0; right: 0; bottom: 0; max-height: 62dvh; display: flex; flex-direction: column;
  background: var(--surface); border-radius: 20px 20px 0 0; box-shadow: var(--shadow-lg); overflow: hidden;
  padding-bottom: var(--safe-b); animation: sheetup .22s cubic-bezier(.2,.8,.2,1); outline: none;
}
.tour.centered .tour-pop { max-height: 86dvh; }
.tp-head {
  display: flex; align-items: flex-start; gap: 10px; padding: 16px 12px 14px 18px; color: #fff;
  background: var(--tex-green); position: relative;
}
.tp-head::after { content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: 3px; background: linear-gradient(90deg, var(--gold), var(--gold-deep) 40%, transparent); }
.tp-head > div { flex: 1; min-width: 0; }
.tp-head h2 { font-size: 18px; color: #fff; }
.tp-head .btn { color: #fff; }
.tp-head .btn:hover { background: rgba(255,255,255,.14); }
.tp-eyebrow { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 1.1px; color: var(--gold); margin-bottom: 4px; }
.tp-head, .tp-foot { flex: 0 0 auto; }
.tp-body { flex: 1 1 auto; min-height: 0; padding: 16px 18px; overflow-y: auto; overscroll-behavior: contain; font-size: 14.5px; line-height: 1.6; color: var(--text-2); }
.tp-body p { margin: 0 0 10px; }
.tp-body b { color: var(--text); }
.tour-lead { font-size: 15.5px; color: var(--text); }
.tour-why { background: var(--brand-soft); border-left: 3px solid var(--brand); border-radius: 0 10px 10px 0; padding: 10px 12px; color: var(--text); }
.tw-label { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .8px; color: var(--brand); margin-bottom: 4px; }
.tour-who { margin: 4px 0 0; padding-left: 18px; }
.tour-flow { counter-reset: f; list-style: none; margin: 0; padding: 0; }
.tour-flow li { counter-increment: f; position: relative; padding: 0 0 14px 40px; color: var(--text); }
.tour-flow li::before { content: counter(f); position: absolute; left: 0; top: -1px; width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; font-size: 12.5px; font-weight: 700; color: var(--on-brand); background: var(--brand); }
.tour-flow li::after { content: ""; position: absolute; left: 12.5px; top: 27px; bottom: 2px; width: 1px; background: color-mix(in srgb, var(--brand) 35%, transparent); }
.tour-flow li:last-child::after { display: none; }
.tour-dl { margin: 6px 0 0; }
.tour-dl dt { font-weight: 700; color: var(--text); margin-top: 10px; }
.tour-dl dt:first-child { margin-top: 0; }
.tour-dl dd { margin: 2px 0 0; }
.tour-dl.terms dt { color: var(--brand); }
.tour-tasks details { border: 1px solid var(--border); border-radius: 12px; margin-bottom: 8px; background: var(--surface-2); }
.tour-tasks summary { cursor: pointer; padding: 11px 14px; font-weight: 650; color: var(--text); list-style: none; display: flex; align-items: center; gap: 8px; }
.tour-tasks summary::-webkit-details-marker { display: none; }
.tour-tasks summary::before { content: "›"; font-size: 18px; line-height: 1; color: var(--brand); transition: transform .15s; }
.tour-tasks details[open] summary::before { transform: rotate(90deg); }
.tour-tasks ol { margin: 0; padding: 0 16px 12px 36px; }
.tour-tasks li { margin-bottom: 4px; }
.tour-rules { list-style: none; padding: 0; margin: 0; }
.tour-rules li { position: relative; padding: 8px 0 8px 30px; border-bottom: 1px solid var(--border); color: var(--text); }
.tour-rules li:last-child { border-bottom: 0; }
.tour-rules li::before { content: ""; position: absolute; left: 2px; top: 11px; width: 18px; height: 18px; border-radius: 6px; background: var(--good-soft) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%230f8a3c' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M20 6L9 17l-5-5'/%3E%3C/svg%3E") center / 12px no-repeat; }
.tour-links { display: grid; gap: 8px; margin: 8px 0 12px; }
.tour-links a { display: block; padding: 10px 12px; border-radius: 12px; border: 1px solid var(--border); background: var(--surface-2); color: var(--text-2); font-size: 13.5px; }
.tour-links a b { display: block; color: var(--brand); font-size: 14px; }
.tour-links a:hover { border-color: var(--brand); text-decoration: none; }
.tour-end { font-size: 13.5px; color: var(--text-3); }
.tp-foot { display: flex; align-items: center; gap: 10px; padding: 12px 16px; border-top: 1px solid var(--border); background: var(--surface-2); }
.tp-dots { flex: 1; display: flex; gap: 5px; flex-wrap: wrap; min-width: 0; }
.tp-dots button { width: 8px; height: 8px; min-height: 0; padding: 0; border: 0; border-radius: 4px; background: var(--border-strong); cursor: pointer; transition: width .2s, background .2s; }
.tp-dots button.done { background: color-mix(in srgb, var(--brand) 45%, var(--border)); }
.tp-dots button.on { width: 22px; background: var(--brand); }
.tp-btns { display: flex; gap: 8px; }

@media (min-width: 640px) {
  .tour-pop { right: auto; bottom: auto; width: 420px; max-height: min(560px, calc(100dvh - 32px)); border-radius: 18px; border: 1px solid var(--border); padding-bottom: 0; animation: pop .18s ease-out; transition: left .3s cubic-bezier(.2,.8,.2,1), top .3s cubic-bezier(.2,.8,.2,1); }
  .tour.centered .tour-pop { left: 50%; top: 50%; width: min(600px, calc(100vw - 48px)); transform: translate(-50%, -50%); max-height: min(720px, calc(100dvh - 48px)); animation: none; }
  .tp-head { padding: 18px 14px 16px 22px; }
  .tp-body { padding: 18px 22px; }
  .tp-foot { padding: 12px 20px; }
}
@media (min-width: 1024px) {
  .tab-intro { margin-top: 0; font-size: 13px; }
}

/* Hover-capable pointers only: avoid sticky hover states on touch */
@media (hover: none) {
  .tbl tbody tr:hover td { background: none; }
  .kpi.link:hover { border-color: var(--border); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}

/* Print */
@media print {
  #sidebar, #topbar, #bottomnav, .nav-backdrop, .page-actions, .btn, .info-i, .tab-intro, .tour-nudge { display: none !important; }
  .page-head { background: none !important; color: #000; box-shadow: none; padding: 0; }
  .page-head h1, .page-head p { color: #000; }
  #view { padding: 0; }
  .card { box-shadow: none; }
  .tbl-cards thead { display: table-header-group !important; }
}
