/* ===== Variables & Reset ===== */
:root {
  --bg-primary: #1a1a2e;
  --bg-secondary: #16213e;
  --bg-card: #0f3460;
  --bg-surface: #1e2a3a;
  --bg-input: #243447;
  --accent-orange: #e94560;
  --accent-blue: #4fc3f7;
  --accent-green: #66bb6a;
  --text-primary: #e8eaf6;
  --text-secondary: #90a4ae;
  --text-muted: #546e7a;
  --income-color: #4fc3f7;
  --expense-color: #ef5350;
  --divider: #1e3a5f;
  --nav-base-height: 64px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --nav-height: calc(var(--nav-base-height) + var(--safe-bottom));
  --header-height: 56px;
  --tab-height: 44px;
  --summary-height: 60px;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 4px 24px rgba(0,0,0,0.4);
  --font: 'Prompt', sans-serif;
}

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  height: 100%;
  overflow: hidden;
  background: var(--bg-primary);
  font-family: var(--font);
  color: var(--text-primary);
  font-size: 15px;
}

/* ===== App Container ===== */
#app {
  position: relative;
  width: 100%;
  max-width: 480px;
  height: 100dvh;
  margin: 0 auto;
  background: var(--bg-primary);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ===== Screens ===== */
.screen {
  position: absolute;
  inset: 0;
  bottom: var(--nav-height);
  display: flex;
  flex-direction: column;
  background: var(--bg-primary);
  transform: translateX(100%);
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  z-index: 10;
  overflow: hidden;
}

.screen.active {
  transform: translateX(0);
  z-index: 20;
}

/* Add screen needs to allow numpad overlay to escape */
#add-screen {
  overflow: visible;
}

#main-screen {
  transform: translateX(0);
  z-index: 5;
}

/* ===== App Header ===== */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--divider);
  height: var(--header-height);
  flex-shrink: 0;
}

.month-nav {
  display: flex;
  align-items: center;
  gap: 8px;
}

.month-title {
  font-size: 18px;
  font-weight: 600;
  color: var(--text-primary);
  min-width: 110px;
  text-align: center;
}

.nav-btn {
  background: none;
  border: none;
  color: var(--text-primary);
  font-size: 24px;
  cursor: pointer;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  transition: background 0.2s;
}

.nav-btn:hover {
  background: var(--bg-input);
}

.header-actions {
  display: flex;
  gap: 4px;
}

.icon-btn {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 18px;
  cursor: pointer;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  transition: background 0.2s, color 0.2s;
}

.icon-btn:hover {
  background: var(--bg-input);
  color: var(--text-primary);
}

/* Language Toggle Pill */
.lang-toggle-btn {
  display: flex;
  align-items: center;
  gap: 4px;
  background: var(--bg-input);
  border: 1.5px solid var(--divider);
  color: var(--text-primary);
  font-family: var(--font);
  font-size: 11px;
  font-weight: 700;
  padding: 5px 9px;
  border-radius: 20px;
  cursor: pointer;
  letter-spacing: 0.5px;
  transition: border-color 0.2s, background 0.2s, transform 0.15s;
  user-select: none;
}
.lang-toggle-btn:hover {
  border-color: var(--accent-orange);
  background: rgba(233,69,96,0.08);
}
.lang-toggle-btn:active { transform: scale(0.95); }
#lang-flag { font-size: 14px; line-height: 1; }
#lang-text { font-size: 11px; font-weight: 800; color: var(--accent-orange); }

/* ===== Tab Navigation ===== */
.tab-nav {
  display: flex;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--divider);
  height: var(--tab-height);
  flex-shrink: 0;
}

.tab-btn {
  flex: 1;
  background: none;
  border: none;
  color: var(--text-muted);
  font-family: var(--font);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  position: relative;
  transition: color 0.2s;
  padding: 0 2px;
}

.tab-btn::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 10%;
  right: 10%;
  height: 2.5px;
  background: var(--accent-orange);
  border-radius: 2px 2px 0 0;
  transform: scaleX(0);
  transition: transform 0.2s;
}

