/* ═══════════════════════════════════════════════════════════════════════════
   Mellow Labs Financials
   Tokens first; every colour below should come from them. Money colours have
   two roles: *marks* (bars, dots, fills — --income / --expense) and *text*
   (--income-text / --expense-text), because the bright mark greens fail text
   contrast on white.
   ═══════════════════════════════════════════════════════════════════════════ */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --sidebar-w:      240px;
  --sidebar-bg:     #0f172a;
  --sidebar-border: #1e293b;
  --nav-text:       #94a3b8;
  --nav-icon:       #7c8aa0;
  --nav-active:     #f8fafc;
  --nav-hover-bg:   rgba(148, 163, 184, .09);
  --nav-active-bg:  rgba(56, 189, 248, .14);

  --accent:         #38bdf8;   /* brand sky: fills, focus, progress */
  --accent-hover:   #1eb0f0;
  --accent-text:    #0369a1;   /* sky as text on white (≥ 4.5:1) */
  --accent-soft:    #e0f2fe;
  --focus-ring:     0 0 0 3px rgba(56, 189, 248, .28);

  --bg:             #f1f5f9;
  --card-bg:        #ffffff;
  --surface-2:      #f8fafc;
  --hover-bg:       #f5f8fc;
  --seg-bg:         #e6ebf2;
  --border:         #e2e8f0;
  --border-soft:    #eef2f6;
  --border-strong:  #cbd5e1;

  --text:           #0f172a;
  --text-2:         #334155;
  --text-muted:     #64748b;   /* 4.8:1 on white — the lightest readable text */
  --text-faint:     #94a3b8;   /* placeholders, dashes, decoration only */

  --income:         #059669;
  --income-text:    #047857;
  --income-bg:      #ecfdf5;
  --income-border:  #a7f3d0;
  --expense:        #ef4444;
  --expense-text:   #dc2626;
  --expense-bg:     #fef2f2;
  --expense-border: #fecaca;
  --pending:        #b45309;
  --pending-bg:     #fffbeb;
  --pending-border: #fde68a;

  /* Widest the page content grows to before it centres in the viewport.
     Roomy enough for the 12-column summary table on a 1080p+ monitor. */
  --content-max: 1760px;

  --radius:    8px;
  --radius-lg: 12px;
  --shadow:    0 1px 2px rgba(15, 23, 42, .05), 0 1px 3px rgba(15, 23, 42, .04);
  --shadow-md: 0 6px 16px rgba(15, 23, 42, .08), 0 2px 4px rgba(15, 23, 42, .04);
  --shadow-lg: 0 24px 60px rgba(15, 23, 42, .22);
}

/* Collapsed width lives on <html> so both the sidebar and the main column pick
   it up from the same custom property. */
:root.nav-collapsed { --sidebar-w: 68px; }

