/* ═══════════════════════════════════════════════════════════════════
   DESIGN TOKENS
   ═══════════════════════════════════════════════════════════════════ */
:root {
  --brand:          #b71c1c;
  --brand-dark:     #7f1111;
  --bg:             #f6f8fb;
  --card:           #ffffff;
  --surface:        #ffffff;   /* FIX: was undefined — caused transparent bg on mobile WebViews */
  --text:           #10212b;
  --muted:          #60727d;
  --border:         #e5e7eb;
  --border-subtle:  #f0f2f5;

  --green:          #2e7d32;
  --yellow:         #f9a825;
  --orange:         #ef6c00;
  --red:            #c62828;

  /* Semantic colour tokens */
  --color-text-primary:       #10212b;
  --color-text-secondary:     #60727d;
  --color-text-success:       #065f46;
  --color-text-danger:        #991b1b;
  --color-text-warning:       #92400e;
  --color-text-info:          #1e40af;

  --color-background-success: #d1fae5;
  --color-background-danger:  #fee2e2;
  --color-background-warning: #fef3c7;
  --color-background-info:    #dbeafe;
  --color-background-secondary: #f3f4f6;

  --color-border-primary:     #d1d5db;
  --color-border-success:     #6ee7b7;
  --color-border-danger:      #fca5a5;
  --color-border-warning:     #fcd34d;
  --color-border-info:        #93c5fd;
  --color-border-tertiary:    #e5e7eb;

  --shadow:         0 2px 12px rgba(16,33,43,0.07), 0 1px 3px rgba(16,33,43,0.05);
  --shadow-lg:      0 8px 32px rgba(16,33,43,0.10);
  --radius:         8px;
  --radius-sm:      8px;
  --radius-xs:      6px;

  /* Aliases used by alternate templates */
  --surface2:  var(--color-background-secondary);
  --font-mono: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  --accent:    var(--brand);

  /* Typography scale */
  --text-xs:   11px;
  --text-sm:   13px;
  --text-base: 14px;
  --text-md:   15px;
  --text-lg:   18px;
  --text-xl:   22px;

  /* Spacing */
  --gap-xs:   6px;
  --gap-sm:   10px;
  --gap-md:   14px;
  --gap-lg:   20px;
  --gap-xl:   28px;
}

/* ═══════════════════════════════════════════════════════════════════
   RESET & BASE
   ═══════════════════════════════════════════════════════════════════ */
*, *::before, *::after { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  font-size: var(--text-base);
  line-height: 1.5;
  background: var(--bg);
  color: var(--text);
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 { margin: 0; line-height: 1.25; }
h1 { font-size: var(--text-xl); font-weight: 700; }
h3 { font-size: var(--text-md); font-weight: 650; margin-bottom: var(--gap-sm); }
a  { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
p  { margin: 0 0 0.75rem; }

/* ═══════════════════════════════════════════════════════════════════
   TOP BAR
   ═══════════════════════════════════════════════════════════════════ */
.topbar {
  background: var(--brand);
  color: white;
  padding: 14px 18px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  position: sticky;
  top: 0;
  z-index: 50;
}
.brand {
  display: flex;
  gap: 10px;
  align-items: center;
  font-weight: 700;
  font-size: var(--text-md);
  white-space: nowrap;
}
.brand .dot {
  width: 10px;
  height: 10px;
  border-radius: 99px;
  background: white;
  opacity: 0.9;
  flex-shrink: 0;
}
.topbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
}
.user {
  display: flex;
  gap: 6px;
  align-items: center;
  flex-wrap: wrap;
}
.pill {
  background: rgba(255,255,255,0.18);
  padding: 4px 10px;
  border-radius: 999px;
  font-size: var(--text-xs);
  font-weight: 500;
  white-space: nowrap;
}

/* ═══════════════════════════════════════════════════════════════════
   APP SHELL — sidebar + main
   ═══════════════════════════════════════════════════════════════════ */
.app-shell {
  display: grid;
  grid-template-columns: 256px minmax(0, 1fr);
  min-height: calc(100dvh - 52px);
}

/* ── Sidebar ── */
.sidenav {
  background: var(--card);
  border-right: 1px solid var(--border);
  padding: 16px 10px;
  height: calc(100dvh - 52px);
  position: sticky;
  top: 52px;
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}
.sidenav::-webkit-scrollbar { width: 4px; }
.sidenav::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

.sidenav-section { margin-bottom: 18px; }
.sidenav-title {
  font-size: var(--text-xs);
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding: 0 10px;
  margin-bottom: 6px;
}
.sidenav-link {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 10px;
  border-radius: var(--radius-sm);
  color: var(--text);
  text-decoration: none;
  font-size: var(--text-sm);
  font-weight: 500;
  margin: 2px 0;
  min-height: 40px;
  transition: background 0.12s, color 0.12s;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
  cursor: pointer;
  font-family: inherit;
}
.sidenav-link:hover { background: rgba(183,28,28,0.10); color: var(--brand-dark); text-decoration: none; }
.sidenav-link.active {
  background: rgba(183,28,28,0.14);
  color: var(--brand-dark);
  font-weight: 650;
  border-left: 3px solid var(--brand);
  padding-left: 7px;
}
.sidenav-link--button { /* same as sidenav-link, already covered */ }

/* ── Main content ── */
.main {
  min-width: 0;
  padding: 20px 18px;
}

/* ═══════════════════════════════════════════════════════════════════
   HAMBURGER + MOBILE DRAWER
   ═══════════════════════════════════════════════════════════════════ */
.nav-toggle {
  display: none;
  flex-direction: column;
  justify-content: center;
  gap: 5px;
  width: 36px;
  height: 36px;
  padding: 6px;
  background: rgba(255,255,255,0.15);
  border: none;
  border-radius: 8px;
  cursor: pointer;
  flex-shrink: 0;
}
.nav-toggle span {
  display: block;
  width: 100%;
  height: 2px;
  background: white;
  border-radius: 2px;
  transition: transform 0.2s, opacity 0.2s;
}
.nav-toggle[aria-expanded="true"] span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
.nav-toggle[aria-expanded="true"] span:nth-child(2) { opacity: 0; }
.nav-toggle[aria-expanded="true"] span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }

