/* ── Variables ─────────────────────────────────── */
:root {
  --bg:         #0a1628;
  --surface:    #0e2144;
  --surface-2:  #132952;
  --border:     #1e3a6e;
  --accent:     #38bdf8;
  --accent-dim: #1e6ea8;
  --income:     #4ade80;
  --expense:    #fb923c;
  --danger:     #ef4444;
  --warning:    #f59e0b;
  --text:       #e0eef8;
  --muted:      #7ea8c9;
  --radius:     10px;
  --nav-h:      60px;
}

/* ── Reset ──────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body { background: var(--bg); color: var(--text); font-family: system-ui, -apple-system, sans-serif; font-size: 14px; min-height: 100vh; }
a { text-decoration: none; color: inherit; }
button { cursor: pointer; border: none; background: none; font-family: inherit; font-size: 14px; }
input, select, textarea { font-family: inherit; font-size: 14px; }

/* ── Utilities ──────────────────────────────────── */
.hidden { display: none !important; }
.error-msg { color: var(--danger); font-size: 13px; margin-bottom: 8px; }

/* ── Login ──────────────────────────────────────── */
#login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(ellipse at 60% 40%, #0e2a50 0%, var(--bg) 70%);
}
.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 40px;
  width: 100%;
  max-width: 380px;
}
.login-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 32px;
  justify-content: center;
}
.login-logo h1 { font-size: 22px; font-weight: 700; color: var(--accent); }
.logo-icon { font-size: 22px; color: var(--accent); }

/* ── Nav ────────────────────────────────────────── */
#top-nav {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--nav-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 24px;
  gap: 32px;
  z-index: 100;
}
.nav-brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 16px;
  color: var(--accent);
  white-space: nowrap;
}
.nav-links {
  display: flex;
  gap: 4px;
  flex: 1;
}
.nav-link {
  padding: 6px 14px;
  border-radius: 6px;
  color: var(--muted);
  font-size: 13px;
  transition: color .15s, background .15s;
}
.nav-link:hover { color: var(--text); background: var(--surface-2); }
.nav-link.active { color: var(--accent); background: rgba(56,189,248,.1); }

/* ── Main Content ───────────────────────────────── */
#main-content {
  margin-top: var(--nav-h);
  padding: 28px 28px;
  max-width: 1400px;
  margin-left: auto;
  margin-right: auto;
}
.section { padding-top: 4px; }

/* ── Buttons ────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: 7px;
  font-weight: 500;
  transition: opacity .15s, background .15s;
}
.btn:hover { opacity: .85; }
.btn-primary { background: var(--accent); color: #0a1628; }
.btn-ghost { background: transparent; color: var(--muted); border: 1px solid var(--border); }
.btn-ghost:hover { color: var(--text); border-color: var(--muted); }
.btn-danger { background: rgba(239,68,68,.15); color: var(--danger); }
.btn-sm { padding: 5px 11px; font-size: 12px; }
.btn-full { width: 100%; justify-content: center; }
.btn-icon { padding: 6px 8px; }

/* ── Cards ──────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}
.card-sm { padding: 14px 16px; }

/* ── KPI Cards ──────────────────────────────────── */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
.kpi-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  border-left: 3px solid var(--accent);
}
.kpi-card.income  { border-left-color: var(--income); }
.kpi-card.expense { border-left-color: var(--expense); }
.kpi-card.danger  { border-left-color: var(--danger); }
.kpi-card.warning { border-left-color: var(--warning); }
.kpi-label { font-size: 11px; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); margin-bottom: 8px; }
.kpi-value { font-size: 22px; font-weight: 700; color: var(--text); }
.kpi-sub   { font-size: 12px; color: var(--muted); margin-top: 4px; }
.kpi-sub.up   { color: var(--income); }
.kpi-sub.down { color: var(--expense); }

/* ── Charts Grid ────────────────────────────────── */
.charts-grid {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 16px;
  margin-bottom: 24px;
}
.chart-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}
.chart-title { font-size: 12px; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); margin-bottom: 16px; }

/* ── Section Header ─────────────────────────────── */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}
.section-title { font-size: 20px; font-weight: 700; color: var(--text); }

