/* Dark (default) — navy slate, plan blue / fact amber */
html[data-theme="dark"] {
  --bg: #0F172A;
  --bg-elev: #1E293B;
  --bg-panel: #1E293B;
  --bg-sidebar: #020617;
  --bg-top: #0B1220;
  --line: #334155;
  --text: #F1F5F9;
  --muted: #94A3B8;
  --plan: #60A5FA;
  --plan-dim: #3B82F6;
  --fact: #F59E0B;
  --accent: #38BDF8;
  --red: #F87171;
  --green: #4ADE80;
  --hint-bg: #1E293B;
  --shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  --row-alt: rgba(96, 165, 250, 0.04);
  --row-hover: rgba(96, 165, 250, 0.1);
  --th-bg: #162032;
  --section-bg: #243044;
  --drawer-bg: #0B1220;
  --hl: rgba(245, 158, 11, 0.14);
  /* aliases (legacy class/var names) */
  --teal: var(--plan);
  --teal-dim: var(--plan-dim);
  --magenta: var(--fact);
  --gold: var(--accent);
  --pink: var(--red);
  color-scheme: dark;
}

/* Light — report sheet, plan blue / fact amber */
html[data-theme="light"] {
  --bg: #F8FAFC;
  --bg-elev: #FFFFFF;
  --bg-panel: #FFFFFF;
  --bg-sidebar: #0F2744;
  --bg-top: #FFFFFF;
  --line: #E2E8F0;
  --text: #0F172A;
  --muted: #64748B;
  --plan: #2563EB;
  --plan-dim: #1D4ED8;
  --fact: #D97706;
  --accent: #0284C7;
  --red: #DC2626;
  --green: #059669;
  --hint-bg: #FFFFFF;
  --shadow: 0 8px 24px rgba(15, 39, 68, 0.08);
  --row-alt: rgba(37, 99, 235, 0.04);
  --row-hover: rgba(37, 99, 235, 0.08);
  --th-bg: #EEF2F7;
  --section-bg: #E8EEF5;
  --drawer-bg: #FFFFFF;
  --hl: rgba(217, 119, 6, 0.12);
  --teal: var(--plan);
  --teal-dim: var(--plan-dim);
  --magenta: var(--fact);
  --gold: var(--accent);
  --pink: var(--red);
  color-scheme: light;
}

:root {
  --sidebar-w: 260px;
  --sidebar-w-collapsed: 64px;
  --topbar-h: 56px;
  --font: "DM Sans", "Segoe UI", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font-family: var(--font); }
button, select, input { font: inherit; color: inherit; }
a { color: var(--plan); }

.app {
  min-height: 100%;
  display: flex;
}

/* ——— Sidebar ——— */
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--bg-sidebar);
  color: #E8EEF6;
  border-right: 1px solid rgba(255,255,255,0.06);
  display: flex;
  flex-direction: column;
  height: 100vh;
  position: sticky;
  top: 0;
  z-index: 40;
  transition: width 0.2s ease;
}

.sidebar.collapsed {
  width: var(--sidebar-w-collapsed);
}

.sidebar-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.35rem;
  padding: 0.85rem 0.75rem;
  border-bottom: 1px solid rgba(255,255,255,0.08);
  min-height: var(--topbar-h);
}
.sidebar-top-label {
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: rgba(232,238,246,0.55);
}
.sidebar.collapsed .sidebar-top-label { display: none; }
.sidebar.collapsed .sidebar-top { justify-content: center; }

.sidebar.collapsed .sidebar-foot-text {
  display: none;
}

.sidebar-toggle {
  color: #E8EEF6 !important;
  border-color: rgba(255,255,255,0.15) !important;
  flex-shrink: 0;
}
.sidebar.collapsed .sidebar-toggle { transform: rotate(180deg); }

.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: 0.5rem 0.4rem;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  scrollbar-width: thin;
}
.nav-group { display: flex; flex-direction: column; gap: 0.12rem; }
.nav-group-title {
  font-size: 0.62rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: rgba(232,238,246,0.38);
  padding: 0.45rem 0.65rem 0.2rem;
}
.sidebar.collapsed .nav-group-title { display: none; }

