/* Spends — dark-first, mobile-first. Light theme is a token swap. */

:root {
  --bg: #0d0d0d;
  --surface: #161616;
  --surface-2: #1e1e1e;
  --line: #2a2a2a;
  --line-soft: #232323;
  --text: #f2f2f2;
  --text-dim: #9a9a9a;
  --text-faint: #6e6e6e;
  --accent: #fadfc5;          /* peach — primary buttons, active pills */
  --accent-ink: #1a1508;      /* text on accent */
  --money: #ef8e37;           /* rupee figures */
  --danger: #e5484d;
  --logo-bg: #3d3227;
  --radius: 18px;
  --radius-sm: 12px;
  --pad: 16px;
  --shadow: 0 10px 30px rgba(0, 0, 0, .45);
}

:root[data-theme="light"] {
  --bg: #f6f5f3;
  --surface: #ffffff;
  --surface-2: #f0efec;
  --line: #e2e0dc;
  --line-soft: #eceae6;
  --text: #1a1a1a;
  --text-dim: #6b6b6b;
  --text-faint: #93918c;
  --accent: #f5c99a;
  --accent-ink: #2b1e0c;
  --money: #c2681a;
  --danger: #c62a2f;
  --logo-bg: #e8dbc9;
  --shadow: 0 10px 30px rgba(0, 0, 0, .10);
}

:root[data-theme="light"] .logo { color: #4a3a26; }

* { box-sizing: border-box; }

/* several components set `display`, which would otherwise beat [hidden] */
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font: 400 16px/1.5 "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: contain;
  padding-bottom: calc(96px + env(safe-area-inset-bottom));
}

h1, h2 { margin: 0; font-weight: 700; letter-spacing: -.01em; }

.sprite { display: none; }

.ic {
  width: 20px; height: 20px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ── top bar ─────────────────────────────────────────────────────── */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: calc(12px + env(safe-area-inset-top)) var(--pad) 12px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line-soft);
}

.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }

.logo {
  display: grid;
  place-items: center;
  width: 40px; height: 40px;
  border-radius: 50%;
  background: var(--logo-bg);
  color: var(--accent);
  font-size: 19px;
  font-weight: 600;
}

.topbar h1 { font-size: 20px; }

.icon-btn {
  display: grid;
  place-items: center;
  width: 44px; height: 44px;
  flex: none;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  transition: background .15s, border-color .15s;
}

.icon-btn.sm { width: 36px; height: 36px; }
.icon-btn:active { background: var(--surface-2); }
.icon-btn:hover { border-color: var(--text-faint); }

/* ── layout ──────────────────────────────────────────────────────── */
.wrap {
  max-width: 760px;
  margin: 0 auto;
  padding: 16px var(--pad) 0;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  padding: 20px var(--pad);
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.card-title { font-size: 19px; }
.center { text-align: center; }
.ta-r { text-align: right; }

/* ── segmented tabs ──────────────────────────────────────────────── */
.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  padding: 4px;
  background: var(--surface-2);
  border-radius: 999px;
}

.segmented.three { grid-template-columns: repeat(3, 1fr); }

.seg {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 10px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--text-dim);
  font: inherit;
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  transition: background .18s, color .18s;
}

.seg.is-active {
  background: color-mix(in srgb, var(--text) 12%, transparent);
  color: var(--text);
  font-weight: 600;
}

.seg span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ── forms ───────────────────────────────────────────────────────── */
form { display: flex; flex-direction: column; gap: 12px; }

.field {
  width: 100%;
  min-height: 50px;
  padding: 12px 16px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  font-size: 16px; /* keeps iOS from zooming on focus */
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}

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

.field:focus-visible {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent);
}

.field[type="date"], .field[type="month"] { appearance: none; }

/* keep the native picker icon visible on dark backgrounds */
:root[data-theme="dark"] .field::-webkit-calendar-picker-indicator { filter: invert(1) opacity(.65); }

.fl { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.fl > span { font-size: 13px; color: var(--text-dim); padding-left: 4px; }
.fl.block { gap: 8px; }

.btn-primary, .btn-muted {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 50px;
  padding: 12px 20px;
  border: 0;
  border-radius: 999px;
  font: inherit;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: filter .15s, background .15s;
}

.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-primary:active { filter: brightness(.92); }

.btn-muted {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--line);
}
.btn-muted:active { background: var(--line); }
.grow { flex: 1; }

.owe-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.owe-grid .fl:first-child { grid-column: 1 / -1; }
.owe-grid button { grid-column: 1 / -1; }

/* ── stats ───────────────────────────────────────────────────────── */
.stat {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 14px 16px;
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
}

.stat-label { font-size: 13px; color: var(--text-dim); }
.stat-value { font-size: 22px; font-weight: 700; letter-spacing: -.02em; }
.accent { color: var(--money); }

.stat-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* ── toolbar (search + sorts) ────────────────────────────────────── */
.toolbar { display: flex; flex-direction: column; gap: 12px; }
.search { border-radius: 999px; }
.sorts { display: flex; gap: 8px; }

.pill {
  flex: 1;
  min-height: 42px;
  padding: 8px 16px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
  transition: background .15s, color .15s, border-color .15s;
}

.pill.is-active { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }

