/* ============================================================
   Expense Tracker — Mobile-first PWA
   ============================================================ */
:root {
  --bg: #0f172a;
  --bg-elev: #1e293b;
  --card: #ffffff;
  --card-bg: #1e293b;
  --text: #f1f5f9;
  --text-muted: #94a3b8;
  --primary: #6366f1;
  --primary-hover: #818cf8;
  --accent: #22c55e;
  --danger: #ef4444;
  --warning: #f59e0b;
  --border: #334155;
  --chip: #334155;
  --chip-text: #c7d2fe;
  --tag-text: #93c5fd;
  --tag-bg: #1e3a5f;
  --shadow: 0 4px 16px rgba(0,0,0,0.25);
  --radius: 14px;
  --radius-sm: 8px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  min-height: 100vh;
  overscroll-behavior-y: none;
}

button { font-family: inherit; cursor: pointer; }
input, textarea, select { font-family: inherit; font-size: 15px; }

.app {
  max-width: 480px;
  min-height: 100vh;
  margin: 0 auto;
  padding-bottom: 80px;
  position: relative;
  background: var(--bg);
}

.hidden { display: none !important; }
.muted { color: var(--text-muted); }
.small { font-size: 12px; }
.danger { color: var(--danger); }

/* Top bar */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 16px 12px;
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 10;
}
.topbar-date { font-size: 12px; color: var(--text-muted); }
.topbar-title { font-size: 20px; font-weight: 700; }

/* Cards */
.card {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 16px;
  margin: 0 16px 12px;
  border: 1px solid var(--border);
}

/* Today summary */
.today-summary { padding: 16px; }
.today-row { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }
.today-row .amount { font-size: 22px; font-weight: 700; }
.progress {
  height: 8px;
  background: var(--border);
  border-radius: 4px;
  overflow: hidden;
  margin-top: 8px;
}
.progress-bar {
  height: 100%;
  background: var(--accent);
  width: 0%;
  transition: width 0.3s;
}
.progress-bar.warn { background: var(--warning); }
.progress-bar.over { background: var(--danger); }

/* Quick add tiles */
.quickadd-section { padding: 0 16px 6px; }
.section-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
  font-weight: 600;
  font-size: 14px;
  color: var(--text-muted);
}
.tiles-row {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  padding-bottom: 6px;
  scrollbar-width: none;
}
.tiles-row::-webkit-scrollbar { display: none; }
.tile {
  flex: 0 0 auto;
  min-width: 90px;
  padding: 10px 12px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  text-align: center;
  color: var(--text);
  display: flex;
  flex-direction: column;
  gap: 2px;
  align-items: center;
  user-select: none;
  transition: transform 0.15s, background 0.15s;
}
.tile:active { transform: scale(0.95); background: var(--primary); }
.tile-emoji { font-size: 22px; line-height: 1; }
.tile-amount { font-weight: 700; font-size: 14px; }
.tile-label { font-size: 11px; color: var(--text-muted); }

/* Input area */
.input-card {
  margin: 8px 16px 16px;
  padding: 12px;
  background: var(--card-bg);
  border-radius: var(--radius);
  border: 1px solid var(--border);
}
.mode-toggle {
  display: flex;
  background: var(--bg);
  border-radius: 999px;
  padding: 3px;
  margin-bottom: 10px;
  border: 1px solid var(--border);
}
.mode-btn {
  flex: 1;
  padding: 8px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  border-radius: 999px;
  font-weight: 600;
  font-size: 13px;
  transition: all 0.2s;
}
.mode-btn.active {
  background: var(--primary);
  color: #fff;
}
.input {
  width: 100%;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  outline: none;
  resize: none;
}
.input:focus { border-color: var(--primary); }
.main-input { min-height: 44px; max-height: 120px; }
.input-row { margin-bottom: 8px; }
.input-actions { display: flex; gap: 8px; align-items: center; justify-content: flex-end; }
.input-hint { font-size: 12px; color: var(--text-muted); margin-top: 6px; min-height: 14px; }

.btn {
  border: none;
  border-radius: var(--radius-sm);
  padding: 10px 18px;
  font-weight: 600;
  font-size: 14px;
  transition: opacity 0.2s, transform 0.1s;
}
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-secondary { background: var(--card-bg); color: var(--text); border: 1px solid var(--border); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-ghost { background: transparent; color: var(--primary); }

.icon-btn {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 50%;
  width: 38px;
  height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text);
  font-size: 16px;
  padding: 0;
}
.mic-btn { background: var(--bg); }
.mic-btn.recording { background: var(--danger); animation: pulse 1.2s infinite; }
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(239,68,68,0.6); }
  50% { box-shadow: 0 0 0 8px rgba(239,68,68,0); }
}
.send-btn { padding: 10px 20px; }
.link-btn {
  background: transparent;
  border: none;
  color: var(--primary);
  font-size: 13px;
  font-weight: 600;
}

