/* ---------- Tokens ---------- */
:root {
  --bg: #0b0d12;
  --bg-2: #11141b;
  --bg-3: #161a23;
  --surface: #1a1f2b;
  --surface-2: #232938;
  --border: #2a3142;
  --border-strong: #3a4358;
  --text: #e8ebf2;
  --text-dim: #a1a8b8;
  --text-mute: #6b7388;
  --accent: #6366f1;
  --accent-2: #8b5cf6;
  --accent-glow: rgba(99, 102, 241, 0.18);
  --green: #10b981;
  --green-dim: rgba(16, 185, 129, 0.12);
  --red: #ef4444;
  --red-dim: rgba(239, 68, 68, 0.12);
  --yellow: #f59e0b;
  --blue: #3b82f6;
  --safe-top: env(safe-area-inset-top);
  --safe-bottom: env(safe-area-inset-bottom);
  --safe-left: env(safe-area-inset-left);
  --safe-right: env(safe-area-inset-right);
  --nav-height: 60px;
  --mobile-header-height: 56px;
  --radius: 14px;
  --radius-sm: 8px;
  --radius-lg: 20px;
  --shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  --shadow-soft: 0 4px 14px rgba(0, 0, 0, 0.25);
  --transition: 180ms cubic-bezier(0.4, 0, 0.2, 1);
}

[data-theme="light"] {
  --bg: #f6f7fb;
  --bg-2: #ffffff;
  --bg-3: #f0f2f7;
  --surface: #ffffff;
  --surface-2: #f4f6fb;
  --border: #e3e6ee;
  --border-strong: #d2d6e0;
  --text: #0b0d12;
  --text-dim: #4a5063;
  --text-mute: #80879a;
  --accent: #4f46e5;
  --accent-2: #7c3aed;
  --accent-glow: rgba(79, 70, 229, 0.12);
  --shadow: 0 8px 24px rgba(15, 23, 42, 0.08);
  --shadow-soft: 0 4px 14px rgba(15, 23, 42, 0.06);
}

/* ---------- Reset ---------- */
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  font-size: 14px;
  line-height: 1.5;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
  touch-action: manipulation;
}
button { font-family: inherit; cursor: pointer; border: 0; background: none; color: inherit; -webkit-tap-highlight-color: transparent; }
input, select, textarea { font-family: inherit; font-size: 16px; color: inherit; } /* 16px prevents iOS zoom */
input:focus, select:focus, textarea:focus { outline: none; }
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 6px; }
::-webkit-scrollbar-track { background: transparent; }

.muted { color: var(--text-dim); }
.small { font-size: 12px; }

/* ---------- Layout ---------- */
.app {
  display: grid;
  grid-template-columns: 240px 1fr;
  height: 100vh;
  height: 100dvh;
  background:
    radial-gradient(ellipse 800px 400px at 0% 0%, var(--accent-glow), transparent 60%),
    var(--bg);
}

/* ---------- Sidebar (desktop) ---------- */
.sidebar {
  display: flex;
  flex-direction: column;
  padding: 24px 16px;
  border-right: 1px solid var(--border);
  background: var(--bg-2);
}
.brand { display: flex; align-items: center; gap: 12px; padding: 0 8px 24px; }
.logo {
  width: 36px; height: 36px; border-radius: 10px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  display: grid; place-items: center;
  font-weight: 700; font-size: 18px; color: white;
  box-shadow: 0 0 24px var(--accent-glow);
  flex-shrink: 0;
}
.logo-sm { width: 24px; height: 24px; font-size: 14px; box-shadow: none; }
.brand h1 { font-size: 16px; font-weight: 700; letter-spacing: -0.01em; }
.brand .tag { font-size: 11px; color: var(--text-mute); }
.nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  font-size: 13px; font-weight: 500;
  color: var(--text-dim);
  text-align: left;
  transition: var(--transition);
  position: relative;
}
.nav-item:hover { background: var(--surface); color: var(--text); }
.nav-item.active { background: var(--surface); color: var(--text); }
.nav-item.active .nav-icon { color: var(--accent); }
.nav-icon { font-size: 14px; width: 16px; text-align: center; flex-shrink: 0; }
.nav-badge {
  margin-left: auto;
  background: var(--accent);
  color: white;
  font-size: 10px; font-weight: 600;
  padding: 2px 7px;
  border-radius: 10px;
  min-width: 18px; text-align: center;
}
.nav-badge[hidden] { display: none; }

