:root {
  /* Red accent (variable names kept for brevity; the app theme is black + red) */
  --teal: #ef4444;
  --teal-dark: #b91c1c;
  --teal-700: #7f1d1d;
  /* Black surfaces */
  --bg: #0a0a0b;
  --card: #18181b;
  --ink: #fafafa;
  --muted: #a1a1aa;
  --line: #2a2a2e;
  --danger: #f87171;
  --shadow: 0 1px 3px rgba(0, 0, 0, .5), 0 8px 24px rgba(0, 0, 0, .45);
  --radius: 16px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  overscroll-behavior-y: none;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: .82rem; }
.center { text-align: center; }
.danger { color: var(--danger); }
.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0);
}

button { font: inherit; cursor: pointer; }

/* ---------- LOCK SCREEN ---------- */
.lock {
  position: fixed; inset: 0; z-index: 100;
  background: linear-gradient(160deg, var(--teal) 0%, var(--teal-700) 100%);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  padding: calc(24px + var(--safe-top)) 24px calc(24px + var(--safe-bottom));
}
.lock-inner { width: 100%; max-width: 320px; text-align: center; }
.brand img { border-radius: 18px; box-shadow: 0 8px 24px rgba(0,0,0,.25); }
.brand h1 { margin: 12px 0 2px; font-size: 1.6rem; letter-spacing: .5px; }
.lock .muted { color: rgba(255,255,255,.8); }
.pin-dots { display: flex; gap: 14px; justify-content: center; margin: 28px 0 8px; height: 18px; }
.pin-dots span {
  width: 14px; height: 14px; border-radius: 50%;
  border: 2px solid rgba(255,255,255,.6); transition: all .15s;
}
.pin-dots span.filled { background: #fff; border-color: #fff; }
.pin-error { min-height: 20px; color: #fecaca; font-size: .85rem; margin: 4px 0 12px; }
.keypad {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; margin-top: 8px;
}
.keypad button {
  aspect-ratio: 1; border-radius: 50%; border: none;
  background: rgba(255,255,255,.16); color: #fff; font-size: 1.5rem; font-weight: 500;
  display: flex; align-items: center; justify-content: center;
  transition: transform .08s, background .15s;
}
.keypad button:active { transform: scale(.92); background: rgba(255,255,255,.32); }
.keypad .key-ghost { background: transparent; font-size: 1.2rem; }
.lock.shake .pin-dots { animation: shake .4s; }
@keyframes shake {
  0%,100% { transform: translateX(0); }
  20%,60% { transform: translateX(-8px); }
  40%,80% { transform: translateX(8px); }
}

/* ---------- APP SHELL ---------- */
.app { min-height: 100%; padding-bottom: calc(72px + var(--safe-bottom)); }
.topbar {
  position: sticky; top: 0; z-index: 5;
  background: linear-gradient(160deg, var(--teal) 0%, var(--teal-dark) 100%);
  color: #fff;
  padding: calc(16px + var(--safe-top)) 20px 18px;
  display: flex; align-items: flex-start; justify-content: space-between;
  border-radius: 0 0 22px 22px;
}
.topbar-title { margin: 0; font-size: 1.35rem; }
.topbar-sub { margin: 2px 0 0; font-size: .85rem; opacity: .85; }
.icon-btn {
  background: rgba(255,255,255,.18); border: none; color: #fff;
  width: 40px; height: 40px; border-radius: 12px; font-size: 1.1rem;
}
main { padding: 16px; max-width: 640px; margin: 0 auto; }
.view-title { margin: 4px 0 16px; font-size: 1.2rem; }

/* ---------- SUMMARY ---------- */
.summary-card {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 18px; margin-top: -8px;
}
.summary-label { color: var(--muted); font-size: .85rem; }
.summary-total { display: block; font-size: 2.2rem; font-weight: 700; margin-top: 2px; }
.summary-breakdown { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.cat-pill {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--bg); border-radius: 999px; padding: 6px 12px; font-size: .82rem;
}
.cat-pill .dot { width: 9px; height: 9px; border-radius: 50%; }

/* ---------- FILTERS ---------- */
.filter-row { display: flex; gap: 10px; margin: 18px 0 10px; }
.filter-row select {
  flex: 1; padding: 11px 12px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--card); color: var(--ink); font-size: .9rem;
}

/* ---------- EXPENSE LIST ---------- */
.expense-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.day-header {
  font-size: .78rem; text-transform: uppercase; letter-spacing: .04em;
  color: var(--muted); margin: 14px 2px 2px; display: flex; justify-content: space-between;
}
.expense-item {
  background: var(--card); border-radius: 14px; box-shadow: var(--shadow);
  padding: 14px; display: flex; align-items: center; gap: 12px; border: none; width: 100%; text-align: left;
}
.expense-item:active { transform: scale(.99); }
.exp-icon {
  width: 42px; height: 42px; border-radius: 12px; flex: none;
  display: flex; align-items: center; justify-content: center; font-size: 1.2rem; color: #fff;
}
.exp-body { flex: 1; min-width: 0; }
.exp-cat { font-weight: 600; }
.exp-meta { color: var(--muted); font-size: .82rem; margin-top: 2px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.exp-amount { font-weight: 700; font-size: 1.05rem; white-space: nowrap; }
.empty { text-align: center; color: var(--muted); margin-top: 48px; line-height: 1.6; }

/* ---------- SETTINGS ---------- */
.setting-group {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 16px 18px; margin-bottom: 16px;
}
.setting-group h3 { margin: 0 0 4px; font-size: 1rem; }
.setting-row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 0; border-top: 1px solid var(--line);
}
.setting-group h3 + .setting-row, .setting-group p + .setting-row { border-top: none; }
.setting-group p + .setting-row { padding-top: 4px; }

/* ---------- BUTTONS ---------- */
.btn { border: 1px solid var(--line); background: var(--card); color: var(--ink);
  padding: 9px 16px; border-radius: 10px; font-weight: 600; font-size: .9rem; }
.btn-primary { background: var(--teal); border-color: var(--teal); color: #fff; }
.btn-ghost { background: transparent; }
.btn-danger { background: transparent; border-color: var(--danger); color: var(--danger); }
.btn:disabled { opacity: .5; }
.full { width: 100%; margin-top: 12px; }

/* ---------- FAB ---------- */
.fab {
  position: fixed; right: 20px; bottom: calc(84px + var(--safe-bottom)); z-index: 8;
  width: 60px; height: 60px; border-radius: 50%; border: none;
  background: var(--teal); color: #fff; font-size: 2rem; line-height: 1;
  box-shadow: 0 8px 24px rgba(239,68,68,.45);
}
.fab:active { transform: scale(.93); }

/* ---------- BOTTOM NAV ---------- */
.bottom-nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 7;
  background: var(--card); border-top: 1px solid var(--line);
  display: flex; padding: 8px 0 calc(8px + var(--safe-bottom));
}
.nav-btn {
  flex: 1; background: none; border: none; color: var(--muted);
  display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: .72rem;
}
.nav-btn .nav-ico { font-size: 1.3rem; filter: grayscale(1); opacity: .7; }
.nav-btn.active { color: var(--teal); font-weight: 600; }
.nav-btn.active .nav-ico { filter: none; opacity: 1; }

/* ---------- SHEET ---------- */
.sheet-backdrop { position: fixed; inset: 0; background: rgba(15,23,42,.45); z-index: 19; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  background: var(--card); border-radius: 22px 22px 0 0;
  padding: 10px 20px calc(24px + var(--safe-bottom));
  max-width: 640px; margin: 0 auto;
  box-shadow: 0 -8px 40px rgba(15,23,42,.2);
  animation: slideUp .25s ease;
  max-height: 92vh; overflow-y: auto;
}
@keyframes slideUp { from { transform: translateY(100%); } to { transform: translateY(0); } }
.sheet-handle { width: 40px; height: 4px; border-radius: 2px; background: var(--line); margin: 4px auto 12px; }
.sheet h2 { margin: 0 0 16px; font-size: 1.2rem; }
.field { display: block; margin-bottom: 16px; border: none; padding: 0; }
.field > span, .field legend { display: block; font-size: .85rem; color: var(--muted); margin-bottom: 6px; padding: 0; }
.field input {
  width: 100%; padding: 13px 14px; border: 1px solid var(--line); border-radius: 12px;
  font-size: 1rem; background: var(--bg); color: var(--ink);
}
.field input:focus { outline: 2px solid var(--teal); border-color: var(--teal); background: var(--card); }
.amount-input { display: flex; align-items: center; background: var(--bg); border: 1px solid var(--line); border-radius: 12px; padding-left: 14px; }
.amount-input:focus-within { outline: 2px solid var(--teal); border-color: var(--teal); }
.amount-input .currency { font-size: 1.3rem; color: var(--muted); }
.amount-input input { border: none; background: transparent; font-size: 1.4rem; font-weight: 600; padding-left: 6px; }
.amount-input input:focus { outline: none; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  border: 1px solid var(--line); background: var(--bg); color: var(--ink);
  padding: 9px 14px; border-radius: 999px; font-size: .9rem; display: inline-flex; align-items: center; gap: 6px;
}
.chip.selected { background: var(--teal); border-color: var(--teal); color: #fff; }
.sheet-actions { display: flex; gap: 10px; align-items: center; margin-top: 4px; }

/* ---------- RECEIPT PHOTO ---------- */
.photo-controls { display: flex; gap: 10px; }
.photo-controls .btn { flex: 1; }
.photo-preview { margin-top: 12px; display: flex; flex-direction: column; gap: 10px; align-items: flex-start; }
.photo-preview img {
  width: 100%; max-height: 320px; object-fit: contain;
  border-radius: 12px; border: 1px solid var(--line); background: #000;
}
.exp-thumb {
  width: 40px; height: 40px; flex: none; border-radius: 9px;
  object-fit: cover; border: 1px solid var(--line);
}

/* ---------- TOAST ---------- */
.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(96px + var(--safe-bottom)); z-index: 30;
  background: #27272a; color: #fafafa; padding: 12px 18px; border-radius: 12px;
  border: 1px solid var(--line);
  font-size: .9rem; box-shadow: var(--shadow); max-width: 90%; text-align: center;
  animation: toastIn .2s ease;
}
@keyframes toastIn { from { opacity: 0; transform: translate(-50%, 10px); } to { opacity: 1; transform: translate(-50%, 0); } }
