:root {
  /* ---- Light theme (default) ---- */
  --bg: #f6f5f2;
  --bg-alt: #efeee9;
  --card-bg: #ffffff;
  --card-bg-2: #f4f3ef;
  --border: rgba(24, 20, 14, 0.09);
  --accent: #dd7a2c;
  --accent-ink: #ffffff;
  --accent-soft: rgba(221, 122, 44, 0.12);
  --good: #16a34a;
  --good-soft: rgba(22, 163, 74, 0.12);
  --danger: #dc3545;
  --danger-soft: rgba(220, 53, 69, 0.1);
  --danger-border: rgba(220, 53, 69, 0.3);
  --danger-text: #a3283a;
  --warn: #ca8a04;
  --warn-soft: rgba(202, 138, 4, 0.12);
  --text: #1c1a17;
  --text-dim: #736f66;
  --text-faint: #a19c92;
  --shadow: rgba(30, 25, 15, 0.08);
  --overlay-1: rgba(24, 20, 14, 0.04);
  --overlay-2: rgba(24, 20, 14, 0.07);
  --overlay-3: rgba(24, 20, 14, 0.11);
  --input-bg: #ffffff;
  --input-border: rgba(24, 20, 14, 0.13);
  --modal-backdrop: rgba(20, 16, 10, 0.35);
  --row-alt: rgba(24, 20, 14, 0.025);

  --radius: 22px;
  --radius-btn: 14px;
  --radius-pill: 999px;
  --ease: cubic-bezier(0.16, 1, 0.3, 1);
  --card-shadow: 0 1px 2px var(--shadow), 0 12px 28px -8px var(--shadow);

  /* ---- Liquid glass ---- */
  --glass-bg: rgba(255, 255, 255, 0.58);
  --glass-bg-2: rgba(255, 255, 255, 0.4);
  --glass-border: rgba(255, 255, 255, 0.65);
  --glass-sheen: rgba(255, 255, 255, 0.85);
  --glass-blur: blur(24px) saturate(180%);
}

:root[data-theme="dark"] {
  --bg: #0e0d11;
  --bg-alt: #131218;
  --card-bg: #18171d;
  --card-bg-2: #201f26;
  --border: rgba(255, 255, 255, 0.07);
  --accent: #f0923b;
  --accent-ink: #1a1206;
  --accent-soft: rgba(240, 146, 59, 0.14);
  --good: #34d399;
  --good-soft: rgba(52, 211, 153, 0.14);
  --danger: #f0596a;
  --danger-soft: rgba(240, 89, 106, 0.14);
  --danger-border: rgba(240, 89, 106, 0.35);
  --danger-text: #ffb4bd;
  --warn: #eab308;
  --warn-soft: rgba(234, 179, 8, 0.14);
  --text: #f3f2f4;
  --text-dim: #97949e;
  --text-faint: #605d68;
  --shadow: rgba(0, 0, 0, 0.45);
  --overlay-1: rgba(255, 255, 255, 0.045);
  --overlay-2: rgba(255, 255, 255, 0.08);
  --overlay-3: rgba(255, 255, 255, 0.12);
  --input-bg: #1d1c22;
  --input-border: rgba(255, 255, 255, 0.09);
  --modal-backdrop: rgba(4, 4, 6, 0.6);
  --row-alt: rgba(255, 255, 255, 0.03);
  --card-shadow: 0 1px 0 rgba(255, 255, 255, 0.02) inset, 0 10px 26px -8px var(--shadow);

  --glass-bg: rgba(30, 28, 36, 0.55);
  --glass-bg-2: rgba(30, 28, 36, 0.38);
  --glass-border: rgba(255, 255, 255, 0.1);
  --glass-sheen: rgba(255, 255, 255, 0.09);
  --glass-blur: blur(24px) saturate(160%);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100vh;
  /* A real system-font stack, not a Google Fonts promise we never actually
     load: -apple-system/Segoe UI/Roboto each render clean, modern text on
     their native OS with zero extra network requests or CDN dependency. */
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
  transition: background-color 0.2s ease, color 0.15s ease;
}

