:root {
  --indigo: #6366f1;
  --indigo-dark: #4f46e5;
  --indigo-glow: rgba(99,102,241,0.25);
  --bg: #0b0c10;
  --surface: #13141a;
  --surface2: #1c1d26;
  --border: #2a2b38;
  --text: #e8e9f0;
  --muted: #6b6e85;
  --danger: #ef4444;
  --success: #22c55e;
  --radius: 14px;
  --radius-sm: 8px;
  --transition: 0.22s cubic-bezier(.4,0,.2,1);
}

html.light {
  --bg: #f1f2f7;
  --surface: #ffffff;
  --surface2: #e8eaf2;
  --border: #d4d6e5;
  --text: #111218;
  --muted: #7a7d96;
}

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

html, body {
  min-height: 100%;
  width: 100%;
  overflow-x: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: 'DM Sans', sans-serif;
  -webkit-font-smoothing: antialiased;
  transition: background var(--transition), color var(--transition);
}

body { position: relative; }

body::before {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0.03;
  z-index: 0;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

/* ── ORB BACKGROUNDS ─────────────────────────────────── */
.orb {
  position: fixed;
  border-radius: 50%;
  filter: blur(90px);
  pointer-events: none;
  z-index: 0;
}
.orb-1 { width: 480px; height: 480px; background: rgba(99,102,241,0.12); top: -120px; right: -120px; }
.orb-2 { width: 340px; height: 340px; background: rgba(139,92,246,0.08); bottom: 10%; left: -80px; }
html.light .orb-1 { background: rgba(99,102,241,0.08); }
html.light .orb-2 { background: rgba(139,92,246,0.05); }

/* ── LAYOUT ──────────────────────────────────────────── */
#app {
  position: relative;
  z-index: 1;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 2rem 1rem 5rem;
}

