/* =========================================================
   UK Budget Tracker — styles
   Palette + tokens follow the validated dataviz reference palette.
   ========================================================= */

:root {
  color-scheme: light;

  /* surfaces */
  --page:        #f9f9f7;
  --surface:     #fcfcfb;
  --surface-2:   #f2f1ed;
  --border:      rgba(11,11,11,0.10);
  --border-strong: rgba(11,11,11,0.16);

  /* ink */
  --text-primary:   #0b0b0b;
  --text-secondary: #52514e;
  --text-muted:     #898781;

  /* categorical (fixed order — never cycled) */
  --series-1: #2a78d6; /* transport / blue */
  --series-2: #eb6834; /* food / orange */
  --series-3: #1baf7a; /* incidentals / aqua */
  --series-4: #eda100;
  --series-5: #e87ba4;

  /* status */
  --good:     #0ca30c;
  --warning:  #fab219;
  --serious:  #ec835a;
  --critical: #d03b3b;

  /* accent (uses series-1 blue as the app's action color) */
  --accent:      #2a78d6;
  --accent-ink:  #ffffff;

  --radius-sm: 10px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --shadow-sheet: 0 -8px 30px rgba(0,0,0,0.18);
  --shadow-card: 0 1px 2px rgba(11,11,11,0.06);

  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page:        #0d0d0d;
    --surface:     #1a1a19;
    --surface-2:   #232322;
    --border:      rgba(255,255,255,0.10);
    --border-strong: rgba(255,255,255,0.18);

    --text-primary:   #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted:     #898781;

    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
    --series-4: #c98500;
    --series-5: #d55181;

    --good:     #0ca30c;
    --warning:  #fab219;
    --serious:  #ec835a;
    --critical: #e66767;

    --accent: #3987e5;
    --shadow-sheet: 0 -8px 30px rgba(0,0,0,0.5);
    --shadow-card: 0 1px 2px rgba(0,0,0,0.3);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page:        #0d0d0d;
  --surface:     #1a1a19;
  --surface-2:   #232322;
  --border:      rgba(255,255,255,0.10);
  --border-strong: rgba(255,255,255,0.18);
  --text-primary:   #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted:     #898781;
  --series-1: #3987e5;
  --series-2: #d95926;
  --series-3: #199e70;
  --series-4: #c98500;
  --series-5: #d55181;
  --good:     #0ca30c;
  --warning:  #fab219;
  --serious:  #ec835a;
  --critical: #e66767;
  --accent: #3987e5;
  --shadow-sheet: 0 -8px 30px rgba(0,0,0,0.5);
  --shadow-card: 0 1px 2px rgba(0,0,0,0.3);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body {
  margin: 0;
  padding: 0;
  background: var(--page);
  color: var(--text-primary);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}
body {
  min-height: 100vh;
  min-height: 100dvh;
}
h1, h2, h3, p { margin: 0; }
button { font-family: inherit; }
input, select {
  font-family: inherit;
  font-size: 16px; /* prevents iOS Safari zoom-on-focus */
}

/* ---------------- Lock screen ---------------- */
.lock-screen {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--page);
  padding: 24px calc(24px + var(--safe-right)) calc(24px + var(--safe-bottom)) calc(24px + var(--safe-left));
  z-index: 100;
}
.lock-card {
  width: 100%;
  max-width: 360px;
  text-align: center;
}
.lock-icon { font-size: 40px; margin-bottom: 8px; }
.lock-card h1 { font-size: 20px; font-weight: 700; margin-bottom: 6px; }
.lock-sub { color: var(--text-secondary); font-size: 14px; margin-bottom: 20px; }
.lock-card form { display: flex; flex-direction: column; gap: 12px; }
.lock-error { color: var(--critical); font-size: 13px; text-align: left; margin: -4px 0 0; }
.lock-remember {
  display: flex;
  align-items: center;
  gap: 8px;
  justify-content: center;
  margin-top: 18px;
  font-size: 13px;
  color: var(--text-secondary);
}
.lock-remember input { width: 18px; height: 18px; }