/* Soft blurred color blobs fixed behind everything -- glass cards need
   something with visual variation behind them for backdrop-filter to
   actually read as "glass" instead of a flat tinted rectangle. Fixed (not
   absolute) so they don't affect document height or scroll with content;
   pointer-events:none so they never intercept clicks; z-index:0 with the
   app's real content stacked above via .app-shell/.login-wrap z-index. */
.bg-blobs { position: fixed; inset: 0; z-index: 0; overflow: hidden; pointer-events: none; }
.bg-blobs::before, .bg-blobs::after {
  content: ""; position: absolute; border-radius: 50%; filter: blur(80px);
}
.bg-blobs::before {
  width: 46vw; height: 46vw; top: -14vw; right: -10vw;
  background: radial-gradient(circle, var(--accent) 0%, transparent 70%);
  opacity: 0.22;
}
.bg-blobs::after {
  width: 40vw; height: 40vw; bottom: -16vw; left: -12vw;
  background: radial-gradient(circle, var(--good) 0%, transparent 70%);
  opacity: 0.16;
}

a { color: inherit; }
::selection { background: var(--accent); color: var(--accent-ink); }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 6px;
}

/* Liquid glass: translucent background + backdrop blur/saturate over the
   fixed .bg-blobs layer, a bright inset border for the "wet edge" look, and
   a soft diagonal sheen for specular highlight. position:relative+overflow
   hidden so the ::before sheen clips to the card's rounded corners --
   deliberately safe to do now that live-search dropdowns are reparented to
   <body> (see liveSearch.js) instead of living inside .glass ancestors:
   backdrop-filter/transform on an ancestor makes it the containing block
   for position:fixed descendants, which would otherwise silently break
   dropdown positioning again. */
.glass {
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius);
  box-shadow: var(--card-shadow);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  position: relative;
  overflow: hidden;
  transition: background 0.2s var(--ease), border-color 0.2s var(--ease), box-shadow 0.2s var(--ease), transform 0.2s var(--ease);
}
.glass::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, var(--glass-sheen) 0%, transparent 45%);
  opacity: 0.5;
  pointer-events: none;
}

/* ---------- Icon system (inline SVG, see icons.js) ---------- */

[data-icon] svg,
.nav-icon svg,
.bn-icon svg,
.ls-icon svg,
.ls-clear svg,
.btn-icon svg,
.theme-toggle svg,
.hamburger svg,
.icon-badge svg,
.card-link svg,
.dd-chevron svg {
  display: block;
  width: 100%;
  height: 100%;
}

/* ---------- Theme toggle / icon buttons ---------- */

.theme-toggle, .hamburger, .card-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  padding: 9px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--border);
  background: var(--card-bg-2);
  color: var(--text-dim);
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.18s var(--ease), color 0.18s var(--ease), transform 0.18s var(--ease);
}
.theme-toggle:hover, .hamburger:hover, .card-link:hover { background: var(--overlay-2); color: var(--text); transform: translateY(-1px); }
.theme-toggle:active, .hamburger:active, .card-link:active { transform: scale(0.92); }

/* ---------- Login page ---------- */

.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  position: relative;
  z-index: 1;
}

.login-wrap .theme-toggle {
  position: absolute;
  top: 20px;
  right: 20px;
}

.login-card {
  width: 100%;
  max-width: 380px;
  padding: 40px 36px;
  text-align: center;
  border-radius: 28px;
  animation: rise-in 0.4s var(--ease) both;
}

@keyframes rise-in {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

.login-card h1 { font-size: 1.5rem; margin: 0 0 4px; }
.login-card p.sub { color: var(--text-dim); margin: 0 0 28px; font-size: 0.9rem; }

.field { text-align: left; margin-bottom: 16px; }
.field label { display: block; font-size: 0.8rem; color: var(--text-dim); margin-bottom: 6px; }

.field input {
  width: 100%;
  padding: 13px 16px;
  border-radius: var(--radius-btn);
  border: 1px solid var(--input-border);
  background: var(--input-bg);
  color: var(--text);
  font-size: 0.95rem;
  outline: none;
  transition: border-color 0.18s var(--ease), box-shadow 0.18s var(--ease);
}
.field input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: none;
  border-radius: var(--radius-btn);
  padding: 12px 22px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  background: var(--accent);
  color: var(--accent-ink);
  box-shadow: 0 4px 14px var(--accent-soft);
  transition: transform 0.18s var(--ease), box-shadow 0.18s var(--ease), opacity 0.15s;
  width: 100%;
  will-change: transform;
}
.btn:hover { transform: translateY(-1px); box-shadow: 0 8px 20px var(--accent-soft); }
.btn:active { transform: translateY(0) scale(0.97); }
.btn:disabled { opacity: 0.6; cursor: not-allowed; transform: none; }