.tab-btn.active {
  color: var(--text-primary);
  font-weight: 600;
}

.tab-btn.active::after {
  transform: scaleX(1);
}

/* ===== Summary Bar ===== */
.summary-bar {
  display: none;
  background: var(--bg-secondary);
  padding: 10px 16px;
  border-bottom: 1px solid var(--divider);
  flex-shrink: 0;
}

.summary-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.summary-label {
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.summary-value {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-primary);
}

.summary-value.income { color: var(--income-color); }
.summary-value.expense { color: var(--expense-color); }

/* ===== Tab Content ===== */
.tab-content {
  flex: 1;
  overflow: hidden;
  position: relative;
}

.tab-panel {
  position: absolute;
  inset: 0;
  overflow-y: auto;
  display: none;
  scrollbar-width: thin;
  scrollbar-color: var(--divider) transparent;
}

.tab-panel::-webkit-scrollbar { width: 4px; }
.tab-panel::-webkit-scrollbar-track { background: transparent; }
.tab-panel::-webkit-scrollbar-thumb { background: var(--divider); border-radius: 4px; }

.tab-panel.active { display: block; }

/* ===== Daily List ===== */
.daily-list {
  padding-bottom: calc(var(--nav-height) + 16px);
}

.day-group {
  border-bottom: 1px solid var(--divider);
}

.day-header {
  display: flex;
  align-items: center;
  padding: 12px 16px 8px;
  position: sticky;
  top: 0;
  background: var(--bg-primary);
  z-index: 1;
  gap: 8px;
}

.day-number {
  font-size: 26px;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1;
  min-width: 36px;
}

.day-badge {
  padding: 2px 8px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
}

