:root {
  /* === Palette === */
  --bg: #0a0d16;
  --surface: #10172a;
  --surface2: #1a2440;
  --surface3: #26334f;
  --border: #1e2a45;
  --border-strong: #2a3958;

  /* === Text === */
  --text: #eef2f8;
  --text2: #a3b1c6;
  --muted: #64748b;

  /* === Accent === */
  --accent: #6366f1;
  --accent2: #818cf8;
  --accent-glow: rgba(99,102,241,0.20);

  /* === Semantic === */
  --positive: #22c55e;
  --positive-soft: rgba(34,197,94,0.12);
  --negative: #ef4444;
  --negative-soft: rgba(239,68,68,0.12);
  --warn: #f59e0b;
  --warn-soft: rgba(245,158,11,0.12);

  /* === Spacing 8pt === */
  --s-1: 0.25rem;
  --s-2: 0.5rem;
  --s-3: 0.75rem;
  --s-4: 1rem;
  --s-5: 1.5rem;
  --s-6: 2rem;
  --s-7: 3rem;

  /* === Radius === */
  --radius: 16px;
  --radius-sm: 10px;
  --radius-xs: 6px;
  --radius-full: 9999px;

  /* === Shadows === */
  --shadow-1: 0 1px 2px rgba(0,0,0,0.3);
  --shadow-2: 0 4px 16px rgba(0,0,0,0.4);
  --shadow-modal: 0 24px 72px rgba(0,0,0,0.6), 0 0 0 1px rgba(255,255,255,0.04);
  --inset-highlight: inset 0 1px 0 rgba(255,255,255,0.03);

  /* === Layout === */
  --sidebar-w: 240px;
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Inter', sans-serif;
  --font-mono: 'SF Mono', 'Menlo', 'JetBrains Mono', monospace;
}

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

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  font-size: 0.9375rem;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}

/* === Tabular numbers everywhere it matters === */
.kpi-value, .account-balance, .data-table td, .insight-value,
.cat-amt, .alloc-num, .delta, .stat-num {
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum";
}

/* === SCROLLBAR === */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--border-strong); }

/* === SIDEBAR === */
#sidebar {
  width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 0;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
  overflow-y: auto;
}

.logo {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 1.5rem 1.5rem 1.25rem;
  border-bottom: 1px solid var(--border);
}

.logo-icon { font-size: 1.3rem; color: var(--accent); }
.logo-text { font-size: 1.05rem; font-weight: 700; color: var(--text); letter-spacing: 0.01em; }

.nav-links {
  list-style: none;
  padding: var(--s-3) var(--s-2);
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0.65rem 0.85rem;
  color: var(--text2);
  text-decoration: none;
  transition: background 0.15s ease, color 0.15s ease;
  font-size: 0.875rem;
  font-weight: 500;
  border-radius: var(--radius-sm);
}

.nav-link:hover { color: var(--text); background: var(--surface2); }

.nav-link.active {
  color: var(--accent2);
  background: var(--accent-glow);
  font-weight: 600;
}

.icon {
  font-size: 0.95rem;
  width: 18px;
  text-align: center;
  opacity: 0.85;
}

.nav-link.active .icon { opacity: 1; }

/* === MAIN === */
#main {
  margin-left: var(--sidebar-w);
  flex: 1;
  padding: var(--s-6) 2.5rem;
  overflow-y: auto;
  min-height: 100vh;
}

/* === PAGE === */
.page { max-width: 1280px; animation: fadeIn 220ms cubic-bezier(0.16, 1, 0.3, 1); }

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

.page-title {
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: -0.025em;
  margin-bottom: var(--s-6);
  color: var(--text);
}

.page-subtitle {
  color: var(--text2);
  font-size: 0.875rem;
  margin-top: -1.25rem;
  margin-bottom: var(--s-6);
}

.disclaimer-note {
  margin-top: var(--s-6);
  padding: 0.85rem 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface2);
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.5;
}

/* ===== Schermata autenticazione ===== */
body.auth-active #sidebar,
body.auth-active #bottom-nav,
body.auth-active #main { display: none; }

#auth-screen {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  background: radial-gradient(1200px 600px at 50% -10%, var(--surface) 0%, var(--bg) 60%);
}

.auth-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-modal);
  padding: 2rem 1.75rem;
}

.auth-brand {
  font-size: 1.6rem;
  font-weight: 700;
  text-align: center;
  color: var(--text);
  letter-spacing: 0.02em;
}
.auth-mark { color: var(--accent); }

