:root {
  --bg: #2d2d2d;
  --bg-2: #383838;
  --surface: #3a3a3a;
  --surface-2: #4a4a4a;
  --border: #505050;
  --text: #eaeaea;
  --muted: #9aa3a8;
  --income: #8acca5;
  --expense: #f08a8a;
  --accent: #8acca5;
  --radius: 14px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

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

html, body {
  margin: 0; padding: 0;
  background: var(--bg); color: var(--text);
  font-family: system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  font-size: 16px;
  min-height: 100vh;
  overscroll-behavior-y: none;
}
body {
  overflow-x: hidden;
  overflow-x: clip;
}

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

.app {
  max-width: 640px;
  margin: 0 auto;
  padding-bottom: calc(120px + var(--safe-bottom));
  min-height: 100vh;
}

.icon-btn {
  width: 40px; height: 40px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  color: var(--text); background: transparent;
  flex: 0 0 40px;
}
.icon-btn:active { background: var(--surface); }
.icon-btn svg { width: 22px; height: 22px; }

.period {
  position: sticky; top: 0; z-index: 10;
  background: var(--bg);
  padding: 10px 16px 4px;
  display: flex; gap: 6px;
  align-items: center; justify-content: center;
  overflow-x: auto; scrollbar-width: none;
}
.period::-webkit-scrollbar { display: none; }
.period-spacer { width: 40px; flex: 0 0 40px; }
.period button:not(.icon-btn) {
  padding: 4px 12px; border-radius: 999px;
  background: transparent; color: var(--muted);
  font-size: 13px; white-space: nowrap;
  border: 1px solid transparent;
}
.period button:not(.icon-btn).active {
  color: var(--accent); border-color: var(--accent);
}

.range-nav {
  display: flex; align-items: center; justify-content: center;
  margin-top: 6px; gap: 6px; padding: 0 4px;
}
.range-nav .label {
  flex: 0 1 auto; text-align: center;
  font-size: 18px; font-weight: 500;
  color: var(--accent); text-transform: capitalize;
  min-width: 140px;
}
.range-nav button {
  padding: 6px 14px; color: var(--muted); font-size: 22px;
}

.balance-pill {
  margin: 10px 16px 10px;
  padding: 6px 14px;
  border-radius: 18px;
  background: var(--expense);
  text-align: center;
  font-size: 13px; font-weight: 500;
  color: #fff;
  box-shadow: 0 2px 8px rgba(0,0,0,0.25);
}
.balance-pill.positive { background: var(--income); color: #1a1a1a; }
.balance-pill.zero { background: var(--surface-2); color: var(--text); }

.pie-wrap {
  display: flex; justify-content: center; align-items: center;
  gap: 14px; padding: 4px 16px 10px;
  flex-wrap: wrap;
}
.pie-wrap svg { width: 260px; max-width: 100%; height: auto; aspect-ratio: 1 / 1; display: block; }
.pie-wrap svg .label { fill: #9aa3a8; font-size: 10px; font-weight: 500; letter-spacing: 0.5px; text-transform: uppercase; }
.pie-wrap svg .amount { fill: var(--expense); font-size: 15px; font-weight: 600; }
.pie-wrap svg .amount-in { fill: var(--income); font-size: 15px; font-weight: 600; }

.savings-box {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 12px 16px;
  min-width: 104px;
  text-align: center;
  box-shadow: 0 2px 6px rgba(0,0,0,0.2);
}
.savings-box .s-label {
  color: var(--muted);
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.5px;
  text-transform: uppercase;
}
.savings-box .s-amount {
  color: var(--income);
  font-size: 15px;
  font-weight: 600;
  margin-top: 6px;
  white-space: nowrap;
}
.savings-box .s-amount.negative { color: var(--expense); }

.category-row {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 16px;
  border-bottom: 1px solid rgba(255,255,255,0.04);
  cursor: pointer;
}
.category-row:active { background: rgba(255,255,255,0.03); }
.category-row .chev {
  color: var(--muted); padding: 4px;
  display: flex; align-items: center;
  transition: transform 0.2s;
}
.category-row.expanded .chev { transform: rotate(180deg); }
.category-row .chev svg { width: 14px; height: 14px; }
.category-row .icon-wrap {
  width: 40px; height: 40px; flex: 0 0 40px;
  display: flex; align-items: center; justify-content: center;
}
.category-row .icon-wrap svg { width: 34px; height: 34px; }
.category-row .name { flex: 1; font-size: 16px; }
.category-row .count {
  background: var(--accent); color: #1a1a1a;
  font-size: 11px; font-weight: 700;
  padding: 2px 8px; border-radius: 999px;
  min-width: 22px; text-align: center;
}
.category-row .amount {
  font-weight: 500; font-size: 15px;
  min-width: 92px; text-align: right; white-space: nowrap;
}
.category-row .amount.income { color: var(--income); }
.category-row .amount.expense { color: var(--expense); }

.category-entries {
  padding: 4px 16px 8px 60px;
  background: rgba(0,0,0,0.15);
}
.sub-entry {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 0; gap: 10px;
  border-bottom: 1px solid rgba(255,255,255,0.04);
  cursor: pointer;
}
.sub-entry:last-child { border-bottom: none; }
.sub-entry .info { min-width: 0; flex: 1; }
.sub-entry .note {
  font-size: 14px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.sub-entry .note.no-note { color: var(--muted); font-style: italic; }
.sub-entry .date { font-size: 12px; color: var(--muted); margin-top: 2px; }
.sub-entry .amt { font-size: 14px; font-weight: 500; white-space: nowrap; }
.sub-entry .amt.income { color: var(--income); }
.sub-entry .amt.expense { color: var(--expense); }

.sort-toggle {
  display: flex; align-items: center; justify-content: center;
  gap: 8px; padding: 4px 16px 8px;
}
.sort-toggle .sort-label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: 0.5px; }
.sort-toggle button {
  padding: 4px 12px; border-radius: 999px;
  background: transparent; color: var(--muted);
  font-size: 13px; border: 1px solid transparent;
}
.sort-toggle button.active { color: var(--accent); border-color: var(--accent); }

.date-entry {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px; gap: 10px;
  border-bottom: 1px solid rgba(255,255,255,0.04);
  cursor: pointer;
}
.date-entry:active { background: rgba(255,255,255,0.03); }
.date-entry .info { min-width: 0; flex: 1; }
.date-entry .label {
  font-size: 15px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.date-entry .date { font-size: 12px; color: var(--muted); margin-top: 2px; }
.date-entry .amt { font-weight: 500; font-size: 15px; white-space: nowrap; }
.date-entry .amt.income { color: var(--income); }
.date-entry .amt.expense { color: var(--expense); }

.date-header {
  padding: 14px 16px 4px;
  font-size: 12px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.6px;
  font-weight: 600;
}

.empty {
  text-align: center; color: var(--muted);
  padding: 40px 16px; font-size: 14px;
}

.fab-dock {
  position: fixed; left: 0; right: 0;
  bottom: calc(20px + var(--safe-bottom));
  display: flex; justify-content: space-around; align-items: center;
  pointer-events: none; z-index: 20;
  max-width: 640px; margin: 0 auto;
  padding: 0 40px;
}
.fab {
  width: 72px; height: 72px; border-radius: 50%;
  background: var(--bg-2);
  display: flex; align-items: center; justify-content: center;
  font-size: 38px; font-weight: 300; line-height: 1;
  box-shadow: 0 4px 16px rgba(0,0,0,0.5);
  pointer-events: auto;
  border: 3px solid;
}
.fab.expense { color: var(--expense); border-color: var(--expense); }
.fab.income  { color: var(--income); border-color: var(--income); }
.fab:active { transform: scale(0.95); }

.backup-banner {
  margin: 0 16px 10px;
  padding: 10px 12px;
  background: rgba(240, 138, 138, 0.14);
  border: 1px solid rgba(240, 138, 138, 0.4);
  color: #f3c8c8;
  border-radius: 10px;
  font-size: 12px;
  display: flex; align-items: center; gap: 8px;
  cursor: pointer;
}
.backup-banner.danger {
  background: rgba(239, 68, 68, 0.22);
  border-color: rgba(239, 68, 68, 0.55);
  color: #fecaca;
}
.backup-banner .chev { margin-left: auto; opacity: 0.7; }

.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.65);
  display: flex; align-items: flex-end; justify-content: center;
  z-index: 100;
}
.modal {
  background: var(--surface);
  width: 100%; max-width: 640px;
  border-top-left-radius: 18px; border-top-right-radius: 18px;
  padding: 20px 16px calc(20px + var(--safe-bottom));
  max-height: 92vh; overflow-y: auto;
}
.modal h2 {
  margin: 0 0 16px; font-size: 18px; font-weight: 500;
  color: var(--accent);
}

.field { margin-bottom: 12px; }
.field label {
  display: block; font-size: 12px;
  color: var(--muted); margin-bottom: 4px;
  text-transform: uppercase; letter-spacing: 0.5px;
}
.field input, .field select, .field textarea {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 16px;
}
.field textarea { resize: vertical; min-height: 60px; }

.type-toggle { display: flex; gap: 8px; margin-bottom: 12px; }
.type-toggle button {
  flex: 1; padding: 10px; border-radius: 10px;
  background: var(--bg); color: var(--muted);
  border: 1px solid var(--border); font-weight: 600;
}
.type-toggle button.active.income { background: var(--income); color: #1a1a1a; border-color: var(--income); }
.type-toggle button.active.expense { background: var(--expense); color: #fff; border-color: var(--expense); }

.icon-grid {
  display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px;
  max-height: 200px; overflow-y: auto;
  padding: 8px; background: var(--bg); border-radius: 10px;
}
.icon-choice {
  aspect-ratio: 1; display: flex; align-items: center; justify-content: center;
  background: var(--surface-2); border-radius: 8px; padding: 6px;
  border: 2px solid transparent;
}
.icon-choice svg { width: 100%; height: 100%; }
.icon-choice.selected { border-color: var(--accent); }

.color-grid {
  display: grid; grid-template-columns: repeat(10, 1fr); gap: 6px;
}
.color-choice {
  aspect-ratio: 1; border-radius: 50%;
  border: 2px solid transparent;
}
.color-choice.selected { border-color: white; }

.modal-actions {
  display: flex; gap: 8px; margin-top: 16px;
}
.btn {
  flex: 1; padding: 12px; border-radius: 10px; font-weight: 600;
  background: var(--surface-2); color: var(--text);
  cursor: pointer;
}
.btn.primary { background: var(--accent); color: #1a1a1a; }
.btn.danger { background: var(--expense); color: #fff; }
.btn.ghost { background: transparent; color: var(--muted); border: 1px solid var(--border); }
.btn.compact { flex: 0 0 auto; padding: 8px 14px; }

.section-label.income { color: var(--income); }
.section-label.expense { color: var(--expense); }

.input-hidden { display: none; }

.settings-item {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px; background: var(--bg);
  border-radius: 10px; margin-bottom: 8px;
  gap: 10px;
}
.cat-manage-row {
  display: flex; align-items: center; gap: 10px;
  padding: 10px; background: var(--bg); border-radius: 10px;
  margin-bottom: 6px;
}
.cat-manage-row .icon-wrap {
  width: 32px; height: 32px;
  display: flex; align-items: center; justify-content: center;
}
.cat-manage-row .icon-wrap svg { width: 26px; height: 26px; }
.cat-manage-row .name { flex: 1; cursor: pointer; padding: 4px 0; }
.cat-manage-row .del { color: var(--muted); padding: 6px 10px; font-size: 16px; }
.cat-manage-row .del:active { color: var(--expense); }
.section-label {
  font-size: 12px; text-transform: uppercase;
  margin: 14px 0 6px; letter-spacing: 0.5px;
}
.hint { color: var(--muted); font-size: 12px; margin-top: 2px; }

#swipe-content.slide-in-from-left {
  animation: slide-in-from-left 250ms ease-out;
}
#swipe-content.slide-in-from-right {
  animation: slide-in-from-right 250ms ease-out;
}
@keyframes slide-in-from-left {
  from { transform: translateX(-32px); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}
@keyframes slide-in-from-right {
  from { transform: translateX(32px); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

.excluded-tag {
  display: block;
  color: var(--muted);
  font-size: 11px;
  font-style: italic;
  font-weight: normal;
  margin-top: 2px;
  line-height: 1.2;
}

.exclude-toggle {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 10px 0; cursor: pointer; margin-bottom: 4px;
}
.exclude-toggle input[type="checkbox"] {
  margin-top: 2px; width: 18px; height: 18px; flex: 0 0 auto;
  accent-color: var(--accent);
}
.exclude-toggle .exclude-title { font-size: 14px; color: var(--text); }