.sidebar-footer { margin-top: auto; padding-top: 16px; border-top: 1px solid var(--border); }
.data-status { display: flex; align-items: center; gap: 8px; font-size: 11px; color: var(--text-mute); padding: 0 8px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--green); box-shadow: 0 0 8px var(--green); }

.sidebar-backdrop { display: none; }

/* ---------- Main ---------- */
.main { overflow-y: auto; padding: 32px 40px 64px; -webkit-overflow-scrolling: touch; }
.view { display: none; animation: fadeIn 0.25s ease; }
.view.active { display: block; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.page-header {
  display: flex; justify-content: space-between; align-items: flex-end;
  margin-bottom: 24px; gap: 12px; flex-wrap: wrap;
}
.page-header h2 { font-size: 26px; font-weight: 700; letter-spacing: -0.02em; }
.page-header p { margin-top: 4px; font-size: 13px; }
.header-actions { display: flex; gap: 8px; }

/* ---------- Mobile header (hidden on desktop) ---------- */
.mobile-header {
  display: none;
  position: sticky; top: 0;
  height: var(--mobile-header-height);
  padding: 0 12px;
  background: var(--bg-2);
  border-bottom: 1px solid var(--border);
  align-items: center;
  z-index: 50;
  padding-top: var(--safe-top);
  height: calc(var(--mobile-header-height) + var(--safe-top));
}
.mobile-title { display: flex; align-items: center; gap: 10px; font-weight: 600; flex: 1; }
.btn-fab { padding: 10px; border-radius: 10px; min-width: 40px; min-height: 40px; }

/* ---------- Bottom nav (hidden on desktop) ---------- */
.bottom-nav {
  display: none;
  position: fixed; bottom: 0; left: 0; right: 0;
  height: var(--nav-height);
  padding-bottom: var(--safe-bottom);
  background: var(--bg-2);
  border-top: 1px solid var(--border);
  z-index: 50;
  box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.15);
}
.bottom-nav-inner, .bottom-nav { display: flex; }
.bottom-nav {
  justify-content: space-around;
  align-items: stretch;
}
.bottom-nav-item {
  flex: 1;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 2px;
  color: var(--text-mute);
  font-size: 10px;
  font-weight: 500;
  position: relative;
  padding: 6px 0;
  min-height: 48px;
  transition: var(--transition);
}
.bottom-nav-item.active { color: var(--accent); }
.bn-icon { font-size: 20px; line-height: 1; }
.bn-label { font-size: 10px; letter-spacing: 0.02em; }
.bn-badge {
  position: absolute; top: 4px; right: calc(50% - 20px);
  background: var(--accent);
  color: white;
  font-size: 9px; font-weight: 700;
  padding: 1px 5px;
  border-radius: 8px;
  min-width: 14px; text-align: center;
}
.bn-badge[hidden] { display: none; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 9px 14px;
  border-radius: var(--radius-sm);
  font-size: 13px; font-weight: 500;
  transition: var(--transition);
  border: 1px solid transparent;
  white-space: nowrap;
  min-height: 36px;
}
.btn-sm { padding: 6px 10px; font-size: 12px; min-height: 28px; }
.btn-primary { background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: white; box-shadow: 0 4px 14px var(--accent-glow); }
.btn-primary:active { transform: scale(0.97); }
.btn-ghost { background: var(--surface); border-color: var(--border); color: var(--text); }
.btn-ghost:active { background: var(--surface-2); }
.btn-danger { background: var(--red-dim); color: var(--red); border-color: rgba(239, 68, 68, 0.3); }
.btn-danger:active { background: var(--red); color: white; }
.icon-btn {
  width: 40px; height: 40px;
  display: grid; place-items: center;
  border-radius: var(--radius-sm);
  font-size: 20px;
  color: var(--text-dim);
}
.icon-btn:active { background: var(--surface); color: var(--text); }
.file-btn { position: relative; cursor: pointer; }

