:root {
  --bg: #f5efe6;
  --bg-soft: #efe7d9;
  --card: #ffffff;
  --ink: #2b2a26;
  --ink-soft: #6b6759;
  --ink-faint: #9a9382;
  --line: #e3dccd;
  --accent: #c2592a;
  --accent-soft: #f4d8c5;
  --good: #4a7c59;
  --good-soft: #d9e4dc;
  --warn: #b8851e;
  --bad: #a84432;
  --bad-soft: #f0d4cf;
  --shadow: 0 1px 2px rgba(43, 42, 38, .04), 0 8px 24px rgba(43, 42, 38, .06);
  --shadow-lg: 0 20px 60px rgba(43, 42, 38, .15);
  --radius: 18px;
  --radius-sm: 12px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  font-family: 'Inter', -apple-system, system-ui, sans-serif;
  background: var(--bg);
  color: var(--ink);
  min-height: 100vh;
  line-height: 1.5;
  font-size: 16px;
  background-image:
    radial-gradient(ellipse 60% 40% at 80% 0%, rgba(194, 89, 42, 0.08), transparent 60%),
    radial-gradient(ellipse 50% 30% at 0% 100%, rgba(74, 124, 89, 0.06), transparent 60%);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

.serif { font-family: 'Fraunces', Georgia, serif; font-optical-sizing: auto; letter-spacing: -0.01em; }

.app {
  max-width: 640px;
  margin: 0 auto;
  padding: 24px 18px 120px;
}

/* === LOGIN === */
.login-screen {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  padding: 24px;
}
.login-card {
  background: var(--card);
  border-radius: 24px;
  padding: 36px 28px;
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 380px;
  position: relative;
  overflow: hidden;
}
.login-card::before {
  content: '';
  position: absolute;
  top: -60px; right: -60px;
  width: 200px; height: 200px;
  background: radial-gradient(circle, var(--accent-soft), transparent 70%);
  border-radius: 50%;
}
.login-logo {
  font-family: 'Fraunces', serif;
  font-size: 38px;
  font-weight: 500;
  letter-spacing: -0.03em;
  margin-bottom: 6px;
  position: relative;
}
.login-logo em { font-style: italic; color: var(--accent); }
.login-tag {
  color: var(--ink-soft);
  font-size: 14px;
  margin-bottom: 28px;
  position: relative;
}
.login-tabs {
  display: flex;
  gap: 4px;
  background: var(--bg-soft);
  padding: 4px;
  border-radius: 12px;
  margin-bottom: 20px;
  position: relative;
}
.login-tabs button {
  flex: 1;
  padding: 9px;
  border: none;
  background: transparent;
  font-family: inherit;
  font-size: 14px;
  font-weight: 500;
  color: var(--ink-soft);
  border-radius: 9px;
  cursor: pointer;
}
.login-tabs button.active {
  background: var(--card);
  color: var(--ink);
  box-shadow: 0 1px 3px rgba(0,0,0,.06);
}

/* === HEADER === */
.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 18px;
}
.header h1 {
  font-family: 'Fraunces', serif;
  font-weight: 500;
  font-size: 28px;
  margin: 0;
  letter-spacing: -0.02em;
}
.header h1 em { font-style: italic; color: var(--accent); font-weight: 400; }
.header-actions { display: flex; align-items: center; gap: 4px; }
.icon-btn {
  background: none;
  border: none;
  width: 40px; height: 40px;
  border-radius: 50%;
  font-size: 18px;
  cursor: pointer;
  color: var(--ink-soft);
  transition: all .2s;
  display: flex; align-items: center; justify-content: center;
}
.icon-btn:hover, .icon-btn:active { background: var(--bg-soft); color: var(--ink); }

