/* ── MasariFlow Design System ─────────────────────────────── */
:root {
  --bg-primary: #0a0a0f;
  --bg-secondary: #12121a;
  --bg-card: #1a1a26;
  --bg-card-hover: #22222f;
  --bg-input: #16161f;
  --border: #2a2a3a;
  --border-focus: #6ee7b7;
  --text-primary: #f0f0f5;
  --text-secondary: #8888a0;
  --text-muted: #55556a;
  --accent: #6ee7b7;
  --accent-dim: rgba(110,231,183,0.15);
  --accent-gradient: linear-gradient(135deg, #6ee7b7, #3b82f6);
  --danger: #ef4444;
  --danger-dim: rgba(239,68,68,0.15);
  --warning: #f59e0b;
  --success: #10b981;
  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --radius-xl: 28px;
  --shadow-card: 0 2px 20px rgba(0,0,0,0.3);
  --shadow-glow: 0 0 30px rgba(110,231,183,0.08);
  --nav-height: 72px;
  --header-height: 56px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
  font-family: 'Plus Jakarta Sans', system-ui, -apple-system, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%; width: 100%;
  background: var(--bg-primary);
  color: var(--text-primary);
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }
.screen { position: fixed; inset: 0; z-index: 100; display: none; }
.screen.active { display: flex; }

/* ── Login ──────────────────────────────────────────────── */
.login-container {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  width: 100%; height: 100%; padding: 24px;
  background: var(--bg-primary);
}
.login-logo { text-align: center; margin-bottom: 40px; }
.logo-icon { font-size: 56px; margin-bottom: 12px; animation: float 3s ease-in-out infinite; }
@keyframes float { 0%,100%{transform:translateY(0)} 50%{transform:translateY(-8px)} }
.logo-text {
  font-size: 28px; font-weight: 800;
  background: var(--accent-gradient); -webkit-background-clip: text; -webkit-text-fill-color: transparent;
}
.logo-subtitle { color: var(--text-secondary); font-size: 14px; margin-top: 4px; }
.pin-input-group { text-align: center; margin-bottom: 32px; }
.pin-label { color: var(--text-secondary); font-size: 13px; display: block; margin-bottom: 16px; }
.pin-dots { display: flex; gap: 16px; justify-content: center; margin-bottom: 8px; }
.pin-dot {
  width: 14px; height: 14px; border-radius: 50%;
  border: 2px solid var(--border); transition: all 0.2s;
}
.pin-dot.filled { background: var(--accent); border-color: var(--accent); transform: scale(1.15); }
.pin-dot.error { border-color: var(--danger); animation: shake 0.4s; }
@keyframes shake { 25%{transform:translateX(-4px)} 75%{transform:translateX(4px)} }
.pin-hidden-input { position: absolute; opacity: 0; pointer-events: none; }
.pin-error { color: var(--danger); font-size: 13px; min-height: 20px; margin-top: 8px; }
.pin-keypad {
  display: grid; grid-template-columns: repeat(3, 72px); gap: 12px; justify-content: center;
}
.key-btn {
  width: 72px; height: 56px; border-radius: var(--radius-md);
  background: var(--bg-card); border: 1px solid var(--border);
  color: var(--text-primary); font-size: 22px; font-weight: 600;
  cursor: pointer; transition: all 0.15s;
  font-family: inherit;
}
.key-btn:active { background: var(--accent-dim); border-color: var(--accent); transform: scale(0.95); }
.key-empty { visibility: hidden; }
.key-delete { font-size: 18px; }

/* ── App Layout ─────────────────────────────────────────── */
.app {
  display: flex; flex-direction: column;
  height: 100%; width: 100%; max-width: 480px; margin: 0 auto;
  position: relative; overflow: hidden;
}
.app-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 20px; padding-top: calc(12px + var(--safe-top));
  height: calc(var(--header-height) + var(--safe-top));
  background: var(--bg-primary); border-bottom: 1px solid var(--border);
  position: relative; z-index: 10; flex-shrink: 0;
}
.header-title { font-size: 20px; font-weight: 700; }
.header-btn {
  width: 40px; height: 40px; border-radius: var(--radius-sm);
  background: none; border: none; color: var(--text-secondary);
  display: flex; align-items: center; justify-content: center; cursor: pointer;
  transition: color 0.2s;
}
.header-btn:active { color: var(--accent); }