html, body {
  height: 100%;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 14px;
  line-height: 1.45;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

.icon {
  width: 1em;
  height: 1em;
  flex-shrink: 0;
  display: inline-block;
  vertical-align: -0.125em;
}

.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

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

/* ── Layout ──────────────────────────────────────────────────────────────── */
body { display: flex; }

.sidebar {
  position: fixed;
  top: 0; left: 0; bottom: 0;
  width: var(--sidebar-w);
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  overflow: hidden;                 /* the inner .sidebar-scroll scrolls instead */
  z-index: 100;
  border-right: 1px solid var(--sidebar-border);
  transition: width .22s ease;
}

/* A flex item defaults to min-width:auto, so a table wider than the viewport
   would push .main itself wider and scroll the WHOLE PAGE sideways. min-width:0
   lets it shrink, so an oversized table scrolls inside its own .table-scroll. */
.main {
  margin-left: var(--sidebar-w);
  flex: 1;
  min-width: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  transition: margin-left .22s ease;
}

.page-content {
  flex: 1;
  width: 100%;
  min-width: 0;
  max-width: min(var(--content-max), 100%);
  margin: 0 auto;
  padding: 28px 32px 40px;
}

@media (prefers-reduced-motion: reduce) {
  .sidebar, .main { transition: none; }
}

/* ── Sidebar ─────────────────────────────────────────────────────────────── */
.sidebar-header {
  position: relative;
  padding: 18px 44px 16px 18px;
  border-bottom: 1px solid var(--sidebar-border);
}

.sidebar-logo { display: flex; align-items: center; gap: 10px; }

.logo-mark {
  width: 30px;
  height: 30px;
  border-radius: 9px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: #fff;
  background: linear-gradient(135deg, #38bdf8 0%, #6366f1 100%);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .18);
}
.logo-mark svg { width: 17px; height: 17px; }

.logo-words { display: flex; flex-direction: column; min-width: 0; line-height: 1.2; }

.logo-text {
  font-size: 15px;
  font-weight: 700;
  color: #f8fafc;
  letter-spacing: .1px;
  white-space: nowrap;
}

.sidebar-sub {
  font-size: 10.5px;
  color: var(--nav-text);
  letter-spacing: .9px;
  text-transform: uppercase;
}

.sidebar-toggle {
  position: absolute;
  top: 20px;
  right: 10px;
  width: 26px;
  height: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  border-radius: 6px;
  color: var(--nav-text);
  cursor: pointer;
  transition: background .15s, color .15s;
}
.sidebar-toggle:hover { background: var(--nav-hover-bg); color: #f1f5f9; }

/* Nav list scrolls; header, Settings and the version footer stay pinned. */
.sidebar-scroll {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-width: thin;
  scrollbar-color: #1e293b transparent;
  padding-bottom: 8px;
}
.sidebar-scroll::-webkit-scrollbar       { width: 6px; }
.sidebar-scroll::-webkit-scrollbar-thumb { background: #1e293b; border-radius: 3px; }

.sidebar-section { padding: 14px 0 2px; }

.sidebar-label {
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 1.1px;
  color: #56657b;
  padding: 0 22px 6px;
  text-transform: uppercase;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 1px 10px;
  padding: 8px 12px;
  border-radius: 8px;
  color: var(--nav-text);
  text-decoration: none;
  font-size: 13.5px;
  font-weight: 500;
  transition: background .15s, color .15s;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.nav-item:hover { background: var(--nav-hover-bg); color: #e2e8f0; }
.nav-item:hover .nav-icon { color: #cbd5e1; }
.nav-item.active { background: var(--nav-active-bg); color: var(--nav-active); font-weight: 600; }
.nav-item.active .nav-icon { color: var(--accent); }

.nav-icon {
  width: 18px;
  height: 18px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: var(--nav-icon);
}
.nav-icon .icon { width: 17px; height: 17px; }

/* Income / expense pages: a coloured dot (initials when the rail is collapsed) */
.nav-dot::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
}
.nav-icon.income-dot,
.nav-item.active .nav-icon.income-dot  { color: #34d399; }
.nav-icon.expense-dot,
.nav-item.active .nav-icon.expense-dot { color: #f87171; }

.sidebar-bottom {
  margin-top: auto;
  padding: 6px 0;
  border-top: 1px solid var(--sidebar-border);
}

.sidebar-footer {
  padding: 10px 22px 12px;
  font-size: 11px;
  color: #3d4a5e;
  border-top: 1px solid var(--sidebar-border);
}

/* ── Collapsed rail (desktop only — phones keep the slide-over drawer) ──── */
@media (min-width: 768px) {
  :root.nav-collapsed .logo-words,
  :root.nav-collapsed .nav-label,
  :root.nav-collapsed .sidebar-footer { display: none; }

  :root.nav-collapsed .sidebar-header { padding: 14px 0 10px; }
  :root.nav-collapsed .sidebar-logo   { justify-content: center; gap: 0; }

  /* Group headings become hairline dividers. */
  :root.nav-collapsed .sidebar-label {
    font-size: 0;
    line-height: 0;
    padding: 0;
    margin: 8px 16px;
    border-top: 1px solid var(--sidebar-border);
  }

  :root.nav-collapsed .sidebar-section { padding: 6px 0 2px; }

  :root.nav-collapsed .nav-item {
    justify-content: center;
    gap: 0;
    margin: 2px 12px;
    padding: 9px 0;
  }

  /* The dot tells you nothing once the labels are gone — show the page's
     initials instead. */
  :root.nav-collapsed .nav-dot::before { display: none; }
  :root.nav-collapsed .nav-dot::after {
    content: attr(data-abbr);
    font-size: 10.5px;
    font-weight: 700;
    letter-spacing: .4px;
  }

  :root.nav-collapsed .sidebar-toggle {
    position: static;
    margin: 10px auto 0;
    transform: rotate(180deg);
  }

  /* Fluid gutters: tight on a laptop, generous on a 1440p+ panel. */
  .page-content { padding: clamp(18px, 1.8vw, 34px) clamp(18px, 2.2vw, 48px) 40px; }
}

/* ── Rail tooltip ───────────────────────────────────────────────────────── */
.nav-tip {
  position: fixed;
  left: 0;
  top: 0;
  z-index: 500;
  padding: 6px 10px;
  border-radius: 6px;
  background: #1e293b;
  border: 1px solid #334155;
  color: #f1f5f9;
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
  box-shadow: 0 4px 14px rgba(0, 0, 0, .35);
  pointer-events: none;
  opacity: 0;
  transform: translateX(-4px);
  transition: opacity .12s ease, transform .12s ease;
}
.nav-tip.visible { opacity: 1; transform: translateX(0); }

/* ── Mobile top bar (hidden on desktop) + drawer overlay ─────────────────── */
.mobile-topbar {
  display: none;
  align-items: center;
  gap: 10px;
  padding: 0 12px;
  height: 54px;
  background: var(--sidebar-bg);
  border-bottom: 1px solid var(--sidebar-border);
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 150;
}

.mobile-logo { display: flex; align-items: center; gap: 9px; }
.mobile-logo .logo-mark { width: 26px; height: 26px; border-radius: 8px; }
.mobile-logo .logo-mark svg { width: 15px; height: 15px; }

.hamburger {
  background: none;
  border: none;
  cursor: pointer;
  padding: 10px 8px;
  display: flex;
  flex-direction: column;
  gap: 5px;
  border-radius: 8px;
}
.hamburger span {
  display: block;
  width: 20px;
  height: 2px;
  background: #94a3b8;
  border-radius: 2px;
  transition: background .15s;
}
.hamburger:hover span { background: #f1f5f9; }

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, .5);
  z-index: 160;
  opacity: 0;
  transition: opacity .25s;
  pointer-events: none;
}
.sidebar-overlay.visible { opacity: 1; pointer-events: auto; }

/* ── Page header ─────────────────────────────────────────────────────────── */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  min-height: 36px;
  margin-bottom: 20px;
}

.page-title {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -.015em;
  color: var(--text);
}

.page-actions { display: flex; flex-wrap: wrap; gap: 8px; }

.badge {
  display: inline-flex;
  align-items: center;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .01em;
  padding: 2px 9px;
  border-radius: 999px;
  border: 1px solid transparent;
  white-space: nowrap;
}
.badge.income  { background: var(--income-bg);  color: var(--income-text);  border-color: var(--income-border); }
.badge.expense { background: var(--expense-bg); color: var(--expense-text); border-color: var(--expense-border); }

/* ── Buttons ─────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  height: 34px;
  padding: 0 14px;
  border-radius: 8px;
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  line-height: 1;
  white-space: nowrap;
  cursor: pointer;
  border: 1px solid transparent;
  transition: background .15s, border-color .15s, color .15s, box-shadow .15s;
}
.btn .icon { width: 15px; height: 15px; }
.btn:disabled { opacity: .55; cursor: not-allowed; }

.btn-primary { background: var(--accent); color: #0b1220; border-color: var(--accent); }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); border-color: var(--accent-hover); }

.btn-secondary { background: var(--card-bg); color: var(--text-2); border-color: var(--border); box-shadow: 0 1px 1px rgba(15, 23, 42, .03); }
.btn-secondary:hover:not(:disabled) { background: var(--surface-2); border-color: var(--border-strong); color: var(--text); }

.btn-ghost { background: transparent; color: var(--text-muted); border-color: transparent; }
.btn-ghost:hover:not(:disabled) { background: #eef2f6; color: var(--text); }

.btn-danger { background: var(--card-bg); color: var(--expense-text); border-color: var(--expense-border); }
.btn-danger:hover:not(:disabled) { background: var(--expense-bg); }

.btn-sm { height: 28px; padding: 0 10px; font-size: 12px; border-radius: 7px; }

.btn-icon {
  width: 30px;
  height: 30px;
  padding: 0;
  border-radius: 8px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background .12s, color .12s, border-color .12s, opacity .12s;
}
.btn-icon .icon { width: 16px; height: 16px; }
.btn-icon:hover { background: #eef2f6; color: var(--text); }
.btn-icon.danger:hover { background: var(--expense-bg); color: var(--expense-text); }
.btn-icon:disabled { opacity: .45; cursor: not-allowed; }
.btn-icon.spinning .icon { animation: spin .8s linear infinite; }
a.btn-icon { text-decoration: none; }

/* ── Form fields ─────────────────────────────────────────────────────────── */
.range-custom input,
.sponsor-add-bar input[type="text"],
.settings-input-row input,
.settings-field > input,
.modal-input,
.modal-sponsor-row select,
.modal-sponsor-row input,
#modal-release-date,
#fs-modal-overlay .modal-body input[type="text"],
#fs-modal-overlay .modal-body input[type="number"],
#fs-modal-overlay .modal-body textarea {
  width: 100%;
  height: 36px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--card-bg);
  color: var(--text);
  font-family: inherit;
  font-size: 13px;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}

#fs-modal-overlay .modal-body textarea { height: auto; min-height: 60px; padding: 8px 12px; resize: vertical; }

.range-custom input:focus,
.sponsor-add-bar input[type="text"]:focus,
.settings-input-row input:focus,
.settings-field > input:focus,
.modal-input:focus,
.modal-sponsor-row select:focus,
.modal-sponsor-row input:focus,
#modal-release-date:focus,
#fs-modal-overlay .modal-body input:focus,
#fs-modal-overlay .modal-body textarea:focus { border-color: var(--accent); box-shadow: var(--focus-ring); }

::placeholder { color: var(--text-faint); }

.search-box {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 34px;
  padding: 0 10px;
  flex: 0 1 320px;
  min-width: 200px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--card-bg);
  color: var(--text-muted);
  transition: border-color .15s, box-shadow .15s;
}
.search-box:focus-within { border-color: var(--accent); box-shadow: var(--focus-ring); }
.search-box .icon { width: 15px; height: 15px; }
.search-box input {
  flex: 1;
  min-width: 0;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
  font-family: inherit;
  font-size: 13px;
}

/* ── Segmented control (date presets, financial-year tabs) ───────────────── */
.seg,
.fy-tabs {
  display: flex;
  gap: 2px;
  padding: 3px;
  width: max-content;
  max-width: 100%;
  background: var(--seg-bg);
  border-radius: 10px;
  overflow-x: auto;
  scrollbar-width: none;
}
.seg::-webkit-scrollbar,
.fy-tabs::-webkit-scrollbar { display: none; }

.seg-btn,
.fy-tab {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
  padding: 6px 12px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--text-muted);
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
  transition: background .12s, color .12s, box-shadow .12s;
}
.seg-btn:hover,
.fy-tab:hover { color: var(--text); }

.seg-btn.active,
.fy-tab.active {
  background: var(--card-bg);
  color: var(--text);
  box-shadow: 0 1px 2px rgba(15, 23, 42, .1), 0 0 0 1px rgba(15, 23, 42, .04);
}

/* ── Stat cards ──────────────────────────────────────────────────────────── */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 14px;
  margin-bottom: 24px;
}
.stat-grid:empty { display: none; }
.stat-grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.stat-grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.stat-grid-5 { grid-template-columns: repeat(5, minmax(0, 1fr)); }

@media (max-width: 1180px) {
  .stat-grid-4,
  .stat-grid-5 { grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); }
}