/* ---------------- App shell ---------------- */
.app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(14px) saturate(1.4);
  -webkit-backdrop-filter: blur(14px) saturate(1.4);
  border-bottom: 1px solid var(--border);
  padding-top: var(--safe-top);
}
.topbar-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px 14px calc(20px + var(--safe-left));
  padding-right: calc(20px + var(--safe-right));
  gap: 12px;
}
.topbar-title h1 {
  font-size: 19px;
  font-weight: 700;
  letter-spacing: -0.01em;
}
.topbar-sub {
  font-size: 12.5px;
  color: var(--text-secondary);
  margin-top: 2px;
}
.icon-btn {
  border: none;
  background: var(--surface-2);
  color: var(--text-primary);
  width: 36px;
  height: 36px;
  border-radius: 50%;
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
}
.icon-btn:active { background: var(--border-strong); }

.views {
  flex: 1;
  padding: 16px calc(16px + var(--safe-right)) 100px calc(16px + var(--safe-left));
  max-width: 640px;
  width: 100%;
  margin: 0 auto;
}
.view[hidden] { display: none; }

/* ---------------- Hero / dashboard ---------------- */
.hero-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  box-shadow: var(--shadow-card);
}
.hero-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}
.hero-label {
  display: block;
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 4px;
}
.hero-value {
  display: block;
  font-size: 34px;
  font-weight: 800;
  letter-spacing: -0.02em;
  font-variant-numeric: proportional-nums;
}
.hero-badge {
  flex: 0 0 auto;
  font-size: 12.5px;
  font-weight: 700;
  padding: 6px 12px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--good) 16%, transparent);
  color: var(--good);
  white-space: nowrap;
  margin-top: 4px;
}
.hero-badge.is-over {
  background: color-mix(in srgb, var(--critical) 16%, transparent);
  color: var(--critical);
}
.progress-track {
  margin-top: 16px;
  height: 10px;
  border-radius: 999px;
  background: var(--surface-2);
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  border-radius: 999px;
  background: var(--good);
  width: 0%;
  transition: width .3s ease, background-color .3s ease;
}
.progress-fill.is-over { background: var(--critical); }
.hero-meta {
  display: flex;
  justify-content: space-between;
  margin-top: 10px;
  font-size: 13px;
  color: var(--text-secondary);
}
.hero-meta strong { color: var(--text-primary); font-weight: 700; }

.stat-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-top: 12px;
}
.stat-tile {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-card);
}
.stat-tile-label {
  font-size: 11.5px;
  color: var(--text-secondary);
}
.stat-tile-value {
  font-size: 19px;
  font-weight: 700;
  margin-top: 3px;
  letter-spacing: -0.01em;
}
.stat-tile-sub {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 1px;
}

.today-note {
  margin-top: 12px;
  padding: 12px 14px;
  border-radius: var(--radius-md);
  background: color-mix(in srgb, var(--critical) 10%, var(--surface));
  border: 1px solid color-mix(in srgb, var(--critical) 30%, var(--border));
  color: var(--text-primary);
  font-size: 13.5px;
  line-height: 1.4;
}

.section-block { margin-top: 26px; }
.section-heading {
  font-size: 15px;
  font-weight: 700;
  margin-bottom: 10px;
}
.section-heading-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}
.section-heading-row .section-heading { margin-bottom: 0; }
.link-btn {
  border: none;
  background: none;
  color: var(--accent);
  font-size: 13.5px;
  font-weight: 600;
  padding: 4px 0;
}

/* ---------------- Category breakdown ---------------- */
.category-breakdown {
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.cat-row-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: 13.5px;
  margin-bottom: 6px;
}
.cat-row-name {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
}
.cat-swatch {
  width: 10px;
  height: 10px;
  border-radius: 3px;
  flex: 0 0 auto;
}
.cat-row-amounts { color: var(--text-secondary); font-variant-numeric: tabular-nums; }
.cat-row-amounts strong { color: var(--text-primary); }
.cat-track {
  position: relative;
  height: 10px;
  border-radius: 999px;
  background: var(--surface-2);
  overflow: hidden;
}
.cat-fill {
  position: absolute;
  inset: 0 auto 0 0;
  height: 100%;
  border-radius: 999px;
}
.cat-marker {
  position: absolute;
  top: -2px;
  bottom: -2px;
  width: 2px;
  background: var(--text-primary);
  opacity: 0.35;
}
.cat-row-note {
  font-size: 11.5px;
  color: var(--text-muted);
  margin-top: 5px;
}