.btn.secondary {
  background: var(--card-bg-2);
  color: var(--text);
  border: 1px solid var(--border);
  box-shadow: none;
  width: auto;
}
.btn.secondary:hover { background: var(--overlay-2); box-shadow: none; }

.error-msg {
  background: var(--danger-soft);
  border: 1px solid var(--danger-border);
  color: var(--danger-text);
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 0.85rem;
  margin-bottom: 16px;
  display: none;
}

/* ---------- App shell / top navigation ---------- */

.app-shell { min-height: 100vh; position: relative; z-index: 1; }

.topbar-header {
  position: sticky;
  top: 0;
  z-index: 70;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}

.topbar-row1 {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px;
  gap: 12px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 1.05rem;
}

.brand-badge {
  width: 32px;
  height: 32px;
  border-radius: 10px;
  background: var(--accent);
  color: var(--accent-ink);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 0.95rem;
  flex-shrink: 0;
}

.topbar-actions, .topbar-right { display: flex; align-items: center; gap: 10px; }

.topbar-row2 {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  row-gap: 8px;
  gap: 18px;
  padding: 0 24px 14px;
  /* No overflow-x:auto here: setting it forces overflow-y to clip too (a
     CSS spec quirk), which would cut off .nav-dd-menu dropdowns hanging
     below this row. flex-wrap handles narrow desktop widths instead --
     wrapping never clips a descendant the way overflow does. */
}

.topbar-row2 h2 { margin: 0; font-size: 1.15rem; font-weight: 700; white-space: nowrap; flex-shrink: 0; }

.top-nav {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

.nav-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 16px;
  border-radius: var(--radius-pill);
  font-size: 0.88rem;
  font-weight: 600;
  font-family: inherit;
  color: var(--text-dim);
  cursor: pointer;
  white-space: nowrap;
  border: none;
  background: none;
  margin: 0;
  appearance: none;
  transition: background 0.18s var(--ease), color 0.18s var(--ease);
  font-family: inherit;
}
.nav-pill:hover { background: var(--overlay-1); color: var(--text); }
.nav-pill.active { background: var(--accent); color: var(--accent-ink); }

.dd-chevron { width: 12px; height: 12px; opacity: 0.7; transition: transform 0.18s var(--ease); }
.nav-dropdown { position: relative; }
.nav-dropdown.open .dd-chevron { transform: rotate(180deg); }

.nav-dd-menu {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  min-width: 210px;
  padding: 6px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--card-shadow);
  z-index: 75;
  display: none;
  animation: pop-in 0.15s var(--ease) both;
}
.nav-dropdown.open .nav-dd-menu { display: block; }