.stat-card {
  min-width: 0;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px 18px;
  box-shadow: var(--shadow);
}

.stat-label {
  font-size: 12.5px;
  font-weight: 500;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.stat-value {
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -.01em;
  line-height: 1.2;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.stat-value-sm { font-size: 19px; }
.stat-value.income,
.stat-value.positive { color: var(--income-text); }
.stat-value.expense,
.stat-value.negative { color: var(--expense-text); }
.stat-value.pending  { color: var(--pending); }

.stat-meta {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 6px;
  font-size: 12px;
  color: var(--text-muted);
}

.delta {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: 12px;
  font-weight: 600;
  padding: 1px 8px;
  border-radius: 999px;
  font-variant-numeric: tabular-nums;
}
.delta.good { color: var(--income-text);  background: var(--income-bg); }
.delta.bad  { color: var(--expense-text); background: var(--expense-bg); }
.delta.flat { color: var(--text-muted);   background: #f1f5f9; }

/* Two labelled groups of three ("this year so far" / "all time") */
.stat-groups {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 460px), 1fr));
  gap: 14px 20px;
  margin-bottom: 24px;
}
.stat-groups .stat-grid { margin-bottom: 0; }

.stat-group-title {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 4px 8px;
  margin: 0 0 8px 2px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-2);
}
.stat-group-note { font-size: 12px; font-weight: 400; color: var(--text-muted); }

/* ── Charts ──────────────────────────────────────────────────────────────── */
.chart-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 380px), 1fr));
  gap: 20px;
  margin-bottom: 24px;
}

/* Hold charts to two per row — auto-fit would give four squashed panels on a
   wide monitor. */
@media (min-width: 1100px) {
  .chart-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

.chart-card-wide { grid-column: 1 / -1; }

.chart-card {
  min-width: 0;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px 20px 16px;
  box-shadow: var(--shadow);
}

.chart-card-title {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 12px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}
.chart-card-note { font-size: 12px; font-weight: 400; color: var(--text-muted); }

.chart-canvas-wrap { position: relative; height: 260px; }

@media (min-width: 768px) {
  /* Charts grow with the viewport instead of sitting at a fixed height. */
  .chart-canvas-wrap { height: clamp(240px, 27vh, 340px); }
  .chart-canvas-wrap.chart-canvas-tall { height: clamp(260px, 32vh, 380px); }
}

/* Ranked share bars (plain HTML) */
.share-bars { display: flex; flex-direction: column; gap: 14px; padding-top: 2px; }

.share-head {
  display: flex;
  align-items: baseline;
  gap: 10px;
  margin-bottom: 6px;
  font-size: 13px;
}
.share-label {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text-2);
  font-weight: 500;
}
.share-value { font-weight: 600; color: var(--text); font-variant-numeric: tabular-nums; }
.share-pct {
  width: 38px;
  text-align: right;
  color: var(--text-muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}
.share-track { height: 10px; }
.share-fill { height: 100%; border-radius: 0 4px 4px 0; }   /* square at the baseline */
.share-fill.income  { background: var(--income); }
.share-fill.expense { background: var(--expense); }
.share-empty { color: var(--text-muted); font-size: 13px; padding: 8px 0; }

/* Previous render stays visible, dimmed, while a new range loads */
.is-refreshing { opacity: .5; pointer-events: none; transition: opacity .15s; }

/* ── Date range bar ──────────────────────────────────────────────────────── */
.range-bar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px 16px;
  margin-bottom: 20px;
}
.range-custom { display: flex; align-items: center; gap: 6px; }
.range-custom input { width: 124px; height: 32px; cursor: pointer; }
.range-separator { color: var(--text-faint); font-size: 13px; }
.range-caption { margin-left: auto; font-size: 12.5px; color: var(--text-muted); }

/* ── Tables ──────────────────────────────────────────────────────────────── */
.table-card {
  position: relative;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  overflow: hidden;
  margin-bottom: 24px;
}

.table-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 6px 12px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
}
.table-card-title { font-size: 14px; font-weight: 600; color: var(--text); }
.table-card-note  { font-size: 12px; color: var(--text-muted); }

.table-scroll {
  overflow: auto;
  max-height: min(72vh, 900px);
}

.sheet-toolbar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px 14px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
}
.toolbar-count { font-size: 12.5px; color: var(--text-muted); font-variant-numeric: tabular-nums; }
.toolbar-hint  { margin-left: auto; font-size: 12px; color: var(--text-muted); }

/* Data tables — shared chrome. Summary, editable sheet and transaction tables
   all wear the same header, dividers, hover, padding and sort affordances; the
   per-table blocks below add only what is genuinely different. */
table.summary,
table.sheet-table,
table.txn-table {
  width: 100%;
  min-width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

table.summary thead,
table.sheet-table thead,
table.txn-table thead {
  position: sticky;
  top: 0;
  z-index: 2;
}

table.summary thead th,
table.sheet-table thead th,
table.txn-table thead th {
  position: relative;
  padding: 10px 14px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .04em;
  text-transform: uppercase;
  text-align: left;
  white-space: nowrap;
  user-select: none;
}

table.summary td,
table.sheet-table td,
table.txn-table td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border-soft);
  color: var(--text);
  vertical-align: middle;
}

table.summary tbody tr:last-child td,
table.sheet-table tbody tr:last-child td,
table.txn-table tbody tr:last-child td { border-bottom: 0; }

table.summary tbody tr,
table.sheet-table tbody tr,
table.txn-table tbody tr { transition: background .1s; }

table.summary tbody tr:hover,
table.sheet-table tbody tr:hover,
table.txn-table tbody tr:hover { background: var(--hover-bg); }

/* Numbers right-align and never wrap, in every table */
table.summary th.num,  table.summary td.num,
table.sheet-table th.num, table.sheet-table td.num,
table.txn-table th.num, table.txn-table td.num {
  text-align: right;
  white-space: nowrap;
}

/* Date columns stay on one line and keep a stable width */
th.col-date, td.col-date { white-space: nowrap; min-width: 104px; }

/* Sortable headers — the arrow only appears on hover, focus or when sorted */
th.th-sort { cursor: pointer; transition: color .12s, background .12s; }
th.th-sort:hover { color: var(--text); background: #f1f5f9; }
th.th-sort.sorted { color: var(--text); }
th.th-sort:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }

.sort-arrow {
  display: inline-block;
  margin-left: 2px;
  font-size: 10px;
  opacity: 0;
  transition: opacity .12s;
}
th.th-sort:hover .sort-arrow,
th.th-sort:focus-visible .sort-arrow { opacity: .45; }
.sort-arrow.active,
th.th-sort:hover .sort-arrow.active { opacity: 1; color: var(--accent-text); }