.sidebar-nav button {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  width: 100%;
  text-align: left;
  background: transparent;
  border: none;
  border-radius: 8px;
  color: rgba(232,238,246,0.7);
  padding: 0.5rem 0.65rem;
  cursor: pointer;
  font-size: 0.8rem;
  line-height: 1.25;
}
.sidebar-nav button .nav-ico {
  width: 22px;
  text-align: center;
  flex-shrink: 0;
  opacity: 0.85;
  font-size: 0.75rem;
}
.sidebar-nav button .nav-label { min-width: 0; }
.sidebar.collapsed .sidebar-nav button {
  justify-content: center;
  padding: 0.55rem;
}
.sidebar.collapsed .nav-label { display: none; }
.sidebar-nav button:hover {
  background: rgba(96, 165, 250, 0.1);
  color: #fff;
}
.sidebar-nav button.active {
  background: rgba(96, 165, 250, 0.18);
  color: #60A5FA;
  font-weight: 600;
}

.sidebar-foot {
  padding: 0.75rem;
  border-top: 1px solid rgba(255,255,255,0.08);
  font-size: 0.68rem;
  color: rgba(232,238,246,0.4);
}

.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(11, 31, 58, 0.45);
  z-index: 35;
}
.sidebar-backdrop[hidden] { display: none !important; }

/* ——— Main ——— */
.main-wrap {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  min-height: var(--topbar-h);
  display: flex;
  justify-content: space-between;
  gap: 0.85rem;
  align-items: center;
  padding: 0.55rem 1rem;
  background: var(--bg-top);
  border-bottom: 1px solid var(--line);
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 0.55rem;
}
.page-context-title {
  font-weight: 600;
  font-size: 0.95rem;
}
.refresh-meta {
  font-size: 0.7rem;
  color: var(--muted);
  margin-top: 0.1rem;
}
.mobile-sidebar-btn { display: none; }

.page-filters {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  margin: 0 0 0.85rem;
  padding: 0.65rem 0.85rem;
  background: var(--bg-panel);
  border: 1px solid var(--line);
  border-radius: 10px;
}
.page-filters-label {
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}
.page-filters-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem 0.75rem;
  align-items: end;
}
.gf {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  font-size: 0.65rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.gf select, .gf input[type="date"] {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0.35rem 0.5rem;
  min-width: 100px;
  color: var(--text);
}
.date-row { display: flex; gap: 0.3rem; }

.top-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.link-btn {
  background: transparent;
  border: 1px solid var(--plan-dim);
  color: var(--plan);
  border-radius: 6px;
  padding: 0.35rem 0.55rem;
  cursor: pointer;
  font-size: 0.8rem;
}
.link-btn:hover { background: rgba(96, 165, 250, 0.12); }
a.link-btn { text-decoration: none; display: inline-flex; align-items: center; }
.logout-btn { border-color: rgba(248, 113, 113, 0.45); color: #F87171; }
.logout-btn:hover { background: rgba(248, 113, 113, 0.12); }
.auth-user {
  font-size: 0.78rem;
  color: var(--muted);
  margin-right: 0.25rem;
}

.theme-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  background: var(--bg-panel);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.35rem 0.7rem;
  cursor: pointer;
  font-size: 0.78rem;
  color: var(--text);
}
.theme-btn:hover { border-color: var(--plan); }
.theme-icon { font-size: 0.95rem; }

.content {
  flex: 1;
  padding: 0.85rem 1rem 1.5rem;
  overflow-x: hidden;
}

.icon-btn {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--text);
  width: 32px; height: 32px;
  border-radius: 6px;
  cursor: pointer;
}

/* ——— Hints ——— */
.page-title-wrap {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
}
.hint-wrap {
  position: relative;
  display: inline-flex;
  vertical-align: middle;
}
.hint-btn {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 1.5px solid var(--plan);
  background: transparent;
  color: var(--plan);
  font-size: 0.72rem;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  display: inline-grid;
  place-items: center;
  padding: 0;
  flex-shrink: 0;
}
.hint-btn:hover,
.hint-wrap:focus-within .hint-btn,
.hint-wrap.is-open .hint-btn {
  background: var(--plan);
  color: #fff;
}
.hint-pop {
  display: none;
  position: absolute;
  left: 0;
  top: calc(100% + 8px);
  z-index: 50;
  width: min(340px, 70vw);
  background: var(--hint-bg);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.75rem 0.85rem;
  font-size: 0.8rem;
  font-weight: 400;
  line-height: 1.45;
  box-shadow: var(--shadow);
  text-transform: none;
  letter-spacing: normal;
}
.hint-pop .hq {
  color: var(--plan);
  font-weight: 600;
  margin-bottom: 0.35rem;
}
.hint-wrap.is-open .hint-pop,
.hint-wrap:hover .hint-pop {
  display: block;
}

