/* ============ RESET & TOKENS ============ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --brand: #10b981;
  --brand-dark: #059669;
  --brand-soft: rgba(16, 185, 129, 0.12);
  --bg: #f1f5f9;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --text: #0f172a;
  --text-2: #64748b;
  --text-3: #94a3b8;
  --border: #e2e8f0;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.05);
  --shadow: 0 4px 16px rgba(15, 23, 42, 0.08);
  --shadow-lg: 0 12px 32px rgba(15, 23, 42, 0.14);
  --up: #10b981;
  --down: #f43f5e;
  --radius: 16px;
  --radius-lg: 24px;
  --bottom-nav-h: 76px;
  --font-body: "Plus Jakarta Sans", -apple-system, "Segoe UI", Roboto, system-ui, sans-serif;
  --font-display: "Plus Jakarta Sans", -apple-system, "Segoe UI", Roboto, system-ui, sans-serif;
}

html[data-theme="dark"] {
  --bg: #0b1220;
  --surface: #151d2e;
  --surface-2: #0f1729;
  --text: #e2e8f0;
  --text-2: #94a3b8;
  --text-3: #64748b;
  --border: #24304a;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 12px 32px rgba(0, 0, 0, 0.5);
  --brand-soft: rgba(16, 185, 129, 0.16);
}

html, body { height: 100%; }

body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  line-height: 1.5;
  transition: background 0.25s ease, color 0.25s ease;
}

.hidden { display: none !important; }

button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }
input, select { font-family: inherit; color: inherit; }

/* ============ LAYOUT ============ */
.app {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100dvh;
  position: relative;
  padding-bottom: calc(var(--bottom-nav-h) + env(safe-area-inset-bottom));
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 30;
  background: color-mix(in srgb, var(--surface) 85%, transparent);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border);
  padding-top: env(safe-area-inset-top);
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 18px;
}

.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }

.brand-mark {
  width: 40px;
  height: 40px;
  border-radius: 13px;
  background: linear-gradient(135deg, var(--brand), var(--brand-dark));
  color: #fff;
  display: grid;
  place-items: center;
  flex-shrink: 0;
  box-shadow: 0 6px 16px rgba(16, 185, 129, 0.35);
}
.brand-mark svg { width: 22px; height: 22px; }

.brand-name { font-family: var(--font-display); font-size: 16px; font-weight: 800; letter-spacing: -0.02em; line-height: 1.2; }
.brand-sub { font-size: 11px; color: var(--text-2); }

.header-actions { display: flex; align-items: center; gap: 6px; }