@keyframes pop-in {
  from { opacity: 0; transform: translateY(-4px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.nav-dd-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 10px 12px;
  border: none;
  background: none;
  border-radius: 10px;
  font-size: 0.88rem;
  font-family: inherit;
  font-weight: 500;
  color: var(--text);
  text-align: left;
  cursor: pointer;
  margin: 0;
  appearance: none;
}
.nav-dd-item:hover { background: var(--overlay-1); }
.nav-dd-item span[data-icon] { width: 17px; height: 17px; color: var(--text-dim); flex-shrink: 0; }

.avatar {
  width: 34px; height: 34px; border-radius: 50%;
  background: var(--accent);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 0.82rem;
  color: var(--accent-ink);
}

.user-chip {
  display: flex; align-items: center; gap: 10px;
  padding: 4px;
  border: none;
  background: none;
  font-family: inherit;
  border-radius: var(--radius-pill);
  cursor: pointer;
  margin: 0;
  appearance: none;
  transition: background 0.18s var(--ease);
}
.user-chip:hover { background: var(--overlay-1); }
.user-chip #userLabel { padding-right: 4px; font-size: 0.88rem; font-weight: 600; }
.user-chip .btn-icon { color: var(--text-dim); margin-right: 6px; }

.main { position: relative; z-index: 1; padding: 24px; min-width: 0; max-width: 1400px; margin: 0 auto; }

/* ---------- Mobile slide-in drawer (full menu) ---------- */

.sidebar-backdrop {
  display: none;
  position: fixed; inset: 0; background: var(--modal-backdrop); z-index: 90;
}
.sidebar-backdrop.open { display: block; }

.mobile-drawer {
  display: none;
  position: fixed;
  left: -300px;
  top: 0;
  height: 100vh;
  width: 280px;
  z-index: 95;
  background: var(--card-bg);
  border-right: 1px solid var(--border);
  padding: 20px 14px;
  flex-direction: column;
  transition: left 0.28s var(--ease);
}
.mobile-drawer.open { left: 0; }

.mobile-drawer .brand { padding: 0 10px 20px; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 12px 14px;
  border: none;
  background: none;
  border-radius: 14px;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 0.92rem;
  font-family: inherit;
  font-weight: 500;
  text-align: left;
  margin: 0 0 2px;
  appearance: none;
  transition: background 0.18s var(--ease), color 0.18s var(--ease);
}
.nav-item:hover { background: var(--overlay-1); color: var(--text); }
.nav-item.active { background: var(--accent-soft); color: var(--accent); font-weight: 700; }
.nav-icon { width: 18px; height: 18px; flex-shrink: 0; display: inline-flex; align-items: center; justify-content: center; }

.sidebar-foot {
  margin-top: auto;
  padding-top: 12px;
  border-top: 1px solid var(--border);
  font-size: 0.8rem;
  color: var(--text-dim);
}

/* ---------- KPI cards ---------- */

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 16px;
  margin-bottom: 20px;
}

.kpi-card { padding: 20px; transition: transform 0.22s var(--ease), box-shadow 0.22s var(--ease); }
.kpi-card:hover { transform: translateY(-3px); }

.kpi-card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 18px;
}

.icon-badge {
  width: 38px; height: 38px;
  border-radius: 12px;
  background: var(--card-bg-2);
  color: var(--text-dim);
  display: flex; align-items: center; justify-content: center;
  padding: 9px;
  flex-shrink: 0;
}
.icon-badge.accent { background: var(--accent-soft); color: var(--accent); }
.icon-badge.good { background: var(--good-soft); color: var(--good); }
.icon-badge.bad { background: var(--danger-soft); color: var(--danger); }
.icon-badge.warn { background: var(--warn-soft); color: var(--warn); }

.card-link { width: 30px; height: 30px; padding: 7px; }

.kpi-card .label { color: var(--text-dim); font-size: 0.82rem; margin-bottom: 6px; }
.kpi-card .value { font-size: 1.6rem; font-weight: 700; letter-spacing: -0.01em; }
.kpi-card .sub { font-size: 0.78rem; color: var(--text-faint); margin-top: 6px; }
.kpi-card.accent-good .value { color: var(--good); }
.kpi-card.accent-bad .value { color: var(--danger); }
.kpi-card.accent-warn .value { color: var(--warn); }

.panel { padding: 22px; margin-bottom: 18px; }