/* Layout helpers */
.page-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  margin-bottom: 0.75rem;
  flex-wrap: wrap;
}
.page-head h1 {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
}
.page-actions { display: flex; gap: 0.45rem; flex-wrap: wrap; }
.btn {
  background: var(--bg-panel);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 6px;
  padding: 0.4rem 0.7rem;
  cursor: pointer;
  font-size: 0.82rem;
}
.btn.primary { border-color: var(--plan-dim); color: var(--plan); }
.btn:hover { border-color: var(--plan); }

.grid-2 { display: grid; grid-template-columns: 1.2fr 1fr; gap: 0.75rem; }
.grid-3 { display: grid; grid-template-columns: 1fr 1.4fr 1fr; gap: 0.75rem; }
.grid-home { display: grid; grid-template-columns: 280px 1fr 320px; gap: 0.75rem; }

.panel {
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.75rem 0.85rem;
}
.panel-title {
  font-size: 0.82rem;
  color: var(--muted);
  margin: 0 0 0.55rem;
  font-weight: 600;
}

.kpi-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.65rem;
  margin-bottom: 0.75rem;
}
.kpi {
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.7rem 0.85rem;
}
.kpi .label { font-size: 0.72rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.kpi .value { font-size: 1.35rem; font-weight: 700; margin-top: 0.25rem; letter-spacing: -0.02em; }
.kpi .hint { font-size: 0.75rem; color: var(--muted); margin-top: 0.2rem; }
.kpi .value.plan,
.kpi .value.teal { color: var(--plan); }
.kpi .value.fact,
.kpi .value.magenta { color: var(--fact); }
.kpi .value.accent,
.kpi .value.gold { color: var(--accent); }
.kpi .value.green { color: var(--green); }
.kpi .value.red { color: var(--red); }

.kpi-row-6 {
  grid-template-columns: repeat(6, 1fr);
}

.page-desc {
  margin: 0.35rem 0 0;
  font-size: 0.82rem;
  color: var(--muted);
  max-width: 560px;
  line-height: 1.4;
}
.note {
  margin: 0.55rem 0 0;
  font-size: 0.72rem;
  color: var(--muted);
  line-height: 1.4;
}

.compare-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.65rem;
}
.compare-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.65rem 0.75rem;
  background: var(--bg);
}
.compare-card .name {
  font-size: 0.72rem;
  color: var(--muted);
  font-weight: 600;
  margin-bottom: 0.45rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.compare-card .row {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  font-size: 0.8rem;
  margin-bottom: 0.2rem;
  font-variant-numeric: tabular-nums;
}
.delta-up { color: var(--green); font-weight: 650; }
.delta-down { color: var(--red); font-weight: 650; }
.delta-flat { color: var(--muted); font-weight: 650; }

.data-table .client-row td { font-weight: 700; background: var(--th-bg) !important; }
.data-table .project-row td:first-child { padding-left: 1.35rem; }
.badge-bad { background: rgba(248, 113, 113, 0.14); color: var(--red); border-color: rgba(248, 113, 113, 0.3); }

.margin-filters {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 0.65rem;
}
.margin-table { min-width: 780px; }

@media (max-width: 1100px) {
  .kpi-row-6 { grid-template-columns: repeat(3, 1fr); }
  .compare-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 800px) {
  .kpi-row-6 { grid-template-columns: repeat(2, 1fr); }
  .compare-grid { grid-template-columns: 1fr; }
}

.chart-box { position: relative; height: 240px; }
.chart-box.sm { height: 160px; }
.chart-box.lg { height: 300px; }

.table-wrap {
  overflow: auto;
  max-height: 520px;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}
.table-wrap.tall { max-height: 640px; }
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.78rem;
}
.data-table th {
  position: sticky; top: 0;
  background: var(--th-bg);
  color: var(--muted);
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  text-align: left;
  padding: 0.45rem 0.5rem;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
  z-index: 1;
}
.data-table td {
  padding: 0.4rem 0.5rem;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
.data-table tr:nth-child(even) td { background: var(--row-alt); }
.data-table tr:hover td { background: var(--row-hover); }
.data-table .num { text-align: right; font-variant-numeric: tabular-nums; }
.data-table .neg { color: var(--red); }
.data-table .pos { color: var(--green); }
.pos { color: var(--green); }
.neg { color: var(--red); }
.data-table .tree-cell { white-space: nowrap; }
.data-table .toggle {
  display: inline-grid;
  place-items: center;
  width: 28px; height: 28px;
  min-width: 28px;
  margin-right: 0.35rem;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--bg-panel);
  color: var(--text);
  font-size: 0.75rem;
  cursor: pointer;
  vertical-align: middle;
}
.data-table .toggle.empty { visibility: hidden; }
.data-table .indent-1 { padding-left: 1.1rem; }
.data-table .indent-2 { padding-left: 2.1rem; }
.data-table .indent-3 { padding-left: 3.1rem; }
.data-table .indent-4 { padding-left: 4.1rem; }
.data-table tr.clickable { cursor: pointer; }
.data-table .hl-row td { background: var(--hl) !important; color: var(--fact); }
.data-table .total-row td { font-weight: 700; border-top: 1px solid var(--line); background: var(--th-bg); }

