/* ── Reset & variables ───────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:         #0d1117;
  --surface:    #161b22;
  --surface2:   #1f2937;
  --surface3:   #263044;
  --border:     #30363d;
  --border2:    #21262d;
  --accent:     #6366f1;
  --accent-h:   #4f46e5;
  --accent-lit: rgba(99,102,241,.12);
  --green:      #10b981;
  --green-lit:  rgba(16,185,129,.12);
  --red:        #ef4444;
  --red-lit:    rgba(239,68,68,.12);
  --amber:      #f59e0b;
  --amber-lit:  rgba(245,158,11,.12);
  --blue:       #3b82f6;
  --blue-lit:   rgba(59,130,246,.12);
  --purple:     #8b5cf6;
  --text:       #e6edf3;
  --text2:      #8b949e;
  --text3:      #6e7681;
  --sidebar-w:  240px;
  --header-h:   60px;
  --radius:     10px;
  --radius-sm:  6px;
  --shadow:     0 4px 24px rgba(0,0,0,.4);
  --shadow-sm:  0 2px 8px rgba(0,0,0,.3);
  --trans:      .18s ease;
}

html { font-size: 14px; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  display: flex;
  min-height: 100vh;
  overflow-x: hidden;
}

/* ── Sidebar ─────────────────────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  min-height: 100vh;
  background: var(--surface);
  border-right: 1px solid var(--border2);
  position: fixed;
  top: 0; left: 0;
  display: flex;
  flex-direction: column;
  z-index: 100;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 20px 18px;
  border-bottom: 1px solid var(--border2);
}

.brand-icon {
  width: 32px; height: 32px;
  background: var(--accent);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  flex-shrink: 0;
}

.brand-name {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -.3px;
  color: var(--text);
}
.brand-sub {
  font-size: 10px;
  color: var(--text3);
  letter-spacing: .5px;
  text-transform: uppercase;
}

.sidebar-nav {
  flex: 1;
  padding: 12px 8px;
  overflow-y: auto;
}

.nav-section {
  margin-bottom: 4px;
}

.nav-label {
  font-size: 10px;
  font-weight: 600;
  color: var(--text3);
  text-transform: uppercase;
  letter-spacing: .8px;
  padding: 8px 10px 4px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  color: var(--text2);
  text-decoration: none;
  font-size: 13.5px;
  font-weight: 500;
  transition: background var(--trans), color var(--trans);
  margin-bottom: 2px;
}

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

.nav-item.active {
  background: var(--accent-lit);
  color: var(--accent);
}

.nav-icon {
  width: 18px; height: 18px;
  flex-shrink: 0;
  opacity: .7;
}

.nav-item.active .nav-icon,
.nav-item:hover .nav-icon { opacity: 1; }

.sidebar-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--border2);
  font-size: 11px;
  color: var(--text3);
  text-align: center;
}

.user-chip {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  border-top: 1px solid var(--border2);
  background: var(--surface);
}
.user-avatar {
  width: 32px; height: 32px;
  border-radius: 50%;
  flex-shrink: 0;
  object-fit: cover;
  background: var(--surface2);
}
.user-avatar-fallback {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  font-size: 13px;
}
.user-meta { flex: 1; min-width: 0; }
.user-name {
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.user-email {
  font-size: 10px;
  color: var(--text3);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.user-logout {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 30px; height: 30px;
  border-radius: 6px;
  color: var(--text2);
  flex-shrink: 0;
  transition: var(--trans);
}
.user-logout svg { width: 16px; height: 16px; }
.user-logout:hover { background: var(--red-lit); color: var(--red); }

/* ── Main layout ─────────────────────────────────────────────────────────── */
.main {
  margin-left: var(--sidebar-w);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.topbar {
  height: var(--header-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border2);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  position: sticky;
  top: 0;
  z-index: 50;
}

.topbar-left { display: flex; align-items: center; gap: 12px; }
.page-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -.3px;
}