/* Recent list */
.recent-section { padding: 0 16px; }
.entry-list { list-style: none; padding: 0; margin: 0; }
.entry-list.large li { padding: 14px 12px; }
.entry-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: var(--card-bg);
  border: 1px solid var(--border);
  margin-bottom: 8px;
  cursor: pointer;
}
.entry-main { flex: 1; min-width: 0; }
.entry-title { font-weight: 600; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.entry-sub { font-size: 12px; color: var(--text-muted); display: flex; gap: 6px; flex-wrap: wrap; }
.entry-amount { font-weight: 700; font-size: 15px; margin-left: 8px; white-space: nowrap; }
.entry-amount.income { color: var(--accent); }
.entry-amount.expense { color: var(--text); }
.entry-tag {
  font-size: 11px;
  color: var(--tag-text);
}

/* Bottom nav */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 480px;
  display: flex;
  background: var(--card-bg);
  border-top: 1px solid var(--border);
  padding: 8px 0 max(8px, env(safe-area-inset-bottom));
  z-index: 50;
}
.nav-btn {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 11px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 4px 0;
}
.nav-btn .nav-ico { font-size: 20px; }
.nav-btn.active { color: var(--primary); font-weight: 600; }

/* Onboarding */
.onboarding {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 24px;
}
.onboard-step { text-align: center; padding: 24px; }
.onboard-emoji { font-size: 64px; margin-bottom: 16px; }
.onboard-step h1 { font-size: 28px; margin: 0 0 12px; }
.onboard-step p { color: var(--text-muted); margin: 0 0 20px; }
.onboard-cat-list {
  list-style: none;
  padding: 0;
  margin: 0 0 20px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.onboard-cat-list li {
  background: var(--card-bg);
  padding: 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  font-size: 13px;
}
.checkbox-row { display: flex; align-items: center; gap: 8px; margin: 16px 0; justify-content: center; }

/* Modals */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 100;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  animation: fadein 0.2s;
}
@keyframes fadein { from { opacity: 0; } to { opacity: 1; } }
.modal {
  background: var(--bg);
  width: 100%;
  max-width: 480px;
  max-height: 90vh;
  border-radius: 20px 20px 0 0;
  overflow-y: auto;
  animation: slideup 0.25s;
  border-top: 1px solid var(--border);
}
@keyframes slideup { from { transform: translateY(100%); } to { transform: translateY(0); } }
.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 5;
}
.modal-title { font-size: 17px; font-weight: 700; }
.modal-body { padding: 16px; }
.modal-foot {
  display: flex;
  gap: 10px;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  position: sticky;
  bottom: 0;
  background: var(--bg);
}
.modal-foot .btn { flex: 1; }
.close-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 22px;
  width: 30px;
  height: 30px;
}

/* Form fields */
.field { margin-bottom: 12px; }
.field label { display: block; font-size: 12px; color: var(--text-muted); margin-bottom: 4px; font-weight: 500; }
.field-row { display: flex; gap: 8px; align-items: center; }

.chip-row { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 4px; }
.chip {
  background: var(--chip);
  color: var(--chip-text);
  padding: 5px 10px;
  border-radius: 999px;
  font-size: 12px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: none;
}
.chip.tag { background: var(--tag-bg); color: var(--tag-text); }
.chip.add { background: transparent; border: 1px dashed var(--border); color: var(--text-muted); cursor: pointer; }
.chip-x { cursor: pointer; opacity: 0.7; font-weight: 700; }
.chip-x:hover { opacity: 1; }

/* Tag autocomplete */
.autocomplete {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin-top: 4px;
  max-height: 140px;
  overflow-y: auto;
}
.ac-item {
  padding: 8px 12px;
  cursor: pointer;
  font-size: 13px;
  display: flex;
  justify-content: space-between;
}
.ac-item:hover, .ac-item.active { background: var(--primary); color: #fff; }

/* Confirm warning */
.confidence-warn {
  background: rgba(245,158,11,0.1);
  border: 1px solid var(--warning);
  color: var(--warning);
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  font-size: 12px;
  margin-bottom: 12px;
}

/* Bulk rows */
.bulk-row {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px;
  margin-bottom: 10px;
}
.bulk-row-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: 600;
  font-size: 13px;
  margin-bottom: 4px;
}
.bulk-row-summary { font-size: 13px; color: var(--text-muted); }
.bulk-row-actions { display: flex; gap: 6px; margin-top: 8px; }
.bulk-row.expanded { background: var(--bg); }