/* ── ANIMATIONS ──────────────────────────────────────── */
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(18px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ── SCREENS ─────────────────────────────────────────── */
.screen { display: none; width: 100%; animation: fadeUp 0.4s ease both; }
.screen.active { display: flex; flex-direction: column; align-items: center; }

/* ── LANDING ─────────────────────────────────────────── */
#screen-landing { max-width: 480px; text-align: center; gap: 2rem; }
.logo-ring {
  width: 80px; height: 80px;
  background: linear-gradient(135deg, var(--indigo), #8b5cf6);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  margin: 0 auto;
  box-shadow: 0 0 40px var(--indigo-glow);
}
.logo-ring i { font-size: 2rem; color: #fff; }
.headline { font-size: clamp(2.2rem, 6vw, 3rem); font-weight: 700; letter-spacing: -0.03em; line-height: 1.1; }
.headline span { color: var(--indigo); }
.subhead { color: var(--muted); font-size: 1.05rem; line-height: 1.6; margin-top: 0.5rem; }
.feature-pills { display: flex; gap: 0.5rem; flex-wrap: wrap; justify-content: center; }
.pill {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.35rem 0.9rem;
  font-size: 0.8rem;
  color: var(--muted);
  display: flex; align-items: center; gap: 0.4rem;
}
.pill i { color: var(--indigo); font-size: 0.75rem; }

/* ── NAME SCREEN ─────────────────────────────────────── */
#screen-name { max-width: 420px; }

/* ── CARD ────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2rem;
  width: 100%;
  box-shadow: 0 8px 40px rgba(0,0,0,0.18);
}
html.light .card { box-shadow: 0 4px 24px rgba(0,0,0,0.07); }
.card-title { font-size: 1.4rem; font-weight: 600; margin-bottom: 0.4rem; }
.card-sub { color: var(--muted); font-size: 0.9rem; margin-bottom: 1.5rem; }
.input-row { display: flex; gap: 0.6rem; align-items: center; }

/* ── INPUTS ──────────────────────────────────────────── */
input, select {
  font-family: inherit;
  font-size: 0.95rem;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  padding: 0.7rem 1rem;
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
  width: 100%;
}
input:focus, select:focus {
  border-color: var(--indigo);
  box-shadow: 0 0 0 3px var(--indigo-glow);
}
input::placeholder { color: var(--muted); }
select option { background: var(--surface2); color: var(--text); }
label {
  display: block;
  font-size: 0.82rem; font-weight: 500;
  color: var(--muted); margin-bottom: 0.4rem;
  letter-spacing: 0.02em; text-transform: uppercase;
}
input[type="date"] { color-scheme: dark; }
html.light input[type="date"] { color-scheme: light; }

/* ── BUTTONS ─────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.5rem;
  padding: 0.75rem 1.5rem;
  border: none; border-radius: var(--radius-sm);
  font-family: inherit; font-size: 0.95rem; font-weight: 600;
  cursor: pointer; transition: all var(--transition); white-space: nowrap;
  text-decoration: none;
}
.btn-primary { background: var(--indigo); color: #fff; box-shadow: 0 2px 12px var(--indigo-glow); }
.btn-primary:hover { background: var(--indigo-dark); transform: translateY(-1px); box-shadow: 0 6px 20px var(--indigo-glow); }
.btn-primary:active { transform: translateY(0); }
.btn-ghost { background: var(--surface2); color: var(--text); border: 1px solid var(--border); }
.btn-ghost:hover { border-color: var(--indigo); color: var(--indigo); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { opacity: 0.85; }

.btn-icon {
  width: 40px; height: 40px; padding: 0; border-radius: 50%;
  background: var(--indigo); color: #fff; flex-shrink: 0; border: none;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; transition: all var(--transition);
  box-shadow: 0 2px 10px var(--indigo-glow);
}
.btn-icon:hover { background: var(--indigo-dark); transform: scale(1.08); }
.btn-icon.ghost {
  background: var(--surface2); color: var(--text);
  border: 1px solid var(--border); box-shadow: none;
}
.btn-icon.ghost:hover {
  border-color: var(--indigo); color: var(--indigo);
  background: var(--surface2); transform: scale(1.05);
}

/* ── APP SCREEN ──────────────────────────────────────── */
#screen-app { width: 100%; max-width: 1000px; align-items: stretch; gap: 1.25rem; padding-top: 1rem; }

.topbar { display: flex; align-items: center; justify-content: space-between; padding: 0 0.25rem; }
.welcome-text { font-size: 1.4rem; font-weight: 600; }
.welcome-text span { color: var(--indigo); }
.welcome-text button {
  font-size: 0.75rem; color: var(--muted);
  background: none; border: none; cursor: pointer;
  margin-left: 0.5rem; text-decoration: underline; font-family: inherit;
}
.welcome-text button:hover { color: var(--indigo); }

.main-grid { display: grid; grid-template-columns: 1fr 260px; gap: 1.25rem; align-items: stretch; }
@media (max-width: 680px) { .main-grid { grid-template-columns: 1fr; } }

.form-group { margin-bottom: 1.1rem; }
.select-row { display: flex; gap: 0.5rem; align-items: flex-end; }
.select-row select { flex: 1; }

/* ── SIDEBAR ─────────────────────────────────────────── */
.sidebar-stack { display: flex; flex-direction: column; gap: 1rem; min-height: 100%; }

.summary-top {
  background: linear-gradient(135deg, var(--indigo) 0%, #7c3aed 100%);
  border-radius: var(--radius);
  padding: 1.5rem;
  color: #fff;
}
.summary-label { font-size: 0.78rem; opacity: 0.8; text-transform: uppercase; letter-spacing: 0.06em; margin-bottom: 0.3rem; }
.summary-amount { font-size: 2rem; font-weight: 700; font-family: 'DM Mono', monospace; letter-spacing: -0.02em; }

.cat-bar-row { display: flex; flex-direction: column; gap: 0.2rem; }
.cat-bar-label { display: flex; justify-content: space-between; font-size: 0.8rem; }
.cat-bar-label span:first-child { color: var(--text); font-weight: 500; }
.cat-bar-label span:last-child { color: var(--muted); font-family: 'DM Mono', monospace; font-size: 0.75rem; }
.cat-bar-track { height: 4px; background: var(--border); border-radius: 999px; overflow: hidden; }
.cat-bar-fill { height: 100%; border-radius: 999px; transition: width 0.4s ease; }

/* ── TABLE ───────────────────────────────────────────── */
.table-wrap { overflow-x: auto; border-radius: var(--radius-sm); border: 1px solid var(--border); }
table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
thead tr { background: var(--surface2); }
th {
  padding: 0.8rem 1rem; text-align: left;
  font-weight: 500; color: var(--muted);
  font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.05em;
  border-bottom: 1px solid var(--border); white-space: nowrap;
}
td { padding: 0.85rem 1rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
tr:last-child td { border-bottom: none; }
tbody tr { transition: background var(--transition); }
tbody tr:hover { background: var(--surface2); }

.empty-state { text-align: center; padding: 3rem 1rem; color: var(--muted); }
.empty-state i { font-size: 2rem; margin-bottom: 0.75rem; display: block; opacity: 0.4; }

.badge {
  display: inline-flex; align-items: center;
  padding: 0.2rem 0.65rem;
  border-radius: 999px; font-size: 0.75rem; font-weight: 500;
  background: var(--surface2); color: var(--muted);
  border: 1px solid var(--border);
}
.amount-cell { font-family: 'DM Mono', monospace; font-size: 0.88rem; }

/* ── TOAST ───────────────────────────────────────────── */
.toast {
  position: fixed; bottom: 4rem; left: 50%; transform: translateX(-50%) translateY(20px);
  background: var(--success); color: #fff;
  padding: 0.6rem 1.2rem; border-radius: 999px;
  font-size: 0.85rem; font-weight: 500;
  opacity: 0; transition: all 0.3s ease;
  pointer-events: none; z-index: 9999; white-space: nowrap;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ── OVERLAY + DRAWER ────────────────────────────────── */
.overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.5); backdrop-filter: blur(4px);
  z-index: 100; opacity: 0; visibility: hidden;
  transition: all var(--transition);
}
.overlay.open { opacity: 1; visibility: visible; }

.drawer {
  position: fixed; top: 0; right: 0; bottom: 0;
  width: 300px; background: var(--surface);
  border-left: 1px solid var(--border);
  z-index: 101; padding: 1.5rem;
  transform: translateX(100%);
  transition: transform 0.3s cubic-bezier(.16,1,.3,1);
  overflow-y: auto; display: flex; flex-direction: column; gap: 1.5rem;
}
@media (max-width: 400px) { .drawer { width: 88vw; } }
.drawer.open { transform: translateX(0); }
.drawer-header { display: flex; align-items: center; justify-content: space-between; }
.drawer-title { font-size: 1.2rem; font-weight: 600; }
.drawer-section h3 {
  font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--muted); margin-bottom: 0.6rem;
}
.drawer-link {
  display: flex; align-items: center; gap: 0.75rem;
  padding: 0.7rem 0.9rem; border-radius: var(--radius-sm);
  background: var(--surface2); border: 1px solid var(--border);
  color: var(--text); text-decoration: none; font-size: 0.9rem; font-weight: 500;
  margin-bottom: 0.5rem; transition: all var(--transition);
}
.drawer-link:hover { border-color: var(--indigo); color: var(--indigo); }
.drawer-link i { color: var(--indigo); width: 18px; text-align: center; }
.about-box {
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 1rem; text-align: center;
  font-size: 0.85rem; color: var(--muted); margin-top: auto; line-height: 1.7;
}
.about-box a { color: var(--indigo); text-decoration: none; }
.about-box a:hover { text-decoration: underline; }

/* ── MENU BUTTON ─────────────────────────────────────── */
#menuBtn {
  position: fixed; top: 1.25rem; right: 1.25rem; z-index: 99;
  background: var(--surface); border: 1px solid var(--border);
  box-shadow: 0 4px 16px rgba(0,0,0,0.18);
}

/* ── THEME TOGGLE ────────────────────────────────────── */
.theme-toggle-btn {
  display: flex; align-items: center; justify-content: space-between;
  width: 100%; padding: 0.7rem 0.9rem;
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: var(--radius-sm); cursor: pointer;
  color: var(--text); font-family: inherit; font-size: 0.9rem; font-weight: 500;
  transition: all var(--transition);
}
.theme-toggle-btn:hover { border-color: var(--indigo); }

/* ── FOOTER BRANDING ─────────────────────────────────── */
.site-footer {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.6rem 1rem;
  background: var(--surface);
  border-top: 1px solid var(--border);
  font-size: 0.75rem;
  color: var(--muted);
  letter-spacing: 0.01em;
}
.site-footer .footer-dot { opacity: 0.35; }
.site-footer strong { color: var(--text); font-weight: 600; }
.site-footer a { color: var(--indigo); text-decoration: none; }
.site-footer a:hover { text-decoration: underline; }

/* ── PLOT PAGE LAYOUT ────────────────────────────────── */
.page {
  position: relative; z-index: 1;
  max-width: 1000px; margin: 0 auto;
  padding: 2.5rem 1.25rem 5rem;
  animation: fadeUp 0.4s ease both;
}
.page-header { margin-bottom: 2rem; }
.page-header h1 { font-size: clamp(1.6rem, 4vw, 2.2rem); font-weight: 700; letter-spacing: -0.03em; }
.page-header p { color: var(--muted); margin-top: 0.3rem; font-size: 0.95rem; }

.card-title {
  font-size: 0.78rem; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--muted); margin-bottom: 1.25rem;
}

.stat-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem; margin-bottom: 1.25rem; }
@media (max-width: 500px) { .stat-grid { grid-template-columns: 1fr 1fr; } }
.stat-card { background: var(--surface2); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 1rem; }
.stat-label { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); margin-bottom: 0.3rem; }
.stat-value { font-size: 1.3rem; font-weight: 700; font-family: 'DM Mono', monospace; color: var(--indigo); }
.stat-sub { font-size: 0.75rem; color: var(--muted); margin-top: 0.15rem; }

.charts-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1.25rem; }
@media (max-width: 640px) { .charts-grid { grid-template-columns: 1fr; } }
.chart-full { margin-top: 1.25rem; }
canvas { max-height: 280px; }

.plot-empty-state { display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 4rem 2rem; text-align: center; gap: 1rem; }
.plot-empty-state i { font-size: 2.5rem; color: var(--muted); opacity: 0.4; }
.plot-empty-state p { color: var(--muted); font-size: 0.95rem; }

.back-row { display: flex; justify-content: center; margin-top: 2rem; }