.mini-matrix {
  display: grid;
  grid-template-columns: auto repeat(3, 1fr);
  gap: 1px;
  background: var(--line);
  border-radius: 6px;
  overflow: hidden;
  font-size: 0.72rem;
  margin-bottom: 0.55rem;
}
.mini-matrix > div { background: var(--bg-elev); padding: 0.35rem 0.45rem; }
.mini-matrix .head { color: var(--muted); }
.mini-matrix .row-lab { color: var(--muted); display: flex; align-items: center; }
.mini-matrix .strong { font-weight: 700; color: var(--plan); }
.mini-matrix .matrix-cell {
  display: block;
  width: 100%;
  text-align: right;
  background: var(--bg-elev);
  border: none;
  color: var(--text);
  padding: 0.35rem 0.45rem;
  cursor: pointer;
  font: inherit;
  font-variant-numeric: tabular-nums;
}
.mini-matrix .matrix-cell:hover { background: var(--row-hover); }
.mini-matrix .matrix-cell.is-active {
  background: rgba(96, 165, 250, 0.18);
  color: var(--plan);
  font-weight: 700;
  box-shadow: inset 0 0 0 1px var(--plan);
}
.mini-matrix .matrix-cell.strong { color: var(--plan); font-weight: 700; }

.th-sort {
  background: transparent;
  border: none;
  color: inherit;
  font: inherit;
  font-size: inherit;
  text-transform: inherit;
  letter-spacing: inherit;
  cursor: pointer;
  padding: 0;
}
.th-sort:hover { color: var(--plan); }

.originator-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.65rem;
}
.originator-grid .og-card .chart-box { height: 140px; }
.originator-grid .og-name { font-size: 0.8rem; margin-bottom: 0.35rem; font-weight: 600; }

.split-cash {
  display: grid;
  grid-template-columns: 1.5fr 1fr;
  gap: 0.75rem;
}

.drawer {
  position: fixed; inset: 0; z-index: 60;
  background: rgba(0,0,0,0.55);
  display: flex; justify-content: flex-end;
}
.drawer[hidden] { display: none !important; }
.drawer-panel {
  width: min(520px, 100%);
  height: 100%;
  background: var(--drawer-bg);
  border-left: 1px solid var(--line);
  display: flex; flex-direction: column;
  animation: slideIn 0.2s ease;
}
@keyframes slideIn { from { transform: translateX(24px); opacity: 0.6; } to { transform: none; opacity: 1; } }
.drawer-head {
  display: flex; justify-content: space-between; align-items: flex-start;
  padding: 1rem 1.1rem;
  border-bottom: 1px solid var(--line);
}
.drawer-kicker { font-size: 0.7rem; color: var(--muted); text-transform: uppercase; }
.drawer-head h2 { margin: 0.25rem 0 0; font-size: 1.05rem; }
.drawer-body { padding: 1rem 1.1rem; overflow: auto; flex: 1; }
.drawer-body .meta-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 0.55rem; margin-bottom: 1rem;
}
.drawer-body .meta-item {
  background: var(--bg-elev); border: 1px solid var(--line); border-radius: 8px; padding: 0.55rem 0.65rem;
}
.drawer-body .meta-item .l { font-size: 0.68rem; color: var(--muted); }
.drawer-body .meta-item .v { font-size: 0.95rem; font-weight: 600; margin-top: 0.15rem; }

.warn { color: var(--red); font-size: 0.85rem; margin: 0.4rem 0; }
.audit-note {
  font-size: 0.75rem;
  color: var(--muted);
  margin: 0 0 0.75rem;
  padding: 0.45rem 0.65rem;
  border-left: 3px solid var(--plan);
  background: var(--row-alt);
  border-radius: 0 6px 6px 0;
}