/* ── list "tables" ───────────────────────────────────────────────── */
.tbl { border: 1px solid var(--line-soft); border-radius: var(--radius-sm); overflow: hidden; }

.tbl-head {
  display: none; /* rows are self-describing on small screens */
  gap: 10px;
  padding: 12px 14px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--line-soft);
  font-size: 13px;
  font-weight: 600;
  color: var(--text-dim);
}

.tr {
  display: grid;
  gap: 10px;
  align-items: center;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line-soft);
}

.tr:last-child { border-bottom: 0; }

.exp-cols, .owe-cols { grid-template-columns: minmax(0, 1fr) auto 40px; }
.day-cols { grid-template-columns: minmax(0, 1fr) auto auto; }

.c-main { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.c-name { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.c-sub { font-size: 13px; color: var(--text-dim); }
.c-date { display: none; font-size: 14px; color: var(--text-dim); white-space: nowrap; }
.c-amt { font-weight: 600; color: var(--money); white-space: nowrap; }
.c-num { color: var(--text-dim); font-size: 14px; }

.row-btn {
  display: grid;
  place-items: center;
  width: 36px; height: 36px;
  margin-left: auto;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--text-faint);
  cursor: pointer;
  transition: color .15s, background .15s;
}
.row-btn:hover { color: var(--danger); background: color-mix(in srgb, var(--danger) 14%, transparent); }
.row-btn.settle:hover { color: var(--money); background: color-mix(in srgb, var(--money) 14%, transparent); }

.tr.is-settled .c-name { text-decoration: line-through; color: var(--text-faint); }
.tr.is-settled .c-amt { color: var(--text-faint); }

.empty, .error {
  padding: 28px 14px;
  text-align: center;
  color: var(--text-dim);
  font-size: 15px;
}
.error { color: var(--danger); }

/* ── monthly chart ───────────────────────────────────────────────── */
.chart {
  display: flex;
  align-items: flex-end;
  gap: 2px;
  height: 96px;
  padding: 10px 12px;
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
}

.chart:empty { display: none; }

.bar {
  flex: 1;
  min-height: 2px;
  border-radius: 3px 3px 1px 1px;
  background: color-mix(in srgb, var(--money) 42%, transparent);
  transition: background .15s;
}
.bar.has-value { background: var(--money); }

/* ── FAB + bottom sheet ──────────────────────────────────────────── */
.fab {
  position: fixed;
  right: var(--pad);
  bottom: calc(20px + env(safe-area-inset-bottom));
  z-index: 30;
  display: grid;
  place-items: center;
  width: 54px; height: 54px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
  cursor: pointer;
}
.fab:active { background: var(--surface-2); }

.sheet-scrim {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(0, 0, 0, .55);
  animation: fade .2s ease;
}

.sheet {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 41;
  max-height: 88dvh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 18px var(--pad) calc(22px + env(safe-area-inset-bottom));
  background: var(--surface);
  border-top: 1px solid var(--line);
  border-radius: 22px 22px 0 0;
  box-shadow: var(--shadow);
  animation: rise .24s cubic-bezier(.22, 1, .36, 1);
}

@media (min-width: 640px) {
  .sheet {
    left: 50%; right: auto; bottom: 24px;
    width: min(560px, calc(100vw - 32px));
    transform: translateX(-50%);
    border-radius: 22px;
    border: 1px solid var(--line);
    animation: fade .2s ease;
  }
}

.sheet-head { display: flex; align-items: center; justify-content: space-between; }
.sheet-head h2 { font-size: 19px; }
.sheet-actions { display: flex; gap: 10px; }
.note { margin: 0; font-size: 13px; color: var(--text-dim); }

@keyframes rise { from { transform: translateY(100%); } to { transform: none; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

/* ── install prompt + toast ──────────────────────────────────────── */
.install-bar {
  position: fixed;
  left: var(--pad); right: var(--pad);
  bottom: calc(20px + env(safe-area-inset-bottom));
  z-index: 29;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 10px 10px 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 999px;
  box-shadow: var(--shadow);
  font-size: 14px;
}
.install-bar span { flex: 1; min-width: 0; }
.install-bar .pill { flex: none; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(88px + env(safe-area-inset-bottom));
  z-index: 50;
  transform: translate(-50%, 12px);
  max-width: calc(100vw - 32px);
  padding: 11px 18px;
  border-radius: 999px;
  background: var(--text);
  color: var(--bg);
  font-size: 14px;
  font-weight: 500;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s, transform .2s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ── wider screens ───────────────────────────────────────────────── */
@media (min-width: 560px) {
  .wrap { padding-top: 22px; gap: 18px; }
  .card { padding: 22px 20px; }
  .tbl-head { display: grid; }
  .exp-cols, .owe-cols { grid-template-columns: minmax(0, 1fr) 120px 130px 44px; }
  .c-date { display: block; }
  .c-sub { display: none; }
  .owe-grid { grid-template-columns: minmax(0, 1fr) 130px 170px auto; align-items: end; }
  .owe-grid .fl:first-child { grid-column: auto; }
  .owe-grid button { grid-column: auto; }
  .toolbar { flex-direction: row; align-items: center; justify-content: space-between; }
  .search { max-width: 300px; }
  .sorts .pill { flex: none; }
  .stat-row { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