.auth-tagline {
  text-align: center;
  color: var(--text2);
  font-size: 0.9rem;
  line-height: 1.5;
  margin: 0.5rem 0 1.5rem;
}

.auth-google { width: 100%; justify-content: center; }

.auth-divider {
  display: flex;
  align-items: center;
  text-align: center;
  color: var(--muted);
  font-size: 0.78rem;
  margin: 1.1rem 0;
}
.auth-divider::before,
.auth-divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--border);
}
.auth-divider span { padding: 0 0.75rem; }

.auth-error {
  background: var(--negative-soft);
  border: 1px solid var(--negative);
  color: var(--negative);
  border-radius: var(--radius-sm);
  padding: 0.6rem 0.85rem;
  font-size: 0.82rem;
  margin-bottom: 1rem;
}

.auth-toggle {
  text-align: center;
  color: var(--text2);
  font-size: 0.85rem;
  margin-top: 1.1rem;
}
.auth-toggle a { color: var(--accent2); text-decoration: none; }
.auth-toggle a:hover { text-decoration: underline; }

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--s-6);
  flex-wrap: wrap;
  gap: var(--s-4);
}

.page-header .page-title { margin-bottom: 0; }
.page-actions { display: flex; gap: var(--s-3); align-items: center; flex-wrap: wrap; }

/* === HERO KPI === */
.kpi-hero {
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--inset-highlight);
  border-radius: var(--radius);
  padding: 1.75rem 2rem;
  margin-bottom: var(--s-4);
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--s-5);
  align-items: center;
}

.kpi-hero-label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  font-weight: 600;
  margin-bottom: 0.4rem;
}

.kpi-hero-value {
  font-size: 2.5rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  color: var(--text);
  line-height: 1.05;
}

.kpi-hero-delta {
  margin-top: 0.6rem;
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.85rem;
  font-weight: 600;
}

.delta.positive { color: var(--positive); }
.delta.negative { color: var(--negative); }
.delta.neutral { color: var(--muted); }

.kpi-hero-spark {
  height: 90px;
  position: relative;
}

/* === KPI GRID === */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: var(--s-4);
  margin-bottom: var(--s-6);
}

.kpi-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem 1.5rem;
  transition: border-color 0.15s, transform 0.15s;
  box-shadow: var(--inset-highlight);
}

.kpi-card:hover { border-color: var(--border-strong); }

.kpi-label {
  font-size: 0.7rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.07em;
  font-weight: 600;
  margin-bottom: 0.45rem;
}

.kpi-value {
  font-size: 1.55rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text);
  line-height: 1.1;
}

.kpi-value.accent { color: var(--accent2); }
.kpi-value.positive { color: var(--positive); }
.kpi-value.negative { color: var(--negative); }

.kpi-sub {
  font-size: 0.75rem;
  color: var(--text2);
  margin-top: 0.4rem;
}

/* === CHARTS === */
.charts-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--s-5);
  margin-bottom: var(--s-5);
}

.chart-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.75rem;
  box-shadow: var(--inset-highlight);
}

.chart-card h3 {
  font-size: 0.95rem;
  color: var(--text);
  font-weight: 600;
  letter-spacing: -0.01em;
  margin-bottom: 1.25rem;
}

.chart-wrapper { position: relative; height: 240px; }
.chart-wrapper-tall { position: relative; height: 300px; }

/* === TABLES === */
.table-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: var(--s-5);
  box-shadow: var(--inset-highlight);
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

.data-table thead { background: var(--surface2); }

.data-table th {
  padding: 0.95rem 1.1rem;
  text-align: left;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--muted);
  font-weight: 600;
  white-space: nowrap;
}

.data-table td {
  padding: 0.9rem 1.1rem;
  border-top: 1px solid var(--border);
  vertical-align: middle;
}

.data-table tbody tr:nth-child(even) { background: rgba(255,255,255,0.012); }
.data-table tbody tr:hover { background: rgba(99,102,241,0.05); }

.data-table td.empty {
  text-align: center;
  color: var(--muted);
  padding: 3rem;
  font-size: 0.9rem;
}

.inv-name { font-weight: 600; font-size: 0.875rem; }
.inv-ticker {
  font-size: 0.72rem;
  color: var(--muted);
  margin-top: 2px;
  font-family: var(--font-mono);
  letter-spacing: 0.02em;
}