.page-container {
  flex: 1; overflow-y: auto; overflow-x: hidden;
  padding-bottom: calc(var(--nav-height) + var(--safe-bottom) + 16px);
  scroll-behavior: smooth; -webkit-overflow-scrolling: touch;
}
.page { display: none; padding: 16px 20px; animation: fadeUp 0.25s ease; }
.page.active { display: block; }
@keyframes fadeUp { from{opacity:0;transform:translateY(12px)} to{opacity:1;transform:translateY(0)} }

/* ── Bottom Nav ─────────────────────────────────────────── */
.bottom-nav {
  display: flex; align-items: center; justify-content: space-around;
  height: calc(var(--nav-height) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: var(--bg-secondary); border-top: 1px solid var(--border);
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 50;
  max-width: 480px; margin: 0 auto;
}
.nav-item {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  background: none; border: none; color: var(--text-muted);
  font-size: 10px; font-family: inherit; font-weight: 500;
  cursor: pointer; padding: 8px 0; min-width: 56px; transition: color 0.2s;
}
.nav-item.active { color: var(--accent); }
.nav-item svg { transition: transform 0.2s; }
.nav-item.active svg { transform: scale(1.1); }
.nav-add { position: relative; }
.nav-add-icon {
  width: 48px; height: 48px; border-radius: 50%;
  background: var(--accent-gradient);
  display: flex; align-items: center; justify-content: center;
  color: #0a0a0f;
  box-shadow: 0 4px 20px rgba(110,231,183,0.3);
  transform: translateY(-8px); transition: transform 0.2s, box-shadow 0.2s;
}
.nav-add:active .nav-add-icon { transform: translateY(-8px) scale(0.92); }

/* ── Cards ──────────────────────────────────────────────── */
.safe-to-spend-card {
  background: var(--accent-gradient); border-radius: var(--radius-lg);
  padding: 24px; margin-bottom: 16px; position: relative; overflow: hidden;
}
.safe-to-spend-card::after {
  content: ''; position: absolute; top: -40%; right: -20%;
  width: 200px; height: 200px; border-radius: 50%;
  background: rgba(255,255,255,0.08);
}
.sts-label { font-size: 13px; font-weight: 500; color: rgba(10,10,15,0.6); }
.sts-amount { font-size: 40px; font-weight: 800; color: #0a0a0f; margin: 4px 0; }
.sts-sub { font-size: 12px; color: rgba(10,10,15,0.5); }
.budget-progress {
  height: 6px; background: rgba(10,10,15,0.15);
  border-radius: 3px; margin-top: 16px; overflow: hidden;
}
.budget-bar {
  height: 100%; background: rgba(10,10,15,0.35);
  border-radius: 3px; transition: width 0.6s ease;
}
.sts-details {
  display: flex; justify-content: space-between;
  margin-top: 8px; font-size: 11px; color: rgba(10,10,15,0.5);
}

.stat-cards { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 16px; }
.stat-card {
  background: var(--bg-card); border-radius: var(--radius-md);
  padding: 14px 12px; text-align: center;
  border: 1px solid var(--border); transition: border-color 0.2s;
}
.stat-card:active { border-color: var(--accent); }
.stat-label { display: block; font-size: 11px; color: var(--text-muted); margin-bottom: 4px; }
.stat-value { display: block; font-size: 18px; font-weight: 700; }

.section-card {
  background: var(--bg-card); border-radius: var(--radius-md);
  padding: 18px; margin-bottom: 14px; border: 1px solid var(--border);
}
.section-title { font-size: 15px; font-weight: 600; margin-bottom: 14px; }

/* ── Charts ─────────────────────────────────────────────── */
.chart-container { position: relative; width: 100%; height: 180px; }
.chart-donut-container { height: 200px; }
.category-legend { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.legend-item {
  display: flex; align-items: center; gap: 4px;
  font-size: 11px; color: var(--text-secondary);
}
.legend-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }

/* ── Expense List ───────────────────────────────────────── */
.expense-list { display: flex; flex-direction: column; gap: 2px; }
.expense-item {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 0; border-bottom: 1px solid var(--border);
  position: relative; overflow: hidden; transition: transform 0.2s;
  cursor: pointer;
}
.expense-item:last-child { border-bottom: none; }
.expense-emoji { font-size: 28px; width: 40px; text-align: center; flex-shrink: 0; }
.expense-info { flex: 1; min-width: 0; }
.expense-note { font-size: 14px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.expense-meta { font-size: 11px; color: var(--text-muted); margin-top: 2px; }
.expense-amount { font-size: 16px; font-weight: 700; flex-shrink: 0; }
.expense-actions {
  position: absolute; right: -120px; top: 0; bottom: 0;
  display: flex; width: 120px; transition: right 0.2s;
}
.expense-edit {
  flex: 1; background: var(--warning); display: flex;
  align-items: center; justify-content: center; color: white; font-size: 18px;
}
.expense-delete {
  flex: 1; background: var(--danger); display: flex;
  align-items: center; justify-content: center; color: white; font-size: 18px;
}
.expense-item.swiped .expense-actions { right: 0; }
.expense-item.swiped { transform: translateX(-120px); }

/* ── Add Page ───────────────────────────────────────────── */
.add-container { padding-top: 8px; }
.quick-add-bar { display: flex; gap: 8px; margin-bottom: 12px; }
.quick-input {
  flex: 1; padding: 14px 16px; border-radius: var(--radius-md);
  background: var(--bg-input); border: 1px solid var(--border);
  color: var(--text-primary); font-size: 15px; font-family: inherit;
  outline: none; transition: border-color 0.2s;
}
.quick-input:focus { border-color: var(--accent); }
.quick-parse-btn {
  width: 48px; border-radius: var(--radius-md);
  background: var(--accent-gradient); border: none;
  color: #0a0a0f; font-size: 20px; font-weight: 700; cursor: pointer;
  transition: transform 0.15s;
}
.quick-parse-btn:active { transform: scale(0.92); }
.parse-preview {
  background: var(--accent-dim); border-radius: var(--radius-md);
  padding: 12px 16px; margin-bottom: 12px;
  font-size: 14px; border: 1px solid rgba(110,231,183,0.2);
}
.divider-text {
  text-align: center; margin: 20px 0; position: relative;
  color: var(--text-muted); font-size: 12px;
}
.divider-text::before, .divider-text::after {
  content: ''; position: absolute; top: 50%;
  width: calc(50% - 50px); height: 1px; background: var(--border);
}
.divider-text::before { left: 0; }
.divider-text::after { right: 0; }

.amount-input-group {
  display: flex; align-items: center; gap: 8px;
  background: var(--bg-input); border-radius: var(--radius-lg);
  padding: 8px 20px; margin-bottom: 20px; border: 1px solid var(--border);
  transition: border-color 0.2s;
}
.amount-input-group:focus-within { border-color: var(--accent); }
.amount-currency { color: var(--text-muted); font-size: 16px; font-weight: 600; }
.amount-input {
  flex: 1; background: none; border: none; color: var(--text-primary);
  font-size: 36px; font-weight: 800; font-family: inherit;
  outline: none; text-align: right;
}
.amount-input::placeholder { color: var(--text-muted); }

.category-picker {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 16px;
}
.cat-btn {
  display: flex; align-items: center; gap: 6px;
  padding: 10px 8px; border-radius: var(--radius-sm);
  background: var(--bg-input); border: 1.5px solid var(--border);
  color: var(--text-primary); font-size: 12px; font-family: inherit;
  cursor: pointer; transition: all 0.15s; overflow: hidden;
  white-space: nowrap; text-overflow: ellipsis;
}
.cat-btn:active { transform: scale(0.96); }
.cat-btn.selected { border-color: var(--accent); background: var(--accent-dim); }
.cat-emoji { font-size: 16px; flex-shrink: 0; }

.note-input {
  width: 100%; padding: 14px 16px; border-radius: var(--radius-md);
  background: var(--bg-input); border: 1px solid var(--border);
  color: var(--text-primary); font-size: 14px; font-family: inherit;
  outline: none; margin-bottom: 12px; transition: border-color 0.2s;
}
.note-input:focus { border-color: var(--accent); }

.date-row { display: flex; align-items: center; gap: 8px; margin-bottom: 20px; }
.date-chip {
  padding: 8px 16px; border-radius: 20px;
  background: var(--bg-input); border: 1px solid var(--border);
  color: var(--text-secondary); font-size: 13px; font-family: inherit;
  cursor: pointer; transition: all 0.15s;
}
.date-chip.active { background: var(--accent-dim); border-color: var(--accent); color: var(--accent); }
.date-input {
  flex: 1; padding: 8px 12px; border-radius: 20px;
  background: var(--bg-input); border: 1px solid var(--border);
  color: var(--text-secondary); font-size: 13px; font-family: inherit;
  outline: none; color-scheme: dark;
}

.submit-btn {
  width: 100%; padding: 16px; border-radius: var(--radius-md);
  background: var(--accent-gradient); border: none;
  color: #0a0a0f; font-size: 16px; font-weight: 700;
  font-family: inherit; cursor: pointer; display: flex;
  align-items: center; justify-content: center; gap: 8px;
  transition: transform 0.15s, box-shadow 0.15s;
  box-shadow: 0 4px 20px rgba(110,231,183,0.2);
}
.submit-btn:active { transform: scale(0.97); }
.submit-icon { font-size: 22px; }

/* ── History ────────────────────────────────────────────── */
.history-filters { margin-bottom: 16px; }
.filter-row { margin-bottom: 10px; }
.filter-input {
  width: 100%; padding: 12px 16px; border-radius: var(--radius-md);
  background: var(--bg-input); border: 1px solid var(--border);
  color: var(--text-primary); font-size: 14px; font-family: inherit;
  outline: none; transition: border-color 0.2s;
}
.filter-input:focus { border-color: var(--accent); }
.filter-chips { display: flex; gap: 8px; }
.filter-chip {
  padding: 8px 16px; border-radius: 20px;
  background: var(--bg-input); border: 1px solid var(--border);
  color: var(--text-secondary); font-size: 13px; font-family: inherit;
  cursor: pointer; transition: all 0.15s;
}
.filter-chip.active { background: var(--accent-dim); border-color: var(--accent); color: var(--accent); }
.history-summary {
  font-size: 13px; color: var(--text-muted);
  margin-bottom: 12px; padding: 8px 0;
}
.export-btn {
  width: 100%; padding: 12px; border-radius: var(--radius-md);
  background: var(--bg-card); border: 1px solid var(--border);
  color: var(--text-secondary); font-size: 13px; font-family: inherit;
  cursor: pointer; display: flex; align-items: center;
  justify-content: center; gap: 8px; margin-top: 16px;
  transition: all 0.15s;
}
.export-btn:active { border-color: var(--accent); color: var(--accent); }

/* ── Insights ───────────────────────────────────────────── */
.insight-stat {
  font-size: 28px; font-weight: 800; text-align: center; padding: 12px;
}
.insight-up { color: var(--danger); }
.insight-down { color: var(--success); }
.add-recurring-btn {
  width: 100%; padding: 12px; border-radius: var(--radius-md);
  background: var(--bg-input); border: 1px dashed var(--border);
  color: var(--text-secondary); font-size: 13px; font-family: inherit;
  cursor: pointer; margin-top: 12px; transition: all 0.15s;
}
.add-recurring-btn:active { border-color: var(--accent); color: var(--accent); }

/* ── Settings ───────────────────────────────────────────── */
.settings-group {
  background: var(--bg-card); border-radius: var(--radius-md);
  padding: 18px; margin-bottom: 14px; border: 1px solid var(--border);
}
.setting-row { margin-bottom: 12px; }
.setting-row label { display: block; font-size: 12px; color: var(--text-muted); margin-bottom: 6px; }
.setting-input {
  width: 100%; padding: 12px 16px; border-radius: var(--radius-sm);
  background: var(--bg-input); border: 1px solid var(--border);
  color: var(--text-primary); font-size: 15px; font-family: inherit;
  outline: none; transition: border-color 0.2s;
}
.setting-input:focus { border-color: var(--accent); }
.save-btn {
  width: 100%; padding: 12px; border-radius: var(--radius-sm);
  background: var(--accent-dim); border: 1px solid rgba(110,231,183,0.3);
  color: var(--accent); font-size: 14px; font-weight: 600;
  font-family: inherit; cursor: pointer; transition: all 0.15s;
}
.save-btn:active { transform: scale(0.97); }
.api-key-display {
  padding: 10px 14px; background: var(--bg-input);
  border-radius: var(--radius-sm); font-family: monospace;
  font-size: 11px; color: var(--text-secondary);
  word-break: break-all; user-select: all;
}
.app-version { text-align: center; font-size: 12px; color: var(--text-muted); }
.select-input {
  width: 100%; padding: 12px 16px; border-radius: var(--radius-sm);
  background: var(--bg-input); border: 1px solid var(--border);
  color: var(--text-primary); font-size: 14px; font-family: inherit;
  outline: none; margin-bottom: 12px; color-scheme: dark;
}
.modal-amount { margin-bottom: 16px; }

/* ── Modal ──────────────────────────────────────────────── */
.modal { position: fixed; inset: 0; z-index: 200; display: flex; align-items: flex-end; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,0.6); }
.modal-content {
  position: relative; width: 100%; max-width: 480px; margin: 0 auto;
  background: var(--bg-secondary); border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  padding: 20px; padding-bottom: calc(20px + var(--safe-bottom));
  max-height: 85vh; overflow-y: auto;
  animation: slideUp 0.3s ease;
}
@keyframes slideUp { from{transform:translateY(100%)} to{transform:translateY(0)} }
.modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; }
.modal-header h3 { font-size: 18px; font-weight: 700; }
.modal-close {
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--bg-card); border: none; color: var(--text-secondary);
  font-size: 16px; cursor: pointer;
}

/* ── Toast ──────────────────────────────────────────────── */
.toast {
  position: fixed; bottom: calc(var(--nav-height) + var(--safe-bottom) + 16px);
  left: 50%; transform: translateX(-50%);
  background: var(--bg-card); border: 1px solid var(--border);
  padding: 12px 24px; border-radius: var(--radius-xl);
  font-size: 14px; font-weight: 500; z-index: 300;
  box-shadow: var(--shadow-card); animation: toastIn 0.3s ease;
  max-width: calc(100% - 40px); text-align: center;
}
@keyframes toastIn { from{opacity:0;transform:translateX(-50%) translateY(20px)} to{opacity:1;transform:translateX(-50%) translateY(0)} }
.toast.success { border-color: var(--success); color: var(--success); }
.toast.error { border-color: var(--danger); color: var(--danger); }

/* ── Scrollbar ──────────────────────────────────────────── */
::-webkit-scrollbar { width: 0; }
