/* M-Pesa Spending Tracker — single stylesheet, no external dependencies. */

:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f1f3f6;
  --border: #e3e6eb;
  --text: #14161a;
  --muted: #6b7280;
  --accent: #16a34a;      /* M-Pesa green */
  --accent-soft: #dcfce7;
  --danger: #dc2626;
  --danger-soft: #fee2e2;
  --warn: #b45309;
  --warn-soft: #fef3c7;
  --radius: 12px;
  --shadow: 0 1px 2px rgb(16 24 40 / 6%), 0 1px 3px rgb(16 24 40 / 4%);
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --surface: #171a21;
    --surface-2: #1e222b;
    --border: #2a2f3a;
    --text: #e8eaed;
    --muted: #9aa3b2;
    --accent: #22c55e;
    --accent-soft: #10331f;
    --danger: #f87171;
    --danger-soft: #3a1a1a;
    --warn: #fbbf24;
    --warn-soft: #3a2e10;
    --shadow: 0 1px 2px rgb(0 0 0 / 40%);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; }

/* ---------- Layout ---------- */

.topbar {
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 10px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
  flex-wrap: wrap;
}

.brand {
  font-weight: 650;
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-size: 14px;
  font-weight: 700;
}

.nav { display: flex; gap: 4px; flex: 1; flex-wrap: wrap; }

.nav a {
  padding: 6px 11px;
  border-radius: 8px;
  text-decoration: none;
  color: var(--muted);
  font-weight: 500;
  font-size: 14px;
}

.nav a:hover { background: var(--surface-2); color: var(--text); }
.nav a.active { background: var(--accent-soft); color: var(--accent); }

.logout { margin: 0; }

/* Elements that only exist for the mobile drawer. */
.navtoggle { display: none; }
.nav-signout { display: none; }
.navscrim { display: none; }

/* ---------- Bulk action bar ---------- */

.bulkbar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 12px;
  padding: 10px 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
}

.bulk-group { display: flex; align-items: center; gap: 8px; }
.bulkbar select { width: auto; min-width: 160px; }

.page { max-width: 1180px; margin: 0 auto; padding: 24px 20px 60px; }

.foot {
  text-align: center;
  color: var(--muted);
  font-size: 12px;
  padding: 0 20px 30px;
}

/* ---------- Typography ---------- */

h1 { font-size: 24px; margin: 0 0 4px; letter-spacing: -0.01em; }
h2 { font-size: 16px; margin: 0 0 14px; letter-spacing: -0.01em; }
h3 { font-size: 14px; margin: 0 0 8px; }
.sub { color: var(--muted); font-size: 14px; margin: 0 0 22px; }
.muted { color: var(--muted); }
.mono { font-family: var(--mono); font-size: 12px; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }

.page-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 18px;
}

/* ---------- Cards & grids ---------- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
}

.grid { display: grid; gap: 16px; }
.grid-tiles { grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); }
.stack { display: grid; gap: 16px; }

.tile .label {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  font-weight: 600;
}

.tile .value { font-size: 26px; font-weight: 650; margin-top: 6px; letter-spacing: -0.02em; }
.tile .foot-note { font-size: 12px; color: var(--muted); margin-top: 6px; }

.delta { font-weight: 600; }
.delta.up { color: var(--danger); }
.delta.down { color: var(--accent); }

/* ---------- Bars ---------- */

.barlist { display: grid; gap: 11px; }

.barrow { display: grid; grid-template-columns: 1fr auto; gap: 3px 12px; font-size: 14px; }
.barrow .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.barrow .amt { font-variant-numeric: tabular-nums; font-weight: 600; }
.barrow .track {
  grid-column: 1 / -1;
  height: 6px;
  background: var(--surface-2);
  border-radius: 999px;
  overflow: hidden;
}
.barrow .fill { height: 100%; border-radius: 999px; background: var(--accent); }

/* Daily sparkline */
.spark { display: flex; align-items: flex-end; gap: 2px; height: 90px; }
.spark .col {
  flex: 1;
  min-height: 2px;
  background: var(--accent);
  border-radius: 2px 2px 0 0;
  opacity: 0.85;
}
.spark .col.empty { background: var(--surface-2); }
.spark-axis { display: flex; justify-content: space-between; font-size: 11px; color: var(--muted); margin-top: 6px; }

/* Monthly columns */
.months { display: flex; align-items: flex-end; gap: 10px; height: 130px; }
.months .m { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; height: 100%; }
.months .mbar { background: var(--accent); border-radius: 5px 5px 0 0; min-height: 3px; }
.months .mlabel { font-size: 11px; color: var(--muted); text-align: center; margin-top: 6px; }
.months .mval { font-size: 11px; text-align: center; margin-bottom: 4px; color: var(--muted); font-variant-numeric: tabular-nums; }