/* Actions column: shrink to fit its buttons and keep them on one line, however
   many there are (`width:1%` is the shrink-to-fit idiom for table cells). */
table.summary th.col-actions,  table.summary td.col-actions,
table.sheet-table th.col-actions, table.sheet-table td.col-actions,
table.txn-table th.col-actions, table.txn-table td.col-actions {
  width: 1%;
  white-space: nowrap;
  text-align: right;
  padding-left: 8px;
  padding-right: 10px;
}
.col-actions .btn-icon + .btn-icon { margin-left: 2px; }
/* The buttons are shorter than a row; padding them too would make every row taller. */
table.sheet-table td.col-actions,
table.txn-table td.col-actions { padding-top: 0; padding-bottom: 0; }

/* Row actions appear on hover or keyboard focus where there is a mouse;
   touch screens always show them. */
@media (hover: hover) {
  table.sheet-table tbody tr .col-actions .btn-icon { opacity: 0; }
  table.sheet-table tbody tr:hover .col-actions .btn-icon,
  table.sheet-table tbody tr:focus-within .col-actions .btn-icon { opacity: 1; }
}

/* ── Summary table specifics ─────────────────────────────────────────────── */
table.summary { white-space: nowrap; }
table.summary thead th { text-align: right; }
table.summary thead th:first-child { text-align: left; }
table.summary td { text-align: right; }

table.summary td:first-child {
  text-align: left;
  font-weight: 600;
  color: var(--text);
  min-width: 96px;
}

/* A faint zebra helps follow a row across twelve columns */
table.summary:not(.fy-breakdown) tbody tr:nth-child(even) { background: #fbfcfe; }
table.summary:not(.fy-breakdown) tbody tr:hover { background: var(--hover-bg); }

/* Many-column summaries scroll sideways — pin the period label so a row stays
   readable however far right you scroll. (Not the 2-column FY breakdown.) */
table.summary:not(.fy-breakdown) th:first-child,
table.summary:not(.fy-breakdown) td:first-child {
  position: sticky;
  left: 0;
  z-index: 1;
  background: var(--card-bg);
  box-shadow: 1px 0 0 var(--border);
}
table.summary:not(.fy-breakdown) thead th:first-child { z-index: 3; background: var(--surface-2); }
table.summary:not(.fy-breakdown) tbody tr:nth-child(even) td:first-child { background: #fbfcfe; }
table.summary:not(.fy-breakdown) tbody tr:hover td:first-child { background: var(--hover-bg); }

/* Sources in plain ink; colour is saved for the totals and the net */
table.summary td.income-val,
table.summary td.expense-val { color: var(--text-2); }
table.summary td[class=""] { color: var(--text-faint); }
table.summary td.total-col         { font-weight: 700; color: var(--income-text);  background: rgba(236, 253, 245, .75) !important; }
table.summary td.total-expense-col { font-weight: 700; color: var(--expense-text); background: rgba(254, 242, 242, .75) !important; }
table.summary td.net-pos { font-weight: 700; color: var(--income-text); }
table.summary td.net-neg { font-weight: 700; color: var(--expense-text); }

@media (min-width: 768px) {
  /* The 12-column summary used to force a sideways scroll on anything under
     ~1500px purely because every heading was nowrap. Letting headings wrap
     costs a second header line only when the width is genuinely tight —
     auto table layout still keeps them on one line when there is room. */
  table.summary thead th {
    white-space: normal;
    line-height: 1.25;
    vertical-align: bottom;
  }

  /* Every column but the period label is numeric — keep enough room for a
     £00,000.00 value so wrapping headings do not crush them. */
  table.summary thead th + th { min-width: 80px; }

  /* Gutters shrink with the viewport before the table gives up and scrolls. */
  table.summary thead th,
  table.summary td { padding: 10px clamp(8px, .62vw, 14px); }

  table.summary { font-size: clamp(12px, .8vw, 13px); }
}

/* ── Editable sheet table ────────────────────────────────────────────────── */
.col-resize-handle {
  position: absolute;
  right: 0;
  top: 0;
  bottom: 0;
  width: 5px;
  cursor: col-resize;
  z-index: 1;
}
.col-resize-handle:hover,
.col-resize-handle.resizing { background: rgba(56, 189, 248, .45); }

/* Source row number — narrow, muted, always the first column */
table.sheet-table th.col-row-no { width: 52px; text-align: center; }
table.sheet-table td.col-row-no {
  width: 52px;
  text-align: center;
  color: var(--text-faint);
  font-size: 11px;
  padding: 10px 6px;
}

/* Editable cells hand their padding to .cell-inner so the whole cell is a
   click target; read-only sheet cells keep the shared padding. */
table.sheet-table td[data-col] { padding: 0; }

table.sheet-table td .cell-inner {
  display: block;
  padding: 10px 14px;
  min-height: 40px;
  cursor: text;
  white-space: normal;
  word-break: break-word;
  overflow-wrap: break-word;
  border-radius: 4px;
}
table.sheet-table td[data-col]:hover .cell-inner { box-shadow: inset 0 0 0 1px var(--border-strong); }

table.sheet-table td.editing .cell-inner { display: none; }

table.sheet-table td input.cell-input {
  display: none;
  width: 100%;
  min-height: 40px;
  padding: 9px 14px;
  border: none;
  background: #f0f9ff;
  box-shadow: inset 0 0 0 2px var(--accent);
  font-size: 13px;
  font-family: inherit;
  outline: none;
}
table.sheet-table td.editing input.cell-input { display: block; }
table.sheet-table td.dirty { background: #fefce8 !important; }

/* Add-row form, pinned to the top of the table */
table.sheet-table tbody tr.new-row { background: #f0f9ff !important; }
table.sheet-table td.new-row-cell { padding: 6px 6px; }
table.sheet-table td.new-row-tag {
  color: var(--accent-text);
  font-weight: 700;
  font-size: 10.5px;
  letter-spacing: .04em;
  text-transform: uppercase;
}
.new-row-input {
  width: 100%;
  min-width: 90px;
  height: 32px;
  padding: 0 10px;
  border: 1px solid #7dd3fc;
  border-radius: 6px;
  background: var(--card-bg);
  font-family: inherit;
  font-size: 12.5px;
  outline: none;
}
.new-row-input:focus { border-color: var(--accent); box-shadow: var(--focus-ring); }

/* ── Scroll affordance on tables still too wide to fit ──────────────────── */
.table-card::before,
.table-card::after {
  content: "";
  position: absolute;
  top: var(--thead-offset, 0px);
  bottom: 0;
  width: 26px;
  z-index: 4;               /* above the sticky header (3) and first column (1) */
  pointer-events: none;
  opacity: 0;
  transition: opacity .15s ease;
}
.table-card::before { left: 0;  background: linear-gradient(to right, rgba(15, 23, 42, .12), rgba(15, 23, 42, 0)); }
.table-card::after  { right: 0; background: linear-gradient(to left,  rgba(15, 23, 42, .12), rgba(15, 23, 42, 0)); }
.table-card.has-scroll-left::before  { opacity: 1; }
.table-card.has-scroll-right::after  { opacity: 1; }

/* ── Transactions panels ─────────────────────────────────────────────────── */
.txn-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 20px;
  margin-bottom: 24px;
}

.txn-panel {
  min-width: 0;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.txn-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}
.txn-panel-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}
.txn-panel-title::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
}
.txn-panel-header.income  .txn-panel-title::before { background: var(--income); }
.txn-panel-header.expense .txn-panel-title::before { background: var(--expense); }
.txn-panel-count {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  background: #f1f5f9;
  border-radius: 999px;
  padding: 1px 8px;
}
.txn-panel-total { font-size: 15px; font-weight: 700; font-variant-numeric: tabular-nums; }
.txn-panel-header.income  .txn-panel-total { color: var(--income-text); }
.txn-panel-header.expense .txn-panel-total { color: var(--expense-text); }

td.txn-date   { color: var(--text-muted); }
td.txn-source { font-weight: 500; }
td.txn-amount { font-weight: 600; }

/* ── Loading / empty / error ─────────────────────────────────────────────── */
.loading-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 80px 40px;
  color: var(--text-muted);
}