.hb-layout { display: grid; grid-template-columns: 1fr 340px; gap: 16px; align-items: start; }
.pc-tables-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: start; margin-bottom: 18px; }
.hb-list-item {
  display: block; width: 100%; text-align: left; cursor: pointer;
  padding: 10px 12px; border-radius: 12px; border: 1px solid var(--border);
  background: var(--card-bg); font-size: 13px;
}
.hb-list-item:hover { background: var(--overlay-2); }
.hb-list-item.editing { border-color: var(--accent); background: var(--overlay-2); }
.hb-acc-item { margin-bottom: 8px; }
.hb-acc-item .hb-list-item { margin-bottom: 0; }
.hb-acc-item.open .hb-list-item { border-radius: 12px 12px 0 0; }
.hb-acc-row { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.hb-acc-chevron { flex-shrink: 0; width: 16px; height: 16px; opacity: 0.55; transition: transform 0.2s var(--ease); margin-top: 2px; }
.hb-acc-item.open .hb-acc-chevron { transform: rotate(180deg); }
.hb-acc-panel {
  max-height: 0; overflow: hidden;
  transition: max-height 0.25s var(--ease);
  border: 1px solid transparent; border-top: none;
  border-radius: 0 0 12px 12px;
}
.hb-acc-item.open .hb-acc-panel { border-color: var(--border); background: var(--card-bg); }
.hb-acc-panel-inner { padding: 10px 12px; }

.hb-totals-box { border-radius: 14px; padding: 14px 16px; background: var(--overlay-2); }
.hb-totals-row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 9px 0; border-bottom: 1px solid var(--border);
}
.hb-totals-row:last-child { border-bottom: none; }
.hb-totals-row > span { font-size: 13px; font-weight: 600; color: var(--text-dim); }
.hb-totals-box .field {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  margin: 0; padding: 9px 0; border-bottom: 1px solid var(--border);
}
.hb-totals-box .field:last-child { border-bottom: none; }
.hb-totals-box .field label { margin: 0; font-size: 13px; font-weight: 600; color: var(--text-dim); white-space: nowrap; }
.hb-totals-box .field input { width: 130px; padding: 8px 10px; text-align: right; }
.hb-totals-total > span { font-size: 15px; font-weight: 700; color: var(--text); }
.hb-totals-total > strong { font-size: 1.3rem; }
.hb-totals-due > span, .hb-totals-due > strong { color: var(--danger); }
.hb-totals-due > span { font-size: 15px; font-weight: 700; }
.hb-totals-due > strong { font-size: 1.3rem; }
@media (max-width: 900px) {
  .hb-layout { grid-template-columns: 1fr; }
  .pc-tables-grid { grid-template-columns: 1fr; }
}

/* Recent Hold Bills as a right-side slide-in drawer on narrow screens --
   otherwise it sits below the whole form and needs scrolling past to reach.
   The opener lives in a normal top-right toolbar (not a floating side tab)
   so it reads as a regular action button and doesn't cover page content. */
.hb-toolbar { display: none; }
.hb-recent-toggle, .hb-recent-backdrop, .hb-recent-close { display: none; }
@media (max-width: 900px) {
  .hb-toolbar { display: flex; justify-content: flex-end; margin-bottom: 12px; }
  .hb-recent-toggle { display: inline-flex; align-items: center; gap: 6px; padding: 8px 14px; font-size: 13px; }
  /* top/height stop at the sticky header's own box (~117px) rather than 0/100vh
     -- .main is a position:relative + z-index:1 stacking context, which caps
     everything nested in it (however high its own z-index) below the header's
     z-index:70 sibling context. Living entirely under the header sidesteps
     that fight instead of fighting it. */
  .hb-recent-backdrop.open { display: block; position: fixed; top: 118px; right: 0; bottom: 0; left: 0; background: var(--modal-backdrop); z-index: 97; }
  .hb-recent-panel {
    position: fixed; top: 118px; right: -100%; height: calc(100vh - 118px); width: min(340px, 88vw);
    z-index: 98; margin: 0; border-radius: 0; overflow-y: auto;
    transition: right 0.18s var(--ease);
  }
  .hb-recent-panel.open { right: 0; }
  .hb-recent-close { display: inline-flex; align-items: center; justify-content: center; width: 32px; height: 32px; padding: 0; }
  .hb-recent-close svg { width: 18px; height: 18px; }
}
.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  gap: 12px;
}
.panel h3 { margin: 0; font-size: 1.02rem; font-weight: 700; }

.charts-row {
  display: grid;
  grid-template-columns: 1.6fr 1fr;
  gap: 16px;
  margin-bottom: 18px;
  align-items: start;
}