/* ---------- Tables ---------- */

.table-wrap { overflow-x: auto; margin: 0 -18px; padding: 0 18px; }

table { width: 100%; border-collapse: collapse; font-size: 14px; }

th {
  text-align: left;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  font-weight: 600;
  padding: 0 12px 8px 0;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

td { padding: 10px 12px 10px 0; border-bottom: 1px solid var(--border); vertical-align: middle; }
tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--surface-2); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; padding-right: 0; }

.rowlink { text-decoration: none; font-weight: 550; }
.rowlink:hover { text-decoration: underline; }

.party { display: flex; align-items: center; gap: 10px; min-width: 0; }
.avatar {
  width: 30px; height: 30px; flex: none;
  border-radius: 9px;
  display: grid; place-items: center;
  font-size: 11px; font-weight: 700; color: #fff;
}

.amount-out { color: var(--danger); font-weight: 600; }
.amount-in { color: var(--accent); font-weight: 600; }
.amount-flat { color: var(--muted); }

/* ---------- Pills & badges ---------- */

.pill {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 550;
  background: var(--surface-2);
  color: var(--muted);
  white-space: nowrap;
}

.pill-dot { display: inline-flex; align-items: center; gap: 6px; }
.pill-dot::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: currentColor; }

.badge-warn { background: var(--warn-soft); color: var(--warn); }
.badge-ok { background: var(--accent-soft); color: var(--accent); }
.badge-bad { background: var(--danger-soft); color: var(--danger); }

/* ---------- Forms & buttons ---------- */

input[type=text], input[type=date], input[type=number], input[type=password],
select, textarea {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 14px;
}

input[type=color] { width: 44px; height: 36px; padding: 2px; border-radius: 9px; border: 1px solid var(--border); background: var(--surface); }
textarea { resize: vertical; font-family: var(--mono); font-size: 13px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }

label { font-size: 13px; font-weight: 550; display: block; margin-bottom: 4px; }
.field { margin-bottom: 14px; }
.field .helptext { font-size: 12px; color: var(--muted); display: block; margin-top: 4px; }
.errorlist { color: var(--danger); font-size: 13px; margin: 4px 0 0; padding-left: 18px; }

.filters { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; align-items: end; }
.filters .field { margin: 0; }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 14px;
  font-weight: 550;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
}

