/* PGVCL Material Inventory - Salesforce Lightning style theme (light) */
:root {
  /* palette */
  --bg-page: #F3F3F3;
  --surface: #FFFFFF;
  --text-primary: #181818;
  --text-secondary: #444444;
  --text-weak: #747474;        /* placeholders, disabled */
  --border: #D8DDE6;
  --border-input: #C9C9C9;
  --primary: #0176D3;
  --primary-dark: #0B5CAB;
  --primary-bg: #EEF4FF;       /* selected rows, info badges */
  --nav-bg: #002467;           /* left navigation rail */
  --header-bg: #98F1E0;        /* header row 2: area name + tabs (mint, as in the Salesforce reference) */

  --success: #2E844A;  --success-text: #22683E; --success-bg: #EBF7E6;
  --warning: #DD7A01;  --warning-text: #8C4B02; --warning-bg: #FEF1E5;  /* #DD7A01 is for dots/bars only (3:1 on white) */
  --error: #BA0517;    --error-bg: #FEF1EE;
  --nodata: #C9C9C9;
  --hover: #F3F3F3;

  /* names used by app.js inline styles */
  --text: var(--text-primary);
  --muted: var(--text-secondary);
  --red: var(--error);
  --green: var(--success-text);
  --amber: var(--warning-text);

  /* typography */
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --fs-page: 20px;     /* page / app title, 600 */
  --fs-section: 16px;  /* card titles, 600 */
  --fs-body: 14px;
  --fs-table: 13px;
  --fs-label: 13px;
  --fs-helper: 12px;

  /* shape and spacing */
  --radius: 8px;       /* cards, modals */
  --radius-sm: 4px;    /* inputs, tables, boxes */
  --shadow: 0 2px 2px rgba(0, 0, 0, .06);
  --shadow-pop: 0 4px 14px rgba(0, 0, 0, .16);
  --rail-w: 76px;
  --panel-w: 340px;
  --gap: 16px;
}