@media (max-width: 900px) {
  .charts-row { grid-template-columns: 1fr; }
}

/* Ranked list (top products, etc.) -- rows with a numbered badge, a title,
   and a right-aligned value, matching the reference's list-panel style. */
.rank-list { display: flex; flex-direction: column; gap: 4px; }
.rank-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 8px;
  border-radius: 12px;
  transition: background 0.15s var(--ease);
}
.rank-row:hover { background: var(--overlay-1); }
.rank-badge {
  width: 34px; height: 34px;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.8rem; font-weight: 700;
  color: white;
}
.rank-info { flex: 1; min-width: 0; }
.rank-name { font-size: 0.87rem; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rank-sub { font-size: 0.74rem; color: var(--text-dim); }
.rank-value { font-size: 0.87rem; font-weight: 700; flex-shrink: 0; }

/* ---------- Filters & tables ---------- */

.filters {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
  position: relative;
  z-index: 10;
}

.filters input, .filters select {
  padding: 10px 14px;
  border-radius: var(--radius-btn);
  border: 1px solid var(--input-border);
  background: var(--input-bg);
  color: var(--text);
  font-size: 0.85rem;
  outline: none;
  transition: border-color 0.18s var(--ease), box-shadow 0.18s var(--ease);
}
.filters input:focus, .filters select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

.filters .btn { width: auto; padding: 10px 18px; font-size: 0.85rem; }
.filters .btn.secondary { color: var(--text); }

.table-wrap { overflow-x: auto; }

table { width: 100%; border-collapse: collapse; font-size: 0.86rem; }
thead th {
  text-align: left;
  color: var(--text-dim);
  font-weight: 600;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
tbody td {
  padding: 12px;
  border-bottom: 1px solid var(--row-alt);
  white-space: nowrap;
}
tbody tr:hover { background: var(--overlay-1); }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.pos { color: var(--good); }
.neg { color: var(--danger); }

.empty-state { text-align: center; padding: 40px 20px; color: var(--text-dim); }
.loading { text-align: center; padding: 40px 20px; color: var(--text-dim); }

.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: var(--radius-pill);
  font-size: 0.72rem;
  font-weight: 600;
  background: var(--overlay-2);
}

.pill-tabs { display: flex; gap: 6px; margin-bottom: 16px; flex-wrap: wrap; background: var(--card-bg-2); padding: 4px; border-radius: var(--radius-pill); width: fit-content; }
.pill-tab {
  padding: 8px 16px;
  border-radius: var(--radius-pill);
  border: none;
  background: none;
  cursor: pointer;
  font-size: 0.85rem;
  font-family: inherit;
  font-weight: 600;
  color: var(--text-dim);
  margin: 0;
  appearance: none;
  transition: background 0.18s var(--ease), color 0.18s var(--ease);
}
.pill-tab:hover { color: var(--text); }
.pill-tab.active { background: var(--accent); color: var(--accent-ink); }

/* ---------- Date range picker (presets + blurred custom-range modal) ---------- */

.drp { display: flex; flex-direction: column; gap: 6px; margin-bottom: 4px; }
.drp-pills { margin-bottom: 0; }
.drp-summary { font-size: 0.78rem; color: var(--text-dim); padding-left: 4px; }

.drp-modal-backdrop {
  position: fixed;
  inset: 0;
  background: var(--modal-backdrop);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  z-index: 200;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.drp-modal-backdrop.open { display: flex; }

.drp-modal { width: 100%; max-width: 360px; padding: 24px; animation: pop-in 0.18s var(--ease) both; }
.drp-modal h3 { margin: 0 0 16px; font-size: 1.05rem; }
.drp-modal-fields { display: flex; gap: 12px; margin-bottom: 8px; }
.drp-modal-fields .field { flex: 1; margin-bottom: 12px; }
.drp-modal-actions { display: flex; gap: 10px; }
.drp-modal-actions .btn { width: auto; flex: 1; }

@media (max-width: 480px) {
  .drp-modal-fields { flex-direction: column; gap: 0; }
}

/* ---------- Live inline search (instant dropdown) ---------- */

.live-search { position: relative; min-width: 220px; flex: 1 1 220px; max-width: 360px; }

.live-search .ls-input {
  width: 100%;
  padding: 10px 36px;
  border-radius: var(--radius-btn);
  border: 1px solid var(--input-border);
  background: var(--input-bg);
  color: var(--text);
  font-size: 0.85rem;
  outline: none;
  transition: border-color 0.18s var(--ease), box-shadow 0.18s var(--ease);
}
.live-search .ls-input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

.live-search .ls-icon {
  position: absolute; left: 13px; top: 50%; transform: translateY(-50%);
  width: 16px; height: 16px; opacity: 0.55; pointer-events: none;
}

.live-search .ls-clear {
  position: absolute; right: 8px; top: 50%; transform: translateY(-50%);
  width: 26px; height: 26px; display: none;
  align-items: center; justify-content: center;
  cursor: pointer; opacity: 0.55; padding: 6px;
  border-radius: var(--radius-pill);
  transition: opacity 0.15s, background 0.15s;
}
.live-search .ls-clear:hover { opacity: 1; background: var(--overlay-2); }
.live-search.has-value .ls-clear { display: inline-flex; }

.ls-dropdown {
  /* position/top/left/width/max-height are all set inline by
     positionDropdown() in liveSearch.js once open -- position:fixed,
     computed from the input's live viewport-relative position, so it
     can't be clipped or buried by any ancestor's stacking context or
     overflow, and adapts to the on-screen keyboard shrinking the visible
     area. These are just pre-JS fallback values. */
  position: fixed;
  max-height: 280px;
  overflow-y: auto;
  z-index: 150;
  display: none;
  padding: 6px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--card-shadow);
  transform-origin: top center;
  animation: pop-in 0.15s var(--ease) both;
}
.ls-dropdown.open { display: block; }
.ls-dropdown::-webkit-scrollbar { width: 8px; }
.ls-dropdown::-webkit-scrollbar-track { background: transparent; }
.ls-dropdown::-webkit-scrollbar-thumb { background: var(--overlay-3); border-radius: var(--radius-pill); }

.ls-item { padding: 10px 12px; border-radius: 10px; cursor: pointer; font-size: 0.87rem; transition: background 0.12s var(--ease); }
.ls-item.active, .ls-item:hover { background: var(--overlay-2); }
.ls-item mark { background: var(--accent-soft); color: var(--accent); border-radius: 3px; padding: 0 1px; }
.ls-item .sri-sub { color: var(--text-dim); font-size: 0.76rem; }

.ls-empty, .ls-loading { padding: 10px; font-size: 0.8rem; color: var(--text-dim); }

/* ---------- Report action buttons (PDF / Share) ---------- */

.report-actions { display: flex; gap: 8px; margin-left: auto; }
.report-actions .btn { width: auto; padding: 10px 18px; font-size: 0.85rem; display: inline-flex; align-items: center; gap: 6px; }
.btn-icon { width: 15px; height: 15px; display: inline-flex; flex-shrink: 0; }

/* ---------- Bottom navigation (mobile primary nav) ---------- */

.bottom-nav {
  display: none;
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 45;
  gap: 2px;
  padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
  background: var(--card-bg);
  border-top: 1px solid var(--border);
  transform: translateY(0);
  transition: transform 0.2s var(--ease), opacity 0.2s var(--ease);
}
body.kb-open .bottom-nav { transform: translateY(100%); opacity: 0; pointer-events: none; }

.bn-item {
  flex: 1;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 3px;
  min-height: 54px;
  padding: 6px 2px;
  border: none;
  background: none;
  border-radius: 16px;
  color: var(--text-dim);
  font-size: 0.68rem;
  font-family: inherit;
  font-weight: 600;
  cursor: pointer;
  user-select: none;
  margin: 0;
  appearance: none;
  transition: color 0.18s var(--ease), background 0.18s var(--ease), transform 0.15s var(--ease);
}
.bn-icon { width: 22px; height: 22px; display: flex; align-items: center; justify-content: center; }
.bn-item.active { color: var(--accent); background: var(--accent-soft); }
.bn-item:active { transform: scale(0.92); }

/* ---------- Toast ---------- */

.toast { position: fixed; bottom: 20px; right: 20px; padding: 12px 18px; border-radius: 12px; font-size: 0.85rem; z-index: 100; max-width: 320px; }

/* ---------- Mobile ---------- */

@media (max-width: 900px) {
  .topbar-row2 .top-nav { display: none; }
  .hamburger { display: inline-flex; }
}

@media (min-width: 901px) {
  .hamburger { display: none; }
}

@media (max-width: 860px) {
  .main { padding: 16px 14px calc(96px + env(safe-area-inset-bottom)); }
  .mobile-drawer { display: flex; }
  .bottom-nav { display: flex; }
  .topbar-row1 { padding: 12px 16px; }
  .topbar-row2 { padding: 0 16px 12px; }

  .nav-item { padding: 13px 16px; font-size: 0.95rem; }
  .filters input, .filters select, .live-search .ls-input { padding-top: 12px; padding-bottom: 12px; font-size: 0.95rem; }
  .pill-tab { padding: 10px 18px; }
  .btn, .btn.secondary { padding-top: 13px; padding-bottom: 13px; }
  .ls-item { padding: 12px; }

  .filters {
    flex-direction: column;
    align-items: stretch;
    position: sticky;
    top: 8px;
    z-index: 20;
  }
  .filters > * { width: 100%; }
  .live-search { max-width: none; }
  .report-actions { margin-left: 0; width: 100%; }
  .report-actions .btn { flex: 1; width: auto; }
}

@media (min-width: 861px) {
  .mobile-drawer, .sidebar-backdrop, .bottom-nav { display: none !important; }
}

/* On phones, a wide data table forces horizontal scrolling to read a
   single row -- unusable for a report someone is checking one-handed.
   Below 700px each row becomes its own card with label: value lines
   instead (data-label is set per <td> by buildTable() in reports.js). */
@media (max-width: 700px) {
  .table-wrap { overflow-x: visible; }
  .table-wrap table, .table-wrap tbody { display: block; width: 100%; }
  .table-wrap thead { display: none; }
  .table-wrap tr {
    display: block;
    margin-bottom: 12px;
    padding: 4px 14px;
    border-radius: 16px;
    background: var(--card-bg);
    border: 1px solid var(--border);
  }
  .table-wrap tr:hover { background: var(--card-bg); }
  .table-wrap td {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 0;
    border-bottom: 1px solid var(--row-alt);
    white-space: normal;
    text-align: right;
  }
  .table-wrap td:last-child { border-bottom: none; }
  .table-wrap td::before {
    content: attr(data-label);
    color: var(--text-dim);
    font-size: 0.76rem;
    font-weight: 600;
    text-align: left;
    flex-shrink: 0;
  }
  .table-wrap td.td-title { font-size: 1rem; font-weight: 700; padding-top: 12px; text-align: left; }
  .table-wrap td.td-title::before { display: none; }
}

/* Notifications / Tasks */

.nt-list { display: flex; flex-direction: column; gap: 10px; }
.nt-item {
  display: flex; justify-content: space-between; align-items: flex-start; gap: 14px;
  padding: 12px 14px; border: 1px solid var(--border); border-radius: 12px; background: var(--card-bg);
  flex-wrap: wrap;
}
.nt-item.done { opacity: 0.55; }
.nt-item.done .nt-item-top strong { text-decoration: line-through; }
.nt-item-main { flex: 1; min-width: 200px; }
.nt-item-top { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 4px; }
.nt-desc { font-size: 0.85rem; color: var(--text-dim); margin-bottom: 4px; }
.nt-meta { font-size: 0.78rem; color: var(--text-dim); }
.nt-item-actions { display: flex; flex-wrap: wrap; gap: 6px; align-items: flex-start; }
.nt-item-actions .btn.secondary { padding: 5px 11px; font-size: 12px; }
.nt-snooze-options { display: flex; gap: 6px; flex-wrap: wrap; width: 100%; margin-top: 6px; justify-content: flex-end; }
.nt-snooze-options .btn.secondary { padding: 5px 9px; font-size: 11.5px; }