/* ── Tables ─────────────────────────────────────── */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
thead th {
  text-align: left;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .5px;
  color: var(--muted);
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
tbody tr { border-bottom: 1px solid rgba(30,58,110,.4); transition: background .1s; }
tbody tr:hover { background: var(--surface-2); }
tbody td { padding: 11px 14px; color: var(--text); }
tbody tr:last-child { border-bottom: none; }

/* ── Forms ──────────────────────────────────────── */
.form-group { margin-bottom: 14px; }
.form-group label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 5px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
input[type="text"],
input[type="number"],
input[type="date"],
input[type="email"],
input[type="password"],
select,
textarea {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 7px;
  color: var(--text);
  padding: 9px 12px;
  outline: none;
  transition: border-color .15s;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
select option { background: var(--surface-2); }
.form-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 20px; }

/* ── Modal ──────────────────────────────────────── */
#modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
}
.modal-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  width: 100%;
  max-width: 480px;
  max-height: 90vh;
  overflow-y: auto;
  padding: 24px;
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}
.modal-header h3 { font-size: 16px; font-weight: 600; }
.modal-close { color: var(--muted); font-size: 18px; padding: 4px 8px; border-radius: 4px; }
.modal-close:hover { color: var(--text); background: var(--surface-2); }

/* ── Toast ──────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 28px;
  right: 28px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 18px;
  color: var(--text);
  font-size: 13px;
  z-index: 300;
  animation: slideUp .2s ease;
}
.toast.success { border-left: 3px solid var(--income); }
.toast.error   { border-left: 3px solid var(--danger); }
@keyframes slideUp { from { transform: translateY(10px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

/* ── Badges ─────────────────────────────────────── */
.badge {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
}
.badge-active  { background: rgba(251,146,60,.15); color: var(--expense); }
.badge-paid    { background: rgba(74,222,128,.15);  color: var(--income); }
.badge-income  { background: rgba(74,222,128,.15);  color: var(--income); }
.badge-expense { background: rgba(251,146,60,.15);  color: var(--expense); }
.badge-stocks  { background: rgba(56,189,248,.15);  color: var(--accent); }
.badge-crypto  { background: rgba(245,158,11,.15);  color: var(--warning); }
.badge-gold    { background: rgba(245,158,11,.15);  color: var(--warning); }
.badge-silver  { background: rgba(126,168,201,.15); color: var(--muted); }
.badge-other   { background: rgba(129,140,248,.15); color: #818cf8; }

/* ── Filter Bar ─────────────────────────────────── */
.filter-bar { display: flex; gap: 8px; margin-bottom: 20px; flex-wrap: wrap; }
.filter-btn { padding: 5px 13px; border-radius: 20px; font-size: 12px; background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); }
.filter-btn:hover, .filter-btn.active { background: rgba(56,189,248,.15); color: var(--accent); border-color: var(--accent-dim); }

/* ── Tabs ───────────────────────────────────────── */
.tabs { display: flex; gap: 4px; margin-bottom: 20px; border-bottom: 1px solid var(--border); padding-bottom: 0; }
.tab-btn { padding: 8px 18px; border-radius: 7px 7px 0 0; font-size: 13px; color: var(--muted); position: relative; bottom: -1px; border: 1px solid transparent; }
.tab-btn.active { color: var(--accent); background: var(--surface); border-color: var(--border); border-bottom-color: var(--surface); }

/* ── Account Cards ──────────────────────────────── */
.accounts-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 16px; margin-bottom: 24px; }
.account-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; position: relative; }
.account-card-header { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.account-type-icon { font-size: 22px; }
.account-name { font-weight: 600; font-size: 15px; }
.account-type-label { font-size: 11px; color: var(--muted); text-transform: capitalize; }
.account-balance { font-size: 26px; font-weight: 700; color: var(--text); }
.account-currency { font-size: 12px; color: var(--muted); margin-left: 4px; }
.account-actions { display: flex; gap: 6px; margin-top: 14px; }

/* ── Progress Bar ───────────────────────────────── */
.progress-bar-wrap { background: var(--surface-2); border-radius: 20px; height: 8px; margin: 10px 0 4px; overflow: hidden; }
.progress-bar-fill { height: 100%; border-radius: 20px; background: var(--accent); transition: width .4s ease; }

/* ── Goal Cards ─────────────────────────────────── */
.goals-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; }
.goal-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; }
.goal-name { font-size: 16px; font-weight: 600; margin-bottom: 6px; }
.goal-amounts { display: flex; justify-content: space-between; font-size: 13px; color: var(--muted); }
.goal-amounts span { color: var(--text); font-weight: 600; }
.goal-deadline { font-size: 12px; color: var(--muted); margin-top: 8px; }

/* ── P&L Colors ─────────────────────────────────── */
.positive { color: var(--income); }
.negative { color: var(--expense); }