/* === BUTTONS === */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.6rem 1.1rem;
  border-radius: var(--radius-sm);
  border: none;
  cursor: pointer;
  font-size: 0.875rem;
  font-weight: 500;
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
  font-family: var(--font);
  white-space: nowrap;
}

.btn:active { transform: scale(0.97); }

.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: #4f46e5; }

.btn-secondary {
  background: var(--surface2);
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-secondary:hover { background: var(--surface3); border-color: var(--border-strong); }

.btn-danger { background: var(--negative); color: #fff; }
.btn-danger:hover { background: #dc2626; }

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

.btn-icon {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 0.9rem;
  padding: 0.35rem 0.45rem;
  opacity: 0.5;
  transition: all 0.15s ease;
  border-radius: var(--radius-xs);
  line-height: 1;
  color: var(--text);
}
.btn-icon:hover { opacity: 1; background: var(--surface2); }
.btn-icon:focus-visible { opacity: 1; box-shadow: 0 0 0 2px var(--accent-glow); outline: none; }

.btn-group { display: flex; gap: var(--s-3); flex-wrap: wrap; align-items: center; }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* === FAB === */
.fab {
  display: none;
  position: fixed;
  right: 1.25rem;
  bottom: calc(70px + env(safe-area-inset-bottom));
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  box-shadow: 0 8px 20px rgba(99,102,241,0.4);
  z-index: 90;
  transition: transform 0.15s, box-shadow 0.15s;
}
.fab:active { transform: scale(0.92); }

/* === FORMS === */
.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  margin-bottom: 1.1rem;
}

.form-group:last-child { margin-bottom: 0; }

.form-group label {
  font-size: 0.8125rem;
  color: var(--text2);
  font-weight: 500;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--s-4);
}

.form-row-3 {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: var(--s-3);
}

input[type="text"],
input[type="number"],
input[type="date"],
select,
textarea {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.65rem 0.95rem;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  width: 100%;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
  font-family: var(--font);
  -webkit-appearance: none;
  height: 40px;
}

textarea { height: auto; min-height: 80px; padding: 0.7rem 0.95rem; resize: vertical; }

input:focus, select:focus, textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

select option { background: var(--surface); color: var(--text); }

input[type="date"]::-webkit-calendar-picker-indicator {
  filter: invert(0.55);
  cursor: pointer;
}

input::placeholder, textarea::placeholder { color: var(--muted); }

/* === FILTERS === */
.filters {
  display: flex;
  gap: var(--s-3);
  margin-bottom: var(--s-5);
  align-items: center;
  flex-wrap: wrap;
}

.filters select { width: auto; min-width: 120px; }

/* === ACCOUNTS === */
.accounts-list { display: flex; flex-direction: column; gap: var(--s-3); }

.account-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.1rem 1.4rem;
  display: flex;
  align-items: center;
  gap: var(--s-4);
  transition: border-color 0.15s;
  box-shadow: var(--inset-highlight);
}

.account-card:hover { border-color: var(--border-strong); }
.account-info { flex: 1; min-width: 0; }
.account-name { font-weight: 600; font-size: 0.95rem; }
.account-meta { font-size: 0.75rem; color: var(--muted); margin-top: 2px; }
.account-balance { font-size: 1.2rem; font-weight: 700; white-space: nowrap; }
.account-actions { display: flex; gap: 0.1rem; }

/* === BADGES & PILLS === */
.badge {
  display: inline-block;
  padding: 0.2rem 0.6rem;
  border-radius: var(--radius-full);
  font-size: 0.72rem;
  font-weight: 600;
  background: var(--surface2);
  color: var(--text2);
  border: 1px solid var(--border);
  letter-spacing: 0.02em;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  height: 22px;
  padding: 0 0.55rem;
  border-radius: var(--radius-full);
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.pill-positive { background: var(--positive-soft); color: var(--positive); }
.pill-negative { background: var(--negative-soft); color: var(--negative); }
.pill-warn { background: var(--warn-soft); color: var(--warn); }
.pill-neutral { background: var(--surface2); color: var(--text2); }

.badge-warn {
  font-size: 0.65rem;
  color: var(--warn);
  background: var(--warn-soft);
  border: 1px solid rgba(245,158,11,0.2);
  border-radius: var(--radius-xs);
  padding: 1px 6px;
  margin-left: 4px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* === COLORS === */
.positive { color: var(--positive); }
.negative { color: var(--negative); }
.muted { color: var(--muted); }
.accent { color: var(--accent2); }
.text2 { color: var(--text2); }

/* === CATEGORY BARS === */
.cat-row {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  margin-bottom: 0.75rem;
  font-size: 0.85rem;
}

.cat-row:last-child { margin-bottom: 0; }

.cat-name { min-width: 120px; color: var(--text2); font-weight: 500; }
.cat-bar-wrap { flex: 1; height: 8px; background: var(--surface2); border-radius: var(--radius-full); overflow: hidden; }
.cat-bar {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--accent2));
  border-radius: var(--radius-full);
  transition: width 0.5s cubic-bezier(0.16, 1, 0.3, 1);
}
.cat-bar.muted-bar { background: var(--border-strong); }
.cat-amt { font-weight: 600; min-width: 90px; text-align: right; }