.pl-wrap { overflow: auto; max-height: calc(100vh - 180px); }
.pl-table td, .pl-table th { font-size: 0.72rem; padding: 0.28rem 0.4rem; }
.pl-table .section td { background: var(--section-bg); font-weight: 600; }
.pl-mode-note {
  margin: -0.35rem 0 0.65rem;
  font-size: 0.78rem;
  color: var(--muted);
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.2rem;
  padding: 0.15rem 0.45rem;
  border-radius: 4px;
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  white-space: nowrap;
  border: 1px solid transparent;
}
.badge-ok { background: rgba(74, 222, 128, 0.12); color: #4ADE80; border-color: rgba(74, 222, 128, 0.25); }
.badge-amber { background: rgba(245, 158, 11, 0.12); color: #FBBF24; border-color: rgba(245, 158, 11, 0.28); }
.badge-warn { background: rgba(249, 115, 22, 0.14); color: #FB923C; border-color: rgba(249, 115, 22, 0.3); }
.badge-danger { background: rgba(248, 113, 113, 0.14); color: #F87171; border-color: rgba(248, 113, 113, 0.3); }
.badge-court { background: rgba(167, 139, 250, 0.14); color: #C4B5FD; border-color: rgba(167, 139, 250, 0.3); }
.badge-fee { background: rgba(96, 165, 250, 0.12); color: var(--plan); border-color: rgba(96, 165, 250, 0.28); }

.aging-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin: 0 0 0.75rem;
  align-items: center;
}
button.aging-chip {
  cursor: pointer;
  font: inherit;
  transition: box-shadow 0.15s ease, transform 0.1s ease, filter 0.15s ease;
}
button.aging-chip:hover {
  filter: brightness(1.12);
  box-shadow: 0 0 0 1px currentColor;
}
button.aging-chip.is-active {
  box-shadow: 0 0 0 2px currentColor;
  filter: brightness(1.15);
  font-weight: 700;
}
button.aging-chip-all {
  background: var(--bg-elev);
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 0.15rem 0.55rem;
  font-size: 0.68rem;
  font-weight: 600;
}
button.aging-chip-all.is-active {
  color: var(--plan);
  border-color: var(--plan);
  box-shadow: 0 0 0 2px var(--plan);
}

.meta-hint {
  font-size: 0.68rem;
  color: var(--muted);
  font-weight: 400;
  margin-top: 0.15rem;
}

.data-table td.num, .data-table th.num { font-variant-numeric: tabular-nums; }

/* ——— Mobile shell extras ——— */
.mobile-report-wrap { display: none; }
.mobile-filters-btn { display: none; }
.mobile-tabs-scroll {
  display: none;
  gap: 0.4rem;
  padding: 0.45rem 0.75rem;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border-bottom: 1px solid var(--line);
  background: var(--bg-top);
  scrollbar-width: thin;
}
.mobile-tabs-scroll .mob-tab {
  flex: 0 0 auto;
  border: 1px solid var(--line);
  background: var(--bg-elev);
  color: var(--muted);
  border-radius: 999px;
  padding: 0.45rem 0.85rem;
  min-height: 44px;
  font: inherit;
  font-size: 0.78rem;
  cursor: pointer;
  white-space: nowrap;
}
.mobile-tabs-scroll .mob-tab.active {
  color: var(--plan);
  border-color: var(--plan);
  background: rgba(96, 165, 250, 0.14);
  font-weight: 600;
}

.filters-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(2, 6, 23, 0.55);
  z-index: 52;
}
.filters-backdrop:not([hidden]) { display: block; }

.filters-sheet {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 53;
  max-height: min(88vh, 640px);
  background: var(--bg-panel);
  border: 1px solid var(--line);
  border-bottom: none;
  border-radius: 16px 16px 0 0;
  box-shadow: 0 -12px 40px rgba(0, 0, 0, 0.35);
  display: flex;
  flex-direction: column;
  transform: translateY(110%);
  transition: transform 0.25s ease;
  padding-bottom: env(safe-area-inset-bottom, 0);
}
.filters-sheet:not([hidden]) { display: flex; }
.filters-sheet.is-open { transform: translateY(0); }
.filters-sheet-handle {
  width: 42px; height: 4px;
  border-radius: 999px;
  background: var(--line);
  margin: 0.55rem auto 0.15rem;
}
.filters-sheet-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 0.75rem;
  padding: 0.55rem 1rem 0.65rem;
  border-bottom: 1px solid var(--line);
}
.filters-sheet-kicker {
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}
.filters-sheet-head h2 {
  margin: 0.15rem 0 0;
  font-size: 1.05rem;
}
.filters-sheet-body {
  flex: 1;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  padding: 0.85rem 1rem;
}
.filters-sheet-body .page-filters {
  margin: 0;
  padding: 0;
  border: none;
  background: transparent;
}
.filters-sheet-foot {
  padding: 0.75rem 1rem calc(0.85rem + env(safe-area-inset-bottom, 0));
  border-top: 1px solid var(--line);
}
.filters-sheet-foot .btn {
  width: 100%;
  min-height: 48px;
  font-size: 0.95rem;
}

.icon-btn, .link-btn, .theme-btn, .btn, .hint-btn, .sidebar-nav button, button.aging-chip {
  touch-action: manipulation;
}

@media (max-width: 1200px) {
  .grid-home, .grid-3, .split-cash, .grid-2 { grid-template-columns: 1fr; }
  .kpi-row { grid-template-columns: repeat(2, 1fr); }
  .originator-grid { grid-template-columns: 1fr 1fr; }
  .topbar { flex-wrap: wrap; }
  .chart-box { height: 220px; }
  .chart-box.lg { height: 260px; }
}

/* Tablet / phones: off-canvas reports + filter sheet */
@media (max-width: 900px) {
  .app { flex-direction: column; }

  .sidebar {
    position: fixed;
    left: 0; top: 0;
    width: min(86vw, 300px);
    max-width: 100%;
    transform: translateX(-105%);
    transition: transform 0.22s ease;
    box-shadow: var(--shadow);
    z-index: 45;
  }
  .sidebar.mobile-open { transform: none; }
  .sidebar.collapsed { width: min(86vw, 300px); }
  .sidebar.collapsed .nav-label,
  .sidebar.collapsed .sidebar-foot-text,
  .sidebar.collapsed .nav-group-title { display: block; }
  .sidebar.collapsed .sidebar-nav button {
    justify-content: flex-start;
    padding: 0.65rem 0.75rem;
  }
  .mobile-sidebar-btn {
    display: inline-grid;
    place-items: center;
    width: 44px;
    height: 44px;
    min-width: 44px;
  }
  .sidebar-backdrop:not([hidden]) { display: block; }
  .sidebar-toggle { display: none; }

  .main-wrap { width: 100%; min-width: 0; }
  .content { padding: 0.7rem 0.75rem 1.25rem; }

  .topbar {
    display: grid;
    grid-template-columns: 1fr auto;
    grid-template-areas:
      "left actions"
      "report report";
    gap: 0.45rem 0.55rem;
    padding: 0.55rem 0.7rem;
    align-items: center;
  }
  .topbar-left { grid-area: left; min-width: 0; }
  .top-actions { grid-area: actions; flex-wrap: wrap; justify-content: flex-end; }
  .mobile-report-wrap {
    grid-area: report;
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
    width: 100%;
  }
  .mobile-report-label {
    font-size: 0.62rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--muted);
  }
  .mobile-report-select {
    width: 100%;
    min-height: 44px;
    font: inherit;
    font-size: 0.92rem;
    color: var(--text);
    background: var(--bg-elev);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 0.45rem 0.65rem;
  }
  .mobile-tabs-scroll {
    display: flex;
  }
  .mobile-filters-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 44px;
    min-width: 44px;
    padding: 0.45rem 0.75rem;
  }
  .mobile-filters-btn[hidden] { display: none !important; }
  .desktop-only-btn { display: none !important; }
  .auth-user { display: none; }
  .refresh-meta { display: none; }
  .page-context-title { font-size: 0.9rem; }

  /* Inline filters stay for desktop; on tablet+phone they live in sheet */
  .page-filters.page-filters-inline {
    display: none;
  }

  .link-btn, .theme-btn, .btn {
    min-height: 44px;
  }
  .theme-btn { border-radius: 10px; padding: 0.4rem 0.65rem; }

  .kpi-row {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.5rem;
  }
  .kpi {
    padding: 0.75rem 0.8rem;
  }
  .kpi .label { font-size: 0.68rem; }
  .kpi .value { font-size: 1.2rem; }

  .page-head {
    flex-direction: column;
    align-items: flex-start;
  }
  .page-actions { width: 100%; }
  .page-actions .btn { flex: 1; text-align: center; }

  .chart-box { height: 200px; }
  .chart-box.sm { height: 150px; }
  .chart-box.lg { height: 220px; }

  .table-wrap, .table-wrap.tall, .pl-wrap {
    max-height: min(60vh, 420px);
  }

  /* Sticky first column for horizontal scroll tables */
  .data-table {
    border-collapse: separate;
    border-spacing: 0;
  }
  .data-table th:first-child,
  .data-table td:first-child {
    position: sticky;
    left: 0;
    z-index: 2;
    background: var(--bg-elev);
    box-shadow: 4px 0 8px rgba(0, 0, 0, 0.12);
  }
  .data-table th:first-child {
    z-index: 3;
    background: var(--th-bg);
  }
  .data-table tr:nth-child(even) td:first-child { background: var(--bg-elev); }
  html[data-theme="light"] .data-table tr:nth-child(even) td:first-child { background: #F8FAFC; }
  .data-table tr:hover td:first-child { background: var(--row-hover); }
  .data-table .hl-row td:first-child { background: var(--hl) !important; }
  .data-table .total-row td:first-child { background: var(--th-bg); }

  .aging-legend {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 0.2rem;
  }
  button.aging-chip,
  button.aging-chip-all {
    min-height: 44px;
    padding: 0.45rem 0.75rem;
    font-size: 0.78rem;
    flex: 0 0 auto;
  }

  .mini-matrix {
    font-size: 0.7rem;
    overflow-x: auto;
  }
  .mini-matrix .matrix-cell {
    min-height: 44px;
    padding: 0.55rem 0.45rem;
  }

  .drawer-panel { width: 100%; }
  .drawer-body .meta-grid { grid-template-columns: 1fr; }

  .sidebar-nav button {
    min-height: 44px;
    padding: 0.65rem 0.75rem;
    font-size: 0.88rem;
  }

  .gf select, .gf input[type="date"] {
    min-height: 44px;
    min-width: 0;
    width: 100%;
    font-size: 1rem; /* avoid iOS zoom */
  }
  .page-filters-row,
  .filters-sheet-body .page-filters-row {
    display: grid;
    grid-template-columns: 1fr;
    gap: 0.65rem;
  }
  .date-row { display: grid; grid-template-columns: 1fr 1fr; gap: 0.45rem; }
}

@media (max-width: 720px) {
  .kpi-row {
    grid-template-columns: 1fr;
  }
  .kpi .value { font-size: 1.45rem; }
  .originator-grid { grid-template-columns: 1fr; }
  .theme-label { display: none; }
  .help-btn { padding-left: 0.65rem; padding-right: 0.65rem; }
  .content { padding: 0.55rem 0.6rem 1.5rem; }
  .page-head h1 { font-size: 1.05rem; }
  .chart-box { height: 190px; }
  .chart-box.lg { height: 210px; }
  .panel { padding: 0.65rem 0.7rem; border-radius: 8px; }
}

/* Narrow phones 375–430 */
@media (max-width: 430px) {
  .top-actions { gap: 0.3rem; }
  .logout-btn .visually-hidden { /* keep */ }
  .logout-btn { padding: 0.4rem 0.55rem; font-size: 0.75rem; }
  .mobile-tabs-scroll { padding: 0.4rem 0.55rem; }
  .mobile-tabs-scroll .mob-tab { font-size: 0.72rem; padding: 0.4rem 0.7rem; }
}

@media (max-width: 800px) {
  #helpReports { grid-template-columns: 1fr; height: auto; max-height: 70vh; overflow: auto; }
  .help-report-nav {
    border-right: none;
    border-bottom: 1px solid var(--line);
    padding: 0 0 0.65rem;
    max-height: 160px;
  }
  .help-panel {
    max-height: 96vh;
    border-radius: 12px;
  }
  .help-tabs { flex-wrap: wrap; }
  .help-tab { min-height: 40px; }
}

/* Desktop: filters stay inline; sheet unused */
@media (min-width: 901px) {
  .filters-sheet,
  .filters-backdrop,
  .mobile-filters-btn,
  .mobile-report-wrap,
  .mobile-tabs-scroll {
    display: none !important;
  }
  .page-filters.page-filters-inline { display: flex; }
}

/* ——— Help center ——— */
.help-btn {
  border-color: rgba(56, 189, 248, 0.45);
  color: #38BDF8;
}
.help-btn:hover { background: rgba(56, 189, 248, 0.12); }
.export-btn {
  border-color: rgba(96, 165, 250, 0.45);
  color: var(--plan);
  font-weight: 600;
}
.export-btn:hover { background: rgba(96, 165, 250, 0.12); }

.help-overlay {
  position: fixed;
  inset: 0;
  z-index: 80;
  background: rgba(2, 6, 23, 0.72);
  display: grid;
  place-items: center;
  padding: 1rem;
}
.help-overlay[hidden] { display: none !important; }

.help-panel {
  width: min(980px, 100%);
  max-height: min(90vh, 860px);
  display: flex;
  flex-direction: column;
  background: var(--bg-panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: 0 28px 80px rgba(0, 0, 0, 0.45);
  overflow: hidden;
}

.help-head {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 1.15rem 0.75rem;
  border-bottom: 1px solid var(--line);
}
.help-kicker {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}
.help-head h2 {
  margin: 0.15rem 0 0;
  font-size: 1.25rem;
}
.help-sub {
  margin: 0.25rem 0 0;
  font-size: 0.82rem;
  color: var(--muted);
}

.help-tabs {
  display: flex;
  gap: 0.35rem;
  padding: 0.65rem 1.15rem 0;
}
.help-tab {
  border: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  border-radius: 999px;
  padding: 0.35rem 0.85rem;
  cursor: pointer;
  font: inherit;
  font-size: 0.82rem;
}
.help-tab.active {
  color: var(--text);
  border-color: var(--plan);
  background: rgba(96, 165, 250, 0.12);
}

.help-body {
  flex: 1;
  min-height: 0;
  overflow: hidden;
  padding: 0.85rem 1.15rem 1.15rem;
}
.help-pane {
  height: 100%;
  min-height: 0;
}
#helpReports {
  display: grid;
  grid-template-columns: 220px 1fr;
  gap: 1rem;
  height: min(62vh, 560px);
}
#helpReports[hidden], #helpGlossary[hidden] { display: none !important; }

.help-report-nav {
  overflow: auto;
  border-right: 1px solid var(--line);
  padding-right: 0.65rem;
}
.help-nav-group { margin-bottom: 0.65rem; }
.help-nav-title {
  font-size: 0.62rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  margin-bottom: 0.25rem;
}
.help-report-nav button {
  display: block;
  width: 100%;
  text-align: left;
  border: none;
  background: transparent;
  color: var(--text);
  border-radius: 6px;
  padding: 0.4rem 0.5rem;
  cursor: pointer;
  font: inherit;
  font-size: 0.82rem;
}
.help-report-nav button:hover { background: var(--row-alt); }
.help-report-nav button.active {
  background: rgba(96, 165, 250, 0.14);
  color: var(--plan);
}

.help-report-detail {
  overflow: auto;
  padding-right: 0.25rem;
}
.help-badge {
  display: inline-block;
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--plan);
  margin-bottom: 0.35rem;
}
.help-report-detail h3 {
  margin: 0 0 0.85rem;
  font-size: 1.15rem;
}
.help-block {
  margin-bottom: 0.85rem;
  padding: 0.7rem 0.8rem;
  border-radius: 8px;
  background: var(--row-alt);
  border: 1px solid var(--line);
}
.help-block h4 {
  margin: 0 0 0.35rem;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}