.day-badge.Mon { background: #37474f; }
.day-badge.Tue { background: #37474f; }
.day-badge.Wed { background: #37474f; }
.day-badge.Thu { background: #37474f; }
.day-badge.Fri { background: #2e7d32; }
.day-badge.Sat { background: #1565c0; }
.day-badge.Sun { background: #c62828; }

.day-date-text {
  font-size: 12px;
  color: var(--text-muted);
}

.day-totals {
  margin-left: auto;
  display: flex;
  gap: 12px;
  font-size: 13px;
}

.txn-list {
  padding: 0 0 8px 0;
}

.txn-item {
  display: flex;
  align-items: center;
  padding: 10px 16px;
  gap: 12px;
  cursor: pointer;
  transition: background 0.15s;
  position: relative;
}

.txn-item:hover {
  background: rgba(255,255,255,0.03);
}

.txn-item:active {
  background: rgba(255,255,255,0.06);
}

.txn-icon {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--bg-surface);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  flex-shrink: 0;
}

.txn-info {
  flex: 1;
  min-width: 0;
}

.txn-category {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.txn-note {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.txn-account {
  font-size: 11px;
  color: var(--text-muted);
}

.txn-amount {
  font-size: 15px;
  font-weight: 600;
  text-align: right;
  flex-shrink: 0;
}

.txn-amount.income { color: var(--income-color); }
.txn-amount.expense { color: var(--expense-color); }

.txn-delete {
  position: absolute;
  right: 4px;
  top: 50%;
  transform: translateY(-50%);
  background: var(--expense-color);
  border: none;
  color: white;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  font-size: 14px;
  cursor: pointer;
  display: none;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s;
  z-index: 2;
}

.txn-item:hover .txn-delete {
  display: flex;
}

/* ===== Empty State ===== */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 80px 32px;
  gap: 12px;
  text-align: center;
}

.empty-icon {
  font-size: 56px;
  animation: float 3s ease-in-out infinite;
}

@keyframes float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-8px); }
}

.empty-state p {
  color: var(--text-secondary);
  font-size: 16px;
}

.empty-sub {
  color: var(--text-muted) !important;
  font-size: 13px !important;
}

/* ===== FAB ===== */
.fab {
  position: absolute;
  right: 20px;
  bottom: calc(20px + var(--safe-bottom));
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent-orange), #ff6b35);
  border: none;
  color: white;
  cursor: pointer;
  box-shadow: 0 6px 20px rgba(233, 69, 96, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  transition: transform 0.2s, box-shadow 0.2s;
}

.fab:hover {
  transform: scale(1.1);
  box-shadow: 0 8px 28px rgba(233, 69, 96, 0.7);
}

.fab:active {
  transform: scale(0.95);
}

.fab-icon {
  font-size: 32px;
  line-height: 1;
  margin-top: -2px;
  transition: transform 0.3s;
}

/* ===== Bottom Nav ===== */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 50%;
  width: 100%;
  max-width: 480px;
  height: var(--nav-height);
  padding-bottom: var(--safe-bottom);
  background: var(--bg-secondary);
  border-top: 1px solid var(--divider);
  display: flex;
  transform: translateX(-50%);
  z-index: 1000;
}

.nav-item {
  flex: 1;
  background: none;
  border: none;
  color: var(--text-muted);
  font-family: var(--font);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  min-height: var(--nav-base-height);
  transition: color 0.2s;
}

.nav-icon {
  font-size: 22px;
  transition: transform 0.2s;
}

.nav-label {
  font-size: 10px;
  font-weight: 500;
}

.nav-item.active {
  color: var(--accent-orange);
}

.nav-item.active .nav-icon {
  transform: translateY(-2px);
}

/* ===== Add Screen ===== */
.add-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--divider);
  flex-shrink: 0;
}

.back-btn {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 18px;
  cursor: pointer;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  transition: background 0.2s, color 0.2s;
}

.back-btn:hover {
  background: var(--bg-input);
  color: var(--text-primary);
}

.add-title {
  font-size: 16px;
  font-weight: 600;
}

.save-btn {
  background: linear-gradient(135deg, var(--accent-orange), #ff6b35);
  border: none;
  color: white;
  font-family: var(--font);
  font-size: 14px;
  font-weight: 600;
  padding: 8px 16px;
  border-radius: 20px;
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s;
}

.save-btn:hover {
  transform: scale(1.05);
  box-shadow: 0 4px 12px rgba(233, 69, 96, 0.4);
}

/* ===== NEW ADD SCREEN ===== */
.add-header-new {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--divider);
  flex-shrink: 0;
}

.add-back-btn {
  background: none;
  border: none;
  color: var(--text-primary);
  font-size: 22px;
  cursor: pointer;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  transition: background 0.2s;
}
.add-back-btn:hover { background: var(--bg-input); }

.add-screen-title {
  font-size: 17px;
  font-weight: 600;
  color: var(--text-primary);
}

/* 3-way type bar */
.type3-bar {
  display: flex;
  gap: 8px;
  padding: 12px 16px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--divider);
  flex-shrink: 0;
}

.type3-btn {
  flex: 1;
  background: var(--bg-input);
  border: 1.5px solid var(--divider);
  color: var(--text-muted);
  font-family: var(--font);
  font-size: 13px;
  font-weight: 600;
  padding: 8px 4px;
  border-radius: 20px;
  cursor: pointer;
  transition: all 0.2s;
}
.type3-btn.active[data-type="income"] {
  border-color: var(--income-color);
  color: var(--income-color);
  background: rgba(79,195,247,0.12);
}
.type3-btn.active[data-type="expense"] {
  border-color: var(--expense-color);
  color: var(--expense-color);
  background: rgba(239,83,80,0.12);
}
.type3-btn.active[data-type="transfer"] {
  border-color: #ab47bc;
  color: #ab47bc;
  background: rgba(171,71,188,0.12);
}

/* Form rows list */
.form-list {
  flex: 1;
  overflow-y: auto;
}

.form-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  border-bottom: 1px solid var(--divider);
  min-height: 52px;
  gap: 12px;
}

.form-row-tap { cursor: pointer; }
.form-row-tap:hover { background: rgba(255,255,255,0.03); }
.form-row-tap:active { background: rgba(255,255,255,0.06); }

.frow-label {
  font-size: 14px;
  color: var(--text-secondary);
  font-weight: 500;
  flex-shrink: 0;
  min-width: 72px;
}

.frow-value {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
}

.date-value {
  gap: 10px;
}

