:root {
  --bg: #f5f7fb;
  --bg-2: #eef2ff;
  --surface: rgba(255, 255, 255, 0.82);
  --surface-strong: #ffffff;
  --text: #0f172a;
  --muted: #64748b;
  --line: #d8deeb;
  --accent: #4f46e5;
  --accent-2: #0ea5e9;
  --income: #087443;
  --expense: #b42318;
  --shadow: 0 16px 40px rgba(15, 23, 42, 0.08);
}

body[data-theme="dark"] {
  --bg: #090d16;
  --bg-2: #121a2b;
  --surface: rgba(18, 24, 38, 0.78);
  --surface-strong: #111827;
  --text: #e8edf8;
  --muted: #94a3b8;
  --line: #273247;
  --accent: #8b85ff;
  --accent-2: #22d3ee;
  --income: #36c488;
  --expense: #ff8a80;
  --shadow: 0 18px 42px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at 15% 15%, var(--bg-2) 0%, transparent 40%),
    radial-gradient(circle at 85% 0%, rgba(79, 70, 229, 0.12) 0%, transparent 40%),
    var(--bg);
  transition: background 220ms ease, color 220ms ease;
}

.app-shell {
  max-width: 1180px;
  margin: 0 auto;
  padding: 22px 16px 28px;
}

.app-hidden {
  display: none !important;
}

.topbar-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.lock-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 16px;
}

.lock-card {
  width: min(100%, 430px);
  padding: 18px;
  display: grid;
  gap: 10px;
}

.lock-form {
  display: grid;
  gap: 10px;
}

.glass {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(10px);
}

.topbar {
  padding: 18px;
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: flex-start;
  animation: rise 300ms ease;
}

.kicker {
  margin: 0;
  font-size: 11px;
  color: var(--accent);
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.09em;
}

h1 { margin: 4px 0 0; font-size: 31px; letter-spacing: -0.02em; }
h2 { margin: 0 0 12px; font-size: 18px; }
.sub { margin: 8px 0 0; color: var(--muted); font-size: 14px; }

.layout {
  margin-top: 14px;
  display: grid;
  gap: 12px;
}

.panel { padding: 16px; }
.cards { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }

.metric {
  padding: 14px;
  animation: rise 340ms ease;
}

.metric p {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 700;
}

.metric strong {
  display: block;
  margin-top: 10px;
  font-size: 30px;
  line-height: 1.1;
  letter-spacing: -0.02em;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

input, select, button {
  font: inherit;
}

input, select {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface-strong);
  color: var(--text);
  padding: 8px 10px;
  outline: none;
  transition: border-color 150ms ease, box-shadow 150ms ease;
}

input:focus, select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.14);
}

.is-hidden { display: none !important; }

.toggle-line {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 52px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface-strong);
  color: var(--text);
}

.toggle-line input {
  width: 20px;
  height: 20px;
  min-height: 20px;
  accent-color: var(--accent);
  flex: 0 0 auto;
}

.toggle-line span { display: grid; gap: 3px; }
.toggle-line small { color: var(--muted); font-size: 12px; font-weight: 600; }

.btn {
  min-height: 42px;
  border-radius: 10px;
  border: 0;
  padding: 9px 12px;
  cursor: pointer;
  font-weight: 700;
  transition: transform 130ms ease, opacity 130ms ease;
}

.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(0); }

.btn-primary {
  background: linear-gradient(120deg, var(--accent), var(--accent-2));
  color: #fff;
}

.btn-ghost {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--text);
}

.controls { display: grid; gap: 10px; }

.health-grid {
  display: grid;
  grid-template-columns: minmax(180px, 0.55fr) minmax(0, 1fr);
  gap: 10px;
}

.health-score-card,
.health-score-meta {
  border: 1px solid var(--line);
  background: var(--surface-strong);
  border-radius: 12px;
  padding: 12px;
}

.health-score-card {
  display: grid;
  justify-items: center;
  align-content: center;
  gap: 10px;
}

.health-score-ring {
  width: 120px;
  height: 120px;
  border-radius: 999px;
  display: grid;
  place-items: center;
  text-align: center;
  border: 8px solid rgba(79, 70, 229, 0.18);
  box-shadow: inset 0 0 0 1px var(--line);
}

.health-score-ring strong {
  display: block;
  font-size: 34px;
  line-height: 1;
  letter-spacing: -0.02em;
}

.health-score-ring span {
  display: block;
  margin-top: 2px;
  font-size: 12px;
  color: var(--muted);
  font-weight: 700;
}

.health-label {
  margin: 0;
  font-size: 13px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}

.health-score-meta h3 {
  margin: 0 0 8px;
  font-size: 14px;
}

.health-recommendations {
  margin: 0;
  padding-left: 18px;
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 650;
}

.health-label.score-needs-attention { color: var(--expense); }
.health-label.score-stable { color: #b45309; }
.health-label.score-healthy { color: var(--income); }
.health-label.score-strong { color: var(--accent); }

.tools-panel { display: grid; gap: 12px; }

.tools-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
}

.import-box {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 9px 12px;
  background: var(--surface-strong);
  color: var(--text);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
}

.import-box input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

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

.chip {
  border: 1px solid var(--line);
  background: var(--surface-strong);
  color: var(--muted);
  border-radius: 999px;
  min-height: 34px;
  padding: 7px 11px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}

.chip.is-active {
  background: rgba(79, 70, 229, 0.12);
  color: var(--accent);
  border-color: rgba(79, 70, 229, 0.35);
}

.split {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(280px, 0.8fr);
  gap: 12px;
}

.section-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}

.section-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}

.helper-note {
  margin: -2px 0 12px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
  line-height: 1.45;
}