.icon-btn {
  width: 38px;
  height: 38px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  color: var(--text-2);
  transition: background 0.2s, color 0.2s;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn svg { width: 20px; height: 20px; }

html[data-theme="dark"] .icon-sun { display: none; }
html:not([data-theme="dark"]) .icon-moon { display: none; }

/* ============ APP MAIN ============ */
.app-main {
  padding: 16px 16px 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.view { display: flex; flex-direction: column; gap: 16px; animation: fadeUp 0.25s ease; }

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}

/* ============ HERO ============ */
.hero-card {
  border-radius: var(--radius-lg);
  padding: 22px;
  color: #fff;
  background:
    radial-gradient(120% 160% at 110% -20%, rgba(255, 255, 255, 0.16) 0%, transparent 50%),
    linear-gradient(135deg, #0f172a 0%, #1e293b 55%, #134e4a 130%);
  box-shadow: var(--shadow-lg);
  position: relative;
  overflow: hidden;
}
.hero-card::after {
  content: "";
  position: absolute;
  right: -40px;
  top: -40px;
  width: 140px;
  height: 140px;
  border-radius: 50%;
  border: 1.5px solid rgba(255, 255, 255, 0.08);
}
.hero-card::before {
  content: "";
  position: absolute;
  right: -10px;
  top: 20px;
  width: 90px;
  height: 90px;
  border-radius: 50%;
  border: 1.5px solid rgba(255, 255, 255, 0.08);
}

.hero-top { display: flex; align-items: center; justify-content: space-between; margin-bottom: 4px; }
.hero-label { font-size: 13px; font-weight: 600; color: rgba(255, 255, 255, 0.7); letter-spacing: 0.02em; }

.chip {
  font-size: 11px;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--brand-soft);
  color: var(--brand-dark);
}
.chip-dark { background: rgba(255, 255, 255, 0.14); color: #fff; }
.chip-sub { background: var(--surface-2); color: var(--text-2); border: 1px solid var(--border); }

.hero-balance {
  font-family: var(--font-display);
  font-size: 34px;
  font-weight: 800;
  letter-spacing: -0.03em;
  margin: 6px 0 16px;
  text-shadow: 0 2px 20px rgba(0, 0, 0, 0.3);
}

.hero-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}
.hero-stat {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 14px;
  padding: 10px;
  backdrop-filter: blur(4px);
}
.hero-stat-icon {
  width: 30px;
  height: 30px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  flex-shrink: 0;
}
.hero-stat-icon svg { width: 15px; height: 15px; }
.hero-stat-icon.up { background: rgba(16, 185, 129, 0.25); color: #6ee7b7; }
.hero-stat-icon.down { background: rgba(244, 63, 94, 0.25); color: #fda4af; }
.hero-stat-icon.saved { background: rgba(56, 189, 248, 0.25); color: #7dd3fc; }

.hero-stat-label { font-size: 10px; font-weight: 600; color: rgba(255, 255, 255, 0.6); text-transform: uppercase; letter-spacing: 0.05em; }
.hero-stat-value { font-size: 14px; font-weight: 800; color: #fff; }

/* ============ CARDS ============ */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow-sm);
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 12px;
}
.card-head h2 {
  font-family: var(--font-display);
  font-size: 15px;
  font-weight: 800;
  letter-spacing: -0.01em;
}

.grid-2 { display: grid; grid-template-columns: 1fr; gap: 16px; }

/* ============ BUTTONS ============ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-size: 14px;
  font-weight: 700;
  padding: 12px 16px;
  border-radius: 13px;
  transition: transform 0.15s, box-shadow 0.15s, background 0.15s;
  min-height: 44px;
}
.btn:active { transform: scale(0.97); }
.btn svg { width: 17px; height: 17px; }

.btn-primary {
  background: linear-gradient(135deg, var(--brand), var(--brand-dark));
  color: #fff;
  box-shadow: 0 6px 16px rgba(16, 185, 129, 0.35);
}
.btn-primary:hover { box-shadow: 0 8px 20px rgba(16, 185, 129, 0.45); }

.btn-secondary {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-secondary:hover { border-color: var(--text-3); }

.btn-ghost {
  background: transparent;
  color: var(--brand-dark);
  padding: 8px 12px;
  min-height: 0;
  font-size: 13px;
}
.btn-ghost:hover { background: var(--brand-soft); }

.btn-danger {
  background: rgba(244, 63, 94, 0.1);
  color: var(--down);
  border: 1px solid rgba(244, 63, 94, 0.25);
}
.btn-danger:hover { background: rgba(244, 63, 94, 0.16); }

.btn-sm { padding: 8px 12px; font-size: 13px; min-height: 0; border-radius: 10px; }
.btn-sm svg { width: 15px; height: 15px; }

.btn-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.btn-row .btn { width: 100%; }

/* ============ CHART ============ */
.chart-box { width: 100%; }
.chart-box svg { display: block; width: 100%; height: auto; }
.donut-box { display: flex; justify-content: center; padding: 4px 0; }

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
  margin-top: 10px;
}
.legend-item { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-2); font-weight: 600; }
.legend-dot { width: 9px; height: 9px; border-radius: 3px; flex-shrink: 0; }

/* ============ LISTS ============ */
.tx-list { display: flex; flex-direction: column; }

.tx-day { margin-bottom: 14px; }
.tx-day:last-child { margin-bottom: 0; }
.tx-day-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}
.tx-day-label { font-size: 12px; font-weight: 800; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-2); }
.tx-day-balance { font-size: 12px; color: var(--text-3); }