.nav-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.40);
  z-index: 99;
}
.nav-overlay--visible { display: block; }

/* ═══════════════════════════════════════════════════════════════════
   PAGE HEADER
   ═══════════════════════════════════════════════════════════════════ */
.page-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-bottom: 1.25rem;
}
.page-head__actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}
.date-form {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}
.date-form label { font-size: var(--text-sm); color: var(--muted); white-space: nowrap; }
.date-form input {
  padding: 7px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: white;
  font-size: 15px;
}

/* ═══════════════════════════════════════════════════════════════════
   BUTTONS
   ═══════════════════════════════════════════════════════════════════ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  padding: 0 1rem;
  height: 38px;
  border-radius: var(--radius-sm);
  font-size: var(--text-sm);
  font-weight: 600;
  cursor: pointer;
  border: 1px solid transparent;
  text-decoration: none;
  white-space: nowrap;
  transition: opacity 0.12s, background 0.12s;
  background: var(--brand);
  color: white;
  font-family: inherit;
}
.btn:hover { opacity: 0.88; text-decoration: none; }
.btn:active { opacity: 0.72; }

.btn--sm    { height: 30px; padding: 0 0.7rem; font-size: 12px; }
.btn--lg    { height: 44px; padding: 0 1.4rem; font-size: var(--text-base); }

.btn--secondary {
  background: var(--color-background-secondary);
  color: var(--color-text-primary);
  border-color: var(--color-border-primary);
}
.btn--ghost {
  background: transparent;
  color: var(--color-text-secondary);
  border-color: var(--color-border-primary);
}
.btn--danger {
  background: var(--color-background-danger);
  color: var(--color-text-danger);
  border-color: var(--color-border-danger);
}
.btn--outline {
  background: transparent;
  color: var(--brand);
  border-color: var(--brand);
}
.btn--outline:hover { background: var(--brand); color: white; opacity: 1; }

/* ═══════════════════════════════════════════════════════════════════
   CARDS
   ═══════════════════════════════════════════════════════════════════ */
.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  margin-bottom: var(--gap-md);
}
.card h3 { margin-bottom: 12px; }

/* ═══════════════════════════════════════════════════════════════════
   KPI CARDS
   ═══════════════════════════════════════════════════════════════════ */
.kpi-card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  border-left: 5px solid var(--brand);
}
.kpi-title {
  font-size: var(--text-sm);
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 12px;
}
.kpi-row {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}
.kpi-label {
  font-size: var(--text-xs);
  color: var(--muted);
  margin-bottom: 3px;
  white-space: nowrap;
}
.kpi-value {
  font-size: var(--text-lg);
  font-weight: 800;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  line-height: 1.2;
}
.kpi-green  { border-left-color: var(--green); }
.kpi-yellow { border-left-color: var(--yellow); }
.kpi-orange { border-left-color: var(--orange); }