.btn:hover { background: var(--surface-2); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { filter: brightness(1.06); background: var(--accent); }
.btn-danger { color: var(--danger); border-color: var(--danger); background: transparent; }
.btn-ghost { border-color: transparent; background: transparent; color: var(--muted); }
.btn-sm { padding: 5px 10px; font-size: 13px; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- Flashes & callouts ---------- */

.flashes { display: grid; gap: 8px; margin-bottom: 18px; }
.flash { padding: 10px 14px; border-radius: 10px; font-size: 14px; border: 1px solid var(--border); background: var(--surface); }
.flash-success { background: var(--accent-soft); border-color: transparent; color: var(--accent); }
.flash-warning { background: var(--warn-soft); border-color: transparent; color: var(--warn); }
.flash-error { background: var(--danger-soft); border-color: transparent; color: var(--danger); }

.callout {
  border: 1px dashed var(--border);
  background: var(--surface);
  border-radius: var(--radius);
  padding: 18px;
}

.empty { text-align: center; color: var(--muted); padding: 40px 20px; }
.empty h2 { color: var(--text); }

/* ---------- Code blocks ---------- */

pre.code {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  overflow-x: auto;
  font-family: var(--mono);
  font-size: 12.5px;
  line-height: 1.65;
  margin: 0;
}

code.inline {
  font-family: var(--mono);
  font-size: 12.5px;
  background: var(--surface-2);
  padding: 1px 5px;
  border-radius: 5px;
  word-break: break-all;
}

.token-box {
  display: flex;
  gap: 8px;
  align-items: center;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 12px;
  font-family: var(--mono);
  font-size: 12.5px;
  word-break: break-all;
}

/* ---------- Steps ---------- */

.steps { counter-reset: step; display: grid; gap: 18px; margin: 0; padding: 0; list-style: none; }
.steps > li { counter-increment: step; display: grid; grid-template-columns: 28px 1fr; gap: 12px; }
.steps > li::before {
  content: counter(step);
  width: 28px; height: 28px;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent);
  display: grid; place-items: center;
  font-size: 13px; font-weight: 700;
}
.steps h3 { margin: 4px 0 8px; }

/* ---------------------------------------------------------------------------
   Charts.
   Series hues are categorical slots 1-6 of the validated data-viz palette,
   with a neutral for "Other". Each mode is stepped for its own surface —
   the dark column is not an automatic flip of the light one.
   --------------------------------------------------------------------------- */

.viz {
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --series-4: #eda100;
  --series-5: #e87ba4;
  --series-6: #008300;
  --series-other: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .viz {
    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
    --series-4: #c98500;
    --series-5: #d55181;
    --series-6: #008300;
    --series-other: #898781;
    --grid: #2c2c2a;
    --axis: #383835;
  }
}

.slot-1 { --slot: var(--series-1); }
.slot-2 { --slot: var(--series-2); }
.slot-3 { --slot: var(--series-3); }
.slot-4 { --slot: var(--series-4); }
.slot-5 { --slot: var(--series-5); }
.slot-6 { --slot: var(--series-6); }
.slot-0 { --slot: var(--series-other); }

/* ---------- Donut ---------- */

.donut-layout {
  display: grid;
  grid-template-columns: minmax(180px, 240px) minmax(0, 1fr);
  gap: 24px;
  align-items: center;
}

.donut-figure { margin: 0; min-width: 0; }

.donut { width: 100%; height: auto; display: block; }

.donut-track {
  fill: none;
  stroke: var(--surface-2);
  stroke-width: 26;
}

.donut-arc {
  fill: none;
  stroke: var(--slot);
  stroke-width: 26;
  /* Start at twelve o'clock and run clockwise. */
  transform: rotate(-90deg);
  transform-origin: 100px 100px;
  transition: stroke-width 0.15s ease;
}

.donut-arc:hover { stroke-width: 30; }

.donut-total {
  text-anchor: middle;
  font-size: 24px;
  font-weight: 650;
  fill: var(--text);
}

.donut-caption {
  text-anchor: middle;
  font-size: 11px;
  fill: var(--muted);
}

/* ---------- Legend ---------- */

.legend { list-style: none; margin: 0; padding: 0; display: grid; gap: 9px; min-width: 0; }

.legend li {
  display: grid;
  grid-template-columns: 12px minmax(0, 1fr) auto auto;
  align-items: baseline;
  gap: 10px;
  font-size: 14px;
}

.legend-swatch {
  width: 12px;
  height: 12px;
  border-radius: 3px;
  background: var(--slot);
  display: inline-block;
  flex: none;
}

.legend-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.legend-value { font-variant-numeric: tabular-nums; font-weight: 600; }
.legend-share { font-variant-numeric: tabular-nums; color: var(--muted); min-width: 44px; text-align: right; }

.tableview { margin-top: 18px; }
.tableview summary { cursor: pointer; color: var(--muted); font-size: 13px; }
.tableview summary:hover { color: var(--text); }
.tableview .legend-swatch { vertical-align: middle; margin-right: 6px; }

/* ---------- Clickable daily bars ---------- */

/* `overflow-x: auto` makes the vertical axis scroll as well, which would clip
   the tooltips that sit above the bars — so reserve room for them inside the
   scroll box rather than letting them overflow it. */
.daybars-scroll { overflow-x: auto; padding: 46px 0 4px; }

.daybars {
  display: flex;
  align-items: flex-end;
  gap: 2px;
  height: 160px;
  min-width: 100%;
}

.daybar {
  flex: 1 1 0;
  min-width: 9px;
  height: 100%;
  display: flex;
  align-items: flex-end;
  position: relative;
  border-radius: 4px;
  text-decoration: none;
  outline-offset: 2px;
}

.daybar-fill {
  display: block;
  width: 100%;
  min-height: 3px;
  border-radius: 4px 4px 0 0;
  background: var(--series-1);
  transition: background 0.12s ease;
}

.daybar.is-empty .daybar-fill { background: var(--surface-2); }
.daybar:hover .daybar-fill,
.daybar:focus-visible .daybar-fill { background: var(--series-2); }

.daybar.is-selected .daybar-fill {
  background: var(--series-2);
  box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--series-2);
}

/* Hover tooltip */
.daybar-tip {
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: var(--surface);
  padding: 6px 9px;
  border-radius: 7px;
  font-size: 12px;
  line-height: 1.35;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.12s ease;
  z-index: 5;
}

.daybar-tip strong { display: block; font-weight: 650; }
.daybar:hover .daybar-tip,
.daybar:focus-visible .daybar-tip { opacity: 1; }