/* === MONTH SWITCHER === */
.month-switcher {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--card);
  padding: 10px 14px;
  border-radius: 99px;
  margin-bottom: 20px;
  box-shadow: var(--shadow);
}
.month-switcher button {
  background: var(--bg-soft);
  border: none;
  width: 32px; height: 32px;
  border-radius: 50%;
  cursor: pointer;
  color: var(--ink);
  font-size: 16px;
  display: flex; align-items: center; justify-content: center;
}
.month-switcher button:disabled { opacity: .35; cursor: default; }
.month-switcher .label {
  font-family: 'Fraunces', serif;
  font-size: 18px;
  font-weight: 500;
  letter-spacing: -0.01em;
}
.month-switcher .today-pill {
  font-size: 10px;
  background: var(--accent);
  color: var(--bg);
  padding: 2px 8px;
  border-radius: 99px;
  margin-left: 8px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-family: 'Inter', sans-serif;
  font-weight: 600;
}

/* === TABS === */
.tabs {
  display: flex;
  gap: 4px;
  background: var(--bg-soft);
  padding: 4px;
  border-radius: 14px;
  margin-bottom: 22px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  flex: 1 0 auto;
  padding: 10px 14px;
  border: none;
  background: transparent;
  color: var(--ink-soft);
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  border-radius: 10px;
  cursor: pointer;
  transition: all .25s;
  white-space: nowrap;
}
.tab.active { background: var(--card); color: var(--ink); box-shadow: 0 1px 3px rgba(43,42,38,.08); }

.view { display: none; animation: fade .3s ease; }
.view.active { display: block; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

/* === HERO === */
.hero {
  background: var(--card);
  border-radius: var(--radius);
  padding: 28px 24px;
  box-shadow: var(--shadow);
  margin-bottom: 14px;
  position: relative;
  overflow: hidden;
}
.hero::before {
  content: '';
  position: absolute;
  top: -40px; right: -40px;
  width: 160px; height: 160px;
  background: radial-gradient(circle, var(--accent-soft), transparent 70%);
  border-radius: 50%;
  pointer-events: none;
}
.hero-label {
  font-size: 12px;
  color: var(--ink-soft);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  margin-bottom: 8px;
  position: relative;
}
.hero-amount {
  font-family: 'Fraunces', serif;
  font-size: 56px;
  font-weight: 500;
  letter-spacing: -0.03em;
  line-height: 1;
  margin-bottom: 6px;
  position: relative;
}
.hero-amount.positive { color: var(--good); }
.hero-amount.negative { color: var(--bad); }
.hero-sub { font-size: 14px; color: var(--ink-soft); position: relative; }

.alert-banner {
  background: var(--bad-soft);
  color: var(--bad);
  padding: 12px 16px;
  border-radius: 12px;
  font-size: 14px;
  margin-bottom: 14px;
  display: flex; gap: 10px; align-items: center;
}

/* === STATS === */
.stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 18px;
}
.stat {
  background: var(--card);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  box-shadow: var(--shadow);
}
.stat-label {
  font-size: 11px;
  color: var(--ink-soft);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 6px;
}
.stat-value {
  font-family: 'Fraunces', serif;
  font-size: 22px;
  font-weight: 500;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}
.stat.income .stat-value { color: var(--good); }
.stat.expense .stat-value { color: var(--accent); }