.frow-date-input,
.frow-time-input {
  background: none;
  border: none;
  border-bottom: 1.5px solid var(--income-color);
  color: var(--text-primary);
  font-family: var(--font);
  font-size: 14px;
  font-weight: 500;
  padding: 2px 4px;
  outline: none;
  cursor: pointer;
  text-align: center;
}
.frow-date-input { width: 130px; }
.frow-time-input { width: 70px; }
.frow-date-input::-webkit-calendar-picker-indicator,
.frow-time-input::-webkit-calendar-picker-indicator {
  filter: invert(0.6);
}

.frow-amount-input {
  background: none;
  border: none;
  border-bottom: 1.5px solid var(--income-color);
  color: var(--text-primary);
  font-family: var(--font);
  font-size: 22px;
  font-weight: 600;
  padding: 2px 8px;
  outline: none;
  text-align: right;
  width: 100%;
  cursor: pointer;
  caret-color: var(--income-color);
}
.frow-amount-input::placeholder {
  color: var(--text-muted);
  font-weight: 300;
}

.frow-cat-display {
  font-size: 14px;
  color: var(--text-primary);
  font-weight: 500;
}

.frow-arrow {
  font-size: 20px;
  color: var(--text-muted);
  font-weight: 300;
}

.frow-select {
  background: none;
  border: none;
  color: var(--text-primary);
  font-family: var(--font);
  font-size: 14px;
  font-weight: 500;
  outline: none;
  text-align: right;
  cursor: pointer;
  direction: rtl;
}
.frow-select option { background: var(--bg-surface); direction: ltr; }

.frow-text-input {
  background: none;
  border: none;
  color: var(--text-primary);
  font-family: var(--font);
  font-size: 14px;
  padding: 2px 0;
  outline: none;
  text-align: right;
  width: 100%;
}
.frow-text-input::placeholder { color: var(--text-muted); }

/* ===== NUMPAD PANEL — direct #app child, above all screens ===== */
.numpad-panel {
  position: absolute;
  bottom: var(--nav-height);   /* sits just above the bottom-nav */
  left: 0;
  right: 0;
  background: #2a2a2a;
  border-top: 2px solid #3a3a3a;
  z-index: 200;                /* highest — above screens, nav, overlays */
  transform: translateY(100%);
  transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1);
  pointer-events: none;
}

.numpad-panel.open {
  transform: translateY(0);
  pointer-events: all;
}

.numpad-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  background: #3a3a3a;
  border-bottom: 1px solid #444;
}

.numpad-title {
  font-size: 15px;
  font-weight: 600;
  color: #ccc;
}

.numpad-hbtn {
  background: none;
  border: none;
  color: #aaa;
  font-size: 16px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
  transition: background 0.15s;
}
.numpad-hbtn:hover { background: rgba(255,255,255,0.1); }

.numpad-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1px;
  background: #1a1a1a;
}