/* ═══════════════════════════════════════════════════════════════════
   GRID LAYOUTS
   ═══════════════════════════════════════════════════════════════════ */
.grid   { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: var(--gap-md); margin-bottom: var(--gap-md); }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: var(--gap-md); margin-bottom: var(--gap-md); }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0,1fr)); gap: var(--gap-md); margin-bottom: var(--gap-md); }

/* ═══════════════════════════════════════════════════════════════════
   TABLE SYSTEM
   ═══════════════════════════════════════════════════════════════════ */
.table-wrap {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  background: var(--card);
}

.table-wrap > .data-table {
  width: 100%;
  min-width: 520px;
  table-layout: auto;
  border-collapse: collapse;
  margin: 0;
}

.table-body-scroll {
  max-height: calc(10 * 45px);
  overflow-y: auto;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  width: 100%;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}
.table-body-scroll::-webkit-scrollbar        { width: 5px; height: 5px; }
.table-body-scroll::-webkit-scrollbar-track  { background: transparent; }
.table-body-scroll::-webkit-scrollbar-thumb  { background: #ccc; border-radius: 3px; }

.table-body-scroll > .data-table {
  width: 100%;
  min-width: 520px;
  table-layout: auto;
  border-collapse: collapse;
  margin: 0;
}

.data-table { font-size: var(--text-sm); border-collapse: collapse; width: 100%; }

.data-table thead tr {
  border-bottom: 2px solid var(--text);
  background: var(--card);
}
.data-table th {
  text-align: left;
  font-size: var(--text-xs);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--muted);
  padding: 10px 14px;
  white-space: nowrap;
  background: var(--card);
}
.data-table th.num,
.data-table th.right { text-align: right; }
.data-table th.actions { text-align: right; }

.data-table td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border-subtle);
  vertical-align: middle;
  color: var(--text);
}
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover td { background: #f8fafb; }

.data-table .num,
.data-table .right { text-align: right; font-variant-numeric: tabular-nums; }
.data-table .actions { text-align: right; white-space: nowrap; }
.data-table .text-muted,
.data-table .muted-cell {
  color: var(--muted);
  font-size: 12px;
}
.data-table .mono { font-family: "SFMono-Regular", Consolas, monospace; font-size: 12px; }

.row-green  { background: rgba(46,125,50,0.05) !important; }
.row-yellow { background: rgba(249,168,37,0.09) !important; }
.row-orange { background: rgba(239,108,0,0.07) !important; }

.leaderboard-me { background: var(--color-background-info) !important; }
.leaderboard-me td { color: var(--color-text-info); }

/* ── Legacy .table ── */
.table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-sm);
}
.table th, .table td {
  padding: 10px 8px;
  border-bottom: 1px solid var(--border-subtle);
  vertical-align: middle;
}
.table th {
  text-align: left;
  color: var(--muted);
  font-weight: 700;
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  white-space: nowrap;
}
.table td.right,
.table th.right { text-align: right; font-variant-numeric: tabular-nums; }

/* ═══════════════════════════════════════════════════════════════════
   VIEW TOGGLE
   ═══════════════════════════════════════════════════════════════════ */
.view-toggle {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  margin-bottom: var(--gap-md);
}
.view-toggle__btn {
  padding: 0 16px;
  height: 36px;
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--muted);
  text-decoration: none;
  background: transparent;
  transition: background 0.12s, color 0.12s;
  display: inline-flex;
  align-items: center;
  white-space: nowrap;
  border-right: 1px solid var(--border);
}
.view-toggle__btn:last-child { border-right: none; }
.view-toggle__btn:hover { background: var(--color-background-secondary); color: var(--text); text-decoration: none; }
.view-toggle__btn--active { background: var(--text); color: white; font-weight: 600; }

/* ═══════════════════════════════════════════════════════════════════
   FORMS
   ═══════════════════════════════════════════════════════════════════ */