/* === CAT MANAGEMENT === */
.cat-list-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.55rem 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.875rem;
}

.cat-list-item:last-child { border-bottom: none; }

/* === TWO COL === */
.two-col {
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: var(--s-5);
  align-items: start;
}

/* === CARD === */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.4rem 1.5rem;
  box-shadow: var(--inset-highlight);
}

.card h3 {
  font-size: 0.8rem;
  color: var(--muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  margin-bottom: 1rem;
}

.card-title {
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--text);
  margin-bottom: 0.4rem;
}

/* === MODAL === */
#modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.75);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  backdrop-filter: blur(3px);
  animation: overlayIn 150ms ease;
}

@keyframes overlayIn { from { opacity: 0; } to { opacity: 1; } }

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-modal);
  animation: modalIn 220ms cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes modalIn {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}

.modal-small { max-width: 400px; }

.modal-handle { display: none; }

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.3rem 1.5rem;
  border-bottom: 1px solid var(--border);
}

.modal-header h3 { font-size: 1rem; font-weight: 600; letter-spacing: -0.01em; }

.modal-body { padding: 1.5rem; }
.modal-body p { color: var(--text2); font-size: 0.9rem; }

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: var(--s-3);
  padding: 1.1rem 1.5rem;
  border-top: 1px solid var(--border);
}

/* === TOAST === */
.toast {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.75rem 1.1rem;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  z-index: 2000;
  transform: translateY(12px);
  opacity: 0;
  transition: all 0.22s cubic-bezier(0.16, 1, 0.3, 1);
  pointer-events: none;
  box-shadow: var(--shadow-2);
  border-left: 3px solid var(--positive);
}

.toast.show { transform: translateY(0); opacity: 1; }
.toast.toast-error { border-left-color: var(--negative); color: var(--text); }
.toast.toast-success { border-left-color: var(--positive); }

/* === SETTINGS === */
.settings-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  margin-bottom: var(--s-5);
  box-shadow: var(--inset-highlight);
}

.settings-section h3 { font-size: 1rem; font-weight: 600; margin-bottom: 0.4rem; }
.settings-section .desc { color: var(--text2); font-size: 0.875rem; margin-bottom: 1.1rem; }
.danger-zone { border-color: rgba(239,68,68,0.25); }

/* === EMPTY STATE === */
.empty-state {
  text-align: center;
  color: var(--muted);
  padding: 4rem 2rem;
  font-size: 0.9rem;
}

.empty-state-icon {
  font-size: 2.5rem;
  opacity: 0.25;
  margin-bottom: 1rem;
  display: block;
}

.empty-state-title { color: var(--text); font-size: 1rem; font-weight: 600; margin-bottom: 0.3rem; }

/* === INSIGHTS === */
.insights-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(360px, 1fr));
  gap: var(--s-4);
}

.insight-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 4px solid var(--border);
  border-radius: var(--radius);
  padding: 1.4rem 1.5rem;
  box-shadow: var(--inset-highlight);
  transition: border-color 0.15s;
}

.insight-card:hover { border-color: var(--border-strong); }

.insight-card.insight-good { border-left-color: var(--positive); }
.insight-card.insight-warn { border-left-color: var(--warn); }
.insight-card.insight-bad  { border-left-color: var(--negative); }
.insight-card.insight-action {
  border-left-color: var(--accent);
  background: linear-gradient(135deg, var(--surface), rgba(99,102,241,0.04));
}

.insight-header {
  display: flex;
  align-items: flex-start;
  gap: 0.9rem;
  margin-bottom: 0.85rem;
}