/* Keep the tooltip inside the card at the extremes. */
.daybar:first-child .daybar-tip { left: 0; transform: none; }
.daybar:last-child .daybar-tip { left: auto; right: 0; transform: none; }

/* ---------- Range picker ---------- */

.rangepicker {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: 9px;
  overflow: hidden;
  background: var(--surface);
}

.rangepicker a {
  padding: 7px 14px;
  font-size: 14px;
  text-decoration: none;
  color: var(--muted);
  border-right: 1px solid var(--border);
  white-space: nowrap;
}

.rangepicker a:last-child { border-right: none; }
.rangepicker a:hover { background: var(--surface-2); color: var(--text); }
.rangepicker a.active { background: var(--accent); color: #fff; }

@media (prefers-reduced-motion: reduce) {
  .donut-arc, .daybar-fill, .daybar-tip { transition: none; }
}

/* ---------- Pagination ---------- */

.pager { display: flex; gap: 8px; align-items: center; justify-content: center; margin-top: 20px; font-size: 14px; }

/* ---------- Login ---------- */

.auth-wrap { max-width: 380px; margin: 10vh auto; }
.auth-wrap .brand { justify-content: center; margin-bottom: 18px; font-size: 18px; }

/* ---------------------------------------------------------------------------
   Narrow screens: the horizontal nav becomes an off-canvas drawer.
   1000px is where the eight nav items plus the brand stop fitting on one line.
   --------------------------------------------------------------------------- */

@media (max-width: 1000px) {
  .topbar { gap: 12px; }

  /* Hamburger */
  .navtoggle {
    display: grid;
    place-items: center;
    width: 38px;
    height: 38px;
    flex: none;
    padding: 0;
    border: 1px solid var(--border);
    border-radius: 9px;
    background: var(--surface);
    color: var(--text);
    cursor: pointer;
  }
  .navtoggle .bars,
  .navtoggle .bars::before,
  .navtoggle .bars::after {
    content: "";
    display: block;
    width: 17px;
    height: 2px;
    border-radius: 2px;
    background: currentColor;
  }
  .navtoggle .bars { position: relative; }
  .navtoggle .bars::before { position: absolute; top: -5px; }
  .navtoggle .bars::after { position: absolute; top: 5px; }

  /* The drawer itself */
  .nav {
    position: fixed;
    inset: 0 auto 0 0;
    width: min(78vw, 280px);
    z-index: 60;
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 14px 12px;
    background: var(--surface);
    border-right: 1px solid var(--border);
    box-shadow: 2px 0 24px rgb(0 0 0 / 18%);
    transform: translateX(-102%);
    transition: transform 0.22s ease;
    overflow-y: auto;
    overscroll-behavior: contain;
  }

  body.nav-open .nav { transform: translateX(0); }

  .nav a {
    padding: 11px 12px;
    font-size: 15px;
    border-radius: 9px;
  }


  .nav-signout {
    display: block;
    margin-top: auto;
    padding-top: 14px;
    border-top: 1px solid var(--border);
  }
  .nav-signout .btn { width: 100%; justify-content: center; }

  /* The top-bar sign-out is redundant once it lives in the drawer. */
  .logout { display: none; }

  .navscrim {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 50;
    background: rgb(0 0 0 / 45%);
    animation: fade-in 0.18s ease;
  }
  .navscrim[hidden] { display: none; }

  body.nav-open { overflow: hidden; }
}

@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }

@media (prefers-reduced-motion: reduce) {
  .nav { transition: none; }
  .navscrim { animation: none; }
}

/* ---------------------------------------------------------------------------
   Responsive hardening.
   Grid and flex children default to min-width:auto, which lets long content
   (payee names, SMS bodies, tables) push the page wider than the viewport.
   Pinning them to 0 is what actually stops the sideways scroll.
   --------------------------------------------------------------------------- */

html, body { max-width: 100%; overflow-x: hidden; }

.grid > *, .stack > *, .barrow, .party, .tile { min-width: 0; }
.card { min-width: 0; overflow-wrap: break-word; }
.mono, .legend-name, .barrow .name { overflow-wrap: anywhere; }

@media (max-width: 760px) {
  .donut-layout { grid-template-columns: 1fr; gap: 20px; }
  .donut-figure { max-width: 230px; margin: 0 auto; }
  .grid-2 { grid-template-columns: 1fr; }
}