.target-form {
  display: flex;
  flex-direction: column;
  gap: 1.4rem;
  max-width: 720px;
}
.form-group  { border: none; padding: 0; margin: 0; }
.form-row    { display: flex; gap: 1rem; flex-wrap: wrap; }
.form-field  { display: flex; flex-direction: column; gap: 0.3rem; flex: 1; min-width: 160px; }
.form-field--amount { max-width: 280px; }
.form-label  { font-size: var(--text-sm); font-weight: 600; color: var(--text); }
legend.form-label { margin-bottom: 0.5rem; }
.form-hint   { font-size: 12px; color: var(--muted); }
.form-actions {
  display: flex;
  gap: 0.75rem;
  align-items: center;
  padding-top: 0.5rem;
  flex-wrap: wrap;
}

input[type="text"],
input[type="number"],
input[type="date"],
input[type="week"],
input[type="month"],
input[type="password"],
input[type="email"],
select,
textarea {
  border: none;
  border-bottom: 1.5px solid #ccc;
  border-radius: 0;
  background: transparent;
  padding: 6px 2px;
  outline: none;
  width: 100%;
  transition: border-color 0.18s;
  font-family: inherit;
  font-size: 15px;
  color: inherit;
  -webkit-appearance: none;
  appearance: none;
}
input:focus, select:focus, textarea:focus { border-bottom-color: var(--brand); }

/* ═══════════════════════════════════════════════════════════════════
   MESSAGES & ALERTS
   ═══════════════════════════════════════════════════════════════════ */
.messages { margin-bottom: 1rem; display: flex; flex-direction: column; gap: 0.5rem; }
.message {
  padding: 0.65rem 1rem;
  border-radius: var(--radius-sm);
  font-size: var(--text-sm);
  font-weight: 500;
}
.message--success { background: var(--color-background-success); color: var(--color-text-success); border: 1px solid var(--color-border-success); }
.message--error   { background: var(--color-background-danger);  color: var(--color-text-danger);  border: 1px solid var(--color-border-danger);  }
.message--warning { background: var(--color-background-warning); color: var(--color-text-warning); border: 1px solid var(--color-border-warning); }
.message--info    { background: var(--color-background-info);    color: var(--color-text-info);    border: 1px solid var(--color-border-info);    }

.form-errors {
  padding: 0.75rem 1rem;
  background: var(--color-background-danger);
  border: 1px solid var(--color-border-danger);
  border-radius: var(--radius-sm);
  margin-bottom: 1rem;
}
.form-error, .field-error {
  font-size: 12px;
  color: var(--color-text-danger);
  margin: 0.2rem 0 0;
}
.form-notice {
  padding: 0.75rem 1rem;
  background: var(--color-background-warning);
  border: 1px solid var(--color-border-warning);
  border-radius: var(--radius-sm);
  font-size: var(--text-sm);
  color: var(--color-text-warning);
  margin-bottom: 1rem;
}

/* ═══════════════════════════════════════════════════════════════════
   PILLS & BADGES
   ═══════════════════════════════════════════════════════════════════ */