.insight-icon {
  font-size: 1.35rem;
  line-height: 1;
  padding-top: 2px;
  color: var(--accent2);
  font-weight: 400;
  width: 28px;
  text-align: center;
}

.insight-card.insight-good  .insight-icon { color: var(--positive); }
.insight-card.insight-warn  .insight-icon { color: var(--warn); }
.insight-card.insight-bad   .insight-icon { color: var(--negative); }

.insight-title {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  font-weight: 600;
  margin-bottom: 0.25rem;
}

.insight-value {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.015em;
  line-height: 1.3;
}

.insight-badge {
  font-size: 0.62rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  padding: 0.22rem 0.55rem;
  border-radius: var(--radius-full);
  white-space: nowrap;
  flex-shrink: 0;
  margin-top: 4px;
}

.insight-badge-good   { background: var(--positive-soft); color: var(--positive); }
.insight-badge-warn   { background: var(--warn-soft);     color: var(--warn); }
.insight-badge-bad    { background: var(--negative-soft); color: var(--negative); }
.insight-badge-action { background: var(--accent-glow);   color: var(--accent2); }

.insight-desc {
  font-size: 0.85rem;
  color: var(--text2);
  line-height: 1.6;
  margin-bottom: 0.85rem;
}

.insight-rec {
  font-size: 0.825rem;
  color: var(--text);
  background: var(--surface2);
  border-left: 2px solid var(--accent);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  padding: 0.6rem 0.85rem;
  line-height: 1.55;
}

/* === ALLOCATION === */
.alloc-stack {
  display: flex;
  flex-direction: column;
  gap: var(--s-3);
}

.alloc-row {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.9rem 1.1rem;
}

.alloc-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 0.55rem;
  font-size: 0.875rem;
}

.alloc-name { font-weight: 600; color: var(--text); }
.alloc-num { color: var(--text2); }

.alloc-bar-bg { height: 8px; background: var(--surface2); border-radius: var(--radius-full); overflow: hidden; position: relative; }
.alloc-bar-fill { height: 100%; background: var(--accent); border-radius: var(--radius-full); transition: width 0.5s cubic-bezier(0.16,1,0.3,1); }
.alloc-bar-target { position: absolute; top: -2px; bottom: -2px; width: 2px; background: var(--positive); }

.alloc-delta {
  font-size: 0.78rem;
  margin-top: 0.4rem;
  color: var(--text2);
}

/* === PROGRESS BAR (emergency plan, goals) === */
.progress-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 0.45rem;
  font-size: 0.85rem;
}

.progress-row .progress-label { color: var(--text2); }
.progress-row .progress-value { font-weight: 600; }

.progress-bar {
  height: 10px;
  background: var(--surface2);
  border-radius: var(--radius-full);
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--accent2));
  border-radius: var(--radius-full);
  transition: width 0.6s cubic-bezier(0.16,1,0.3,1);
}

