:root {
  --teal-900: #134e4a;
  --teal-700: #0f766e;
  --teal-600: #0d9488;
  --teal-50: #f0fdfa;
  --green-600: #16a34a;
  --green-50: #f0fdf4;
  --amber-500: #f59e0b;
  --amber-50: #fffbeb;
  --red-600: #dc2626;
  --red-50: #fef2f2;
  --indigo-600: #4f46e5;
  --ink: #0f172a;
  --muted: #64748b;
  --line: #e2e8f0;
  --bg: #f1f5f9;
  --card: #ffffff;
  --radius: 16px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 8px 24px rgba(15, 23, 42, .06);
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, .08);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
h1, h2, h3 { margin: 0; line-height: 1.2; }
button { font-family: inherit; cursor: pointer; }

/* ---------- Buttons ---------- */
.btn {
  border: 1px solid transparent;
  border-radius: 12px;
  padding: 12px 18px;
  font-size: 15px;
  font-weight: 600;
  background: #fff;
  color: var(--ink);
  transition: transform .04s ease, background .15s ease, box-shadow .15s ease;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--teal-700); color: #fff; box-shadow: var(--shadow-sm); }
.btn-primary:hover { background: var(--teal-600); }
.btn-ghost { background: transparent; border-color: var(--line); color: var(--ink); }
.btn-ghost:hover { background: #fff; }
.btn-danger { background: var(--red-50); color: var(--red-600); border-color: #fecaca; }
.btn-danger:hover { background: #fee2e2; }
.btn-block { width: 100%; }
.btn-sm { padding: 8px 12px; font-size: 13px; border-radius: 10px; }
.icon-btn { background: none; border: none; font-size: 18px; color: var(--muted); padding: 6px; line-height: 1; }

/* ---------- Auth ---------- */
.auth-view {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: radial-gradient(1200px 600px at 50% -10%, #ccfbf1, var(--bg));
}
.auth-card {
  width: 100%;
  max-width: 420px;
  background: var(--card);
  border-radius: 22px;
  box-shadow: var(--shadow);
  padding: 32px 28px;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-mark { font-size: 30px; }
.brand h1 { font-size: 24px; letter-spacing: -.02em; }
.tagline { color: var(--muted); margin: 12px 0 22px; font-size: 15px; }
.seg {
  display: flex; gap: 4px; background: var(--bg);
  padding: 4px; border-radius: 12px; margin-bottom: 18px;
}
.seg-btn {
  flex: 1; border: none; background: transparent; padding: 10px;
  border-radius: 9px; font-weight: 600; color: var(--muted); font-size: 14px;
}
.seg-btn.is-active { background: #fff; color: var(--teal-700); box-shadow: var(--shadow-sm); }
.seg-sm .seg-btn { padding: 8px 12px; }
.auth-form { display: grid; gap: 14px; }
.field { display: grid; gap: 6px; }
.field > span { font-size: 13px; font-weight: 600; color: #334155; }
.field input, .field textarea, .select {
  width: 100%; padding: 12px 14px; font-size: 16px;
  border: 1px solid var(--line); border-radius: 12px; background: #fff; color: var(--ink);
}
.field input:focus, .field textarea:focus, .select:focus {
  outline: none; border-color: var(--teal-600); box-shadow: 0 0 0 3px rgba(13,148,136,.15);
}
.form-error { background: var(--red-50); color: var(--red-600); border-radius: 10px; padding: 10px 12px; font-size: 14px; margin: 0; }
.auth-note { text-align: center; color: var(--muted); font-size: 13px; margin: 16px 0 0; }

/* ---------- Top bar ---------- */
.topbar { background: var(--teal-900); color: #fff; }
.topbar-inner {
  max-width: 1080px; margin: 0 auto; padding: 12px 16px;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.brand-sm strong { font-size: 16px; letter-spacing: -.01em; }
.brand-sm .brand-mark { font-size: 20px; }
.topbar-right { display: flex; align-items: center; gap: 10px; }
.user-email { font-size: 13px; opacity: .85; max-width: 40vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar .btn-ghost { color: #fff; border-color: rgba(255,255,255,.25); }
.topbar .btn-ghost:hover { background: rgba(255,255,255,.1); }

/* ---------- Controls ---------- */
.controls { background: #fff; border-bottom: 1px solid var(--line); }
.controls-inner {
  max-width: 1080px; margin: 0 auto; padding: 14px 16px;
  display: flex; flex-wrap: wrap; align-items: flex-end; gap: 16px;
}
.control-group { display: grid; gap: 6px; }
.control-label { font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.controls .btn-primary { margin-left: auto; }
.select { padding: 9px 12px; font-size: 14px; }
.mode-btn.is-active { color: var(--teal-700); }
.control-hint { align-self: center; font-size: 13px; color: var(--muted); }
.control-hint strong { color: var(--teal-700); }

/* ---------- Alerts ---------- */
.alerts { max-width: 1080px; margin: 0 auto; padding: 14px 16px 0; display: grid; gap: 8px; }
.alert {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 14px; border-radius: 12px; font-size: 14px; font-weight: 500;
}
.alert-icon { font-size: 16px; }
.alert.ok { background: var(--green-50); color: #166534; border: 1px solid #bbf7d0; }
.alert.warn { background: var(--amber-50); color: #92400e; border: 1px solid #fde68a; }
.alert.danger { background: var(--red-50); color: #991b1b; border: 1px solid #fecaca; }
.alert.info { background: var(--teal-50); color: var(--teal-900); border: 1px solid #99f6e4; }

/* ---------- Tabs ---------- */
.tabs {
  max-width: 1080px; margin: 16px auto 0; padding: 0 8px;
  display: flex; gap: 2px; overflow-x: auto;
}
.tab {
  border: none; background: none; padding: 12px 14px; font-size: 14px; font-weight: 600;
  color: var(--muted); border-bottom: 3px solid transparent; white-space: nowrap;
}
.tab.is-active { color: var(--teal-700); border-bottom-color: var(--teal-700); }

/* ---------- Content ---------- */
.content { max-width: 1080px; margin: 0 auto; padding: 18px 16px 80px; }
.panel { display: grid; gap: 16px; }

/* Stat cards */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; }
.stat {
  background: var(--card); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow);
  border: 1px solid var(--line);
}
.stat-label { font-size: 13px; color: var(--muted); font-weight: 600; }
.stat-value { font-size: 28px; font-weight: 800; letter-spacing: -.02em; margin-top: 6px; }
.stat-sub { font-size: 13px; color: var(--muted); margin-top: 4px; }
.stat.accent { background: linear-gradient(135deg, var(--teal-700), var(--teal-600)); color: #fff; border: none; }
.stat.accent .stat-label, .stat.accent .stat-sub { color: rgba(255,255,255,.85); }

/* Card section */
.card {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  border: 1px solid var(--line); overflow: hidden;
}
.card-head { padding: 16px 18px; border-bottom: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.card-head h3 { font-size: 16px; }
.card-body { padding: 8px 18px 18px; }
.card-body.flush { padding: 0; }

.muted { color: var(--muted); }
.empty { padding: 28px 18px; text-align: center; color: var(--muted); font-size: 14px; }

/* Bill rows */
.bill-row {
  display: flex; align-items: center; gap: 12px; padding: 14px 18px; border-bottom: 1px solid var(--line);
}
.bill-row:last-child { border-bottom: none; }
.bill-main { flex: 1; min-width: 0; }
.bill-name { font-weight: 700; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.bill-meta { font-size: 13px; color: var(--muted); margin-top: 2px; }
.bill-amount { font-weight: 800; font-size: 17px; white-space: nowrap; }
.bill-actions { display: flex; gap: 6px; align-items: center; }
.pill { font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 999px; text-transform: uppercase; letter-spacing: .03em; }
.pill.paid { background: var(--green-50); color: #166534; }
.pill.auto { background: #eef2ff; color: var(--indigo-600); }
.pill.due-soon { background: var(--amber-50); color: #92400e; }
.pill.overdue { background: var(--red-50); color: var(--red-600); }
.pill.recurring { background: #f1f5f9; color: #475569; }
.bill-row.is-paid .bill-name { color: var(--muted); text-decoration: line-through; }

/* Table */
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: 12px 18px; text-align: left; font-size: 14px; border-bottom: 1px solid var(--line); }
.table th { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.table td.num, .table th.num { text-align: right; font-variant-numeric: tabular-nums; }
.table tr:last-child td { border-bottom: none; }
.deposit-amt { font-weight: 800; color: var(--green-600); }
.row-urgent td { background: var(--red-50); }

/* ---------- Timeline ---------- */
.timeline-totals {
  display: flex; flex-wrap: wrap; gap: 8px 18px; margin-top: 12px;
  font-size: 13px; color: var(--muted);
}
.timeline-totals strong { color: var(--ink); font-variant-numeric: tabular-nums; }
.timeline { display: grid; }
.tl-item {
  display: flex; gap: 14px; padding: 14px 18px; border-bottom: 1px solid var(--line);
  border-left: 3px solid var(--teal-600);
}
.tl-item:last-child { border-bottom: none; }
.tl-item.is-due { border-left-color: var(--amber-500); background: #fcfdfe; }
.tl-item.is-over { background: var(--red-50); border-left-color: var(--red-600); }
.tl-date {
  display: grid; place-items: center; align-content: center; width: 48px; flex: none;
  background: var(--bg); border-radius: 12px; padding: 6px 0; height: fit-content;
}
.tl-dow { font-size: 10px; font-weight: 700; text-transform: uppercase; color: var(--muted); letter-spacing: .04em; }
.tl-day { font-size: 19px; font-weight: 800; line-height: 1.1; }
.tl-mon { font-size: 10px; font-weight: 700; text-transform: uppercase; color: var(--muted); letter-spacing: .04em; }
.tl-body { flex: 1; min-width: 0; }
.tl-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 6px 12px; }
.tl-title { font-weight: 700; font-size: 15px; }
.tl-sub { font-size: 13px; margin-top: 2px; }
.alloc-list { margin-top: 8px; display: grid; gap: 2px; }
.alloc-row {
  display: grid; grid-template-columns: minmax(0, 1fr) auto auto; gap: 10px; align-items: baseline;
  font-size: 14px; padding: 5px 10px; border-radius: 9px; background: var(--bg);
}
.alloc-row.is-urgent { background: var(--red-50); }
.alloc-row .muted { font-size: 12px; }
.alloc-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.alloc-amt { font-weight: 700; font-variant-numeric: tabular-nums; }
.alloc-list .empty { padding: 8px 0; text-align: left; }

/* Bill progress */
.bill-card { border-bottom: 1px solid var(--line); }
.bill-card:last-child { border-bottom: none; }
.bill-card .bill-row { border-bottom: none; padding-bottom: 4px; }
.bill-progress { padding: 0 18px 16px; display: grid; gap: 8px; }
.progress { height: 8px; border-radius: 999px; background: var(--bg); overflow: hidden; }
.progress-fill { height: 100%; background: linear-gradient(90deg, var(--teal-600), var(--green-600)); border-radius: 999px; }
.progress-meta { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 8px; font-size: 13px; color: var(--muted); }
.progress-meta strong { color: var(--ink); font-variant-numeric: tabular-nums; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.chips-label { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.chip {
  font-size: 12px; font-weight: 600; padding: 4px 9px; border-radius: 999px;
  background: var(--teal-50); color: var(--teal-900); border: 1px solid #99f6e4;
  font-variant-numeric: tabular-nums;
}
.chip.is-urgent { background: var(--red-50); color: var(--red-600); border-color: #fecaca; }

/* Switches in form */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.switch-row { display: flex; flex-wrap: wrap; gap: 14px; margin-top: 4px; }
.switch { display: flex; align-items: center; gap: 8px; font-size: 14px; font-weight: 600; }
.switch input { width: 20px; height: 20px; accent-color: var(--teal-700); }

/* ---------- Modal ---------- */
.modal { position: fixed; inset: 0; z-index: 50; display: grid; place-items: end center; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(15,23,42,.45); }
.modal-card {
  position: relative; width: 100%; max-width: 520px; background: #fff;
  border-radius: 22px 22px 0 0; box-shadow: var(--shadow); max-height: 92dvh; overflow-y: auto;
}
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 20px 8px; }
.modal-head h2 { font-size: 19px; }
.bill-form { display: grid; gap: 14px; padding: 8px 20px 22px; }
.modal-actions { display: flex; align-items: center; gap: 10px; margin-top: 6px; }
.modal-actions .spacer { flex: 1; }

/* Toast */
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  background: var(--ink); color: #fff; padding: 12px 18px; border-radius: 12px;
  font-size: 14px; font-weight: 600; box-shadow: var(--shadow); z-index: 60; max-width: 90vw;
}

@media (min-width: 640px) {
  .modal { place-items: center; }
  .modal-card { border-radius: 22px; }
}
@media (max-width: 480px) {
  .stat-value { font-size: 24px; }
  .controls .btn-primary { margin-left: 0; width: 100%; }
  .bill-amount { font-size: 15px; }
}