.pill {
  border: 1px solid var(--line);
  background: var(--surface-strong);
  border-radius: 999px;
  padding: 4px 9px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
}

.history-list, .totals-list {
  display: grid;
  gap: 8px;
}

.row {
  border: 1px solid var(--line);
  background: var(--surface-strong);
  border-radius: 12px;
  padding: 10px;
  display: grid;
  gap: 8px;
  animation: fade 200ms ease;
}

.row.is-overdue { border-color: rgba(180, 35, 24, 0.46); }
.row.is-due-soon { border-color: rgba(245, 158, 11, 0.5); }
.row.is-paid { border-color: rgba(8, 116, 67, 0.42); }

.row-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
}

.row-title {
  font-weight: 700;
  font-size: 14px;
}

.row-sub {
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
}

.amt {
  font-weight: 800;
  font-size: 14px;
}

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

.row-foot {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
}

.delete-btn,
.mini-btn {
  border: 1px solid var(--line);
  background: transparent;
  border-radius: 8px;
  padding: 5px 8px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 700;
}

.delete-btn { color: var(--expense); }
.mini-btn { color: var(--accent); }

.status-pill {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 4px 8px;
  font-size: 11px;
  font-weight: 800;
  background: rgba(100, 116, 139, 0.12);
  color: var(--muted);
}

.status-pill.overdue { background: rgba(180, 35, 24, 0.13); color: var(--expense); }
.status-pill.due-soon { background: rgba(245, 158, 11, 0.17); color: #b45309; }
.status-pill.paid { background: rgba(8, 116, 67, 0.14); color: var(--income); }

.recurring-list {
  display: grid;
  gap: 8px;
}

.trend-chart {
  display: grid;
  grid-template-columns: repeat(6, minmax(96px, 1fr));
  gap: 10px;
  overflow-x: auto;
  padding-bottom: 4px;
}

.trend-month {
  min-height: 220px;
  min-width: 96px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface-strong);
  padding: 10px 8px;
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 8px;
}

.trend-label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-align: center;
}

.trend-bars {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 5px;
  align-items: end;
  min-height: 118px;
}

.trend-bar {
  min-height: 4px;
  border-radius: 8px 8px 3px 3px;
}

.trend-bar.income { background: var(--income); }
.trend-bar.expense { background: var(--expense); }
.trend-bar.net { background: linear-gradient(180deg, var(--accent-2), var(--accent)); }
.trend-bar.net.negative { background: var(--expense); opacity: 0.72; }

.trend-values {
  display: grid;
  gap: 3px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
}

.trend-values b { color: var(--text); }

.span-2 { grid-column: span 2; }

.budget-summary-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 10px;
}

.budget-summary-card {
  border: 1px solid var(--line);
  background: var(--surface-strong);
  border-radius: 12px;
  padding: 10px;
  display: grid;
  gap: 8px;
}

.budget-summary-card p {
  margin: 0;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.budget-summary-card strong {
  font-size: 20px;
  letter-spacing: -0.01em;
}

.budget-planner-list {
  display: grid;
  gap: 8px;
}

.budget-row {
  border: 1px solid var(--line);
  background: var(--surface-strong);
  border-radius: 12px;
  padding: 10px;
  display: grid;
  gap: 8px;
}

.budget-row-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.budget-row-title {
  font-size: 14px;
  font-weight: 800;
}

.budget-row-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.budget-row-grid b {
  display: block;
  margin-top: 2px;
  color: var(--text);
  font-size: 14px;
}

.budget-input {
  width: 130px;
  min-height: 36px;
}

.budget-progress {
  width: 100%;
  height: 8px;
  border-radius: 999px;
  background: rgba(100, 116, 139, 0.18);
  overflow: hidden;
}

.budget-progress-bar {
  height: 100%;
  width: 0;
  border-radius: inherit;
  background: linear-gradient(120deg, var(--accent), var(--accent-2));
  transition: width 220ms ease;
}

.budget-row.is-over .budget-progress-bar {
  background: var(--expense);
}

.budget-warning {
  color: var(--expense);
  font-size: 12px;
  font-weight: 800;
}

.empty {
  border: 1px dashed var(--line);
  border-radius: 12px;
  padding: 16px;
  color: var(--muted);
  text-align: center;
  font-size: 13px;
}

@keyframes fade { from { opacity: .4; transform: translateY(4px); } to { opacity: 1; transform: translateY(0); } }
@keyframes rise { from { opacity: .3; transform: translateY(5px); } to { opacity: 1; transform: translateY(0); } }

@media (max-width: 1020px) {
  .cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .split { grid-template-columns: 1fr; }
  .trend-chart { grid-template-columns: repeat(6, minmax(112px, 1fr)); }
  .health-grid { grid-template-columns: 1fr; }
  .budget-summary-grid { grid-template-columns: 1fr; }
  .budget-row-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 640px) {
  .app-shell { padding: 14px 10px 20px; }
  .topbar { padding: 14px; }
  h1 { font-size: 26px; }
  .topbar-actions { width: 100%; }
  .topbar-actions .btn { width: 100%; }
  .cards { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .span-2 { grid-column: span 1; }
  .metric strong { font-size: 26px; }
  .tools-row { align-items: stretch; }
  .tools-row .btn, .import-box { width: 100%; }
  .section-head { align-items: flex-start; flex-direction: column; }
  .section-actions { width: 100%; justify-content: stretch; }
  .section-actions .btn { width: 100%; }
  .budget-row-head { flex-direction: column; align-items: stretch; }
  .budget-input { width: 100%; }
  .budget-row-grid { grid-template-columns: 1fr; }
}