.progress-fill.good { background: linear-gradient(90deg, var(--positive), #4ade80); }
.progress-fill.warn { background: linear-gradient(90deg, var(--warn), #fbbf24); }
.progress-fill.bad  { background: linear-gradient(90deg, var(--negative), #f87171); }

/* === BUDGET === */
.budget-grid {
  display: flex;
  flex-direction: column;
  gap: var(--s-3);
}

.budget-row {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.1rem 1.3rem;
  box-shadow: var(--inset-highlight);
}

.budget-row.budget-untracked {
  background: transparent;
  border-style: dashed;
  border-color: var(--border);
}

.budget-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 0.6rem;
}

.budget-cat {
  font-weight: 600;
  font-size: 0.9rem;
}

.budget-nums {
  font-size: 0.9rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.budget-foot {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: 0.55rem;
  font-size: 0.8rem;
}

.budget-status { font-weight: 600; flex: 1; }

/* === LOGIN OVERLAY === */
#login-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg);
  z-index: 3000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}

.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2.5rem 2rem;
  max-width: 400px;
  width: 100%;
  text-align: center;
  box-shadow: var(--shadow-modal);
}

.login-logo {
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--accent2);
  letter-spacing: -0.02em;
  margin-bottom: 1.75rem;
}

.login-card h2 {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.025em;
  margin-bottom: 0.75rem;
  line-height: 1.3;
}

.login-card > p {
  color: var(--text2);
  font-size: 0.875rem;
  margin-bottom: 1.75rem;
  line-height: 1.6;
}

.btn-google {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  width: 100%;
  background: #fff;
  color: #1f1f1f;
  border: none;
  border-radius: var(--radius-sm);
  padding: 0.75rem 1.25rem;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s, box-shadow 0.15s;
  font-family: var(--font);
  box-shadow: var(--shadow-1);
}

.btn-google:hover { opacity: 0.94; box-shadow: var(--shadow-2); }
.btn-google:disabled { opacity: 0.5; cursor: not-allowed; }

.google-g {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: linear-gradient(135deg, #4285F4 25%, #EA4335 25% 50%, #FBBC05 50% 75%, #34A853 75%);
  color: transparent;
  font-size: 0;
  flex-shrink: 0;
}

.login-note {
  color: var(--muted);
  font-size: 0.75rem;
  margin-top: 1.25rem;
  line-height: 1.5;
}

/* === SYNC INDICATOR === */
.sync-indicator {
  padding: 0.5rem 1rem 0.75rem;
  font-size: 0.72rem;
  font-weight: 500;
  letter-spacing: 0.03em;
  border-top: 1px solid var(--border);
  margin-top: auto;
}

.sync-indicator.ok    { color: var(--positive); }
.sync-indicator.saving { color: var(--warn); }
.sync-indicator.error  { color: var(--negative); }

/* === BOTTOM NAV === */
#bottom-nav { display: none; }

/* === RESPONSIVE === */
@media (max-width: 1024px) {
  .charts-row { grid-template-columns: 1fr; }
  .two-col { grid-template-columns: 1fr; }
  .kpi-hero { grid-template-columns: 1fr; }
  .kpi-hero-spark { height: 70px; }
}

@media (max-width: 768px) {
  #sidebar { display: none; }

  #main {
    margin-left: 0;
    padding: 1.25rem 1rem 6rem;
  }

  .page-title { font-size: 1.45rem; margin-bottom: var(--s-4); }
  .kpi-hero { padding: 1.25rem 1.4rem; }
  .kpi-hero-value { font-size: 2rem; }
  .kpi-card { padding: 1rem 1.2rem; }
  .kpi-value { font-size: 1.35rem; }

  #bottom-nav {
    display: flex;
    position: fixed;
    bottom: 0; left: 0; right: 0;
    background: rgba(16,23,42,0.92);
    backdrop-filter: blur(14px);
    border-top: 1px solid var(--border);
    justify-content: space-around;
    z-index: 100;
    padding: 0.5rem 0 calc(0.5rem + env(safe-area-inset-bottom));
  }

  .bnav-link {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    text-decoration: none;
    color: var(--muted);
    font-size: 0.65rem;
    padding: 0.35rem 0.65rem;
    border-radius: var(--radius-sm);
    transition: color 0.15s;
    font-weight: 500;
  }

  .bnav-link.active { color: var(--accent2); }
  .bnav-link.active .bnav-icon-wrap {
    background: var(--accent-glow);
  }
  .bnav-icon-wrap {
    width: 36px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-sm);
    transition: background 0.15s;
  }
  .bnav-icon { font-size: 1.05rem; }

  .kpi-grid { grid-template-columns: 1fr 1fr; gap: var(--s-3); }
  .form-row { grid-template-columns: 1fr; }
  .page-header { flex-direction: column; align-items: flex-start; }
  .data-table { font-size: 0.8rem; }
  .data-table th, .data-table td { padding: 0.7rem 0.65rem; }
  .table-card { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .table-card .data-table { min-width: 520px; }

  .insights-grid { grid-template-columns: 1fr; }

  /* Bottom-sheet modal */
  #modal-overlay {
    align-items: flex-end;
    padding: 0;
  }
  .modal {
    max-width: 100%;
    max-height: 92vh;
    border-radius: 20px 20px 0 0;
    border-bottom: none;
    animation: sheetIn 280ms cubic-bezier(0.16, 1, 0.3, 1);
  }
  @keyframes sheetIn {
    from { transform: translateY(100%); }
    to { transform: translateY(0); }
  }
  .modal-handle {
    display: block;
    width: 36px;
    height: 4px;
    background: var(--border-strong);
    border-radius: var(--radius-full);
    margin: 10px auto 0;
  }
  .modal-footer { flex-direction: column-reverse; gap: var(--s-2); }
  .modal-footer .btn { width: 100%; justify-content: center; }

  /* Toast bottom-center mobile */
  .toast { left: 1rem; right: 1rem; bottom: calc(78px + env(safe-area-inset-bottom)); }

  /* FAB visible on mobile */
  .fab.fab-active { display: flex; align-items: center; justify-content: center; }

  /* Hide page-actions buttons that have FAB equivalents */
  .page-actions .btn-fab-hide { display: none; }
}

@media (max-width: 480px) {
  .kpi-grid { grid-template-columns: 1fr; }
  #main { padding: 1rem 0.875rem 6rem; }
  .modal-body { padding: 1.25rem; }
  .insight-card { padding: 1.2rem 1.3rem; }
}

/* === BOTTOM-SHEET "ALTRO" === */
.more-sheet-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  backdrop-filter: blur(4px);
  z-index: 200;
  opacity: 0;
  pointer-events: none;
  transition: opacity 220ms ease;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.more-sheet-overlay.open {
  opacity: 1;
  pointer-events: auto;
}
.more-sheet {
  background: var(--surface);
  border-top: 1px solid var(--border);
  border-radius: 20px 20px 0 0;
  width: 100%;
  max-width: 560px;
  padding: 0.5rem 1.25rem calc(1.5rem + env(safe-area-inset-bottom));
  transform: translateY(100%);
  transition: transform 280ms cubic-bezier(0.16, 1, 0.3, 1);
  max-height: 80vh;
  overflow-y: auto;
}
.more-sheet-overlay.open .more-sheet {
  transform: translateY(0);
}
.more-sheet-handle {
  width: 36px;
  height: 4px;
  background: var(--border-strong);
  border-radius: var(--radius-full);
  margin: 10px auto 18px;
}
.more-sheet-title {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin: 0 0 0.85rem;
  font-weight: 600;
}
.more-sheet-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.6rem;
}
.more-sheet-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.45rem;
  text-decoration: none;
  color: var(--text);
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 1.15rem 0.5rem;
  font-size: 0.78rem;
  font-weight: 500;
  text-align: center;
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
}
.more-sheet-item:active {
  transform: scale(0.96);
  background: var(--accent-glow);
  border-color: var(--accent2);
}
.more-icon {
  font-size: 1.35rem;
  color: var(--accent2);
}

