/* 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; }

.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; }

/* ---------- 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; }

@media (max-width: 640px) {
  .page { padding: 16px 14px 50px; }
  .topbar { padding: 10px 14px; gap: 12px; }
  .tile .value { font-size: 22px; }
  th.hide-sm, td.hide-sm { display: none; }
}