/* === PROGRESS === */
.progress-section {
  background: var(--card);
  border-radius: var(--radius);
  padding: 20px 22px;
  box-shadow: var(--shadow);
  margin-bottom: 14px;
}
.progress-header {
  display: flex; justify-content: space-between;
  align-items: baseline; margin-bottom: 12px;
}
.progress-title { font-family: 'Fraunces', serif; font-size: 17px; font-weight: 500; }
.progress-pct { font-size: 13px; color: var(--ink-soft); font-variant-numeric: tabular-nums; }
.progress-bar { height: 10px; background: var(--bg-soft); border-radius: 99px; overflow: hidden; }
.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--good) 0%, #6a9a78 100%);
  border-radius: 99px;
  transition: width .6s cubic-bezier(.2, .8, .2, 1);
}
.progress-fill.warn { background: linear-gradient(90deg, var(--warn), #d4a230); }
.progress-fill.danger { background: linear-gradient(90deg, var(--bad), #c45a48); }

/* === SECTION TITLE === */
.section-title {
  font-family: 'Fraunces', serif;
  font-size: 21px;
  font-weight: 500;
  margin: 26px 4px 12px;
  letter-spacing: -0.01em;
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}
.section-title .total {
  font-family: 'Inter', sans-serif;
  font-size: 14px; color: var(--ink-soft); font-weight: 500;
  font-variant-numeric: tabular-nums;
}

/* === LIST === */
.list {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.item {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  transition: background .2s;
}
.item:last-child { border-bottom: none; }
.item-icon {
  width: 38px; height: 38px;
  border-radius: 11px;
  background: var(--bg-soft);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  font-size: 18px;
}
.item-body { flex: 1; min-width: 0; }
.item-name {
  font-weight: 500; font-size: 15px; color: var(--ink);
  margin-bottom: 2px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.item-name-input {
  font-family: inherit; font-weight: 500; font-size: 15px; color: var(--ink);
  border: none; background: transparent; width: 100%;
  padding: 0; outline: none;
  border-bottom: 1px dashed transparent;
}
.item-name-input:focus { border-bottom-color: var(--accent); }
.item-cat { font-size: 12px; color: var(--ink-soft); }
.item-cat .override-badge {
  display: inline-block;
  background: var(--accent-soft);
  color: var(--accent);
  padding: 1px 6px;
  border-radius: 99px;
  font-size: 10px;
  margin-left: 4px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.item-amount-input {
  font-family: 'Fraunces', serif;
  font-size: 17px; font-weight: 500;
  border: none; background: var(--bg-soft);
  border-radius: 8px;
  padding: 5px 10px;
  width: 92px;
  text-align: right;
  outline: none;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}
.item-amount-input:focus { box-shadow: 0 0 0 2px var(--accent-soft); }

.item-delete {
  background: none; border: none;
  color: var(--ink-faint);
  font-size: 20px;
  cursor: pointer;
  padding: 6px;
  margin-right: -6px;
  border-radius: 8px;
  width: 32px; height: 32px;
  display: flex; align-items: center; justify-content: center;
}
.item-delete:hover { background: var(--bad-soft); color: var(--bad); }

/* Static list (one-off, goals) */
.item-static-amount {
  font-family: 'Fraunces', serif;
  font-size: 18px; font-weight: 500;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
}
.item-static-amount.income { color: var(--good); }
.item-meta { font-size: 12px; color: var(--ink-soft); margin-top: 2px; }

/* === ADD BUTTON === */
.add-btn {
  width: 100%;
  background: var(--card);
  border: 2px dashed var(--line);
  border-radius: var(--radius-sm);
  padding: 14px;
  font-family: inherit;
  font-size: 14px;
  font-weight: 500;
  color: var(--ink-soft);
  cursor: pointer;
  margin-top: 12px;
  transition: all .2s;
  display: flex; align-items: center; justify-content: center;
  gap: 8px;
}
.add-btn:hover { border-color: var(--accent); color: var(--accent); }
.add-btn .plus { font-size: 18px; line-height: 1; }

/* === MODAL === */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(43, 42, 38, .4);
  display: none;
  align-items: flex-end;
  justify-content: center;
  z-index: 100;
  animation: fade .25s;
}
.modal-backdrop.active { display: flex; }
.modal {
  background: var(--card);
  border-radius: 24px 24px 0 0;
  width: 100%;
  max-width: 640px;
  padding: 24px 22px calc(32px + env(safe-area-inset-bottom));
  animation: slideUp .3s cubic-bezier(.2, .8, .2, 1);
  max-height: 90vh;
  overflow-y: auto;
}
@keyframes slideUp { from { transform: translateY(100%); } to { transform: none; } }
.modal-handle {
  width: 40px; height: 4px;
  background: var(--line);
  border-radius: 99px;
  margin: -8px auto 18px;
}
.modal-title {
  font-family: 'Fraunces', serif;
  font-size: 22px; font-weight: 500;
  margin: 0 0 18px;
}
.field { margin-bottom: 14px; }
.field label {
  display: block;
  font-size: 11px;
  color: var(--ink-soft);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 6px;
  font-weight: 600;
}
.field input, .field select, .field textarea {
  width: 100%;
  padding: 13px 14px;
  border: 1.5px solid var(--line);
  border-radius: 12px;
  font-family: inherit;
  font-size: 16px;
  color: var(--ink);
  background: var(--bg);
  outline: none;
  transition: border-color .2s;
}
.field textarea { resize: vertical; min-height: 70px; }
.field input:focus, .field select:focus, .field textarea:focus {
  border-color: var(--accent);
  background: var(--card);
}
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.icon-picker {
  display: flex; gap: 8px; flex-wrap: wrap; margin-top: 6px;
}
.icon-opt {
  width: 42px; height: 42px;
  border: 1.5px solid var(--line);
  border-radius: 10px;
  background: var(--bg);
  font-size: 20px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: all .15s;
}
.icon-opt.selected {
  border-color: var(--accent);
  background: var(--accent-soft);
  transform: scale(1.05);
}
.modal-actions { display: flex; gap: 10px; margin-top: 22px; }
.btn {
  flex: 1;
  padding: 14px;
  border: none;
  border-radius: 12px;
  font-family: inherit;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: all .2s;
}
.btn-primary { background: var(--ink); color: var(--bg); }
.btn-primary:active { transform: scale(0.98); }
.btn-secondary { background: var(--bg-soft); color: var(--ink); }
.btn-danger { background: var(--bad-soft); color: var(--bad); }

/* === DONUT === */
.breakdown {
  background: var(--card);
  border-radius: var(--radius);
  padding: 20px 22px;
  box-shadow: var(--shadow);
  margin-bottom: 14px;
}
.breakdown-title {
  font-family: 'Fraunces', serif;
  font-size: 17px; font-weight: 500;
  margin: 0 0 14px;
}
.donut-wrap { display: flex; align-items: center; gap: 22px; }
.donut {
  width: 130px; height: 130px;
  border-radius: 50%;
  flex-shrink: 0;
  position: relative;
}
.donut::after {
  content: '';
  position: absolute;
  inset: 22px;
  background: var(--card);
  border-radius: 50%;
}
.donut-center {
  position: absolute;
  inset: 0;
  display: flex; align-items: center; justify-content: center;
  flex-direction: column;
  z-index: 1;
}
.donut-center-val { font-family: 'Fraunces', serif; font-size: 20px; font-weight: 500; }
.donut-center-lbl { font-size: 10px; color: var(--ink-soft); text-transform: uppercase; letter-spacing: 0.08em; }
.legend { flex: 1; display: flex; flex-direction: column; gap: 7px; min-width: 0; }
.legend-item { display: flex; align-items: center; gap: 8px; font-size: 13px; min-width: 0; }
.legend-dot { width: 10px; height: 10px; border-radius: 3px; flex-shrink: 0; }
.legend-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.legend-val { font-variant-numeric: tabular-nums; color: var(--ink-soft); font-weight: 500; }

/* === HISTORY CHART === */
.chart-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 22px;
  box-shadow: var(--shadow);
  margin-bottom: 14px;
}
.chart-card h3 {
  font-family: 'Fraunces', serif;
  font-size: 17px; font-weight: 500;
  margin: 0 0 18px;
}
.bars-chart {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 6px;
  height: 160px;
  margin-bottom: 8px;
  padding: 0 4px;
}
.bar-col {
  flex: 1;
  display: flex; flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
  position: relative;
  cursor: pointer;
  height: 100%;
}
.bar-pair {
  display: flex;
  align-items: flex-end;
  gap: 3px;
  width: 100%;
  max-width: 36px;
  flex: 1;
}
.bar {
  flex: 1;
  border-radius: 5px 5px 0 0;
  min-height: 2px;
  transition: opacity .2s;
}
.bar.income { background: var(--good); }
.bar.expense { background: var(--accent); }
.bar-col:hover .bar { opacity: 0.85; }
.bar-label {
  font-size: 10px;
  color: var(--ink-soft);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: 500;
}
.bar-tooltip {
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%) translateY(-6px);
  background: var(--ink);
  color: var(--bg);
  font-size: 11px;
  padding: 6px 10px;
  border-radius: 8px;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transition: opacity .2s;
  z-index: 5;
}
.bar-col:hover .bar-tooltip { opacity: 1; }
.chart-legend {
  display: flex; gap: 14px; justify-content: center;
  font-size: 12px; color: var(--ink-soft);
  margin-top: 12px;
}
.chart-legend span { display: inline-flex; align-items: center; gap: 5px; }
.chart-legend i {
  display: inline-block; width: 10px; height: 10px;
  border-radius: 3px; font-style: normal;
}

/* === GOAL CARD === */
.goal-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 18px 20px;
  box-shadow: var(--shadow);
  margin-bottom: 12px;
}
.goal-header {
  display: flex; align-items: center; gap: 12px;
  margin-bottom: 12px;
}
.goal-icon {
  width: 42px; height: 42px;
  border-radius: 12px;
  background: var(--accent-soft);
  display: flex; align-items: center; justify-content: center;
  font-size: 20px;
}
.goal-name { font-family: 'Fraunces', serif; font-size: 18px; font-weight: 500; flex: 1; }
.goal-progress-row {
  display: flex; justify-content: space-between;
  font-size: 13px; color: var(--ink-soft);
  margin-bottom: 6px;
  font-variant-numeric: tabular-nums;
}
.goal-progress-row strong { color: var(--ink); font-weight: 600; }
.goal-bar { height: 8px; background: var(--bg-soft); border-radius: 99px; overflow: hidden; }
.goal-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), #d97a3e);
  border-radius: 99px;
  transition: width .6s cubic-bezier(.2, .8, .2, 1);
}
.goal-bar-fill.done { background: linear-gradient(90deg, var(--good), #6a9a78); }
.goal-actions {
  display: flex; gap: 6px; margin-top: 12px;
  flex-wrap: wrap;
}
.goal-actions button {
  background: var(--bg-soft);
  border: none;
  padding: 7px 12px;
  border-radius: 99px;
  font-family: inherit;
  font-size: 12px;
  font-weight: 500;
  color: var(--ink);
  cursor: pointer;
  transition: all .15s;
}
.goal-actions button:hover { background: var(--accent-soft); }
.goal-actions button.danger { color: var(--bad); }
.goal-actions button.danger:hover { background: var(--bad-soft); }

.goal-completed { opacity: 0.65; }
.goal-completed .goal-name::after {
  content: ' ✓';
  color: var(--good);
}

/* === EMPTY === */
.empty {
  text-align: center;
  padding: 28px 20px;
  color: var(--ink-soft);
  font-size: 14px;
}
.empty-emoji { font-size: 32px; margin-bottom: 8px; opacity: 0.6; }

/* === TOAST === */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(120%);
  background: var(--ink);
  color: var(--bg);
  padding: 12px 20px;
  border-radius: 99px;
  font-size: 14px;
  font-weight: 500;
  box-shadow: 0 8px 24px rgba(0,0,0,.2);
  z-index: 200;
  transition: transform .35s cubic-bezier(.2, .8, .2, 1);
  max-width: 90vw;
  text-align: center;
}
.toast.show { transform: translateX(-50%) translateY(0); }
.toast.error { background: var(--bad); }
.toast.success { background: var(--good); }

/* === LOADER === */
.loader {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px;
  color: var(--ink-soft);
  font-size: 14px;
}
.spin {
  width: 18px; height: 18px;
  border: 2px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  margin-right: 10px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* === HELPERS === */
.hidden { display: none !important; }
.spacer-sm { height: 12px; }

@media (min-width: 720px) {
  .hero-amount { font-size: 64px; }
  .stats { grid-template-columns: repeat(3, 1fr); }
}