/* Chat bubbles */
.chat-area {
  margin: 0 16px 8px;
  padding: 12px;
  background: var(--card-bg);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  max-height: 320px;
  overflow-y: auto;
}
.chat-bubble {
  max-width: 80%;
  padding: 8px 12px;
  border-radius: 14px;
  margin-bottom: 8px;
  font-size: 14px;
  word-wrap: break-word;
}
.chat-bubble.user {
  background: var(--primary);
  color: #fff;
  margin-left: auto;
  border-bottom-right-radius: 4px;
}
.chat-bubble.assistant {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}
.chat-bubble .view-link {
  display: block;
  margin-top: 6px;
  color: var(--primary);
  font-size: 12px;
  font-weight: 600;
}

/* Filters */
.filters-row {
  display: flex;
  gap: 8px;
  padding: 0 16px 12px;
}
.filters-row .input { flex: 1; }
.active-filters {
  margin: 0 16px 8px;
  padding: 10px 12px;
  background: var(--card-bg);
  border: 1px solid var(--primary);
  border-radius: var(--radius-sm);
  font-size: 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

/* Stats */
.stats-totals {
  display: flex;
  justify-content: space-around;
  text-align: center;
}
.stat-block { padding: 4px 8px; }
.stat-block .stat-num { font-size: 20px; font-weight: 700; }
.stat-block .stat-label { font-size: 11px; color: var(--text-muted); }
.cat-breakdown { list-style: none; padding: 0; margin: 0; }
.cat-row {
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}
.cat-row:last-child { border-bottom: none; }
.cat-row-head {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  margin-bottom: 4px;
}
.cat-row .progress { height: 6px; margin-top: 4px; }
.chart-card { padding: 12px; }

/* Lent */
.lent-totals {
  display: flex;
  justify-content: space-around;
  text-align: center;
}
.lent-totals .stat-num.lent { color: var(--accent); }
.lent-totals .stat-num.borrowed { color: var(--danger); }

.tabs {
  display: flex;
  margin: 0 16px 12px;
  background: var(--card-bg);
  border-radius: 999px;
  border: 1px solid var(--border);
  padding: 3px;
}
.tab-btn {
  flex: 1;
  padding: 8px;
  background: transparent;
  border: none;
  color: var(--text-muted);
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
}
.tab-btn.active { background: var(--primary); color: #fff; }

/* Settings */
.settings-list { padding-bottom: 24px; }
.settings-group-title {
  padding: 16px 16px 6px;
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.5px;
  text-transform: uppercase;
}
.settings-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  background: var(--card-bg);
  color: var(--text);
  border: none;
  border-bottom: 1px solid var(--border);
  width: 100%;
  text-align: left;
  font-size: 14px;
}
.settings-row.danger { color: var(--danger); }
.settings-row.toggle-row { cursor: default; }
.settings-row .chev { color: var(--text-muted); display: flex; align-items: center; gap: 6px; }
.small-input { width: 100px; padding: 6px 8px; font-size: 13px; }

/* Switch */
.switch { position: relative; display: inline-block; width: 42px; height: 24px; }
.switch input { display: none; }
.slider {
  position: absolute; cursor: pointer; inset: 0;
  background: var(--border);
  border-radius: 24px;
  transition: 0.2s;
}
.slider::before {
  content: "";
  position: absolute;
  height: 18px; width: 18px;
  left: 3px; bottom: 3px;
  background: white;
  border-radius: 50%;
  transition: 0.2s;
}
.switch input:checked + .slider { background: var(--primary); }
.switch input:checked + .slider::before { transform: translateX(18px); }

/* Toast */
#toast-root {
  position: fixed;
  bottom: 90px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 200;
  pointer-events: none;
}
.toast {
  background: var(--card-bg);
  color: var(--text);
  padding: 10px 16px;
  border-radius: 999px;
  border: 1px solid var(--border);
  margin-top: 6px;
  display: flex;
  align-items: center;
  gap: 12px;
  box-shadow: var(--shadow);
  pointer-events: auto;
  animation: slideup 0.2s;
  font-size: 13px;
  white-space: nowrap;
}
.toast .undo-btn {
  background: transparent;
  border: none;
  color: var(--primary);
  font-weight: 700;
  font-size: 13px;
}

/* Helpers */
.row-flex { display: flex; align-items: center; gap: 8px; }
.spacer { flex: 1; }
.divider { height: 1px; background: var(--border); margin: 12px 0; }

textarea.input { min-height: 60px; }

/* Scroll fix */
.screen { animation: fadein 0.2s; }