.pill.ok   { background: rgba(46,125,50,0.15); color: #1b5e20; }
.pill.warn { background: rgba(249,168,37,0.18); color: #5f3c00; }

.pill--purple { background: #EEEDFE; color: #3C3489; border-radius: 999px; padding: 0.15rem 0.65rem; font-size: 11px; font-weight: 600; white-space: nowrap; }
.pill--teal   { background: #E1F5EE; color: #085041; border-radius: 999px; padding: 0.15rem 0.65rem; font-size: 11px; font-weight: 600; white-space: nowrap; }
.pill--gray   { background: #F1EFE8; color: #444441; border-radius: 999px; padding: 0.15rem 0.65rem; font-size: 11px; font-weight: 600; white-space: nowrap; }

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
}
.badge--draft     { background: #f3f4f6; color: #374151; }
.badge--submitted { background: #dbeafe; color: #1e40af; }
.badge--approved  { background: #d1fae5; color: #065f46; }
.badge--locked    { background: #f3e8ff; color: #6b21a8; }

/* ═══════════════════════════════════════════════════════════════════
   BRANCH PICKER
   ═══════════════════════════════════════════════════════════════════ */
.branch-picker { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-bottom: var(--gap-md); }
.branch-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.3rem 0.85rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: var(--text-sm);
  color: var(--muted);
  text-decoration: none;
  background: var(--color-background-secondary);
  transition: border-color 0.12s, color 0.12s, background 0.12s;
  min-height: 34px;
}
/* FIX: was rgba(95,158,160,0.08) — teal. Now uses brand red tint. */
.branch-pill--active { border-color: var(--brand); color: var(--brand-dark); background: rgba(183,28,28,0.07); }
.branch-pill:hover { border-color: var(--muted); color: var(--text); text-decoration: none; }

/* ═══════════════════════════════════════════════════════════════════
   RADIO CARDS
   ═══════════════════════════════════════════════════════════════════ */
.radio-group { display: flex; gap: 0.75rem; flex-wrap: wrap; }
.radio-card {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.55rem 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: var(--text-sm);
  color: var(--muted);
  background: var(--color-background-secondary);
  min-height: 40px;
  user-select: none;
}
/* FIX: was rgba(95,158,160,0.08) — teal. Now uses brand red tint. */
.radio-card--active { border-color: var(--brand); color: var(--brand-dark); background: rgba(183,28,28,0.07); }

/* ═══════════════════════════════════════════════════════════════════
   REFUNDS LAYOUT
   ═══════════════════════════════════════════════════════════════════ */
.refunds-layout {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--gap-md);
  margin-bottom: var(--gap-md);
  align-items: start;
}
.refunds-summary     { display: flex; flex-direction: column; gap: var(--gap-sm); }
.refunds-table-card  { margin: 0; }

/* ═══════════════════════════════════════════════════════════════════
   MISC HELPERS
   ═══════════════════════════════════════════════════════════════════ */
.panel     { min-height: 100px; }
.skeleton  { color: var(--muted); font-size: var(--text-sm); padding: 2rem 0; text-align: center; }
.muted     { color: var(--muted); }
.small     { font-size: 12px; }
.right     { text-align: right; }
.text-muted { color: var(--muted); }
.num       { text-align: right; font-variant-numeric: tabular-nums; }

.empty-state { text-align: center; padding: 3rem 1rem; color: var(--muted); }
.empty-state p { margin-bottom: 1rem; }

.refresh-indicator {
  display: none;
  font-size: 12px;
  color: var(--muted);
  text-align: right;
  padding: 0.25rem 0;
}
.htmx-request .refresh-indicator,
.htmx-request.refresh-indicator { display: block; }

.target-section        { margin-bottom: 1.75rem; }
.target-section__header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin-bottom: 0.6rem;
}

/* ═══════════════════════════════════════════════════════════════════
   UTILITY CLASSES
   ═══════════════════════════════════════════════════════════════════ */
.flex            { display: flex; }
.flex-wrap       { flex-wrap: wrap; }
.items-center    { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-sm          { gap: var(--gap-sm); }
.gap-md          { gap: var(--gap-md); }

.text-right  { text-align: right; }
.text-danger { color: var(--color-text-danger); }
.text-sm     { font-size: var(--text-sm); }
.text-accent { color: var(--brand); }
.mono        { font-family: var(--font-mono); font-size: 12px; }

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-bottom: 1.25rem;
}
.page-title         { font-size: var(--text-xl); font-weight: 700; margin: 0; line-height: 1.25; }
.page-title span    { color: var(--brand); }
.page-subtitle      { font-size: var(--text-sm); color: var(--muted); margin: 0.2rem 0 0; }

.card-title {
  font-size: var(--text-md);
  font-weight: 650;
  color: var(--text);
  margin-bottom: 12px;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: var(--gap-md);
  margin-bottom: var(--gap-md);
}
.kpi-grid > .kpi {
  background: var(--card);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  padding: 12px 14px;
}
.kpi-grid > .kpi > .kpi-label {
  font-size: var(--text-xs); font-weight: 700; color: var(--muted);
  text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 4px;
}
.kpi-grid > .kpi > .kpi-value {
  font-size: var(--text-lg); font-weight: 800; color: var(--text);
}

.btn.btn-ghost   { background: transparent; color: var(--color-text-secondary); border-color: var(--color-border-primary); }
.btn.btn-sm      { height: 30px; padding: 0 0.7rem; font-size: 12px; }
.btn.btn-lg      { height: 44px; padding: 0 1.4rem; font-size: var(--text-base); }
.btn.btn-primary { background: var(--brand); color: white; border-color: transparent; }
.btn.btn-warning { background: var(--color-background-warning); color: var(--color-text-warning); border-color: var(--color-border-warning); }
.btn.btn-ok      { background: var(--color-background-success); color: var(--color-text-success); border-color: var(--color-border-success); }
.btn--ok         { background: var(--color-background-success); color: var(--color-text-success); border-color: var(--color-border-success); }

.msg         { padding: 0.65rem 1rem; border-radius: var(--radius-sm); font-size: var(--text-sm); font-weight: 500; margin-bottom: 1rem; }
.msg-success { background: var(--color-background-success); color: var(--color-text-success); border: 1px solid var(--color-border-success); }
.msg-error   { background: var(--color-background-danger);  color: var(--color-text-danger);  border: 1px solid var(--color-border-danger);  }
.msg-warning { background: var(--color-background-warning); color: var(--color-text-warning); border: 1px solid var(--color-border-warning); }
.msg-info    { background: var(--color-background-info);    color: var(--color-text-info);    border: 1px solid var(--color-border-info);    }

.badge-draft    { background: #f3f4f6; color: #374151; }
.badge-sub      { background: #dbeafe; color: #1e40af; }
.badge-approved { background: #d1fae5; color: #065f46; }
.badge-locked   { background: #f3e8ff; color: #6b21a8; }

hr.divider { border: none; border-top: 1px solid var(--border); margin: 1rem 0; }

/* ═══════════════════════════════════════════════════════════════════
   COLLAPSIBLE NAV GROUPS
   ═══════════════════════════════════════════════════════════════════ */
.nav-group {
  margin-bottom: 2px;
}

.nav-group__toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 6px 10px;
  background: none;
  border: none;
  cursor: pointer;
  font-family: inherit;
  font-size: var(--text-xs);
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  border-radius: var(--radius-xs);
  transition: background 0.12s, color 0.12s;
  user-select: none;
  min-height: 32px;
  margin-top: 4px;
}
/* FIX: was rgba(95,158,160,0.08) — teal. Now uses brand red tint. */
.nav-group__toggle:hover {
  background: rgba(183,28,28,0.08);
  color: var(--brand-dark);
}

.nav-group__chevron {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
  transition: transform 0.2s ease;
  opacity: 0.55;
}

.nav-group__body {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.22s ease;
}

.nav-group--open .nav-group__body {
  max-height: 600px;
}
.nav-group--open .nav-group__chevron {
  transform: rotate(90deg);
}

.nav-group__body .sidenav-link {
  padding-left: 18px;
}
.nav-group__body .sidenav-link.active {
  padding-left: 15px;
}

.sidenav-divider {
  height: 1px;
  background: var(--border-subtle);
  margin: 10px 6px;
}

/* ═══════════════════════════════════════════════════════════════════
   KPI VALUE COLOUR HELPERS
   ═══════════════════════════════════════════════════════════════════ */
.kpi-refund-deduction {
  color: var(--orange);
  font-weight: 700;
}
.kpi-deduction {
  color: var(--red);
}
/* FIX: fallback was #3a8a8c (teal). Now correctly falls back to brand-dark red. */
.kpi-net-value {
  font-weight: 700;
  color: var(--brand-dark, #7f1111);
}
.kpi-pos {
  color: var(--green);
}
.kpi-neg {
  color: var(--red);
}
.kpi-warn {
  color: var(--orange);
}

/* ═══════════════════════════════════════════════════════════════════
   SYSTEM ADMIN PANEL
   ═══════════════════════════════════════════════════════════════════ */
.admin-summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 10px;
  margin-bottom: 20px;
}

.admin-stat-card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px 16px;
  border-top: 3px solid var(--brand);
}

.admin-stat-label {
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin-bottom: 4px;
}

.admin-stat-value {
  font-size: 26px;
  font-weight: 800;
  line-height: 1.1;
  color: var(--text);
}

.admin-role-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
}
.admin-role-exe { background: #fde8d8; color: #b45309; }
.admin-role-ops { background: #dbeafe; color: #1e40af; }
.admin-role-mgr { background: #d1fae5; color: #065f46; }
.admin-role-rep { background: #f3f4f6; color: #374151; }
.admin-role-glv { background: #ede9fe; color: #5b21b6; }

.admin-status-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
}
.admin-status-active   { background: var(--color-background-success); color: var(--color-text-success); }
.admin-status-inactive { background: var(--color-background-secondary); color: var(--muted); }

.admin-panel input:focus,
.admin-panel select:focus {
  outline: 2px solid var(--brand);
  outline-offset: 1px;
}

/* ═══════════════════════════════════════════════════════════════════
   EXECUTIVE DASHBOARD — cashflow + leaders + KPI strip + charts
   ═══════════════════════════════════════════════════════════════════ */
.exec-cashflow-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 16px;
}

.exec-cashflow-card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px 18px;
  border-top: 4px solid var(--brand);
  min-width: 0;
}

.exec-cashflow-card--week  { border-top-color: #1565c0; }
.exec-cashflow-card--month { border-top-color: #2e7d32; }
.exec-cashflow-card--period{ border-top-color: #e65100; }

.exec-cashflow-period {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin-bottom: 6px;
  font-weight: 700;
}

.exec-cashflow-value {
  font-size: 24px;
  font-weight: 800;
  line-height: 1.15;
  letter-spacing: -0.02em;
  color: var(--text);
  margin-bottom: 4px;
  font-variant-numeric: tabular-nums;
}

.exec-cashflow-sub {
  font-size: 11px;
  color: var(--muted);
  margin-top: 2px;
}

.exec-leaders-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.exec-leaders-card {
  min-width: 0;
}

.exec-kpi-strip {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 10px;
  margin-bottom: 16px;
}

.exec-kpi-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  min-width: 0;
}

.exec-kpi-card--alert {
  border-left: 4px solid var(--red);
}

.exec-kpi-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin-bottom: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.exec-kpi-value {
  font-size: 22px;
  font-weight: 700;
  line-height: 1.2;
  letter-spacing: -0.02em;
  color: var(--text);
  margin-bottom: 3px;
}

.exec-kpi-sub {
  font-size: 11px;
  color: var(--muted);
}

.exec-chart-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin-bottom: 16px;
}

.exec-chart-card--wide {
  grid-column: 1 / -1;
}

.exec-chart-card {
  min-width: 0;
}

.exec-chart-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 10px;
  flex-wrap: wrap;
  gap: 4px;
}

.exec-chart-header h3 {
  margin: 0;
  font-size: 14px;
}

.exec-chart-wrap {
  position: relative;
  height: 200px;
}

.exec-period-btn.active,
.exec-period-btn[style*="font-weight: 700"] {
  background: var(--brand);
  color: #fff;
}

/* ═══════════════════════════════════════════════════════════════════
   RESPONSIVE — Large tablet ≤ 980px
   ═══════════════════════════════════════════════════════════════════ */
@media (max-width: 980px) {

  .nav-toggle { display: flex; }

  .sidenav {
    position: fixed;
    top: 0;
    left: 0;
    height: 100dvh;
    width: 272px;
    z-index: 100;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    border-radius: 0;
    border-right: 1px solid var(--border);
    padding-top: 64px;
    box-shadow: none;
  }
  .sidenav--open {
    transform: translateX(0);
    box-shadow: 4px 0 28px rgba(16,33,43,0.18);
  }

  .app-shell { grid-template-columns: 1fr; }
  .main      { padding: 16px 14px; }
}

/* ═══════════════════════════════════════════════════════════════════
   RESPONSIVE — Tablet ≤ 860px
   ═══════════════════════════════════════════════════════════════════ */
@media (max-width: 860px) {
  .grid-3 { grid-template-columns: repeat(2, minmax(0,1fr)); }

  .page-head { align-items: flex-start; flex-direction: column; }
  .page-head__actions { width: 100%; }
  .page-head__actions .btn { flex: 1; justify-content: center; }

  .refunds-layout { grid-template-columns: 1fr; }

  .page-header { flex-direction: column; align-items: flex-start; }
}

/* ═══════════════════════════════════════════════════════════════════
   RESPONSIVE — Tablet ≤ 768px
   ═══════════════════════════════════════════════════════════════════ */
@media (max-width: 768px) {
  .exec-chart-grid {
    grid-template-columns: 1fr;
  }
  .exec-chart-card--wide {
    grid-column: auto;
  }
  .exec-kpi-strip {
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  }
  .exec-kpi-value {
    font-size: 18px;
  }
  .exec-chart-wrap {
    height: 180px;
  }
  .exec-cashflow-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  .exec-leaders-grid {
    grid-template-columns: 1fr;
  }
}

/* ═══════════════════════════════════════════════════════════════════
   RESPONSIVE — Mobile ≤ 640px
   ═══════════════════════════════════════════════════════════════════ */
@media (max-width: 640px) {
  h1 { font-size: 18px; }
  h3 { font-size: var(--text-base); }

  .topbar  { padding: 12px 14px; }
  .main    { padding: 12px 10px; }
  .card    { padding: 12px 10px; }
  .kpi-card { padding: 12px 10px; }

  .grid, .grid-2, .grid-3 { grid-template-columns: 1fr; }

  .kpi-row   { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .kpi-value { font-size: var(--text-md); }
  .kpi-label { white-space: normal; }

  .kpi-grid { grid-template-columns: repeat(2, 1fr); }

  .date-form { flex-direction: column; align-items: stretch; }
  .date-form input { width: 100%; }
  .date-form .btn  { width: 100%; }

  .form-actions { flex-direction: column; align-items: stretch; }
  .form-actions .btn { width: 100%; justify-content: center; }

  .form-field { min-width: 100%; }
  .form-field--amount { max-width: 100%; }
  .form-row { flex-direction: column; gap: 0.75rem; }

  .view-toggle { display: flex; width: 100%; }
  .view-toggle__btn { flex: 1; justify-content: center; padding: 0 10px; }

  .radio-group { flex-direction: column; gap: 0.4rem; }
  .radio-card  { width: 100%; }

  .branch-picker { gap: 0.35rem; }
  .branch-pill   { font-size: 12px; padding: 0.25rem 0.7rem; }

  .data-table th { padding: 8px 10px; font-size: 10px; }
  .data-table td { padding: 9px 10px; font-size: 12px; }
  .data-table td { overflow-wrap: break-word; word-break: break-word; }

  .table th, .table td { padding: 8px 6px; font-size: 12px; }

  .page-header { flex-direction: column; align-items: flex-start; }

  .table-action-group { flex-wrap: wrap !important; }
}

/* ═══════════════════════════════════════════════════════════════════
   RESPONSIVE — Topbar pills ≤ 480px
   ═══════════════════════════════════════════════════════════════════ */
@media (max-width: 480px) {
  .topbar .user .pill:first-child:not(:last-child):not(:nth-last-child(2)) { display: none; }
  .topbar .user .pill:nth-child(3) { display: none; }

  .exec-kpi-strip {
    grid-template-columns: 1fr 1fr;
  }
  .exec-kpi-value {
    font-size: 15px;
  }
  .exec-chart-wrap {
    height: 160px;
  }
  .exec-cashflow-grid {
    grid-template-columns: 1fr 1fr;
  }
  .exec-cashflow-value {
    font-size: 18px;
  }
}

/* ═══════════════════════════════════════════════════════════════════
   RESPONSIVE — Extra small ≤ 380px
   ═══════════════════════════════════════════════════════════════════ */
@media (max-width: 380px) {
  h1 { font-size: 16px; }
  .kpi-value { font-size: var(--text-base); }
  .kpi-label { font-size: 10px; }
  .kpi-row   { grid-template-columns: 1fr; }
  .kpi-grid  { grid-template-columns: 1fr; }
  .card, .kpi-card { padding: 10px 8px; }
  .data-table th, .data-table td { padding: 7px 8px; }
}

/* ═══════════════════════════════════════════════════════════════════
   TOUCH ENHANCEMENTS
   ═══════════════════════════════════════════════════════════════════ */
@media (hover: none) and (pointer: coarse) {
  .btn           { min-height: 44px; }
  .sidenav-link  { min-height: 44px; }
  .radio-card    { min-height: 44px; }
  .data-table tbody tr:hover td { background: transparent; }
  .sidenav-link:hover            { background: transparent; color: var(--text); }
}

/* ═══════════════════════════════════════════════════════════════════
   RESPONSIVE — Boardroom ≥ 1600px
   ═══════════════════════════════════════════════════════════════════ */
@media (min-width: 1600px) {
  .exec-chart-grid {
    grid-template-columns: repeat(3, 1fr);
  }
  .exec-kpi-strip {
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  }
  .exec-chart-wrap {
    height: 240px;
  }
}

/* ── Fluid table improvements ── */
.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

@media (max-width: 600px) {
  .data-table.data-table--responsive thead {
    display: none;
  }
  .data-table.data-table--responsive tr {
    display: block;
    border: 1px solid var(--border);
    border-radius: var(--radius-xs);
    margin-bottom: 8px;
    padding: 8px 10px;
  }
  .data-table.data-table--responsive td {
    display: flex;
    justify-content: space-between;
    padding: 4px 0;
    border: none;
  }
  .data-table.data-table--responsive td::before {
    content: attr(data-label);
    font-weight: 600;
    color: var(--muted);
    font-size: 11px;
    flex-shrink: 0;
    margin-right: 8px;
  }
}