.help-block p {
  margin: 0;
  font-size: 0.9rem;
  line-height: 1.45;
}

.help-search-wrap { margin-bottom: 0.75rem; }
.help-search-wrap input {
  width: 100%;
  box-sizing: border-box;
  font: inherit;
  font-size: 0.95rem;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.7rem 0.85rem;
}
.help-search-wrap input:focus {
  outline: none;
  border-color: var(--plan);
  box-shadow: 0 0 0 3px rgba(96, 165, 250, 0.18);
}

.help-glossary-list {
  overflow: auto;
  max-height: min(58vh, 520px);
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}
.help-term {
  padding: 0.75rem 0.85rem;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--bg);
}
.help-term h3 {
  margin: 0 0 0.35rem;
  font-size: 0.98rem;
  color: var(--plan);
}
.help-aliases {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  margin-bottom: 0.45rem;
}
.help-aliases span {
  font-size: 0.68rem;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.1rem 0.45rem;
}
.help-term p {
  margin: 0;
  font-size: 0.88rem;
  line-height: 1.5;
  color: var(--text);
}
.help-empty {
  color: var(--muted);
  font-size: 0.9rem;
}


/* Открытое демо: без контактов и выхода */
html[data-open] #contactBtn, html[data-open] #logoutBtn { display: none !important; }
a.link-btn[hidden], .link-btn[hidden] { display: none !important; }
html[data-open] #adminLink { display: none !important; }