.topbar-right { display: flex; align-items: center; gap: 10px; }

.content {
  flex: 1;
  padding: 24px;
}

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

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.card-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text2);
  text-transform: uppercase;
  letter-spacing: .6px;
}

/* ── Stat cards ───────────────────────────────────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  position: relative;
  overflow: hidden;
}

.stat-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
}

.stat-card.accent::before  { background: var(--accent); }
.stat-card.green::before   { background: var(--green); }
.stat-card.red::before     { background: var(--red); }
.stat-card.amber::before   { background: var(--amber); }
.stat-card.blue::before    { background: var(--blue); }
.stat-card.purple::before  { background: var(--purple); }

.stat-icon {
  width: 36px; height: 36px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 12px;
  font-size: 16px;
}

.stat-icon.accent { background: var(--accent-lit); color: var(--accent); }
.stat-icon.green  { background: var(--green-lit);  color: var(--green); }
.stat-icon.red    { background: var(--red-lit);    color: var(--red); }
.stat-icon.amber  { background: var(--amber-lit);  color: var(--amber); }
.stat-icon.blue   { background: var(--blue-lit);   color: var(--blue); }
.stat-icon.purple { background: rgba(139,92,246,.12); color: var(--purple); }

.stat-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text3);
  text-transform: uppercase;
  letter-spacing: .6px;
  margin-bottom: 4px;
}

.stat-value {
  font-size: 24px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -.5px;
}

.stat-value.positive { color: var(--green); }
.stat-value.negative { color: var(--red); }

.stat-sub {
  font-size: 11px;
  color: var(--text3);
  margin-top: 4px;
}

/* ── Grid layouts ─────────────────────────────────────────────────────────── */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.grid-3-2 { display: grid; grid-template-columns: 2fr 1fr; gap: 16px; }
.gap-24 { gap: 24px; }

/* ── Tables ───────────────────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

thead th {
  padding: 10px 14px;
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  color: var(--text3);
  text-transform: uppercase;
  letter-spacing: .6px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

tbody tr {
  border-bottom: 1px solid var(--border2);
  transition: background var(--trans);
}

tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: var(--surface2); }

tbody td {
  padding: 12px 14px;
  color: var(--text);
  vertical-align: middle;
}

.td-muted { color: var(--text2); }

/* ── Badges ───────────────────────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 8px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .3px;
}

.badge-income  { background: var(--green-lit);  color: var(--green); }
.badge-expense { background: var(--red-lit);    color: var(--red); }
.badge-accent  { background: var(--accent-lit); color: var(--accent); }
.badge-amber   { background: var(--amber-lit);  color: var(--amber); }
.badge-blue    { background: var(--blue-lit);   color: var(--blue); }
.badge-purple  { background: rgba(139,92,246,.12); color: var(--purple); }
.badge-gray    { background: var(--surface2);   color: var(--text2); }

/* ── Buttons ──────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: background var(--trans), opacity var(--trans), transform .1s;
  text-decoration: none;
  white-space: nowrap;
}

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

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

.btn-success {
  background: var(--green);
  color: #fff;
}
.btn-success:hover { background: #059669; }

.btn-danger {
  background: var(--red-lit);
  color: var(--red);
}
.btn-danger:hover { background: rgba(239,68,68,.2); }

.btn-ghost {
  background: var(--surface2);
  color: var(--text);
}
.btn-ghost:hover { background: var(--surface3); }

.btn-sm {
  padding: 5px 10px;
  font-size: 12px;
}

.btn-icon {
  padding: 7px;
  background: transparent;
  color: var(--text2);
  border-radius: var(--radius-sm);
}
.btn-icon:hover {
  background: var(--surface2);
  color: var(--text);
}

/* ── Forms ────────────────────────────────────────────────────────────────── */
.form-group { margin-bottom: 16px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; }