.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.empty-state {
  text-align: center;
  padding: 60px 40px;
  color: var(--text-muted);
}

.error-banner {
  background: var(--expense-bg);
  border: 1px solid var(--expense-border);
  border-radius: var(--radius);
  padding: 12px 16px;
  color: var(--expense-text);
  margin-bottom: 16px;
  font-size: 13px;
}

/* ── Toast ───────────────────────────────────────────────────────────────── */
#toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  background: #0f172a;
  color: #f1f5f9;
  padding: 11px 16px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 500;
  box-shadow: var(--shadow-md);
  animation: toast-in .2s ease;
  pointer-events: auto;
}
.toast::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
  background: #34d399;
}
.toast.error::before { background: #f87171; }

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

/* ── Misc ────────────────────────────────────────────────────────────────── */
.divider { border: none; border-top: 1px solid var(--border); margin: 20px 0; }
.section-gap { margin-bottom: 24px; }

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 4px; border: 2px solid transparent; background-clip: padding-box; }
::-webkit-scrollbar-thumb:hover { background: #94a3b8; background-clip: padding-box; }

/* ═══════════════════════════════════════════════════════════════
   Sponsor Tracker
   ═══════════════════════════════════════════════════════════════ */

.sponsor-add-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 20px;
}
.sponsor-add-bar input[type="text"] { flex: 1; min-width: 0; height: 38px; }
.sponsor-add-bar .btn { height: 38px; }

/* Sort bar — card lists can't have clickable column headers, so they get the
   same sort controls as a row of chips: same arrows, same three-state cycle. */
.sort-bar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
}
.sort-bar-label { font-size: 12px; font-weight: 500; color: var(--text-muted); margin-right: 4px; }