/* ---------- KPIs ---------- */
.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 20px; }
.kpi {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  display: flex; flex-direction: column; gap: 6px;
  position: relative; overflow: hidden;
}
.kpi-accent {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  border: 0;
  color: white;
}
.kpi-accent::after {
  content: '';
  position: absolute;
  top: -40px; right: -40px;
  width: 140px; height: 140px;
  background: radial-gradient(circle at center, rgba(255,255,255,0.18), transparent 70%);
}
.kpi-label { font-size: 11px; font-weight: 500; text-transform: uppercase; letter-spacing: 0.05em; opacity: 0.7; }
.kpi-value { font-size: 24px; font-weight: 700; letter-spacing: -0.02em; font-family: 'JetBrains Mono', monospace; }
.kpi-value.income { color: var(--green); }
.kpi-value.expense { color: var(--red); }
.kpi-accent .kpi-value { color: white; }
.kpi-delta { font-size: 11px; font-weight: 500; opacity: 0.7; }
.kpi-delta.up { color: var(--green); }
.kpi-delta.down { color: var(--red); }

.subs-kpis { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-bottom: 16px; }
.kpi-stripe {
  padding: 14px 16px;
  display: flex; flex-direction: column; gap: 4px;
}
.kpi-stripe .kpi-label { opacity: 0.7; }
.kpi-stripe .kpi-value { font-size: 20px; }

/* ---------- Cards ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 12px;
}
.card-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; gap: 8px; flex-wrap: wrap; }
.card-header h3 { font-size: 14px; font-weight: 600; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 12px; }

/* ---------- Charts ---------- */
.charts { display: grid; grid-template-columns: 1.5fr 1fr; gap: 12px; margin-bottom: 12px; }
.chart-card { display: flex; flex-direction: column; }
.chart-wrap { position: relative; flex: 1; min-height: 240px; }

/* ---------- Segmented ---------- */
.seg {
  display: inline-flex;
  background: var(--bg-3);
  border-radius: 10px;
  padding: 3px;
  gap: 2px;
}
.seg-sm { padding: 2px; border-radius: 8px; }
.seg-sm .seg-btn { padding: 5px 10px; font-size: 11px; }
.seg-btn {
  padding: 6px 12px;
  border-radius: 7px;
  font-size: 12px; font-weight: 500;
  color: var(--text-dim);
  transition: var(--transition);
  white-space: nowrap;
}
.seg-btn:active { color: var(--text); }
.seg-btn.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow-soft); }
.seg-types { display: flex; margin-bottom: 14px; }

/* ---------- Filters ---------- */
.filters { display: grid; grid-template-columns: 2fr 1fr 1fr 1fr 1fr; gap: 8px; margin-bottom: 12px; }
.filters-row-2 { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.filters input, .filters select, .filters-row-2 input, .filters-row-2 select {
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-3);
  color: var(--text);
  font-size: 14px;
  transition: var(--transition);
  min-height: 40px;
}
.filters input:focus, .filters select:focus, .filters-row-2 input:focus, .filters-row-2 select:focus {
  border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-glow);
}