/* ---------------- Expense list ---------------- */
.expense-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.expense-item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  text-align: left;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  box-shadow: var(--shadow-card);
}
.expense-item:active { background: var(--surface-2); }
.expense-cat-dot {
  width: 10px;
  height: 10px;
  border-radius: 3px;
  flex: 0 0 auto;
}
.expense-main { flex: 1; min-width: 0; }
.expense-what {
  display: block;
  font-size: 14.5px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.expense-sub {
  display: block;
  font-size: 12.5px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 1px;
}
.expense-amount {
  flex: 0 0 auto;
  font-weight: 700;
  font-size: 15px;
  font-variant-numeric: tabular-nums;
}

.list-day-header {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  margin: 18px 0 8px;
}
.list-day-header:first-child { margin-top: 4px; }

.empty-state {
  text-align: center;
  color: var(--text-muted);
  font-size: 13.5px;
  padding: 40px 20px;
}

/* ---------------- Log controls ---------------- */
.log-controls { margin-bottom: 4px; }
#log-search {
  width: 100%;
  padding: 11px 14px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-primary);
  margin-bottom: 10px;
}
.chip-row {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 4px;
  -ms-overflow-style: none;
  scrollbar-width: none;
}
.chip-row::-webkit-scrollbar { display: none; }
.chip {
  flex: 0 0 auto;
  padding: 7px 13px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
}
.chip.is-active {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}
.log-summary {
  font-size: 12.5px;
  color: var(--text-muted);
  margin: 10px 2px 14px;
}

/* ---------------- Daily "latest day" summary panel ---------------- */
.daily-today-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px;
  box-shadow: var(--shadow-card);
  margin-bottom: 16px;
}
.daily-today-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}
.daily-today-heading {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.daily-today-eyebrow {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}
.daily-today-day {
  font-size: 19px;
  font-weight: 800;
  letter-spacing: -0.01em;
}
.daily-today-date {
  font-size: 12.5px;
  color: var(--text-secondary);
}
.daily-today-badge {
  flex: 0 0 auto;
  font-size: 12.5px;
  font-weight: 700;
  padding: 6px 12px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--good) 16%, transparent);
  color: var(--good);
  white-space: nowrap;
  margin-top: 2px;
}
.daily-today-badge.is-over {
  background: color-mix(in srgb, var(--critical) 16%, transparent);
  color: var(--critical);
}
.daily-today-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-top: 16px;
}
.daily-today-stat {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.daily-today-stat-label {
  font-size: 11.5px;
  color: var(--text-secondary);
}
.daily-today-stat-value {
  font-size: 17px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
}
.daily-today-note {
  margin-top: 14px;
  padding: 12px 14px;
  border-radius: var(--radius-md);
  background: color-mix(in srgb, var(--critical) 10%, var(--surface));
  border: 1px solid color-mix(in srgb, var(--critical) 30%, var(--border));
  color: var(--text-primary);
  font-size: 13px;
  line-height: 1.4;
}

/* ---------------- Daily list ---------------- */
.daily-legend {
  display: flex;
  gap: 16px;
  font-size: 12.5px;
  color: var(--text-secondary);
  margin-bottom: 12px;
  align-items: center;
}
.daily-legend span { display: flex; align-items: center; gap: 6px; }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.dot-good { background: var(--good); }
.dot-bad { background: var(--critical); }

.daily-list { display: flex; flex-direction: column; gap: 8px; }
.daily-row {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  box-shadow: var(--shadow-card);
}
.daily-row.is-today {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
}
.daily-row-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.daily-row-day {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 14px;
}
.daily-row-date { color: var(--text-muted); font-weight: 500; font-size: 12.5px; }
.daily-row-total { font-weight: 700; font-variant-numeric: tabular-nums; }
.daily-row-bars {
  display: flex;
  height: 6px;
  border-radius: 999px;
  overflow: hidden;
  margin-top: 10px;
  background: var(--surface-2);
}
.daily-row-bars span { height: 100%; }
.daily-row-meta {
  display: flex;
  justify-content: space-between;
  margin-top: 8px;
  font-size: 12px;
  color: var(--text-secondary);
}
.daily-row-meta-bad { color: var(--critical); font-weight: 700; }
.daily-row-meta-good { color: var(--good); font-weight: 600; }
.daily-row-note {
  margin-top: 8px;
  font-size: 12px;
  color: var(--critical);
  line-height: 1.4;
}
.daily-row.is-future { opacity: 0.45; }

/* ---------------- Settings ---------------- */
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.form-grid label,
.sheet form > label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 12.5px;
  color: var(--text-secondary);
  font-weight: 600;
}
.form-grid input,
.form-grid select,
.sheet form input,
.sheet form select {
  padding: 11px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-primary);
}
.settings-note {
  font-size: 12.5px;
  color: var(--text-secondary);
  line-height: 1.5;
  margin-bottom: 12px;
}
.btn-row {
  display: flex;
  gap: 10px;
  margin-top: 12px;
  flex-wrap: wrap;
}
.app-version {
  text-align: center;
  font-size: 11.5px;
  color: var(--text-muted);
  margin-top: 36px;
  padding-bottom: 10px;
}