.sort-chip {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  height: 28px;
  padding: 0 11px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--card-bg);
  color: var(--text-2);
  font-family: inherit;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: background .12s, color .12s, border-color .12s;
}
.sort-chip:hover { background: var(--surface-2); border-color: var(--border-strong); }
.sort-chip .sort-arrow { opacity: .4; }
.sort-chip.sorted { background: #0f172a; border-color: #0f172a; color: #fff; }
.sort-chip.sorted .sort-arrow { opacity: 1; color: #7dd3fc; }

/* Video rows: separated by hairlines inside one card, not boxes in a box */
.sponsor-list-cards { display: flex; flex-direction: column; }

.sponsor-card {
  display: grid;
  grid-template-columns: 136px minmax(0, 1fr) auto auto;
  grid-template-areas: "thumb main pay actions";
  align-items: center;
  gap: 18px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border-soft);
  transition: background .12s;
}
.sponsor-card:last-child { border-bottom: 0; }
.sponsor-card:hover { background: #fafbfd; }

.sc-thumb {
  grid-area: thumb;
  position: relative;
  aspect-ratio: 16 / 9;
  border-radius: 8px;
  overflow: hidden;
  background: #1e293b;
}
.sc-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }

.sc-status {
  position: absolute;
  left: 6px;
  bottom: 6px;
  padding: 2px 7px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .02em;
  line-height: 1.4;
}
.sc-status.active { background: rgba(4, 120, 87, .92); color: #fff; }
.sc-status.ended  { background: rgba(15, 23, 42, .75); color: #cbd5e1; }

.sc-main {
  grid-area: main;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.sc-title {
  font-size: 14px;
  font-weight: 600;
  line-height: 1.35;
  color: var(--text);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.sc-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 12px;
  font-size: 12.5px;
  color: var(--text-muted);
}

.sc-sponsor {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-weight: 600;
  color: var(--text-2);
}
.sc-sponsor::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent);
}
.sc-sponsor.none { font-weight: 400; color: var(--text-faint); }
.sc-sponsor.none::before { background: var(--border-strong); }

.sc-days        { font-weight: 600; color: var(--accent-text); }
.sc-days.soon   { color: var(--pending); }
.sc-days.urgent { color: var(--expense-text); }

.sc-views {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 10px;
  font-size: 12.5px;
}
.sc-views-num { font-weight: 600; color: var(--text-2); font-variant-numeric: tabular-nums; }

/* Meter: the track is a lighter step of the fill's own hue */
.sc-progress {
  width: 140px;
  height: 6px;
  border-radius: 999px;
  background: var(--accent-soft);
  overflow: hidden;
}
.sc-progress-fill { height: 100%; border-radius: 999px; background: var(--accent); }
.sc-progress-text { font-size: 12px; color: var(--text-muted); }

.sc-pay {
  grid-area: pay;
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 196px;
}

.sc-pill {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 5px 10px;
  border: 1px solid;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}
.sc-pill .icon { width: 13px; height: 13px; }
.sc-pill-label { flex: 1; font-weight: 500; color: var(--text-2); margin-right: 8px; }
.sc-pill.paid    { color: var(--income-text); background: var(--income-bg);  border-color: var(--income-border); }
.sc-pill.pending { color: var(--pending);     background: var(--pending-bg); border-color: var(--pending-border); }
.sc-pill.na      { color: var(--text-faint);  background: var(--card-bg);    border-color: var(--border); font-weight: 500; }
.sc-pill.na .sc-pill-label { color: var(--text-muted); }

.sc-actions {
  grid-area: actions;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

/* Paid / Pending pills (edit modal) */
.toggle-pill {
  display: inline-flex;
  align-items: center;
  padding: 3px 11px;
  border-radius: 999px;
  font-family: inherit;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid transparent;
  transition: opacity .15s, background .15s;
  white-space: nowrap;
  background: none;
}
.toggle-pill.paid    { background: var(--income-bg);  color: var(--income-text); border-color: var(--income-border); }
.toggle-pill.pending { background: var(--pending-bg); color: var(--pending);     border-color: var(--pending-border); }
.toggle-pill:hover   { opacity: .85; }
.toggle-pill:disabled { opacity: .5; cursor: not-allowed; }

.na-label { font-size: 11px; color: var(--text-faint); }

/* ── Feature toggles (used in modal) ──────────────────────────────────────── */
.feature-toggle {
  position: relative;
  display: inline-block;
  width: 34px;
  height: 20px;
  cursor: pointer;
  flex-shrink: 0;
}
.feature-toggle input { opacity: 0; width: 0; height: 0; position: absolute; }

.toggle-slider {
  position: absolute;
  inset: 0;
  background: var(--border-strong);
  border-radius: 20px;
  transition: background .2s;
}
.toggle-slider::before {
  content: "";
  position: absolute;
  width: 14px;
  height: 14px;
  background: #fff;
  border-radius: 50%;
  top: 3px;
  left: 3px;
  box-shadow: 0 1px 2px rgba(15, 23, 42, .25);
  transition: transform .2s;
}
.feature-toggle input:checked + .toggle-slider { background: var(--accent); }
.feature-toggle input:checked + .toggle-slider::before { transform: translateX(14px); }
.feature-toggle input:focus-visible + .toggle-slider { box-shadow: var(--focus-ring); }

/* ── Modal ───────────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 300;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(15, 23, 42, .5);
  backdrop-filter: blur(2px);
}

.modal-card {
  width: 100%;
  max-width: 440px;
  max-height: calc(100dvh - 40px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--card-bg);
  border-radius: 14px;
  box-shadow: var(--shadow-lg);
  animation: modal-in .16s ease;
}

@keyframes modal-in {
  from { transform: translateY(10px) scale(.98); opacity: 0; }
  to   { transform: none; opacity: 1; }
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 20px 14px;
  border-bottom: 1px solid var(--border);
}

.modal-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 360px;
}

.modal-close {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.modal-close:hover { background: #f1f5f9; color: var(--text); }

/* Body scrolls so the header/footer (incl. Save) stay reachable on short screens */
.modal-body {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 18px 20px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.modal-message { font-size: 14px; color: var(--text); margin: 0; line-height: 1.5; }

.modal-field { display: flex; flex-direction: column; gap: 6px; }
.modal-field label { font-size: 12.5px; font-weight: 600; color: var(--text-2); }

.modal-sponsor-row { display: flex; gap: 8px; }

.modal-section-divider {
  padding-top: 12px;
  border-top: 1px solid var(--border);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .05em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.modal-toggle-row {
  flex-direction: row !important;
  align-items: center;
  justify-content: space-between;
}
.modal-toggle-row label {
  font-size: 13px !important;
  font-weight: 500 !important;
  color: var(--text) !important;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  background: var(--surface-2);
}

/* ═══════════════════════════════════════════════════════════════
   Settings page
   ═══════════════════════════════════════════════════════════════ */

.settings-card {
  max-width: 560px;
  padding: 22px 24px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
}

.settings-section-title {
  margin-bottom: 18px;
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
}

.settings-field { margin-bottom: 18px; }
.settings-field label {
  display: block;
  margin-bottom: 7px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-2);
}

.settings-input-row { display: flex; gap: 8px; align-items: center; }
.settings-input-row input { flex: 1; }

.settings-hint { margin-top: 7px; font-size: 12px; color: var(--text-muted); }
.settings-actions { padding-top: 4px; display: flex; gap: 8px; flex-wrap: wrap; }
.settings-card + .settings-card { margin-top: 16px; }
.settings-field > input { width: 100%; max-width: 420px; }

/* ═══════════════════════════════════════════════════════════════
   In-kind contributions
   ═══════════════════════════════════════════════════════════════ */

.fs-badge {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--accent-text);
  background: #f0f9ff;
  border: 1px solid #bae6fd;
  white-space: nowrap;
}

/* Truncate long spec text but keep it readable; full text on hover (title attr) */
.sheet-table td.fs-specs {
  max-width: 280px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ═══════════════════════════════════════════════════════════════
   Bank statements
   ═══════════════════════════════════════════════════════════════ */

/* Upload dropzone (compact, sits inside each expanded account) */
.stmt-dropzone {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  margin: 12px 16px;
  padding: 14px 20px;
  text-align: center;
  border: 1.5px dashed var(--border-strong);
  border-radius: var(--radius-lg);
  background: var(--surface-2);
  color: var(--text-muted);
  cursor: pointer;
  transition: border-color .15s, background .15s;
}
.stmt-dropzone:hover,
.stmt-dropzone.dragover { border-color: var(--accent); background: #f0f9ff; }
.stmt-dropzone.uploading { opacity: .6; pointer-events: none; }
.stmt-dropzone-text { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.stmt-dropzone-text .icon { width: 16px; height: 16px; color: var(--accent-text); }
.stmt-dropzone-text strong { color: var(--accent-text); }
.stmt-dropzone-hint { font-size: 11.5px; color: var(--text-muted); }

/* Collapsible Account → Year → statements tree */
.stmt-group { border-bottom: 1px solid var(--border); }
.stmt-tree > .stmt-group:last-child { border-bottom: none; }

.stmt-group-head {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 16px;
  cursor: pointer;
  font-size: 14px;
  color: var(--text);
  text-align: left;
  transition: background .12s;
}
.stmt-group-head:hover { background: var(--hover-bg); }

.stmt-caret {
  display: inline-flex;
  color: var(--text-faint);
  transition: transform .15s;
  flex-shrink: 0;
}
.stmt-caret .icon { width: 14px; height: 14px; }
.stmt-group.open > .stmt-group-head .stmt-caret { transform: rotate(90deg); }

.stmt-group-label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.stmt-group-count {
  min-width: 24px;
  padding: 1px 8px;
  flex-shrink: 0;
  font-size: 11px;
  font-weight: 700;
  text-align: center;
  color: var(--text-muted);
  background: #f1f5f9;
  border-radius: 999px;
}

/* Per-account action buttons in the header — reveal on hover */
.stmt-group-actions {
  display: inline-flex;
  gap: 2px;
  flex-shrink: 0;
  opacity: 0;
  transition: opacity .12s;
}
.stmt-account > .stmt-group-head:hover .stmt-group-actions,
.stmt-group-actions:focus-within { opacity: 1; }

/* Account level: bold, tinted background */
.stmt-account > .stmt-group-head { font-weight: 700; background: var(--surface-2); }
.stmt-account > .stmt-group-head:hover { background: #eef2f7; }

/* Year level: indented, lighter */
.stmt-year > .stmt-group-head {
  padding-left: 40px;
  font-weight: 600;
  color: var(--text-muted);
}
.stmt-year { border-bottom: none; }
.stmt-account > .stmt-group-body > .stmt-year + .stmt-year > .stmt-group-head {
  border-top: 1px solid var(--border-soft);
}

/* Statement rows */
.stmt-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 7px 16px 7px 62px;
  border-top: 1px solid var(--border-soft);
  font-size: 13px;
}
.stmt-row:hover { background: var(--hover-bg); }

.stmt-row-name {
  flex: 1;
  min-width: 0;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--text);
  text-decoration: none;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.stmt-row-name:hover { color: var(--accent-text); text-decoration: underline; }
.stmt-file-icon { display: inline-flex; color: var(--text-faint); }
.stmt-file-icon .icon { width: 15px; height: 15px; }

.stmt-row-size    { color: var(--text-muted); white-space: nowrap; min-width: 54px; text-align: right; font-size: 12px; }
.stmt-row-actions { display: inline-flex; gap: 2px; flex-shrink: 0; }

/* ═══════════════════════════════════════════════════════════════
   Financial years — accountant view (tabs + per-FY pack)
   ═══════════════════════════════════════════════════════════════ */
.fy-tabs { margin-bottom: 22px; }

.fy-tab-ongoing {
  padding: 1px 7px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--accent-text);
  background: var(--accent-soft);
}

/* Hide / restore controls: only the selected tab offers "hide", so the row
   doesn't reserve space for an invisible button on every tab. */
.fy-tab-icon {
  display: none;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  margin-right: -4px;
  border: none;
  border-radius: 5px;
  background: transparent;
  color: var(--text-faint);
  font-size: 11px;
  line-height: 1;
  cursor: pointer;
  transition: background .12s, color .12s;
}
.fy-tab.active .fy-tab-icon,
.fy-tab-restore { display: inline-flex; }
.fy-tab-hide:hover    { background: var(--expense-bg); color: var(--expense-text); }
.fy-tab-restore:hover { background: var(--income-bg);  color: var(--income-text); }

.fy-tab-muted { color: var(--text-faint); font-style: italic; }

.fy-hidden-toggle {
  flex-shrink: 0;
  margin-left: 4px;
  padding: 6px 10px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--text-muted);
  font-family: inherit;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
}
.fy-hidden-toggle:hover { background: rgba(255, 255, 255, .6); color: var(--text); }

/* Per-FY header */
.fy-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 18px;
}
.fy-head-title {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 19px;
  font-weight: 700;
  letter-spacing: -.01em;
  color: var(--text);
}
.fy-head-range { margin-top: 3px; font-size: 13px; color: var(--text-muted); }

.fy-badge {
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
}
.fy-badge.ongoing  { color: var(--accent-text); background: var(--accent-soft); }
.fy-badge.complete { color: var(--text-muted);  background: #eef2f6; }

/* Statement beside its breakdown */
.fy-split {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(300px, 1fr);
  align-items: start;
  gap: 20px;
}
.fy-split > .table-card,
.fy-split > .chart-card { margin-bottom: 0; }
.fy-share-second { margin-top: 24px; }

@media (max-width: 1100px) {
  .fy-split { grid-template-columns: minmax(0, 1fr); }
}

/* Income/expense statement */
table.summary.fy-breakdown { white-space: normal; }
.fy-breakdown td.fy-num { text-align: right; font-variant-numeric: tabular-nums; min-width: 120px; }
.fy-breakdown td.fy-indent:first-child { padding-left: 32px; font-weight: 500; color: var(--text-2); }
.fy-breakdown tr.fy-section td {
  padding-top: 14px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .05em;
  text-transform: uppercase;
  color: var(--text-muted);
  background: var(--card-bg);
}
.fy-breakdown tr.fy-subtotal td { font-weight: 700; border-bottom: 1px solid var(--border); }
.fy-breakdown tr.fy-net td {
  font-size: 14px;
  font-weight: 800;
  border-top: 2px solid var(--border);
  background: var(--surface-2);
}
.fy-breakdown tr:hover { background: transparent; }

/* Bank statements inside an FY pack (read-only) */
.fy-stmt-wrap { padding: 6px 0; }
.fy-stmt-account { border-bottom: 1px solid var(--border); padding: 6px 0 8px; }
.fy-stmt-account:last-child { border-bottom: none; }
.fy-stmt-account-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  font-size: 14px;
  font-weight: 700;
}
.fy-stmt-year-label {
  padding: 6px 16px 4px 28px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
}
.fy-stmt-row { padding-left: 36px; }

/* ═══════════════════════════════════════════════════════════════
   Phones & small tablets
   ═══════════════════════════════════════════════════════════════ */
@media (max-width: 1023px) {
  .sponsor-card {
    grid-template-columns: 120px minmax(0, 1fr) auto;
    grid-template-areas:
      "thumb main actions"
      "thumb pay  actions";
    align-items: start;
    gap: 10px 16px;
  }
  .sc-pay { flex-direction: row; flex-wrap: wrap; min-width: 0; }
  .sc-pill { flex: 0 1 auto; }
}

@media (max-width: 767px) {
  body { flex-direction: column; overflow-x: hidden; }

  .sidebar {
    width: 272px;
    z-index: 200;
    transform: translateX(-100%);
    transition: transform .25s ease;
  }
  .sidebar.open { transform: translateX(0); box-shadow: var(--shadow-lg); }
  .sidebar-overlay { display: block; }
  .sidebar-toggle { display: none; }   /* collapsing is a desktop-only rail */

  .main { margin-left: 0; padding-top: 54px; }
  .mobile-topbar { display: flex; }
  .page-content { padding: 16px 16px 32px; }

  .page-header { margin-bottom: 14px; }
  .page-title { font-size: 19px; }
  .page-actions { width: 100%; }
  .page-actions .btn { flex: 1; }
  /* Page-header action button drops to its own full-width row (Bank Statements) */
  .page-header > .btn { width: 100%; }

  /* Stats become one compact card of rows: label and note on the left, the
     figure on the right — readable without a screen-length stack of tiles. */
  .stat-grid,
  .stat-grid-3,
  .stat-grid-4,
  .stat-grid-5 {
    display: flex;
    flex-direction: column;
    gap: 0;
    margin-bottom: 16px;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    overflow: hidden;
  }
  .stat-grid .stat-card {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    column-gap: 12px;
    align-items: center;
    padding: 11px 14px;
    border: 0;
    border-bottom: 1px solid var(--border-soft);
    border-radius: 0;
    box-shadow: none;
  }
  .stat-grid .stat-card:last-child { border-bottom: 0; }
  .stat-grid .stat-label { grid-column: 1; grid-row: 1; margin: 0; font-size: 13px; color: var(--text-2); }
  .stat-grid .stat-meta  { grid-column: 1; grid-row: 2; margin-top: 2px; font-size: 11.5px; }
  .stat-grid .stat-value { grid-column: 2; grid-row: 1 / span 2; font-size: 17px; text-align: right; }
  .stat-groups { gap: 16px; margin-bottom: 16px; }

  .chart-grid { gap: 14px; margin-bottom: 16px; }
  .chart-card { padding: 14px 14px 12px; }
  .chart-canvas-wrap { height: 230px; }
  .chart-canvas-wrap.chart-canvas-tall { height: 260px; }

  .range-bar { gap: 10px; }
  .range-custom { width: 100%; }
  .range-custom input { flex: 1; min-width: 0; width: auto; }
  .range-caption { margin-left: 0; }

  .sheet-toolbar { padding: 10px 12px; gap: 8px 10px; }
  .search-box { flex: 1 1 100%; min-width: 0; }
  .toolbar-hint { display: none; }

  .txn-grid { grid-template-columns: 1fr; gap: 14px; }

  .fy-head-title { font-size: 17px; }
  .fy-tabs { margin-bottom: 16px; }

  #toast-container { bottom: 12px; right: 12px; left: 12px; }
  .toast { font-size: 12.5px; }

  /* Sponsor rows: thumbnail + title on top, payments and actions beneath */
  .sponsor-card {
    grid-template-columns: 96px minmax(0, 1fr);
    grid-template-areas:
      "thumb   main"
      "pay     pay"
      "actions actions";
    gap: 10px 12px;
    padding: 12px;
  }
  .sc-title { font-size: 13.5px; }
  .sc-progress { width: 100%; order: 3; }
  .sc-pay { flex-wrap: nowrap; }
  /* Two pills share the row, so each stacks its label over its status
     rather than cutting "Milestone £300" short. */
  .sc-pill { flex: 1 1 0; min-width: 0; flex-wrap: wrap; row-gap: 1px; padding: 6px 10px; }
  .sc-pill-label { flex: 1 0 100%; margin-right: 0; }
  .sc-actions { flex-direction: row; justify-content: flex-end; margin-top: -4px; }
  .sponsor-add-bar { flex-wrap: wrap; }
  .sponsor-add-bar .btn { width: 100%; }

  .settings-card { padding: 16px 18px; }
  .modal-card { margin: 0 4px; }

  .stmt-dropzone { margin: 10px 12px; padding: 12px; }
  .stmt-year > .stmt-group-head { padding-left: 30px; }
  .stmt-row { flex-wrap: wrap; padding: 8px 12px 8px 40px; gap: 4px 10px; }
  .stmt-row-name { flex-basis: 100%; white-space: normal; word-break: break-word; }
  .stmt-row-size { margin-left: auto; }
  /* Actions are always visible on touch devices */
  .stmt-group-actions { opacity: 1; }

  /* Prevent iOS auto-zoom on focus — any field under 16px triggers it */
  input, select, textarea,
  .range-custom input,
  .sponsor-add-bar input[type="text"],
  .search-box input,
  .new-row-input,
  .modal-sponsor-row select,
  .modal-sponsor-row input,
  #modal-release-date,
  #fs-modal-overlay .modal-body input[type="text"],
  #fs-modal-overlay .modal-body input[type="number"],
  #fs-modal-overlay .modal-body textarea,
  table.sheet-table td input.cell-input { font-size: 16px; }

  /* Comfortable tap targets */
  .btn { height: 40px; padding: 0 16px; font-size: 14px; }
  .btn-sm { height: 34px; }
  .nav-item { padding: 11px 12px; }
  .btn-icon { width: 38px; height: 38px; }
  .modal-close { width: 36px; height: 36px; }
  .modal-title { max-width: calc(100vw - 90px); }

  /* Denser, touch-scrollable data tables. Sheet rows stay on one line and the
     table scrolls sideways, instead of every cell wrapping into a tall column. */
  .table-scroll { -webkit-overflow-scrolling: touch; max-height: none; }
  table.summary,
  table.sheet-table,
  table.txn-table { font-size: 12.5px; }
  table.summary thead th, table.summary td,
  table.sheet-table thead th, table.sheet-table td,
  table.txn-table thead th, table.txn-table td { padding: 9px 10px; }
  table.sheet-table td[data-col] { padding: 0; }
  table.sheet-table td .cell-inner { padding: 9px 10px; min-height: 38px; white-space: nowrap; }
  th.col-date, td.col-date { min-width: 84px; }
  .sheet-table td.fs-specs { max-width: 150px; }
}

@media (max-width: 380px) {
  .page-content { padding: 14px 12px 28px; }
  .sponsor-card { grid-template-columns: 80px minmax(0, 1fr); }
}

/* ═══════════════════════════════════════════════════════════════
   Print: hand a single FY to the accountant
   ═══════════════════════════════════════════════════════════════ */
@media print {
  .sidebar, .sidebar-overlay, .mobile-topbar, .nav-tip, .sidebar-toggle,
  .no-print, .fy-tabs, .page-actions { display: none !important; }
  .main { margin: 0 !important; padding: 0 !important; }
  .page-content { padding: 0 !important; max-width: none !important; }
  body { background: #fff !important; }
  .table-card, .stat-card, .chart-card { box-shadow: none !important; break-inside: avoid; }
  .table-card::before, .table-card::after { display: none !important; }
  .fy-split { grid-template-columns: 1fr 1fr; }
  .fy-stmt-account, .fy-stmt-year, tr { break-inside: avoid; }
  .table-scroll { max-height: none !important; overflow: visible !important; }
}

/* Sponsor Tracker — $ → £ converter inside the Awaiting payment card */
.fx-conv {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid var(--border-soft);
  font-size: 13px;
}
.fx-field {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 30px;
  padding: 0 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-2);
  color: var(--text-muted);
}
.fx-field:focus-within { border-color: var(--accent); box-shadow: var(--focus-ring); }
.fx-field input {
  width: 90px;
  border: 0;
  outline: 0;
  background: transparent;
  font: inherit;
  color: var(--text);
}
.fx-eq  { color: var(--text-muted); }
.fx-gbp { font-weight: 600; color: var(--text); font-variant-numeric: tabular-nums; }
.fx-rate { margin-top: 4px; font-size: 11.5px; color: var(--text-muted); }

/* Sponsor Tracker — sponsor picker in the add bar */
.sponsor-add-bar select {
  height: 38px;
  max-width: 200px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--card-bg);
  color: var(--text);
  font: inherit;
  font-size: 13px;
}
.sponsor-add-bar select:focus { outline: none; border-color: var(--accent); box-shadow: var(--focus-ring); }
.modal-hint { font-size: 12px; color: var(--text-muted); }

/* Sponsor roster (sponsorRoster.js) */
.roster-row {
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr) auto auto;
  gap: 4px 16px;
  align-items: start;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border-soft);
}
.roster-row:last-child { border-bottom: 0; }
.roster-expand {
  width: 28px; height: 28px; margin-top: -2px;
  display: flex; align-items: center; justify-content: center;
  border: 0; border-radius: 7px; background: transparent; color: var(--text-muted); cursor: pointer;
}
.roster-expand:hover { background: var(--surface-2); color: var(--text); }
.roster-expand .icon { width: 15px; height: 15px; transition: transform .15s; }
.roster-row.open .roster-expand .icon { transform: rotate(90deg); }
.roster-name { font-size: 14px; font-weight: 600; color: var(--text); }
.roster-count { margin-left: 6px; font-size: 12px; font-weight: 500; color: var(--text-muted); }
.roster-deal { margin: 4px 0 0; padding: 0; list-style: none; font-size: 12.5px; color: var(--text-2); line-height: 1.55; }
.roster-deal.none { color: var(--pending); }
.roster-money { display: grid; gap: 2px; font-size: 12.5px; text-align: right; font-variant-numeric: tabular-nums; }
.roster-money span { margin-right: 8px; color: var(--text-muted); }
.roster-money b { font-weight: 600; color: var(--text); }
.roster-money b.pending { color: var(--pending); }
.roster-actions { display: flex; flex-wrap: wrap; gap: 6px; justify-content: flex-end; }
.roster-history {
  grid-column: 2 / -1;
  margin-top: 10px;
  padding: 12px 14px;
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  background: var(--surface-2);
}
.rh-head { margin: 4px 0 6px; font-size: 11px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; color: var(--text-muted); }
.rh-list { margin: 0 0 8px; padding: 0; list-style: none; }
.rh-list li {
  display: grid; grid-template-columns: 170px minmax(0, 1fr) auto; gap: 12px; align-items: center;
  padding: 7px 0; border-top: 1px solid var(--border-soft); font-size: 12.5px; color: var(--text-2);
}
.rh-list li:first-child { border-top: 0; }
.rh-when { color: var(--text-muted); }
.rh-tag { margin-left: 4px; padding: 1px 6px; border-radius: 10px; background: var(--income-bg); color: var(--income-text); font-size: 11px; font-weight: 600; }
.rh-acts { display: flex; gap: 2px; }
.rh-notes { margin-top: 3px; font-size: 12px; color: var(--text-muted); white-space: pre-wrap; }
.rh-paid { display: inline-flex; align-items: center; gap: 3px; margin-left: 8px; font-size: 11.5px; font-weight: 600; }
.rh-paid .icon { width: 12px; height: 12px; }
.rh-paid.paid { color: var(--income-text); }
.rh-paid.pending { color: var(--pending); }
.rh-foot { display: flex; gap: 6px; margin-top: 4px; }
.btn.danger { color: var(--expense-text); }