/* ---------- Transaction list ---------- */
.tx-list { display: flex; flex-direction: column; gap: 4px; max-height: 480px; overflow-y: auto; }
.tx-list-large { max-height: none; }
.tx-item {
  display: grid;
  grid-template-columns: 40px 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 12px 12px;
  border-radius: var(--radius-sm);
  transition: var(--transition);
  position: relative;
}
.tx-item:hover { background: var(--surface-2); }
.tx-icon {
  width: 40px; height: 40px;
  border-radius: 10px;
  display: grid; place-items: center;
  font-size: 18px;
  font-weight: 600;
  flex-shrink: 0;
}
.tx-info { min-width: 0; }
.tx-desc { font-weight: 500; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tx-meta { font-size: 11px; color: var(--text-mute); margin-top: 3px; display: flex; gap: 6px; align-items: center; }
.tx-amount { font-family: 'JetBrains Mono', monospace; font-size: 14px; font-weight: 600; text-align: right; flex-shrink: 0; }
.tx-amount.income { color: var(--green); }
.tx-amount.expense { color: var(--red); }
.tx-amount.transfer { color: var(--blue); }
.tx-actions {
  position: absolute; right: 12px; top: 50%; transform: translateY(-50%);
  display: flex; gap: 4px;
  background: var(--surface);
  padding: 2px;
  border-radius: 8px;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transition: var(--transition);
}
/* On touch devices, always show actions */
@media (hover: none) {
  .tx-actions { opacity: 1; position: static; transform: none; box-shadow: none; background: none; padding: 0; }
  .tx-actions { grid-column: 3; justify-self: end; }
}
.tx-item:hover .tx-actions { opacity: 1; pointer-events: auto; right: 8px; }
.tx-action-btn {
  width: 32px; height: 32px;
  border-radius: 6px;
  display: grid; place-items: center;
  font-size: 14px;
  color: var(--text-mute);
}
.tx-action-btn:active { background: var(--bg-3); color: var(--text); }
.tx-action-btn.danger:active { background: var(--red-dim); color: var(--red); }

.empty-state { padding: 60px 20px; text-align: center; color: var(--text-mute); }
.empty-state h4 { color: var(--text-dim); margin-bottom: 6px; font-weight: 600; }

/* ---------- Account / Budget cards ---------- */
.tile {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  display: flex; flex-direction: column; gap: 12px;
  transition: var(--transition);
}
.tile:active { transform: scale(0.99); }
.tile-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.tile-title { font-size: 13px; color: var(--text-dim); font-weight: 500; }
.tile-actions { display: flex; gap: 4px; flex-shrink: 0; }
.tile-balance { font-family: 'JetBrains Mono', monospace; font-size: 22px; font-weight: 700; letter-spacing: -0.01em; }
.tile-meta { display: flex; justify-content: space-between; font-size: 12px; color: var(--text-mute); gap: 8px; flex-wrap: wrap; }
.tile-bar { height: 6px; background: var(--bg-3); border-radius: 4px; overflow: hidden; }
.tile-bar-fill { height: 100%; transition: var(--transition); border-radius: 4px; }

.tile .badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 10px;
  border-radius: 12px;
  font-size: 11px; font-weight: 500;
  background: var(--bg-3);
  color: var(--text-dim);
}
.tile .badge.danger { background: var(--red-dim); color: var(--red); }
.tile .badge.warn { background: rgba(245, 158, 11, 0.12); color: var(--yellow); }
.tile .badge.ok { background: var(--green-dim); color: var(--green); }

/* ---------- Subscription tiles (horizontal on mobile) ---------- */
.sub-tile {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  display: grid;
  grid-template-columns: 40px 1fr auto;
  align-items: center;
  gap: 12px;
  transition: var(--transition);
  cursor: pointer;
}
.sub-tile:active { transform: scale(0.99); }
.sub-tile + .sub-tile { margin-top: 6px; }
/* Urgency borders (Haven pattern: red ≤3d, amber ≤7d, green otherwise) */
.sub-tile.urgent { border-color: rgba(239, 68, 68, 0.4); background: linear-gradient(135deg, var(--surface), rgba(239, 68, 68, 0.04)); }
.sub-tile.soon { border-color: rgba(245, 158, 11, 0.4); background: linear-gradient(135deg, var(--surface), rgba(245, 158, 11, 0.04)); }
.sub-tile.normal { border-color: rgba(16, 185, 129, 0.3); }
.sub-tile-info { min-width: 0; }
.sub-tile-name { font-weight: 600; font-size: 14px; }
.sub-tile-meta { font-size: 11px; color: var(--text-mute); margin-top: 2px; }
.sub-tile-cost { font-family: 'JetBrains Mono', monospace; font-weight: 700; font-size: 14px; text-align: right; }
.sub-tile-cadence { font-size: 10px; color: var(--text-mute); text-align: right; text-transform: uppercase; letter-spacing: 0.05em; }