/* ── Empty State ─────────────────────────────────── */
.empty-state { text-align: center; padding: 60px 20px; color: var(--muted); }
.empty-state p { font-size: 15px; margin-bottom: 16px; }

/* ── Inline Edit ─────────────────────────────────── */
.inline-edit { background: var(--surface-2); border: 1px solid var(--border); border-radius: 5px; color: var(--text); padding: 4px 8px; width: 110px; }

/* ── Transaction summary bar ────────────────────── */
.txn-summary { display: flex; gap: 20px; margin-bottom: 16px; }
.txn-summary-item { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 12px 18px; }
.txn-summary-label { font-size: 11px; color: var(--muted); text-transform: uppercase; }
.txn-summary-value { font-size: 18px; font-weight: 700; }

/* ── Bottom Nav (mobile only) ───────────────────── */
#bottom-nav {
  display: none;
  position: fixed;
  bottom: 0; left: 0; right: 0;
  background: var(--surface);
  border-top: 1px solid var(--border);
  z-index: 100;
  padding: 6px 0 env(safe-area-inset-bottom, 6px);
}
.bottom-nav-link {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
  padding: 4px 2px;
  color: var(--muted);
  gap: 2px;
  min-height: 48px;
}
.bottom-nav-link.active { color: var(--accent); }
.bnav-icon { font-size: 18px; line-height: 1; }
.bnav-label { font-size: 9px; letter-spacing: .3px; }

/* ── Responsive — Tablet (≤900px) ──────────────── */
@media (max-width: 900px) {
  .charts-grid { grid-template-columns: 1fr; }
  .nav-links { gap: 0; }
  .nav-link { padding: 6px 10px; font-size: 12px; }
}

/* ── Responsive — Mobile (≤768px) ──────────────── */
@media (max-width: 768px) {
  /* Show bottom nav, hide top nav links */
  #bottom-nav { display: flex; }
  #top-nav .nav-links { display: none; }
  #top-nav { gap: 0; padding: 0 16px; justify-content: space-between; }
  #top-nav #logout-btn { font-size: 12px; padding: 6px 10px; }

  /* Main content — bottom padding for bottom nav */
  #main-content {
    padding: 16px 14px;
    padding-bottom: calc(72px + env(safe-area-inset-bottom, 8px));
  }

  /* Login */
  .login-card { padding: 28px 20px; margin: 16px; }

  /* KPI grid — 2 columns */
  .kpi-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .kpi-value { font-size: 18px; }
  .kpi-card { padding: 14px 14px; }

  /* Charts — single column */
  .charts-grid { grid-template-columns: 1fr; gap: 12px; }

  /* Section header — stack on very small */
  .section-header { flex-wrap: wrap; gap: 10px; }
  .section-title { font-size: 17px; }

  /* Forms */
  .form-row { grid-template-columns: 1fr; }
  .modal-box { padding: 18px 16px; border-radius: 14px 14px 0 0; align-self: flex-end; max-height: 92vh; }
  #modal-overlay { align-items: flex-end; }

  /* Transaction summary — 2×2 grid */
  .txn-summary {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
  }
  .txn-summary > div:last-child { grid-column: span 2; }
  .txn-summary-value { font-size: 15px; }

  /* Tables — horizontal scroll + compact */
  .table-wrap { -webkit-overflow-scrolling: touch; }
  thead th { padding: 8px 10px; font-size: 10px; }
  tbody td { padding: 9px 10px; font-size: 13px; }

  /* Account cards — single column */
  .accounts-grid { grid-template-columns: 1fr; }
  .account-balance { font-size: 22px; }

  /* Goal cards — single column */
  .goals-grid { grid-template-columns: 1fr; }

  /* Tabs — full width */
  .tabs { gap: 2px; }
  .tab-btn { padding: 8px 14px; font-size: 12px; }

  /* Inline edit input wider on mobile */
  .inline-edit { width: 90px; }

  /* Toast — full width */
  .toast { left: 14px; right: 14px; bottom: calc(72px + 8px); }

  /* Filter bar — scrollable */
  .filter-bar { flex-wrap: nowrap; overflow-x: auto; padding-bottom: 4px; }
  .filter-bar::-webkit-scrollbar { display: none; }
}

/* ── Responsive — Small Mobile (≤400px) ────────── */
@media (max-width: 400px) {
  .kpi-grid { grid-template-columns: 1fr; }
  .kpi-value { font-size: 20px; }
  .nav-brand { font-size: 14px; }
}