/* roster modals */
.roster-modal { max-width: 500px; }
.roster-modal .modal-title { max-width: 400px; }
.roster-modal select.modal-input { padding: 0 8px; }
.modal-textarea { height: auto !important; min-height: 64px; padding: 8px 12px !important; resize: vertical; }
.ct-grid { display: grid; grid-template-columns: minmax(0, 1fr) 110px; gap: 12px; }
.tier-row { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.tier-row input { flex: 1; min-width: 0; }
.tier-arrow { flex-shrink: 0; font-size: 12px; color: var(--text-muted); }
.roster-hint { margin: 0; font-size: 12.5px; color: var(--text-muted); line-height: 1.5; }
.roster-hint-inline { font-weight: 400; color: var(--text-faint); }
.roster-err { font-size: 12.5px; color: var(--expense-text); min-height: 0; }
.roster-err:empty { display: none; }

@media (max-width: 760px) {
  .roster-row { grid-template-columns: 28px minmax(0, 1fr); }
  .roster-money, .roster-actions { grid-column: 2; text-align: left; justify-content: flex-start; }
  .roster-history { grid-column: 1 / -1; }
  .rh-list li { grid-template-columns: minmax(0, 1fr) auto; }
  .rh-list li .rh-what { grid-column: 1 / -1; grid-row: 2; }
  .sponsor-add-bar select { max-width: none; flex: 1; }
}