.tx-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 4px;
  border-bottom: 1px solid var(--border);
}
.tx-item:last-child { border-bottom: none; }

.tx-icon {
  width: 42px;
  height: 42px;
  border-radius: 13px;
  display: grid;
  place-items: center;
  flex-shrink: 0;
  font-size: 19px;
}
.tx-icon.expense { background: rgba(244, 63, 94, 0.12); color: var(--down); }
.tx-icon.income { background: rgba(16, 185, 129, 0.12); color: var(--up); }
.tx-icon.transfer { background: rgba(56, 189, 248, 0.14); color: #0ea5e9; }

.tx-info { flex: 1; min-width: 0; }
.tx-desc { font-weight: 700; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tx-meta { font-size: 12px; color: var(--text-3); margin-top: 1px; }
.tx-meta .cat-dot { display: inline-block; width: 7px; height: 7px; border-radius: 2px; margin-right: 4px; }

.tx-amount { font-weight: 800; font-size: 14px; white-space: nowrap; }
.tx-amount.income { color: var(--up); }
.tx-amount.expense { color: var(--down); }
.tx-amount.transfer { color: var(--text-2); }

.tx-item .icon-btn { width: 30px; height: 30px; }
.tx-item .icon-btn svg { width: 16px; height: 16px; }

.empty {
  text-align: center;
  padding: 32px 16px;
  color: var(--text-3);
  font-size: 13px;
}
.empty svg { width: 40px; height: 40px; margin: 0 auto 10px; opacity: 0.4; }

/* ============ GOALS ============ */
.goals-total {
  border-radius: var(--radius);
  padding: 16px;
  background: linear-gradient(135deg, var(--brand-soft), transparent);
  border: 1px solid var(--brand-dark);
  text-align: center;
}
.goals-total-label { font-size: 12px; font-weight: 700; color: var(--text-2); text-transform: uppercase; letter-spacing: 0.05em; }
.goals-total-value { font-family: var(--font-display); font-size: 24px; font-weight: 800; color: var(--brand-dark); margin-top: 2px; }

.goal-grid { display: grid; grid-template-columns: 1fr; gap: 12px; }

.goal-card {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  position: relative;
  overflow: hidden;
}
.goal-card .goal-top { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.goal-card .goal-icon {
  width: 44px;
  height: 44px;
  border-radius: 14px;
  display: grid;
  place-items: center;
  font-size: 22px;
  flex-shrink: 0;
}
.goal-card .goal-name { font-weight: 800; font-size: 15px; }
.goal-card .goal-target { font-size: 12px; color: var(--text-3); }
.goal-card .goal-actions { margin-left: auto; display: flex; gap: 2px; }

.goal-bar { height: 8px; border-radius: 999px; background: var(--bg); overflow: hidden; }
.goal-bar-fill { height: 100%; border-radius: 999px; transition: width 0.5s ease; }

.goal-foot { display: flex; align-items: center; justify-content: space-between; margin-top: 8px; }
.goal-progress { font-size: 12px; font-weight: 800; color: var(--text-2); }
.goal-deadline { font-size: 11px; color: var(--text-3); }

.goal-quick { display: flex; gap: 6px; margin-top: 12px; }
.goal-quick .btn { flex: 1; min-height: 36px; padding: 6px 8px; font-size: 12px; border-radius: 10px; }

/* ============ BUDGETS ============ */
.budget-list { display: flex; flex-direction: column; gap: 10px; }
.budget-item { display: flex; align-items: center; gap: 10px; }
.budget-cat {
  width: 34px; height: 34px; border-radius: 11px;
  display: grid; place-items: center; flex-shrink: 0; font-size: 16px;
}
.budget-info { flex: 1; min-width: 0; }
.budget-name { font-size: 13px; font-weight: 700; }
.budget-progress { font-size: 11px; color: var(--text-3); margin-top: 1px; }
.budget-bar { height: 6px; border-radius: 999px; background: var(--bg); margin-top: 5px; overflow: hidden; }
.budget-bar-fill { height: 100%; border-radius: 999px; }
.budget-bar-fill.warn { background: #f59e0b; }
.budget-bar-fill.over { background: var(--down); }
.budget-item .icon-btn { width: 28px; height: 28px; }

/* ============ FILTER BAR ============ */
.filter-bar { display: flex; flex-direction: column; gap: 10px; }

.seg {
  display: flex;
  gap: 4px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 13px;
  padding: 4px;
}
.seg-btn {
  flex: 1;
  padding: 8px 6px;
  font-size: 12px;
  font-weight: 700;
  color: var(--text-2);
  border-radius: 9px;
  transition: all 0.2s;
}
.seg-btn.active {
  background: linear-gradient(135deg, var(--brand), var(--brand-dark));
  color: #fff;
  box-shadow: 0 3px 10px rgba(16, 185, 129, 0.3);
}

.filter-row { display: flex; gap: 10px; }

/* ============ FORMS ============ */
.form { display: flex; flex-direction: column; gap: 12px; }
.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field.grow { flex: 1; }
.field label { font-size: 12px; font-weight: 700; color: var(--text-2); }

.field input, .field select {
  width: 100%;
  min-height: 46px;
  padding: 10px 13px;
  font-size: 15px;
  background: var(--surface-2);
  border: 1.5px solid var(--border);
  border-radius: 12px;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
  appearance: none;
}
.field select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='none' stroke='%2394a3b8' stroke-width='2.5' stroke-linecap='round'%3E%3Cpath d='M3 5l3 3 3-3'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 34px;
}
.field input:focus, .field select:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-soft);
}

.field .input-money { font-size: 22px; font-weight: 800; text-align: center; font-family: var(--font-display); }

.type-toggle { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.type-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 10px 6px;
  border-radius: 12px;
  border: 1.5px solid var(--border);
  font-size: 12px;
  font-weight: 700;
  color: var(--text-2);
  transition: all 0.2s;
}
.type-btn svg { width: 19px; height: 19px; }
.type-btn.active {
  border-color: var(--brand);
  background: var(--brand-soft);
  color: var(--brand-dark);
}

.swatches { display: flex; gap: 10px; flex-wrap: wrap; }
.swatch {
  width: 34px; height: 34px; border-radius: 11px;
  border: 2px solid transparent;
  transition: transform 0.15s, box-shadow 0.15s;
}
.swatch.active { transform: scale(1.1); box-shadow: 0 0 0 3px var(--surface), 0 0 0 5px var(--text-3); }

.emoji-row { display: flex; gap: 6px; flex-wrap: wrap; }
.emoji-opt {
  width: 38px; height: 38px; border-radius: 11px;
  display: grid; place-items: center;
  font-size: 19px;
  background: var(--surface-2);
  border: 1.5px solid var(--border);
  transition: all 0.15s;
}
.emoji-opt.active { border-color: var(--brand); background: var(--brand-soft); transform: scale(1.1); }

.color-row { display: flex; gap: 8px; flex-wrap: wrap; }

/* ============ MODAL ============ */
.modal-root {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.modal-root.sheet .modal { border-radius: var(--radius-lg) var(--radius-lg) 0 0; max-height: 92dvh; }

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(2, 6, 23, 0.55);
  backdrop-filter: blur(3px);
  animation: fadeIn 0.2s ease;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.modal {
  position: relative;
  width: 100%;
  max-width: 480px;
  max-height: 88dvh;
  background: var(--surface);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  animation: slideUp 0.28s cubic-bezier(0.16, 1, 0.3, 1);
  overflow: hidden;
}
@keyframes slideUp { from { transform: translateY(40px); opacity: 0; } to { transform: none; opacity: 1; } }

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 18px 8px;
}
.modal-head h3 { font-family: var(--font-display); font-size: 18px; font-weight: 800; }

.modal-body {
  padding: 12px 18px calc(18px + env(safe-area-inset-bottom));
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* ============ MINI LIST (settings) ============ */
.mini-list { display: flex; flex-direction: column; }
.mini-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 4px;
  border-bottom: 1px solid var(--border);
}
.mini-item:last-child { border-bottom: none; }
.mini-icon {
  width: 38px; height: 38px; border-radius: 12px;
  display: grid; place-items: center;
  font-size: 18px; flex-shrink: 0;
}
.mini-info { flex: 1; min-width: 0; }
.mini-name { font-size: 14px; font-weight: 700; }
.mini-sub { font-size: 12px; color: var(--text-3); }
.mini-badge { font-size: 10px; font-weight: 800; padding: 3px 8px; border-radius: 999px; background: var(--brand-soft); color: var(--brand-dark); text-transform: uppercase; letter-spacing: 0.04em; }
.mini-item .icon-btn { width: 30px; height: 30px; }

/* ============ FAB ============ */
.fab {
  position: fixed;
  right: calc(50% - 240px + 20px);
  bottom: calc(var(--bottom-nav-h) + 14px);
  z-index: 40;
  width: 56px;
  height: 56px;
  border-radius: 18px;
  background: linear-gradient(135deg, var(--brand), var(--brand-dark));
  color: #fff;
  display: grid;
  place-items: center;
  box-shadow: 0 10px 24px rgba(16, 185, 129, 0.45);
  transition: transform 0.2s;
}
.fab svg { width: 26px; height: 26px; }
.fab:active { transform: scale(0.92); }
.fab:active svg { transform: rotate(90deg); transition: transform 0.2s; }

@media (max-width: 520px) {
  .fab { right: 20px; }
}

/* ============ BOTTOM NAV ============ */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 480px;
  z-index: 50;
  display: flex;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}
.nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 10px 4px 8px;
  color: var(--text-3);
  font-size: 10.5px;
  font-weight: 700;
  transition: color 0.2s;
  position: relative;
}
.nav-item svg { width: 23px; height: 23px; transition: transform 0.2s; }
.nav-item.active { color: var(--brand-dark); }
.nav-item.active svg { transform: translateY(-1px) scale(1.05); }
.nav-item.active::before {
  content: "";
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 34px;
  height: 3px;
  border-radius: 0 0 4px 4px;
  background: linear-gradient(90deg, var(--brand), var(--brand-dark));
}

/* ============ TOAST ============ */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--bottom-nav-h) + 20px);
  transform: translateX(-50%);
  z-index: 200;
  background: var(--text);
  color: var(--bg);
  font-size: 13px;
  font-weight: 700;
  padding: 12px 20px;
  border-radius: 999px;
  box-shadow: var(--shadow-lg);
  white-space: nowrap;
  animation: toastIn 0.25s ease;
}
@keyframes toastIn { from { opacity: 0; transform: translateX(-50%) translateY(12px); } to { opacity: 1; transform: translateX(-50%); } }

.muted { font-size: 12.5px; color: var(--text-3); }

/* ============ VIEW TITLE ============ */
.view-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.view-title h2 { font-family: var(--font-display); font-size: 22px; font-weight: 800; letter-spacing: -0.02em; }
.view-sub { font-size: 12.5px; color: var(--text-3); margin-top: 1px; }

/* ============ RESPONSIVE ============ */
@media (min-width: 640px) {
  .grid-2 { grid-template-columns: 1fr 1fr; }
  .goal-grid { grid-template-columns: 1fr 1fr; }
  .app-main { padding: 20px; }
  .modal-root { align-items: center; padding: 20px; }
  .modal-root.sheet .modal { border-radius: var(--radius-lg); }
  .modal { border-radius: var(--radius-lg); max-height: 88dvh; }
}