@media (max-width: 640px) {
  .page { padding: 16px 12px 50px; }
  .topbar { padding: 10px 12px; gap: 10px; }
  .brand { font-size: 15px; }
  .card { padding: 14px; border-radius: 10px; }
  h1 { font-size: 20px; }
  h2 { font-size: 15px; }
  .tile .value { font-size: 21px; }
  .grid, .grid-tiles { gap: 12px; }
  .grid-tiles { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); }

  th.hide-sm, td.hide-sm { display: none; }

  /* Stack the header block rather than letting the action buttons squeeze it. */
  .page-head { flex-direction: column; align-items: stretch; gap: 10px; }
  .page-head .btn-row, .page-head .rangepicker { width: 100%; }
  .rangepicker a { flex: 1; text-align: center; padding: 8px 6px; }

  .filters { grid-template-columns: 1fr; }
  .bulkbar { gap: 8px; }
  .bulkbar select { min-width: 0; flex: 1; }
  .bulk-group { flex: 1 1 100%; }

  .daybars { height: 130px; }
  .months { height: 105px; }
  .months .mval { display: none; }
  .spark { height: 70px; }

  /* ---- Wide data tables become cards ----
     A six-column table cannot be read on a 360px screen, and side-scrolling a
     table you are trying to scan is worse than stacking it. */
  table.cards-sm thead { display: none; }
  table.cards-sm,
  table.cards-sm tbody,
  table.cards-sm tr,
  table.cards-sm td { display: block; width: 100%; }

  table.cards-sm tr {
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 10px 12px;
    margin-bottom: 10px;
    background: var(--surface);
  }
  table.cards-sm tr:hover { background: var(--surface); }

  table.cards-sm td {
    border: none;
    padding: 4px 0;
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 14px;
    text-align: right;
  }

  table.cards-sm td::before {
    content: attr(data-label);
    flex: none;
    text-align: left;
    color: var(--muted);
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
  }

  /* The lead cell reads as the card's title, not a labelled row. */
  table.cards-sm td[data-label="Payee"] {
    padding-bottom: 8px;
    margin-bottom: 4px;
    border-bottom: 1px solid var(--border);
    font-size: 15px;
  }
  table.cards-sm td[data-label="Payee"]::before { content: none; }
  table.cards-sm td[data-label="Payee"] { justify-content: flex-start; text-align: left; }
  table.cards-sm td.is-blank { display: none; }
  table.cards-sm .party { width: 100%; }

  /* A card list scrolls vertically, so the horizontal bleed is unwanted. */
  .table-wrap:has(> table.cards-sm) { margin: 0; padding: 0; overflow-x: visible; }

  /* Selection checkboxes ride along the top of each card. */
  table.cards-sm td[data-label="Select"] { justify-content: flex-start; padding: 0 0 6px; }
  table.cards-sm td[data-label="Select"]::before { content: none; }

  /* hide-sm exists to drop columns from a cramped table. A card has room, so
     those fields come back as labelled rows — only the purely decorative
     cells (inline bar charts) stay hidden. */
  table.cards-sm td.hide-sm { display: flex; }
  table.cards-sm td.is-blank { display: none; }
}

/* ---------- Weekly earned-vs-spent rows ---------- */

.weeklist { display: grid; gap: 16px; }

.weekrow {
  display: grid;
  gap: 6px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border);
}
.weeklist .weekrow:last-child { border-bottom: none; padding-bottom: 0; }

.weekrow.is-current { padding-left: 10px; border-left: 3px solid var(--accent); }

.weekhead {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  flex-wrap: wrap;
}
.weekname { font-weight: 600; font-size: 14px; }
.weeknet { font-variant-numeric: tabular-nums; font-size: 14px; }

.weekbar {
  display: grid;
  grid-template-columns: 54px 1fr auto;
  align-items: center;
  gap: 10px;
  font-size: 13px;
}
.weekbar-label { color: var(--muted); }
.weekbar .track {
  height: 8px;
  background: var(--surface-2);
  border-radius: 999px;
  overflow: hidden;
}
.weekbar .fill { display: block; height: 100%; border-radius: 999px; }
.weekbar-value { font-variant-numeric: tabular-nums; font-weight: 600; min-width: 76px; text-align: right; }

.weekfoot { font-size: 12px; color: var(--muted); }
.weekfoot a { color: var(--muted); }

/* A submit button that reads as a link, for inline destructive actions. */
.linkbtn {
  background: none;
  border: 0;
  padding: 0;
  font: inherit;
  color: var(--danger);
  cursor: pointer;
  text-decoration: underline;
}

@media (max-width: 640px) {
  .weekbar { grid-template-columns: 46px 1fr auto; gap: 8px; font-size: 12px; }
  .weekbar-value { min-width: 64px; }
}