/* Hide more-sheet on desktop */
@media (min-width: 769px) {
  .more-sheet-overlay { display: none; }
}

/* === GOALS === */
.goals-grid {
  display: grid;
  gap: var(--s-4);
}

.goal-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem 1.5rem;
  box-shadow: var(--inset-highlight);
  transition: border-color 0.15s;
}
.goal-card:hover { border-color: var(--border-strong); }

.goal-card-inner {
  display: flex;
  align-items: center;
  gap: 1.25rem;
}

.goal-ring { flex-shrink: 0; }

.goal-body {
  flex: 1;
  min-width: 0;
}

.goal-title-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin-bottom: 0.2rem;
  flex-wrap: wrap;
}

.goal-name {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.01em;
}

.goal-type-badge {
  font-size: 0.68rem;
  color: var(--muted);
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  padding: 0.1rem 0.5rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.goal-amounts {
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text);
  line-height: 1.2;
  margin-bottom: 0.3rem;
  font-variant-numeric: tabular-nums;
}

.goal-allocated { color: var(--accent2); }

.goal-meta-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.goal-card-actions {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  align-items: flex-end;
  flex-shrink: 0;
}

/* Source rows in modal */
.source-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.4rem 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.85rem;
}
.source-label { flex: 1; color: var(--text2); }
.source-amount { font-weight: 600; color: var(--text); font-variant-numeric: tabular-nums; }

.source-add-row {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.75rem;
  flex-wrap: wrap;
  align-items: center;
}
.source-add-row select { flex: 1; min-width: 180px; }
.source-add-row input[type="number"] { width: 100px; }

.form-section-title {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  font-weight: 600;
  margin: 1.25rem 0 0.6rem;
  border-top: 1px solid var(--border);
  padding-top: 1rem;
}

@media (max-width: 640px) {
  .goal-card-inner { align-items: flex-start; }
  .goal-card-actions { flex-direction: row; margin-top: 0.75rem; }
  .goal-amounts { font-size: 1.05rem; }
  .source-add-row { flex-direction: column; }
  .source-add-row select,
  .source-add-row input[type="number"] { width: 100%; min-width: 0; }
}