/* ---------- Upcoming row (compact) ---------- */
.upcoming-row {
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  transition: var(--transition);
}
.upcoming-row + .upcoming-row { margin-top: 2px; }
.upcoming-row.urgent { background: rgba(239, 68, 68, 0.06); border-left: 3px solid var(--red); }
.upcoming-row.soon { background: rgba(245, 158, 11, 0.06); border-left: 3px solid var(--yellow); }
.upcoming-row.normal { background: var(--bg-3); border-left: 3px solid transparent; }
.upcoming-info { min-width: 0; flex: 1; }
.upcoming-name { font-weight: 500; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.upcoming-meta { font-size: 11px; color: var(--text-mute); margin-top: 2px; }
.upcoming-rel { font-weight: 600; }
.upcoming-row.urgent .upcoming-rel { color: var(--red); }
.upcoming-row.soon .upcoming-rel { color: var(--yellow); }
.upcoming-row.normal .upcoming-rel { color: var(--green); }
.upcoming-amount { font-family: 'JetBrains Mono', monospace; font-weight: 600; font-size: 14px; }

/* ---------- Forecast strip ---------- */
.forecast-strip {
  display: flex;
  align-items: stretch;
  gap: 16px;
  padding: 16px 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 16px;
}
.forecast-item { flex: 1; display: flex; flex-direction: column; gap: 4px; }
.forecast-label { font-size: 11px; font-weight: 500; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-mute); }
.forecast-value { font-family: 'JetBrains Mono', monospace; font-size: 22px; font-weight: 700; letter-spacing: -0.01em; }
.forecast-delta { font-size: 11px; color: var(--text-mute); }
.forecast-divider { width: 1px; background: var(--border); }
@media (max-width: 768px) {
  .forecast-strip { flex-direction: column; gap: 12px; }
  .forecast-divider { width: 100%; height: 1px; }
}

/* ---------- Forms ---------- */
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 14px; }
label { display: flex; flex-direction: column; gap: 6px; }
label > span { font-size: 12px; font-weight: 500; color: var(--text-dim); }
input[type="text"], input[type="number"], input[type="date"], input[type="month"], input[type="search"], select, textarea {
  padding: 11px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-3);
  color: var(--text);
  font-size: 16px;
  transition: var(--transition);
  width: 100%;
  min-height: 44px;
}
input[type="color"] {
  width: 60px; height: 44px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-3);
  padding: 2px;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-glow); }
textarea { min-height: 60px; resize: vertical; }
.row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* ---------- Modal ---------- */
.modal {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  animation: fadeIn 0.15s ease;
  padding: 16px;
}
.modal[hidden] { display: none; }
.modal-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  width: 100%; max-width: 480px;
  max-height: 90vh;
  max-height: 90dvh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  box-shadow: var(--shadow);
  animation: slideUp 0.2s ease;
  margin: auto;
}
@keyframes slideUp { from { transform: translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } }
.modal-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 16px 18px; border-bottom: 1px solid var(--border);
  position: sticky; top: 0;
  background: var(--surface);
  z-index: 1;
}
.modal-header h3 { font-size: 15px; font-weight: 600; }
.modal-body { padding: 18px; display: flex; flex-direction: column; gap: 12px; }
.modal-footer { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }

/* ---------- Category pills ---------- */
.cat-pills { display: flex; flex-wrap: wrap; gap: 8px; }
.cat-pill {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 6px 12px;
  background: var(--bg-3);
  border-radius: 20px;
  font-size: 12px; font-weight: 500;
  border: 1px solid var(--border);
}
.cat-pill .cat-dot { width: 8px; height: 8px; border-radius: 50%; }
.cat-pill button {
  margin-left: 4px;
  color: var(--text-mute);
  font-size: 14px;
  line-height: 1;
  width: 18px; height: 18px;
}
.cat-pill button:active { color: var(--red); }

/* ---------- Data actions ---------- */
.data-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  bottom: calc(80px + var(--safe-bottom)); left: 50%; transform: translateX(-50%);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  color: var(--text);
  padding: 12px 18px;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  z-index: 200;
  font-size: 13px; font-weight: 500;
  animation: slideUp 0.2s ease;
  max-width: calc(100vw - 32px);
}
.toast[hidden] { display: none; }
.toast.error { border-color: var(--red); color: var(--red); }
.toast.success { border-color: var(--green); color: var(--green); }

/* ---------- Responsive: Tablet ---------- */
@media (max-width: 1100px) {
  .charts { grid-template-columns: 1fr; }
  .kpis { grid-template-columns: repeat(3, 1fr); }
  .filters { grid-template-columns: repeat(2, 1fr); }
  .subs-kpis { grid-template-columns: 1fr; }
}

/* ---------- Responsive: Mobile ---------- */
@media (max-width: 768px) {
  .app { grid-template-columns: 1fr; }

  /* Hide desktop sidebar by default on mobile; show as drawer */
  .sidebar {
    position: fixed; top: 0; left: 0; bottom: 0;
    width: 280px;
    z-index: 100;
    transform: translateX(-100%);
    transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    padding-top: calc(20px + var(--safe-top));
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-backdrop {
    display: none;
    position: fixed; inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 99;
  }
  .sidebar-backdrop.show { display: block; }

  .mobile-header { display: flex; }
  .bottom-nav { display: flex; }

  .main {
    padding: 16px 16px calc(80px + var(--safe-bottom));
    margin-top: 0;
  }
  /* Account for sticky mobile header */
  .view { padding-top: 8px; }

  .page-header {
    margin-bottom: 16px;
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
  }
  .page-header h2 { font-size: 22px; }
  .header-actions { width: 100%; }
  .header-actions .btn { flex: 1; min-height: 40px; }

  .kpis { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .kpi { padding: 14px 16px; }
  .kpi-value { font-size: 18px; }
  .kpi-label { font-size: 10px; }

  .card { padding: 16px; border-radius: 12px; margin-bottom: 10px; }
  .charts { grid-template-columns: 1fr; gap: 10px; }
  .chart-wrap { min-height: 200px; }
  .grid-2 { grid-template-columns: 1fr; gap: 10px; }

  .filters { grid-template-columns: 1fr; gap: 8px; }
  .filters input, .filters select { min-height: 44px; }

  .seg { width: 100%; justify-content: stretch; }
  .seg-btn { flex: 1; text-align: center; }

  .modal { padding: 0; align-items: flex-end; }
  .modal-card {
    max-width: 100%;
    max-height: 92vh;
    max-height: 92dvh;
    border-radius: 18px 18px 0 0;
    margin: 0;
  }

  .tx-item { padding: 14px 12px; grid-template-columns: 40px 1fr auto; gap: 10px; }
  .tx-amount { font-size: 13px; }

  /* Make tx actions always visible on mobile (touch-only, no hover) */
  .tx-actions {
    opacity: 1; pointer-events: auto;
    position: static; transform: none;
    background: none; padding: 0; box-shadow: none;
  }

  .toast { bottom: calc(80px + var(--safe-bottom)); }

  /* Touch target sizes for accessibility */
  .icon-btn, .tx-action-btn { min-width: 36px; min-height: 36px; }
}

@media (max-width: 380px) {
  .kpi-value { font-size: 16px; }
  .tx-amount { font-size: 12px; }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}