.nk {
  background: #2e2e2e;
  border: none;
  color: var(--text-primary);
  font-family: var(--font);
  font-size: 22px;
  font-weight: 400;
  padding: 18px 8px;
  cursor: pointer;
  text-align: center;
  transition: background 0.12s;
  user-select: none;
}
.nk:active { background: #1a1a1a; }

.nk-del  { color: #ef9a9a; font-size: 20px; }
.nk-sym  { color: #ccc; font-size: 20px; background: #252525; }
.nk-empty { background: #252525; cursor: default; }

.nk-done {
  background: linear-gradient(135deg, var(--accent-orange), #ff6b35);
  color: white;
  font-size: 17px;
  font-weight: 700;
}
.nk-done:active { background: #c73652; }

/* ===== CATEGORY PICKER OVERLAY ===== */
.cat-overlay {
  position: absolute;
  inset: 0;
  bottom: var(--nav-height);
  background: rgba(0,0,0,0.65);
  z-index: 300;              /* above numpad (200) */
  display: flex;
  align-items: flex-end;
  backdrop-filter: blur(2px);
}

.cat-overlay.hidden { display: none; }

.cat-sheet {
  background: var(--bg-secondary);
  border-radius: 20px 20px 0 0;
  width: 100%;
  max-height: 70%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: slideUp 0.25s ease;
}

@keyframes slideUp {
  from { transform: translateY(100%); }
  to   { transform: translateY(0); }
}

.cat-sheet-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  border-bottom: 1px solid var(--divider);
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
  flex-shrink: 0;
}
.cat-hbtn {
  background: none; border: none; font-size: 18px; cursor: pointer;
  padding: 4px 8px; border-radius: 8px; transition: background 0.15s; line-height: 1;
}
.cat-hbtn:hover { background: rgba(255,255,255,0.08); }

.cat-edit-mode-label { color: var(--accent-orange); }

.cat-done-btn {
  background: var(--accent-orange); border: none; color: white;
  font-family: var(--font); font-size: 13px; font-weight: 700;
  padding: 6px 16px; border-radius: 20px; cursor: pointer;
  transition: background 0.15s;
}
.cat-done-btn:hover { background: #c73652; }

/* Grid in edit mode: items get relative + delete badge */
.cat-grid-modal {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
  padding: 16px;
  overflow-y: auto;
  padding-bottom: 32px;
}

/* reuse .cat-item, .cat-emoji, .cat-label */
.cat-item {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 10px 4px;
  border-radius: 10px;
  cursor: pointer;
  border: 1.5px solid transparent;
  background: var(--bg-surface);
  transition: all 0.18s;
}
.cat-item:hover  { border-color: var(--accent-orange); background: rgba(233,69,96,0.1); }
.cat-item.selected { border-color: var(--accent-orange); background: rgba(233,69,96,0.18); }
.cat-emoji { font-size: 22px; }
.cat-label {
  font-size: 9px;
  color: var(--text-muted);
  text-align: center;
  line-height: 1.2;
  word-break: break-all;
}

/* Delete badge on cat-item in edit mode */
.cat-del-badge {
  position: absolute;
  top: -6px; right: -6px;
  width: 18px; height: 18px;
  background: var(--expense-color);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 10px; color: white; font-weight: 700;
  cursor: pointer;
  z-index: 2;
  line-height: 1;
  border: 1.5px solid var(--bg-secondary);
}

/* Edit mode: items show edit cursor */
.cat-item.edit-mode { cursor: default; }
.cat-item.edit-mode:hover { border-color: #4fc3f7; background: rgba(79,195,247,0.1); }

/* Add new category row */
.cat-add-row {
  padding: 8px 16px 20px;
  flex-shrink: 0;
}
.cat-add-btn {
  width: 100%;
  background: rgba(79,195,247,0.1);
  border: 1.5px dashed var(--income-color);
  color: var(--income-color);
  font-family: var(--font);
  font-size: 14px;
  font-weight: 600;
  padding: 12px;
  border-radius: 12px;
  cursor: pointer;
  transition: all 0.2s;
}
.cat-add-btn:hover { background: rgba(79,195,247,0.2); }

/* Category add/edit inline dialog */
.cat-dialog {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
  border-radius: 20px 20px 0 0;
  backdrop-filter: blur(2px);
}
.cat-dialog.hidden { display: none; }

.cat-dialog-inner {
  background: var(--bg-input);
  border-radius: 16px;
  padding: 20px;
  width: 85%;
  box-shadow: 0 8px 32px rgba(0,0,0,0.5);
}
.cat-dialog-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--text-primary);
  text-align: center;
  margin-bottom: 16px;
}
.cat-dialog-row {
  display: flex;
  gap: 10px;
  margin-bottom: 16px;
}
.cat-dlg-emoji {
  width: 60px;
  background: var(--bg-surface);
  border: 1.5px solid var(--divider);
  border-radius: 10px;
  color: var(--text-primary);
  font-size: 24px;
  text-align: center;
  padding: 8px 4px;
  outline: none;
  flex-shrink: 0;
}
.cat-dlg-emoji:focus { border-color: var(--income-color); }
.cat-dlg-name {
  flex: 1;
  background: var(--bg-surface);
  border: 1.5px solid var(--divider);
  border-radius: 10px;
  color: var(--text-primary);
  font-family: var(--font);
  font-size: 15px;
  padding: 10px 14px;
  outline: none;
}
.cat-dlg-name:focus { border-color: var(--income-color); }
.cat-dialog-btns {
  display: flex;
  gap: 8px;
}
.cat-dlg-btn-cancel {
  flex: 1;
  background: var(--bg-surface);
  border: 1px solid var(--divider);
  color: var(--text-secondary);
  font-family: var(--font);
  font-size: 14px;
  font-weight: 600;
  padding: 11px;
  border-radius: 10px;
  cursor: pointer;
  transition: background 0.15s;
}
.cat-dlg-btn-cancel:hover { background: var(--divider); }
.cat-dlg-btn-save {
  flex: 1;
  background: linear-gradient(135deg, var(--accent-orange), #ff6b35);
  border: none;
  color: white;
  font-family: var(--font);
  font-size: 14px;
  font-weight: 700;
  padding: 11px;
  border-radius: 10px;
  cursor: pointer;
  transition: opacity 0.15s;
}
.cat-dlg-btn-save:hover { opacity: 0.88; }

/* Save button in add screen */
.add-save-row {
  padding: 14px 20px 10px;
  flex-shrink: 0;
}
.add-save-btn {
  width: 100%;
  background: linear-gradient(135deg, var(--accent-orange), #ff6b35);
  border: none;
  color: white;
  font-family: var(--font);
  font-size: 16px;
  font-weight: 700;
  padding: 15px;
  border-radius: 14px;
  cursor: pointer;
  letter-spacing: 0.5px;
  transition: transform 0.15s, box-shadow 0.15s;
  box-shadow: 0 4px 16px rgba(233,69,96,0.35);
}
.add-save-btn:hover  { transform: translateY(-1px); box-shadow: 0 6px 20px rgba(233,69,96,0.5); }
.add-save-btn:active { transform: scale(0.98); }


/* ===== Calendar ===== */
.calendar-view {
  padding: 8px;
  padding-bottom: calc(var(--nav-height) + 16px);
}

.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  text-align: center;
  padding: 4px 0;
}

.cal-day-header {
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 600;
  padding: 8px 0;
}

.calendar-days {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 2px;
}

.cal-day {
  min-height: 64px;
  border-radius: var(--radius-sm);
  padding: 4px 3px;
  cursor: pointer;
  transition: background 0.2s;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.cal-day:hover {
  background: var(--bg-surface);
}

.cal-day.today .cal-num {
  background: var(--accent-orange);
  color: white;
  border-radius: 50%;
  width: 22px;
  height: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.cal-day.other-month {
  opacity: 0.3;
}

.cal-num {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  width: 22px;
  height: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.cal-exp {
  font-size: 9px;
  color: var(--expense-color);
  font-weight: 600;
  text-align: center;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cal-inc {
  font-size: 9px;
  color: var(--income-color);
  font-weight: 600;
  text-align: center;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ===== Monthly View ===== */
.monthly-view {
  padding: 16px;
  padding-bottom: calc(var(--nav-height) + 16px);
}

.section-title {
  font-size: 14px;
  color: var(--text-secondary);
  margin-bottom: 12px;
  font-weight: 600;
}

.chart-section {
  margin-bottom: 24px;
}

.bar-chart {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.bar-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.bar-cat {
  width: 70px;
  font-size: 12px;
  color: var(--text-secondary);
  text-align: right;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.bar-track {
  flex: 1;
  height: 20px;
  background: var(--bg-surface);
  border-radius: 10px;
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  border-radius: 10px;
  transition: width 0.6s ease;
}

.bar-fill.expense { background: linear-gradient(90deg, var(--expense-color), #ff8a80); }
.bar-fill.income { background: linear-gradient(90deg, #0288d1, var(--income-color)); }

.bar-amount {
  width: 80px;
  font-size: 12px;
  color: var(--text-primary);
  font-weight: 600;
  text-align: right;
}

/* ===== Total View ===== */
.total-view {
  padding: 16px;
  padding-bottom: calc(var(--nav-height) + 16px);
}

.total-card {
  background: var(--bg-surface);
  border-radius: var(--radius);
  padding: 16px;
  border: 1px solid var(--divider);
}

.total-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 0;
  border-bottom: 1px solid var(--divider);
  font-size: 15px;
  color: var(--text-secondary);
}

.total-row:last-child {
  border-bottom: none;
}

.total-row.grand-total {
  font-size: 16px;
  font-weight: 700;
  color: var(--text-primary);
  padding-top: 16px;
}

/* ===== Note View ===== */
.note-view {
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.note-textarea {
  width: 100%;
  min-height: 200px;
  background: var(--bg-input);
  border: 1px solid var(--divider);
  border-radius: var(--radius);
  color: var(--text-primary);
  font-family: var(--font);
  font-size: 14px;
  padding: 12px;
  outline: none;
  resize: vertical;
  transition: border-color 0.2s;
}

.note-textarea:focus {
  border-color: var(--accent-orange);
}

.save-note-btn {
  background: linear-gradient(135deg, var(--accent-orange), #ff6b35);
  border: none;
  color: white;
  font-family: var(--font);
  font-size: 14px;
  font-weight: 600;
  padding: 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s;
}

.save-note-btn:hover {
  transform: scale(1.02);
  box-shadow: 0 4px 16px rgba(233, 69, 96, 0.4);
}

/* ===== Stats Screen ===== */
#stats-screen {
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* Stats Header */
.stats-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--divider);
  flex-shrink: 0;
}

.stats-month-nav {
  display: flex;
  align-items: center;
  gap: 4px;
}

/* Filter Button */
.stats-filter-wrap {
  position: relative;
}

.stats-filter-btn {
  display: flex;
  align-items: center;
  gap: 4px;
  background: var(--bg-input);
  border: 1px solid var(--divider);
  color: var(--text-primary);
  font-family: var(--font);
  font-size: 13px;
  font-weight: 600;
  padding: 6px 12px;
  border-radius: 20px;
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s;
}

.stats-filter-btn:hover {
  border-color: var(--accent-orange);
}

.filter-arrow {
  font-size: 10px;
  color: var(--text-muted);
}

.filter-dropdown {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  background: var(--bg-surface);
  border: 1px solid var(--divider);
  border-radius: var(--radius-sm);
  overflow: hidden;
  z-index: 200;
  box-shadow: 0 8px 24px rgba(0,0,0,0.5);
  min-width: 120px;
}

.filter-dropdown.hidden { display: none; }

.filter-opt {
  display: block;
  width: 100%;
  background: none;
  border: none;
  color: var(--text-secondary);
  font-family: var(--font);
  font-size: 14px;
  font-weight: 500;
  padding: 10px 16px;
  text-align: left;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.filter-opt:hover {
  background: var(--bg-input);
  color: var(--text-primary);
}

.filter-opt.active {
  color: var(--accent-orange);
  font-weight: 700;
}

/* Range Picker Row */
.stats-range-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 16px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--divider);
  flex-shrink: 0;
}

.stats-range-row.hidden { display: none; }

.range-field {
  flex: 1;
}

.range-sep {
  color: var(--text-muted);
  font-size: 18px;
  padding-bottom: 8px;
}

.range-apply-btn {
  background: linear-gradient(135deg, var(--accent-orange), #ff6b35);
  border: none;
  color: white;
  font-family: var(--font);
  font-size: 13px;
  font-weight: 700;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: transform 0.2s;
  white-space: nowrap;
}

.range-apply-btn:hover { transform: scale(1.04); }

/* Income/Expense Type Bar */
.stats-type-bar {
  display: flex;
  background: var(--bg-secondary);
  border-bottom: 2px solid var(--divider);
  flex-shrink: 0;
}

.stats-type-tab {
  flex: 1;
  background: none;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 11px 16px;
  gap: 8px;
  position: relative;
  transition: background 0.2s;
  border-bottom: 2.5px solid transparent;
  margin-bottom: -2px;
}

.stats-type-tab[data-stype="expense"].active { border-bottom-color: var(--expense-color); }
.stats-type-tab[data-stype="income"].active  { border-bottom-color: var(--income-color); }

.stats-type-tab + .stats-type-tab {
  border-left: 1px solid var(--divider);
}

.stype-label {
  font-size: 13px;
  color: var(--text-muted);
  font-weight: 500;
}

.stats-type-tab.active .stype-label {
  color: var(--text-primary);
  font-weight: 600;
}

.stype-amount {
  font-size: 14px;
  font-weight: 700;
}

/* Pie Chart */
.pie-wrap {
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
  /* Extra padding to give space for labels outside the circle */
  padding: 56px 72px;
  flex-shrink: 0;
}

.pie-canvas-box {
  position: relative;
  width: 200px;
  height: 200px;
  flex-shrink: 0;
}

#pie-canvas {
  width: 200px;
  height: 200px;
  display: block;
}

/* Labels are positioned relative to pie-wrap (the larger padded box) */
.pie-labels {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: visible;
}

.pie-label-item {
  position: absolute;
  display: flex;
  flex-direction: column;
  align-items: center;
  transform: translate(-50%, -50%);
  pointer-events: none;
  gap: 1px;
}

.pie-label-name {
  font-size: 10.5px;
  font-weight: 700;
  color: var(--text-primary);
  white-space: nowrap;
  text-shadow: 0 1px 6px rgba(0,0,0,0.9), 0 0 2px rgba(0,0,0,1);
  line-height: 1.2;
}

.pie-label-pct {
  font-size: 9.5px;
  font-weight: 600;
  color: rgba(200,210,220,0.9);
  text-shadow: 0 1px 4px rgba(0,0,0,0.9);
}

/* Stats Category List */
.stats-cat-list {
  flex: 1;
  overflow-y: auto;
  padding: 0 0 80px 0;
  scrollbar-width: thin;
  scrollbar-color: var(--divider) transparent;
}

.stats-cat-list::-webkit-scrollbar { width: 4px; }
.stats-cat-list::-webkit-scrollbar-thumb { background: var(--divider); border-radius: 4px; }

.scat-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 13px 16px;
  border-bottom: 1px solid var(--divider);
  transition: background 0.15s;
}

.scat-row:hover { background: rgba(255,255,255,0.03); }

.scat-badge {
  min-width: 50px;
  height: 30px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 800;
  /* Text dark on light badge colors (yellow/green) for contrast */
  color: rgba(0,0,0,0.75);
  flex-shrink: 0;
  letter-spacing: 0.3px;
}

.scat-info {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  min-width: 0;
}

.scat-emoji {
  font-size: 22px;
}

.scat-name {
  font-size: 14px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.scat-amount {
  font-size: 15px;
  font-weight: 700;
  flex-shrink: 0;
}

.stats-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px 16px;
  gap: 8px;
  color: var(--text-muted);
  font-size: 14px;
}

/* ===== Accounts Screen ===== */
.accounts-list {
  padding: 16px;
  overflow-y: auto;
  flex: 1;
  padding-bottom: calc(var(--nav-height) + 16px);
}

.account-card {
  background: var(--bg-surface);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
  border: 1px solid var(--divider);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.account-name {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
}

.account-balance {
  font-size: 16px;
  font-weight: 700;
}

/* ===== Toast ===== */
.toast {
  position: fixed;
  bottom: calc(var(--nav-height) + 16px);
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--bg-card);
  color: var(--text-primary);
  padding: 10px 20px;
  border-radius: 24px;
  font-size: 14px;
  font-weight: 500;
  opacity: 0;
  transition: opacity 0.3s, transform 0.3s;
  pointer-events: none;
  z-index: 999;
  box-shadow: var(--shadow);
  white-space: nowrap;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ===== Utility ===== */
.income { color: var(--income-color); }
.expense { color: var(--expense-color); }

/* ===== Responsive Desktop ===== */
@media (min-width: 480px) {
  #app {
    box-shadow: 0 0 60px rgba(0,0,0,0.8);
    border-radius: 24px;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    position: fixed;
    height: min(95dvh, 900px);
  }

  .bottom-nav {
    border-radius: 0 0 24px 24px;
  }
}