.btn {
  border: none;
  border-radius: var(--radius-sm);
  padding: 11px 18px;
  font-size: 14.5px;
  font-weight: 700;
  cursor: pointer;
}
.btn-block { width: 100%; margin-top: 8px; }
.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-primary:active { opacity: 0.85; }
.btn-secondary { background: var(--surface-2); color: var(--text-primary); }
.btn-ghost { background: transparent; color: var(--text-secondary); border: 1px solid var(--border); }
.btn-danger { background: color-mix(in srgb, var(--critical) 14%, transparent); color: var(--critical); }
.btn-primary:disabled { opacity: 0.5; }

/* category editor rows */
.category-editor { display: flex; flex-direction: column; gap: 10px; }
.category-edit-row {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px;
}
.category-edit-row-top {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}
.category-edit-row-top input[type="text"] {
  flex: 1;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-primary);
  font-weight: 700;
}
.category-edit-row input[type="color"] {
  width: 34px;
  height: 34px;
  border: none;
  border-radius: 8px;
  background: none;
  padding: 0;
  flex: 0 0 auto;
}
.category-edit-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.category-edit-grid label {
  font-size: 11.5px;
  color: var(--text-secondary);
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.category-edit-grid input {
  padding: 8px 9px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-primary);
}
.cat-remove-btn {
  border: none;
  background: none;
  color: var(--critical);
  font-size: 12px;
  font-weight: 700;
  margin-top: 8px;
}

/* ---------------- Tab bar ---------------- */
.tabbar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 30;
  display: flex;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(14px) saturate(1.4);
  -webkit-backdrop-filter: blur(14px) saturate(1.4);
  border-top: 1px solid var(--border);
  padding: 8px calc(8px + var(--safe-right)) calc(8px + var(--safe-bottom)) calc(8px + var(--safe-left));
}
.tab-btn {
  flex: 1;
  border: none;
  background: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 6px 0 2px;
  color: var(--text-muted);
}
.tab-btn.is-active { color: var(--accent); }
.tab-icon { font-size: 20px; line-height: 1; }
.tab-label { font-size: 10.5px; font-weight: 600; }

/* ---------------- FAB ---------------- */
.fab {
  position: fixed;
  right: calc(20px + var(--safe-right));
  bottom: calc(78px + var(--safe-bottom));
  z-index: 25;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 28px;
  font-weight: 400;
  line-height: 1;
  box-shadow: 0 6px 20px rgba(0,0,0,0.25);
  display: flex;
  align-items: center;
  justify-content: center;
}
.fab:active { transform: scale(0.94); }

/* ---------------- Bottom sheet ---------------- */
.sheet-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 40;
}
.sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 41;
  background: var(--surface);
  border-radius: 22px 22px 0 0;
  box-shadow: var(--shadow-sheet);
  padding: 10px 20px calc(24px + var(--safe-bottom));
  max-height: 88vh;
  overflow-y: auto;
  animation: sheet-in .25s ease;
}
@keyframes sheet-in {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}
.sheet-handle {
  width: 36px;
  height: 4px;
  border-radius: 999px;
  background: var(--border-strong);
  margin: 6px auto 12px;
}
.sheet-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}
.sheet-header h2 { font-size: 17px; font-weight: 700; }
.sheet form { display: flex; flex-direction: column; gap: 14px; }
.sheet-actions { margin-top: 6px; display: flex; flex-direction: column; gap: 10px; }

/* ---------------- Toast ---------------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(100px + var(--safe-bottom));
  transform: translateX(-50%);
  background: var(--text-primary);
  color: var(--page);
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  z-index: 60;
  box-shadow: 0 6px 20px rgba(0,0,0,0.25);
  animation: toast-in .2s ease;
}
@keyframes toast-in {
  from { opacity: 0; transform: translate(-50%, 8px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

/* ---------------- Small screens ---------------- */
@media (max-width: 360px) {
  .hero-value { font-size: 28px; }
  .stat-tile-value { font-size: 16px; }
  .daily-today-stat-value { font-size: 15px; }
}