label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text2);
  margin-bottom: 5px;
  letter-spacing: .3px;
}

input, select, textarea {
  width: 100%;
  padding: 9px 12px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 13px;
  font-family: inherit;
  transition: border-color var(--trans), box-shadow var(--trans);
  outline: none;
}

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

select option { background: var(--surface2); }
textarea { resize: vertical; min-height: 70px; }

input[type="color"] {
  padding: 4px;
  height: 36px;
  cursor: pointer;
}

.form-check {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
}

.form-check input[type="checkbox"] {
  width: auto;
  width: 16px; height: 16px;
  accent-color: var(--accent);
  cursor: pointer;
}

/* ── Search & filter bar ──────────────────────────────────────────────────── */
.filter-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.filter-bar input,
.filter-bar select {
  width: auto;
  min-width: 140px;
}

.search-wrap {
  position: relative;
  flex: 1;
  min-width: 200px;
}

.search-wrap input {
  padding-left: 36px;
  width: 100%;
}

.search-icon {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text3);
  pointer-events: none;
}

/* ── Modal ────────────────────────────────────────────────────────────────── */
.modal-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.65);
  backdrop-filter: blur(4px);
  z-index: 200;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.modal-backdrop.open { display: flex; }

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  width: 100%;
  max-width: 480px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow);
  animation: modalIn .2s ease;
}

.modal.wide { max-width: 600px; }

@keyframes modalIn {
  from { opacity: 0; transform: translateY(-12px) scale(.97); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

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

.modal-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
}

.modal-body {
  padding: 20px;
  overflow-y: auto;
  flex: 1;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 14px 20px;
  border-top: 1px solid var(--border2);
}

/* ── Progress bars ────────────────────────────────────────────────────────── */
.progress {
  height: 6px;
  background: var(--surface2);
  border-radius: 10px;
  overflow: hidden;
  margin-top: 6px;
}

.progress-bar {
  height: 100%;
  border-radius: 10px;
  transition: width .6s ease;
  background: var(--accent);
}

.progress-bar.warn { background: var(--amber); }
.progress-bar.over { background: var(--red); }

/* ── Budget card ──────────────────────────────────────────────────────────── */
.budget-card {
  background: var(--surface2);
  border: 1px solid var(--border2);
  border-radius: var(--radius-sm);
  padding: 14px;
}

.budget-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.budget-cat { font-size: 13px; font-weight: 600; }
.budget-pct {
  font-size: 11px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 10px;
}
.budget-pct.ok   { background: var(--green-lit);  color: var(--green); }
.budget-pct.warn { background: var(--amber-lit);  color: var(--amber); }
.budget-pct.over { background: var(--red-lit);    color: var(--red); }

.budget-amounts {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--text2);
  margin-top: 6px;
}

/* ── Account card ─────────────────────────────────────────────────────────── */
.account-card {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  position: relative;
  overflow: hidden;
}

.account-card::before {
  content: '';
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 4px;
  background: var(--card-color, var(--accent));
}

.account-name { font-weight: 700; font-size: 14px; }
.account-type { font-size: 11px; color: var(--text3); }
.account-balance {
  font-size: 22px;
  font-weight: 800;
  letter-spacing: -.5px;
}
.account-institution { font-size: 11px; color: var(--text2); }

/* ── Amount colors ────────────────────────────────────────────────────────── */
.amount-pos { color: var(--green); }
.amount-neg { color: var(--red); }

/* ── Bill item ────────────────────────────────────────────────────────────── */
.bill-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 0;
  border-bottom: 1px solid var(--border2);
}
.bill-item:last-child { border-bottom: none; }
.bill-info { flex: 1; }
.bill-name { font-weight: 600; font-size: 13px; }
.bill-meta { font-size: 11px; color: var(--text2); margin-top: 2px; }
.bill-amount { font-weight: 700; margin: 0 16px; }