* { box-sizing: border-box; }
html { scroll-padding-top: calc(var(--sticky-top, 100px) + 16px); }
body {
  margin: 0;
  font-family: var(--font);
  font-size: var(--fs-body);
  font-weight: 400;
  line-height: 1.45;
  color: var(--text-primary);
  background: var(--bg-page);
  -webkit-font-smoothing: antialiased;
}
@media (max-width: 900px) { body.drawer-open { overflow: hidden; } }
h1, h2, h3 { margin: 0; font-weight: 600; }
h2 { font-size: var(--fs-section); }
h3 { font-size: var(--fs-body); }
p { margin: 0; }
a { color: var(--primary); }
a:hover { color: var(--primary-dark); }
button, input, select, textarea { font: inherit; color: inherit; }
::placeholder { color: var(--text-weak); }
.muted { color: var(--text-secondary); }
.small { font-size: var(--fs-helper); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.num { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.ico { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; border-radius: 4px; }
[hidden] { display: none !important; }

/* ---------- Shell: rail | (header, content, status bar) ---------- */
.shell { display: grid; grid-template-columns: var(--rail-w) minmax(0, 1fr); min-height: calc(100vh - var(--sticky-top, 100px)); }
.main-col { min-width: 0; display: flex; flex-direction: column; min-height: calc(100vh - var(--sticky-top, 100px)); }

/* ---------- Left navigation rail ---------- */
.rail {
  position: sticky; top: var(--sticky-top, 100px); height: calc(100vh - var(--sticky-top, 100px)); background: var(--nav-bg); z-index: 35;
  display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 10px 0; overflow-y: auto;
}
.rail-item {
  position: relative; width: 100%; padding: 7px 2px 8px; display: flex; flex-direction: column; align-items: center; gap: 4px;
  color: #FFFFFF; text-decoration: none; font-size: 11px; font-weight: 700; line-height: 1.2; text-align: center; flex: none;
}
.rail-item:hover { color: #FFFFFF; }
.rail-icon { position: relative; display: grid; place-items: center; width: 40px; height: 40px; border-radius: 10px; transition: background .15s, color .15s; }
.rail-icon .ico { width: 24px; height: 24px; stroke-width: 1.9; }
.rail-item:hover .rail-icon { background: rgba(255, 255, 255, .12); }
/* active area: mint indicator on the left edge + a soft, translucent mint icon tile */
.rail-item::before {
  content: ""; position: absolute; left: 0; top: 50%; width: 4px; height: 0; border-radius: 0 4px 4px 0;
  background: var(--header-bg); transform: translateY(-50%); transition: height .15s;
}
.rail-item.active::before { height: 28px; opacity: .85; }
.rail-item.active .rail-icon, .rail-item.active:hover .rail-icon { background: rgba(152, 241, 224, .2); color: var(--header-bg); }
.rail-item:focus-visible { outline: 2px solid #FFFFFF; outline-offset: -3px; border-radius: 8px; }
.rail-count {
  position: absolute; top: -7px; right: -10px; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 999px;
  background: var(--error); color: #FFFFFF; border: 2px solid var(--nav-bg); font-size: 10.5px; font-weight: 700; line-height: 14px;
  text-align: center; font-variant-numeric: tabular-nums;
}
.scrim { display: none; }

/* ---------- Header row 1 (full width): logo | app title | status ---------- */
.site-head { position: sticky; top: 0; z-index: 40; background: var(--surface); box-shadow: 0 2px 3px rgba(0, 0, 0, .07); }
.topbar {
  background: var(--surface);
  display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); grid-template-areas: "brand title right";
  align-items: center; gap: 16px; height: 56px; padding: 0 24px;
}
.brand { grid-area: brand; display: flex; align-items: center; gap: 8px; min-width: 0; }
.brand-logo { display: inline-flex; align-items: center; min-width: 0; text-decoration: none; }
.brand-logo img { display: block; height: 28px; width: auto; flex: none; }
.icon-btn.menu-btn { display: none; }
.app-title {
  grid-area: title; font-size: var(--fs-page); font-weight: 600; line-height: 1.2; text-align: center; white-space: nowrap;
  min-width: 0; overflow: hidden; text-overflow: ellipsis; letter-spacing: -.01em;
}
.top-right { grid-area: right; justify-self: end; display: flex; align-items: center; gap: 8px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px; font-size: var(--fs-helper); font-weight: 600;
  border: 1px solid var(--border); background: var(--surface); color: var(--text-secondary); white-space: nowrap;
}
.chip-more { margin-left: -2px; }

/* Global search (header row 1) */
.gsearch { position: relative; display: flex; align-items: center; }
.gs-box { position: relative; display: flex; align-items: center; gap: 4px; }
.gs-field { flex: none; width: clamp(200px, 22vw, 300px); min-width: 0; }
.gsearch .gs-toggle, .gsearch .gs-close { display: none; }
.gs-pop {
  position: absolute; top: calc(100% + 6px); right: 0; width: min(520px, calc(100vw - 24px)); max-height: min(70vh, 560px); overflow-y: auto;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-pop); z-index: 80; padding: 6px 0;
}
.gs-group { padding: 8px 14px 4px; font-size: var(--fs-helper); font-weight: 600; color: var(--text-secondary); }
.gs-item {
  display: flex; align-items: center; gap: 10px; width: 100%; border: 0; background: none; text-align: left; padding: 7px 14px;
  cursor: pointer; font-size: var(--fs-label); color: var(--text-primary);
}
.gs-item > .ico { width: 16px; height: 16px; color: var(--text-secondary); flex: none; }
.gs-item.active, .gs-item:hover { background: var(--primary-bg); }
.gs-main { flex: 1; min-width: 0; }
.gs-main .sub { display: block; font-size: var(--fs-helper); color: var(--text-secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.gs-side { flex: none; display: flex; flex-direction: column; align-items: flex-end; gap: 2px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.gs-ai > .ico { color: var(--primary); }
.gs-ai .gs-main > b { color: var(--primary-dark); }
.gs-note { padding: 8px 14px; font-size: var(--fs-helper); color: var(--text-secondary); }
.gs-sep { border-top: 1px solid var(--border); margin: 6px 0; }
mark.gs-hl { background: #FFF1B8; color: inherit; border-radius: 2px; padding: 0 1px; }


/* ---------- Header row 2: page tabs | actions (the rail already names the area) ---------- */
.app-nav {
  display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, max-content) minmax(max-content, 1fr); align-items: stretch; gap: 0 24px;
  min-height: 44px; padding: 0 24px; background: var(--header-bg); border-top: 1px solid rgba(0, 0, 0, .06);
}
/* tabs sit in the centre column; the actions take the right column */
.app-tabs { grid-column: 2; display: flex; align-items: center; gap: 4px; min-width: 0; overflow-x: auto; scrollbar-width: none; padding: 6px 0; }
.app-tab .t-short { display: none; }
/* the active tab is marked by a navy underline and bold navy text */
.app-tab {
  position: relative; display: flex; align-items: center; height: 32px; padding: 0 12px; border-radius: 6px; white-space: nowrap;
  color: var(--text-primary); text-decoration: none; font-size: var(--fs-body);
}
.app-tab::after {
  content: ""; position: absolute; left: 12px; right: 12px; bottom: -6px; height: 3px; border-radius: 3px 3px 0 0;
  background: var(--nav-bg); transform: scaleX(0); transition: transform .15s;
}
.app-tab:hover { color: var(--text-primary); background: rgba(0, 36, 103, .08); }
.app-tab[aria-current="page"] { color: var(--nav-bg); font-weight: 600; }
.app-tab[aria-current="page"]::after { transform: scaleX(1); }
.app-tab[aria-current="page"]:hover { background: none; }
.app-tab:focus-visible { outline-offset: 2px; }
.page-actions { grid-column: 3; justify-self: end; display: flex; align-items: center; gap: 8px; padding: 6px 0; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 32px; padding: 0 16px; border-radius: 999px;
  border: 1px solid var(--border-input); background: var(--surface); color: var(--primary); font-size: var(--fs-body); font-weight: 600;
  cursor: pointer; white-space: nowrap; text-decoration: none; line-height: 1;
}
.btn:hover { background: var(--hover); color: var(--primary-dark); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #FFFFFF; }
.btn.primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); color: #FFFFFF; }
.btn.ghost { color: var(--primary); }
.btn.small { height: 28px; padding: 0 12px; font-size: var(--fs-label); }
.btn.small .ico { width: 14px; height: 14px; }
.btn.small.icon-only { width: 28px; padding: 0; }
.btn.danger { color: var(--error); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }
.icon-btn {
  width: 32px; height: 32px; display: inline-grid; place-items: center; border-radius: var(--radius-sm);
  border: 1px solid transparent; background: transparent; cursor: pointer; color: var(--text-secondary); flex: none;
}
.icon-btn:hover { background: var(--hover); color: var(--text-primary); }
.icon-btn .ico { width: 18px; height: 18px; }
.row-actions { display: flex; gap: 2px; justify-content: flex-end; }
.row-actions .icon-btn { width: 28px; height: 28px; }
.row-actions .icon-btn .ico { width: 16px; height: 16px; }
.row-actions .icon-btn.danger:hover { color: var(--error); background: var(--error-bg); }
.link-btn { border: 0; background: none; padding: 0; color: var(--primary); font-size: var(--fs-label); font-weight: 600; cursor: pointer; text-align: left; }
.link-btn:hover { color: var(--primary-dark); text-decoration: underline; }

/* ---------- Content ---------- */
.content { flex: 1; padding: 16px 24px 24px; display: flex; flex-direction: column; gap: var(--gap); max-width: 1760px; width: 100%; margin: 0 auto; }
.workspace { display: grid; grid-template-columns: minmax(0, 1fr) var(--panel-w); gap: var(--gap); align-items: start; }
.workspace.no-panel { grid-template-columns: minmax(0, 1fr); }
.workspace.no-panel .right-panel { display: none; }
.main-area { min-width: 0; display: flex; flex-direction: column; gap: var(--gap); container: main / inline-size; }
.right-panel {
  position: sticky; top: calc(var(--sticky-top, 100px) + 16px); max-height: calc(100vh - var(--sticky-top, 100px) - 32px);
  overflow: auto; border-radius: var(--radius);
}
.view { min-width: 0; display: flex; flex-direction: column; gap: var(--gap); }
.view.card { gap: 0; }
.content.loading .view { opacity: .6; transition: opacity .15s; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px 20px; min-width: 0; container-type: inline-size; }
.card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.card-head p { font-size: var(--fs-label); color: var(--text-secondary); margin-top: 2px; }
/* the title block takes the free width; buttons / chips stay to its right while they fit */
.card-head > div:first-child { flex: 1 1 160px; min-width: 0; }
.card-head > :not(:first-child) { flex: 0 1 auto; min-width: 0; }
.grid-2-1 { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); gap: var(--gap); align-items: start; }
.grid-2 { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: var(--gap); align-items: start; }

/* ---------- Status bar ---------- */
.statusbar {
  position: sticky; bottom: 0; z-index: 30; display: flex; flex-wrap: wrap; align-items: center; gap: 4px 22px;
  min-height: 32px; padding: 6px 24px; background: var(--surface); border-top: 1px solid var(--border); font-size: var(--fs-helper); color: var(--text-secondary);
}
.sb-item { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.sb-copy { margin-left: auto; white-space: nowrap; }

/* ---------- Messages ---------- */
.messages:empty { display: none; }
/* messages float above the page (bottom right, over the status bar), so they stay visible after the page scrolls */
.messages {
  position: fixed; right: 24px; bottom: 48px; z-index: 90; width: min(440px, calc(100vw - 32px));
  display: flex; flex-direction: column-reverse; gap: 8px; pointer-events: none;
}
.messages .msg { pointer-events: auto; box-shadow: var(--shadow-pop); }
.msg {
  display: flex; align-items: flex-start; gap: 10px; padding: 10px 14px; border-radius: var(--radius-sm); border: 1px solid var(--border);
  border-left-width: 4px; background: var(--surface); box-shadow: var(--shadow);
}
.msg > span { flex: 1; }
.msg .msg-x { border: 0; background: none; cursor: pointer; color: inherit; opacity: .6; padding: 0 2px; font-size: 18px; line-height: 1; }
.msg.ok { border-left-color: var(--success); }
.msg.warn { border-left-color: var(--warning); background: var(--warning-bg); }
.msg.error { border-left-color: var(--error); background: var(--error-bg); color: #7A0410; }

/* ---------- Status ---------- */
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--text-weak); flex: none; }
.dot.critical { background: var(--error); }
.dot.warning, .dot.low { background: var(--warning); }
.dot.normal { background: var(--success); }
.dot.info { background: var(--primary); }
.dot.nodata { background: var(--nodata); }
.badge {
  display: inline-flex; align-items: center; gap: 6px; padding: 1px 9px; border-radius: 999px; font-size: var(--fs-helper); font-weight: 600;
  line-height: 18px; white-space: nowrap; background: var(--hover); color: var(--text-secondary);
}
.badge.normal { background: var(--success-bg); color: var(--success-text); }
.badge.warning, .badge.low { background: var(--warning-bg); color: var(--warning-text); }
.badge.critical { background: var(--error-bg); color: var(--error); }
.badge.info { background: var(--primary-bg); color: var(--primary-dark); }
.badge.estimated { background: #F3F3F3; color: var(--text-secondary); border: 1px dashed var(--border-input); }
.badge.inactive { background: var(--hover); color: var(--text-secondary); }

/* ---------- KPIs ---------- */
.kpi-grid { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: var(--gap); }
.kpi {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: 4px; min-width: 0; text-decoration: none; color: inherit;
}
a.kpi:hover { color: inherit; border-color: var(--primary); }
.kpi-label { font-size: var(--fs-label); color: var(--text-secondary); display: flex; justify-content: space-between; gap: 4px 8px; align-items: center; min-height: 20px; }
.kpi-value { font-size: 28px; font-weight: 600; line-height: 1.15; letter-spacing: -.01em; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kpi-value small { font-size: var(--fs-body); font-weight: 400; color: var(--text-secondary); margin-left: 4px; }
.kpi-foot { font-size: var(--fs-helper); color: var(--text-secondary); }
.kpi-total { border-color: var(--primary); box-shadow: inset 0 3px 0 var(--primary), var(--shadow); }
.kpi.is-critical .kpi-value { color: var(--error); }
.kpi.is-warning .kpi-value { color: var(--warning-text); }

/* ---------- Location-wise stock bars ---------- */
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: var(--fs-helper); color: var(--text-secondary); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.loc-bars { display: flex; flex-direction: column; gap: 2px; }
.loc-bar {
  display: grid; grid-template-columns: minmax(90px, 140px) minmax(0, 1fr) auto; align-items: center; gap: 12px;
  border: 0; background: none; padding: 6px 8px; margin: 0 -8px; border-radius: var(--radius-sm); cursor: pointer; text-align: left; position: relative;
}
.loc-bar:hover { background: var(--hover); }
.loc-bar.selected { background: var(--primary-bg); }
.loc-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.loc-track { display: flex; gap: 2px; height: 12px; }
.loc-track i { display: block; height: 100%; min-width: 4px; }
.loc-track i:first-child { border-radius: 3px 0 0 3px; }
.loc-track i:last-child { border-radius: 0 3px 3px 0; }
.loc-track i:only-child { border-radius: 3px; }
.loc-track i.normal, .status-bar i.normal, .level-track i.normal { background: var(--success); }
.loc-track i.low, .status-bar i.low, .level-track i.low { background: var(--warning); }
.loc-track i.critical, .status-bar i.critical, .level-track i.critical { background: var(--error); }
.loc-meta { font-size: var(--fs-helper); color: var(--text-secondary); font-variant-numeric: tabular-nums; white-space: nowrap; min-width: 92px; text-align: right; }
.loc-meta b { color: var(--text-primary); }
.tooltip {
  position: fixed; pointer-events: none; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm);
  box-shadow: var(--shadow-pop); padding: 8px 10px; font-size: var(--fs-helper); min-width: 150px; z-index: 60;
}
.tooltip .t-head { font-weight: 600; margin-bottom: 4px; font-size: var(--fs-label); }
.tooltip .t-row { display: flex; align-items: center; gap: 8px; }
.tooltip .t-row b { font-variant-numeric: tabular-nums; min-width: 28px; text-align: right; }
.tooltip .t-row span { color: var(--text-secondary); }

/* stock overview: one stacked bar of all records */
.status-bar { display: flex; gap: 2px; height: 16px; margin: 4px 0 12px; }
.status-bar i { display: block; height: 100%; min-width: 4px; }
.status-bar i:first-child { border-radius: 3px 0 0 3px; }
.status-bar i:last-child { border-radius: 0 3px 3px 0; }
.status-legend { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin-bottom: 14px; }
.status-legend button { border: 1px solid var(--border); background: var(--surface); border-radius: var(--radius-sm); padding: 8px 10px; text-align: left; cursor: pointer; }
.status-legend button:hover { background: var(--hover); }
.status-legend span { display: flex; align-items: center; gap: 6px; font-size: var(--fs-helper); color: var(--text-secondary); }
.status-legend b { display: block; font-size: 20px; font-weight: 600; line-height: 1.2; font-variant-numeric: tabular-nums; }

/* ---------- Stat strip ---------- */
.stat-strip { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); border: 1px solid var(--border); border-radius: var(--radius-sm); margin-bottom: 14px; }
.stat-strip:empty { display: none; }
.stat { padding: 8px 12px; border-right: 1px solid var(--border); min-width: 0; }
.stat:last-child { border-right: 0; }
.stat-caption { grid-column: 1 / -1; padding: 6px 12px; font-size: var(--fs-helper); color: var(--text-secondary); background: #FAFAF9; border-bottom: 1px solid var(--border); border-radius: var(--radius-sm) var(--radius-sm) 0 0; }
.stat span { font-size: var(--fs-helper); color: var(--text-secondary); }
.stat b { display: block; font-size: var(--fs-section); font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; border: 1px solid var(--border); border-radius: var(--radius-sm); }
.table { width: 100%; border-collapse: collapse; font-size: var(--fs-table); }
.table th {
  text-align: left; font-size: var(--fs-helper); font-weight: 600; color: var(--text-secondary);
  padding: 8px 10px; background: #FAFAF9; border-bottom: 1px solid var(--border); white-space: nowrap; position: sticky; top: 0; z-index: 1;
}
.table th.num { text-align: right; }
.table td { padding: 8px 10px; border-bottom: 1px solid #E5E5E5; vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table.compact td, .table.compact th { padding: 6px 10px; }
.table tbody tr.clickable { cursor: pointer; }
.table tbody tr.clickable:hover td { background: var(--hover); }
.table tbody tr.selected td { background: var(--primary-bg); }
/* the row a stock entry was just saved to */
.table tbody tr.just-saved td { animation: just-saved 5s ease-out; }
.table tbody tr.just-saved td:first-child { box-shadow: inset 4px 0 0 var(--success); }
@keyframes just-saved { 0%, 40% { background: var(--success-bg); } 100% { background: transparent; } }
.table tbody tr.row-critical td { background: var(--error-bg); }
.table tbody tr.row-warning td { background: #FFF8F0; }
.table tbody tr.row-critical td:first-child { box-shadow: inset 3px 0 0 var(--error); }
.table tbody tr.row-warning td:first-child { box-shadow: inset 3px 0 0 var(--warning); }
.table tbody tr.row-critical:hover td { background: #FCE3DF; }
.table tbody tr.row-warning:hover td { background: var(--warning-bg); }
.table tbody tr.row-critical.selected td, .table tbody tr.row-warning.selected td { background: var(--primary-bg); }
.table tbody tr.row-inactive td { color: var(--text-weak); }
.table .id { font-weight: 600; white-space: nowrap; }
.table td:first-child .id { white-space: normal; }  /* long names may wrap; codes and IDs never do */
.table .sub { display: block; font-size: var(--fs-helper); color: var(--text-secondary); font-weight: 400; }
.table td:first-child .sub { min-width: 180px; }
.table .wrap { white-space: normal; min-width: 160px; }
.table .nowrap { white-space: nowrap; }
.table .empty-row td { text-align: center; color: var(--text-secondary); padding: 22px; }
.table .pos { color: var(--success-text); }
.table .neg { color: var(--error); }
.table .strong { font-weight: 600; }
small.unit { font-size: var(--fs-helper); font-weight: 400; color: var(--text-secondary); }
.table-more { padding: 8px 12px; font-size: var(--fs-helper); color: var(--text-secondary); border-top: 1px solid #E5E5E5; }

/* ---------- Tabs, chips, filters ---------- */
.tabs { display: flex; flex-wrap: wrap; gap: 2px; border-bottom: 1px solid var(--border); margin-bottom: 14px; }
.tabs button {
  border: 0; background: none; padding: 8px 12px; color: var(--text-primary); cursor: pointer;
  border-bottom: 3px solid transparent; margin-bottom: -1px; white-space: nowrap;
}
.tabs button:hover { border-bottom-color: var(--border); }
.tabs button[aria-selected="true"] { color: var(--primary); font-weight: 600; border-bottom-color: var(--primary); }
.tabs .count { font-size: var(--fs-helper); margin-left: 4px; padding: 0 6px; border-radius: 999px; background: var(--error-bg); color: var(--error); }
.filters { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; }
.chips { display: inline-flex; gap: 4px; flex-wrap: wrap; }
.chips button {
  border: 1px solid var(--border-input); background: var(--surface); border-radius: 999px; padding: 3px 12px; font-size: var(--fs-label);
  cursor: pointer; color: var(--text-primary); white-space: nowrap;
}
.chips button:hover { background: var(--hover); }
.chips button[aria-checked="true"] { background: var(--primary); border-color: var(--primary); color: #FFFFFF; font-weight: 600; }
select, .field input, .field textarea, .date-field input {
  height: 32px; padding: 0 10px; border: 1px solid var(--border-input); border-radius: var(--radius-sm); background: var(--surface);
  max-width: 100%; min-width: 0; font-size: var(--fs-body);
}
select:focus, .field input:focus, .field textarea:focus, .date-field input:focus, .search-field input:focus {
  outline: none; border-color: var(--primary); box-shadow: 0 0 0 1px var(--primary);
}
.filters select { max-width: 220px; }
.search-field { position: relative; display: flex; align-items: center; flex: 0 1 280px; min-width: 180px; }
.search-field.grow { flex: 1 1 320px; }
.search-field .ico { position: absolute; left: 10px; color: var(--text-secondary); pointer-events: none; width: 14px; height: 14px; }
.search-field input { width: 100%; height: 32px; padding: 0 10px 0 30px; border: 1px solid var(--border-input); border-radius: var(--radius-sm); background: var(--surface); }
.date-field { display: inline-flex; align-items: center; flex-wrap: wrap; gap: 6px; font-size: var(--fs-label); color: var(--text-secondary); }
.segmented { display: inline-flex; background: var(--surface); border: 1px solid var(--border-input); border-radius: 999px; padding: 2px; gap: 2px; max-width: 100%; }
.segmented button { border: 0; background: transparent; height: 26px; padding: 0 14px; border-radius: 999px; cursor: pointer; color: var(--text-primary); white-space: nowrap; font-size: var(--fs-label); }
.segmented button:hover { background: var(--hover); }
.segmented button[aria-checked="true"] { background: var(--primary); color: #FFFFFF; font-weight: 600; }

/* ---------- Forms ---------- */
.field { display: flex; flex-direction: column; gap: 4px; border: 0; padding: 0; margin: 0; min-width: 0; }
.field > span { font-size: var(--fs-label); color: var(--text-secondary); padding: 0; }
.field input, .field select { width: 100%; }
.field textarea { width: 100%; height: auto; padding: 6px 10px; resize: vertical; line-height: 1.4; }
.field .bad, .bad { border-color: var(--error) !important; box-shadow: 0 0 0 1px var(--error) !important; }
.field-error { color: var(--error); font-size: var(--fs-label); font-weight: 600; }
.field-error:empty { display: none; }
/* inline message under a field (added by formValidator / fieldMsg in app.js) */
.field-msg { display: block; color: var(--error); font-size: var(--fs-helper); line-height: 1.35; }
.field-msg:empty { display: none; }
.date-field .field-msg { flex-basis: 100%; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 16px; }
.span-2 { grid-column: 1 / -1; }
.check { display: inline-flex; align-items: flex-start; gap: 8px; cursor: pointer; }
.check input { accent-color: var(--primary); width: 16px; height: 16px; margin-top: 2px; flex: none; }
.avail-box {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap; min-height: 32px; padding: 6px 12px; border-radius: var(--radius-sm);
  background: var(--bg-page); font-variant-numeric: tabular-nums;
}
.avail-box b { font-size: var(--fs-section); font-weight: 600; }
.avail-box .spinner { margin-right: 4px; }
.avail-box.warn { background: var(--warning-bg); }
.avail-box.bad { background: var(--error-bg); }

/* ---------- Transfer workflow ---------- */
.transfer-flow { display: grid; grid-template-columns: minmax(0, 1fr) 280px; gap: 20px; align-items: start; }
.tf-steps { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 16px; align-items: end; }
.step > span b {
  display: inline-grid; place-items: center; width: 18px; height: 18px; margin-right: 6px; border-radius: 50%;
  background: var(--primary); color: #FFFFFF; font-size: 11px; font-weight: 600;
}
.tf-summary { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 12px 14px; background: #FAFAF9; }
.tf-summary .empty { padding: 16px 4px; }
.tf-route { display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); align-items: center; gap: 8px; margin-bottom: 10px; }
.tf-route .ico { color: var(--text-secondary); }
.tf-node { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 6px 10px; min-width: 0; }
.tf-node span { display: block; font-size: var(--fs-helper); color: var(--text-secondary); }
.tf-node b { display: block; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tf-row { display: flex; justify-content: space-between; gap: 10px; padding: 5px 0; border-top: 1px solid #E5E5E5; font-variant-numeric: tabular-nums; }
.tf-row:first-of-type { border-top: 0; }
.tf-row span { color: var(--text-secondary); }
.tf-row b { text-align: right; font-weight: 600; }
.tf-foot { display: flex; align-items: center; justify-content: space-between; gap: 12px 20px; flex-wrap: wrap; margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--border); }
.transfer-card .field-error { margin-top: 12px; }
.status-select { height: 28px; font-size: var(--fs-label); padding: 0 8px; width: 112px; }

/* ---------- Alerts ---------- */
.alert-counts { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; margin-bottom: 14px; }
.alert-count { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 8px 12px; text-align: left; background: var(--surface); cursor: pointer; }
.alert-count:hover { background: var(--hover); }
.alert-count[aria-pressed="true"] { border-color: var(--primary); box-shadow: 0 0 0 1px var(--primary); }
.alert-count b { display: block; font-size: 20px; font-weight: 600; line-height: 1.2; font-variant-numeric: tabular-nums; }
.alert-count span { font-size: var(--fs-helper); color: var(--text-secondary); display: inline-flex; align-items: center; gap: 6px; }
.alert-count.critical b { color: var(--error); }
.alert-count.warning b { color: var(--warning-text); }
.alert-count.info b { color: var(--primary-dark); }
.alert-list { display: flex; flex-direction: column; gap: 10px; }
/* home: critical alerts side by side while the card is wide enough */
.alert-list.cols-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); align-items: start; }
.alert-list.cols-2 > .empty { grid-column: 1 / -1; }
/* home: the two cards of a row share one height */
.grid-2-1.dash-row { align-items: stretch; }
.grid-2-1.dash-row > .card { display: flex; flex-direction: column; }
.grid-2-1.dash-row #weekStrip { margin-bottom: 0; }
/* the status counts take the spare height of the stretched card instead of leaving a gap */
.grid-2-1.dash-row .status-legend { flex: 1; align-items: stretch; }
.grid-2-1.dash-row .status-legend button { display: flex; flex-direction: column; justify-content: center; gap: 6px; padding: 12px 16px; }
.grid-2-1.dash-row .status-legend b { font-size: 32px; }
.alert {
  border: 1px solid var(--border); border-left-width: 4px; border-radius: var(--radius-sm); padding: 12px 16px;
  display: flex; flex-direction: column; gap: 8px; background: var(--surface); min-width: 0;
}
.alert.critical { border-left-color: var(--error); }
.alert.warning { border-left-color: var(--warning); }
.alert.info { border-left-color: var(--primary); }
/* the whole card is clickable and shows as selected, like a table row */
.alert.clickable { cursor: pointer; transition: background .12s, box-shadow .12s; }
.alert.clickable:hover { background: #FAFBFD; box-shadow: var(--shadow-pop); }
.alert.selected, .alert.selected:hover { background: var(--primary-bg); border-top-color: var(--primary); border-right-color: var(--primary); border-bottom-color: var(--primary); }
.alert.selected .alert-metrics div { background: var(--surface); }
.alert-head { display: flex; align-items: center; gap: 8px 10px; flex-wrap: wrap; }
.alert-title { font-weight: 600; flex: 1 1 260px; min-width: 0; }
.alert-type { display: inline-flex; align-items: center; gap: 4px; font-size: var(--fs-helper); color: var(--text-secondary); }
.alert-metrics { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
.alert-metrics div { background: var(--bg-page); border-radius: var(--radius-sm); padding: 6px 10px; min-width: 0; }
.alert-metrics span { font-size: var(--fs-helper); color: var(--text-secondary); display: block; }
.alert-metrics b { font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.alert-metrics .short b { color: var(--error); }
.alert-foot { display: flex; align-items: center; gap: 8px 14px; flex-wrap: wrap; font-size: var(--fs-helper); color: var(--text-secondary); }
.alert-foot .btn { margin-left: auto; }
.alert-list.compact .alert { padding: 10px 12px; gap: 6px; }
.alert-list.compact .alert-metrics { grid-template-columns: repeat(3, minmax(0, 1fr)); }

/* recommendation */
.rec { border: 1px solid #C9DCF5; background: var(--primary-bg); border-radius: var(--radius-sm); padding: 10px 12px; }
.rec-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-weight: 600; color: var(--primary-dark); margin-bottom: 6px; }
.rec-head .muted { font-weight: 400; }
.rec-plan { display: flex; flex-direction: column; gap: 6px; }
.rec-line {
  display: grid; grid-template-columns: minmax(0, 1fr) auto auto; align-items: center; gap: 10px;
  background: var(--surface); border: 1px solid #C9DCF5; border-radius: var(--radius-sm); padding: 6px 8px 6px 10px;
}
.rec-line > div { min-width: 0; }
.rec-line b { font-weight: 600; font-variant-numeric: tabular-nums; }
.rec-line .sub { display: block; font-size: var(--fs-helper); color: var(--text-secondary); }
.rec-note { font-size: var(--fs-helper); color: var(--text-secondary); margin-top: 6px; }
.rec.none { background: var(--bg-page); border-color: var(--border); }
.rec.none .rec-head { color: var(--text-secondary); }

/* ---------- Availability ---------- */
.avail-groups { display: flex; flex-direction: column; gap: var(--gap); }
.avail-group .card-head { margin-bottom: 12px; align-items: center; }
.avail-group h3 { font-size: var(--fs-section); }
.avail-group .card-head p { margin-top: 0; }
.avail-total { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; font-size: var(--fs-label); color: var(--text-secondary); font-variant-numeric: tabular-nums; }
.avail-total b { color: var(--text-primary); font-weight: 600; }
.level { display: flex; align-items: center; gap: 8px; min-width: 120px; }
.level-track { position: relative; flex: 1; height: 6px; border-radius: 3px; background: #E5E5E5; min-width: 60px; }
.level-track i { position: absolute; inset: 0 auto 0 0; border-radius: 3px; }
.level-track b { position: absolute; top: -3px; width: 2px; height: 12px; background: var(--text-primary); opacity: .5; border-radius: 1px; }

/* ---------- Reports ---------- */
.report-bar { display: flex; flex-wrap: wrap; gap: 12px 16px; align-items: flex-end; margin-bottom: 14px; }
.report-bar > .field { flex: 0 1 auto; }
.report-bar select { min-width: 220px; }

/* ---------- AI assistant ---------- */
.ai-status { cursor: default; }
.ai-form { display: flex; flex-direction: column; gap: 10px; margin-bottom: 16px; }
.ai-focus { color: var(--text-secondary); }
.ai-focus strong { color: var(--text-primary); font-weight: 600; }
.ai-prompts { display: flex; flex-wrap: wrap; gap: 6px; }
.ai-prompts button {
  border: 1px solid var(--border-input); background: var(--surface); border-radius: 999px; padding: 3px 12px; font-size: var(--fs-label);
  cursor: pointer; color: var(--primary);
}
.ai-prompts button:hover { background: var(--hover); color: var(--primary-dark); }
.ai-prompts button:disabled { opacity: .55; cursor: progress; }
.ai-row { display: flex; gap: 10px; }
.grow { flex: 1; min-width: 0; }
.ai-output { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 4px 20px 16px; background: #FAFAF9; min-width: 0; overflow-wrap: anywhere; }
.ai-output > .empty, .ai-output > .msg { margin-top: 14px; }
.ai-output h2 { font-size: var(--fs-section); margin: 16px 0 6px; }
.ai-output h3 { font-size: var(--fs-body); margin: 14px 0 4px; }
.ai-output ul, .ai-output ol { padding-left: 22px; margin: 6px 0; }
.ai-output li { margin: 3px 0; }
.ai-output p { margin: 6px 0; }
.ai-output code { background: var(--bg-page); padding: 1px 5px; border-radius: 4px; font-size: var(--fs-table); }
.ai-output table { border-collapse: collapse; margin: 8px 0; font-size: var(--fs-table); display: block; overflow-x: auto; }
.ai-output th, .ai-output td { border: 1px solid var(--border); padding: 5px 9px; text-align: left; }
.ai-meta { display: flex; gap: 6px 14px; flex-wrap: wrap; font-size: var(--fs-helper); color: var(--text-secondary); padding-top: 12px; margin-top: 10px; border-top: 1px solid #E5E5E5; }
.spinner { width: 14px; height: 14px; border: 2px solid var(--border); border-top-color: var(--primary); border-radius: 50%; animation: spin .8s linear infinite; display: inline-block; vertical-align: -2px; margin-right: 6px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Details panel ---------- */
.details { min-height: 200px; }
.details .empty, .empty { color: var(--text-secondary); padding: 28px 8px; text-align: center; }
.d-head { display: flex; align-items: flex-start; gap: 12px; margin-bottom: 14px; }
.d-icon { width: 36px; height: 36px; border-radius: var(--radius-sm); background: var(--primary); color: #FFFFFF; display: grid; place-items: center; flex: none; }
.d-icon .ico { width: 20px; height: 20px; }
.d-title { font-size: 18px; font-weight: 600; word-break: break-word; line-height: 1.25; }
.d-path { font-size: var(--fs-helper); color: var(--text-secondary); }
.d-close { margin-left: auto; margin-top: -4px; margin-right: -6px; }
.metric-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin-bottom: 14px; }
.metric { background: var(--bg-page); border-radius: var(--radius-sm); padding: 8px 12px; min-width: 0; }
.metric span { font-size: var(--fs-helper); color: var(--text-secondary); display: block; }
.metric b { font-size: var(--fs-body); font-weight: 600; font-variant-numeric: tabular-nums; word-break: break-word; }
.d-section { margin-top: 16px; }
.d-section h3 { font-size: var(--fs-label); font-weight: 600; color: var(--text-secondary); margin-bottom: 6px; }
.d-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 14px; }
.d-list { display: flex; flex-direction: column; }
.d-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 2px 10px; padding: 7px 4px; border-top: 1px solid #E5E5E5; align-items: center; }
.d-row:first-child { border-top: 0; }
.d-row > div { min-width: 0; }
.d-row b { font-weight: 600; }
.d-row .sub { display: block; font-size: var(--fs-helper); color: var(--text-secondary); }
.d-row .num b { display: block; }
.d-row.clickable { cursor: pointer; border-radius: var(--radius-sm); }
.d-row.clickable:hover { background: var(--hover); }
.d-row.selected { background: var(--primary-bg); }
.d-row .badge { margin-top: 2px; }
.d-text { white-space: pre-line; }

/* ---------- Modal ---------- */
.modal { border: 0; padding: 0; border-radius: var(--radius); width: min(640px, calc(100vw - 32px)); max-height: calc(100vh - 48px); box-shadow: 0 8px 32px rgba(0, 0, 0, .25); color: var(--text-primary); }
.modal.small-modal { width: min(440px, calc(100vw - 32px)); }
.modal::backdrop { background: rgba(8, 7, 7, .45); }
.modal-shell { display: flex; flex-direction: column; max-height: calc(100vh - 48px); }
.modal-head { display: flex; justify-content: space-between; gap: 12px; padding: 16px 20px 12px; border-bottom: 1px solid var(--border); }
.modal-head h2 { font-size: var(--fs-page); }
.modal-head p { font-size: var(--fs-label); color: var(--text-secondary); margin-top: 2px; }
.modal-body { padding: 16px 20px; overflow: auto; display: flex; flex-direction: column; gap: 12px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 20px; border-top: 1px solid var(--border); background: var(--bg-page); }

/* ---------- Responsive ---------- */
@container main (max-width: 1100px) {
  .kpi-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@container main (max-width: 880px) {
  .grid-2-1, .grid-2, .alert-list.cols-2 { grid-template-columns: minmax(0, 1fr); }
}
@container main (max-width: 800px) {
  .transfer-flow { grid-template-columns: minmax(0, 1fr); }
}
@container main (max-width: 760px) {
  .alert-metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .alert-list.compact .alert-metrics { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .tf-steps { grid-template-columns: minmax(0, 1fr); }
}
@container (max-width: 900px) {
  /* a table becomes stacked cards when the card that holds it is narrow */
  .table.stack thead { display: none; }
  .table.stack, .table.stack tbody { display: block; }
  .table.stack tr { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 8px 12px; padding: 12px 14px; border-bottom: 1px solid var(--border); }
  .table.stack tr:last-child { border-bottom: 0; }
  .table.stack td { display: block; padding: 0; border: 0; text-align: left; background: none !important; box-shadow: none !important; white-space: normal; min-width: 0; }
  .table.stack td::before { content: attr(data-label); display: block; font-size: var(--fs-helper); color: var(--text-secondary); }
  .table.stack td:first-child, .table.stack td.full { grid-column: 1 / -1; }
  .table.stack td.actions::before { display: none; }
  .table.stack td.actions .row-actions { justify-content: flex-start; }
  .table.stack tr.row-critical { background: var(--error-bg); box-shadow: inset 3px 0 0 var(--error); }
  .table.stack tr.row-warning { background: #FFF8F0; box-shadow: inset 3px 0 0 var(--warning); }
  .table.stack tr.clickable:hover { background: var(--hover); }
  .table.stack tr.just-saved { animation: just-saved 5s ease-out; box-shadow: inset 4px 0 0 var(--success); }
  .table.stack .empty-row { display: block; }
  .table.stack .empty-row td { grid-column: 1 / -1; text-align: center; }
  .table.stack .empty-row td::before { display: none; }
  .table.stack td:empty { display: none; }
  .table.stack .id, .table.stack .sub, .table.stack .nowrap { white-space: normal; }
  .table.stack td:first-child .sub { min-width: 0; }
}
@container (min-width: 561px) and (max-width: 900px) {
  /* tablets: four fields per row keeps the stacked cards short */
  .table.stack tr { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}
@container main (max-width: 560px) {
  .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .alert-counts { gap: 6px; }
  .alert-count { padding: 8px 10px; }
  .loc-bar { grid-template-columns: minmax(0, 1fr) auto; }
  .loc-track { grid-column: 1 / -1; grid-row: 2; }
}
@container main (max-width: 300px) {
  .kpi-grid { grid-template-columns: minmax(0, 1fr); }
}
@container main (max-width: 560px) {
  .kpi-label { flex-wrap: wrap; } /* two KPI cards per row: the badge may go under the label */
}
@container main (max-width: 380px) {
  .kpi { padding: 12px; }
  .kpi-value { font-size: 24px; }
  .alert-metrics, .alert-list.compact .alert-metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 1439px) {
  /* the detail panel moves under the main content, so tables keep their full width */
  .workspace { grid-template-columns: minmax(0, 1fr); }
  .right-panel { position: static; max-height: none; overflow: visible; }
}
@media (max-width: 1100px) {
  .page-actions .btn { width: 32px; padding: 0; }
  .page-actions .btn span { display: none; }
  /* global search collapses to an icon; it opens as a bar over the header */
  .gsearch .gs-toggle { display: inline-grid; }
  .gs-box { display: none; }
  .gsearch.open .gs-box {
    display: flex; position: fixed; left: 12px; right: 12px; top: 8px; z-index: 85;
    background: var(--surface); padding: 6px; border-radius: var(--radius); box-shadow: var(--shadow-pop);
  }
  .gsearch.open .gs-field { flex: 1; width: auto; }
  .gsearch.open .gs-close { display: inline-grid; }
  .gsearch.open .gs-toggle { visibility: hidden; }
  .gs-pop { left: 0; right: 0; width: auto; }
}
@media (max-width: 900px) {
  /* rail becomes a drawer opened from the menu button */
  .shell { grid-template-columns: minmax(0, 1fr); }
  .icon-btn.menu-btn { display: inline-grid; margin-left: -6px; }
  .rail {
    position: fixed; top: 0; bottom: 0; left: 0; height: auto; width: 240px; z-index: 70; align-items: stretch; padding: 12px 10px; gap: 2px;
    transform: translateX(-100%); transition: transform .2s ease;
  }
  .rail.open { transform: none; box-shadow: 0 0 40px rgba(0, 0, 0, .35); }
  .rail-item { flex-direction: row; gap: 12px; padding: 4px 8px; font-size: var(--fs-body); text-align: left; border-radius: var(--radius-sm); }
  .rail-icon { width: 36px; height: 36px; }
  .rail-icon .ico { width: 22px; height: 22px; }
  .rail-item:hover { background: rgba(255, 255, 255, .08); }
  .rail-item:hover .rail-icon { background: none; }
  .scrim { display: block; position: fixed; inset: 0; background: rgba(8, 7, 7, .45); z-index: 60; }
  .topbar { padding: 0 16px; gap: 12px; }
  .app-nav { padding: 0 16px; gap: 0 16px; }
  .content { padding: 16px; }
}
@media (max-width: 767px) {
  /* phones: the logo / title row scrolls away; the page tabs stay pinned */
  .site-head { display: contents; }
  .topbar { background: var(--surface); height: 52px; padding: 0 12px; gap: 8px; grid-template-columns: auto minmax(0, 1fr) auto; }
  .app-title { font-size: 15px; line-height: 1.15; white-space: normal; text-overflow: clip;
    display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
  .brand-logo img { height: 22px; }
  .app-nav {
    position: sticky; top: 0; z-index: 40; background: var(--header-bg); box-shadow: 0 2px 3px rgba(0, 0, 0, .07);
    gap: 0 8px; border-top: 1px solid rgba(0, 0, 0, .06); grid-template-columns: minmax(0, 1fr) auto;
  }
  .app-tabs { grid-column: 1; }
  .page-actions { grid-column: 2; }
  .app-tab .t-full { display: none; }
  .app-tab .t-short { display: inline; }
  .app-tab { height: 30px; padding: 0 10px; }
  .card { padding: 14px 16px; }
  .form-grid { grid-template-columns: minmax(0, 1fr); }
  .filters select, .search-field { flex: 1 1 100%; max-width: none; min-width: 0; }
  .date-field { flex: 1 1 calc(50% - 4px); }
  .date-field input { flex: 1; }
  .report-bar > .field, .report-bar select { flex: 1 1 100%; min-width: 0; width: 100%; }
  .segmented { width: 100%; overflow-x: auto; }
  .segmented button { flex: 1; padding: 0 10px; }
  .stat { border-right: 0; border-bottom: 1px solid var(--border); }
  .modal-head, .modal-body, .modal-foot { padding-left: 16px; padding-right: 16px; }
  .alert-foot .btn { margin-left: 0; }
  .rec-line { grid-template-columns: minmax(0, 1fr) auto; }
  .rec-line .btn { grid-column: 1 / -1; }
  .statusbar { position: static; padding: 8px 16px; }
  .messages { right: 16px; bottom: 16px; }
  .sb-item { white-space: normal; }
  .sb-copy { margin-left: 0; width: 100%; white-space: normal; padding-top: 6px; border-top: 1px solid var(--border); }
  .tf-foot .btn { width: 100%; }
  .ai-row { flex-direction: column; }
  .ai-output { padding: 4px 14px 14px; }
}
@media (max-width: 560px) {
  .chip-more { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; scroll-behavior: auto !important; }
}