/* ── Pill toggle ──────────────────────────────────────────────────────────── */
.toggle-paid {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: background var(--trans);
}
.toggle-paid.unpaid { background: var(--red-lit); color: var(--red); }
.toggle-paid.paid   { background: var(--green-lit); color: var(--green); }

/* ── Investment row ───────────────────────────────────────────────────────── */
.gain-pos { color: var(--green); font-weight: 600; }
.gain-neg { color: var(--red);   font-weight: 600; }

/* ── Empty state ──────────────────────────────────────────────────────────── */
.empty {
  text-align: center;
  padding: 48px 24px;
  color: var(--text3);
}
.empty-icon { font-size: 40px; margin-bottom: 12px; }
.empty-text { font-size: 14px; color: var(--text2); margin-bottom: 4px; }
.empty-sub  { font-size: 12px; }

/* ── Pagination ───────────────────────────────────────────────────────────── */
.pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 0 0;
  font-size: 12px;
  color: var(--text2);
}

.pagination-btns { display: flex; gap: 4px; }
.pagination-btns button {
  padding: 5px 10px;
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 12px;
  transition: background var(--trans);
}
.pagination-btns button:hover { background: var(--surface3); }
.pagination-btns button:disabled { opacity: .4; cursor: not-allowed; }

/* ── Month selector ───────────────────────────────────────────────────────── */
.month-selector {
  display: flex;
  align-items: center;
  gap: 8px;
}
.month-selector button {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 5px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 13px;
}
.month-selector button:hover { background: var(--surface3); }
.month-label { font-size: 14px; font-weight: 600; min-width: 100px; text-align: center; }

/* ── Toast ────────────────────────────────────────────────────────────────── */
#toast-container {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  font-size: 13px;
  color: var(--text);
  box-shadow: var(--shadow);
  animation: toastIn .2s ease;
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 220px;
}

.toast.success { border-left: 3px solid var(--green); }
.toast.error   { border-left: 3px solid var(--red); }
.toast.info    { border-left: 3px solid var(--accent); }

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

/* ── Chart container ──────────────────────────────────────────────────────── */
.chart-wrap {
  position: relative;
  width: 100%;
}

/* ── Net worth trend ──────────────────────────────────────────────────────── */
.nw-hero {
  text-align: center;
  padding: 24px 0 16px;
}
.nw-value {
  font-size: 42px;
  font-weight: 800;
  letter-spacing: -1px;
}
.nw-label { font-size: 12px; color: var(--text3); margin-top: 4px; }

/* ── Allocation list ──────────────────────────────────────────────────────── */
.alloc-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border2);
}
.alloc-item:last-child { border-bottom: none; }
.alloc-dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}
.alloc-name { flex: 1; font-size: 13px; }
.alloc-val  { font-size: 13px; font-weight: 600; }
.alloc-pct  { font-size: 11px; color: var(--text3); width: 40px; text-align: right; }

/* ── Utilities ────────────────────────────────────────────────────────────── */
.flex  { display: flex; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-8  { gap: 8px; }
.gap-12 { gap: 12px; }
.mb-8   { margin-bottom: 8px; }
.mb-16  { margin-bottom: 16px; }
.mb-24  { margin-bottom: 24px; }
.mt-16  { margin-top: 16px; }
.text-sm { font-size: 12px; }
.text-muted { color: var(--text2); }
.text-right { text-align: right; }
.font-bold { font-weight: 700; }

/* ── Responsive ───────────────────────────────────────────────────────────── */
@media (max-width: 900px) {
  .grid-2, .grid-3, .grid-3-2 {
    grid-template-columns: 1fr;
  }
  .form-row, .form-row-3 {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 700px) {
  .sidebar { transform: translateX(-100%); }
  .main { margin-left: 0; }
}

/* ── Scrollbar ────────────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 10px; }
::-webkit-scrollbar-thumb:hover { background: var(--text3); }
