/* ─── Reset & Base ──────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:          #0f1117;
  --surface:     #1a1d27;
  --surface2:    #222636;
  --surface3:    #2c3047;
  --border:      #2e3347;
  --accent:      #6366f1;
  --accent-light:#818cf8;
  --success:     #10b981;
  --danger:      #f43f5e;
  --warning:     #f59e0b;
  --text:        #e2e8f0;
  --text-muted:  #94a3b8;
  --text-dim:    #64748b;
  --radius:      12px;
  --radius-sm:   7px;
  --shadow:      0 4px 24px rgba(0,0,0,.45);
  --transition:  .18s ease;
  --sidebar-w:   230px;
}

html, body { height: 100%; font-family: 'Inter', sans-serif; background: var(--bg); color: var(--text); font-size: 15px; line-height: 1.5; }

/* ─── Layout ────────────────────────────────────────────────────────────── */
#app { display: flex; height: 100vh; overflow: hidden; }

/* ─── Sidebar ───────────────────────────────────────────────────────────── */
#sidebar {
  width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 24px 0 20px;
  flex-shrink: 0;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 20px 24px;
  color: var(--accent-light);
  font-weight: 700;
  font-size: 1.1rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 12px;
}

.nav-links { list-style: none; padding: 0 10px; }
.nav-links li + li { margin-top: 2px; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  text-decoration: none;
  font-weight: 500;
  transition: background var(--transition), color var(--transition);
}
.nav-item:hover { background: var(--surface2); color: var(--text); }
.nav-item.active { background: rgba(99,102,241,.15); color: var(--accent-light); }

/* ─── Main Content ─────────────────────────────────────────────────────── */
#content { flex: 1; overflow-y: auto; padding: 32px 36px; }

.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ─── Page Header ─────────────────────────────────────────────────────── */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 28px;
}
.page-header h1 { font-size: 1.55rem; font-weight: 700; }
.page-header .actions { display: flex; gap: 10px; }

/* ─── Cards ─────────────────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px 24px;
  margin-bottom: 16px;
}
.card-title {
  font-size: .95rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .06em;
  margin-bottom: 16px;
}

/* ─── Grid helpers ─────────────────────────────────────────────────────── */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 20px; }

/* ─── Summary stats ─────────────────────────────────────────────────────── */
.stat-card {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 22px;
}
.stat-card .label { font-size: .82rem; font-weight: 500; color: var(--text-muted); margin-bottom: 6px; }
.stat-card .value { font-size: 1.6rem; font-weight: 700; }
.stat-card .value.positive { color: var(--success); }
.stat-card .value.negative { color: var(--danger); }
.stat-card .value.neutral  { color: var(--accent-light); }

/* ─── Budget Categories ─────────────────────────────────────────────────── */
.category-group {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 10px;
  overflow: hidden;
}

.category-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  cursor: pointer;
  user-select: none;
  transition: background var(--transition);
}
.category-header:hover { background: var(--surface2); }

.cat-color-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  flex-shrink: 0;
}

.cat-chevron {
  margin-left: auto;
  color: var(--text-dim);
  transition: transform var(--transition);
  flex-shrink: 0;
}
.category-group.open .cat-chevron { transform: rotate(90deg); }

.cat-name { font-weight: 600; flex: 1; }
.cat-total { font-weight: 700; color: var(--accent-light); margin-right: 8px; font-size: .95rem; }

.cat-actions { display: flex; gap: 6px; margin-right: 4px; }

.category-children {
  display: none;
  border-top: 1px solid var(--border);
}
.category-group.open .category-children { display: block; }

.child-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px 10px 38px;
  border-bottom: 1px solid var(--border);
  transition: background var(--transition);
}
.child-item:last-child { border-bottom: none; }
.child-item:hover { background: var(--surface2); }

.child-name { flex: 1; font-size: .95rem; color: var(--text); }

.amount-input-wrap { position: relative; }
.amount-prefix {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  font-size: .9rem;
  pointer-events: none;
}
.amount-input {
  background: var(--surface3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: inherit;
  font-size: .95rem;
  padding: 6px 10px 6px 22px;
  width: 130px;
  transition: border-color var(--transition);
}
.amount-input:focus { outline: none; border-color: var(--accent); }

.add-child-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px 8px 38px;
  color: var(--text-dim);
  font-size: .87rem;
  cursor: pointer;
  transition: color var(--transition), background var(--transition);
  border-top: 1px dashed var(--border);
}
.add-child-row:hover { color: var(--accent-light); background: var(--surface2); }

/* ─── Buttons ────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-family: inherit;
  font-size: .9rem;
  font-weight: 500;
  padding: 8px 16px;
  transition: all var(--transition);
  text-decoration: none;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-light); }
.btn-ghost { background: transparent; color: var(--text-muted); border: 1px solid var(--border); }
.btn-ghost:hover { background: var(--surface2); color: var(--text); }
.btn-danger { background: transparent; color: var(--danger); border: 1px solid var(--danger); }
.btn-danger:hover { background: rgba(244,63,94,.12); }
.btn-success { background: var(--success); color: #fff; }
.btn-success:hover { filter: brightness(1.1); }

.btn-icon {
  background: transparent;
  border: none;
  cursor: pointer;
  color: var(--text-dim);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 4px;
  border-radius: 5px;
  transition: color var(--transition), background var(--transition);
}
.btn-icon:hover { color: var(--text); background: var(--surface3); }
.btn-icon.danger:hover { color: var(--danger); background: rgba(244,63,94,.1); }

/* ─── Charts ─────────────────────────────────────────────────────────────── */
.chart-wrap {
  position: relative;
  width: 100%;
}
.chart-wrap canvas { max-width: 100%; }

/* ─── Income ────────────────────────────────────────────────────────────── */
.income-source {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  margin-bottom: 12px;
}
.income-source-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}
.income-name-input {
  background: transparent;
  border: none;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  font-family: inherit;
  font-size: 1.05rem;
  font-weight: 600;
  padding: 2px 4px;
  min-width: 200px;
  transition: border-color var(--transition);
}
.income-name-input:focus { outline: none; border-bottom-color: var(--accent); }

.income-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.field-group { display: flex; flex-direction: column; gap: 6px; }
.field-label { font-size: .82rem; font-weight: 500; color: var(--text-muted); }
.field-input {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: inherit;
  font-size: .95rem;
  padding: 8px 12px 8px 28px;
  transition: border-color var(--transition);
}
.field-input:focus { outline: none; border-color: var(--accent); }
.field-wrap { position: relative; }
.field-prefix {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  font-size: .9rem;
  pointer-events: none;
}

.tax-diff {
  margin-top: 10px;
  padding: 8px 12px;
  background: var(--surface3);
  border-radius: var(--radius-sm);
  font-size: .88rem;
  color: var(--text-muted);
}
.tax-diff span { font-weight: 600; color: var(--warning); }

/* ─── Investments ──────────────────────────────────────────────────────── */
.investment-account {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 14px;
  overflow: hidden;
}
.investment-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  cursor: pointer;
  transition: background var(--transition);
}
.investment-header:hover { background: var(--surface2); }
.investment-name { font-weight: 600; flex: 1; }
.investment-value { font-weight: 700; color: var(--success); margin-right: 8px; }

.investment-body {
  display: none;
  border-top: 1px solid var(--border);
  padding: 18px 18px 14px;
}
.investment-account.open .investment-body { display: block; }

.investment-controls {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

.investment-children { margin-top: 14px; }
.investment-child {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin-bottom: 8px;
}
.investment-child-name { flex: 1; }
.inv-child-input {
  background: var(--surface3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: inherit;
  font-size: .88rem;
  padding: 5px 8px;
  width: 90px;
}
.inv-child-input:focus { outline: none; border-color: var(--accent); }

/* ─── Modal ─────────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.65);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  backdrop-filter: blur(4px);
}
.modal-overlay.hidden { display: none; }
.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  width: min(440px, 92vw);
  box-shadow: var(--shadow);
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 22px 14px;
  border-bottom: 1px solid var(--border);
}
.modal-header h3 { font-size: 1rem; font-weight: 600; }
.modal-body { padding: 20px 22px; }
.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 14px 22px 18px;
  border-top: 1px solid var(--border);
}

.form-group { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.form-label { font-size: .85rem; font-weight: 500; color: var(--text-muted); }
.form-input {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: inherit;
  font-size: .95rem;
  padding: 9px 13px;
  transition: border-color var(--transition);
}
.form-input:focus { outline: none; border-color: var(--accent); }
.color-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 6px; }
.color-swatch {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  cursor: pointer;
  border: 2px solid transparent;
  transition: border-color var(--transition), transform var(--transition);
}
.color-swatch:hover, .color-swatch.selected { border-color: #fff; transform: scale(1.15); }

/* ─── Toast ─────────────────────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 28px;
  right: 28px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-left: 3px solid var(--success);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: .9rem;
  padding: 12px 18px;
  z-index: 200;
  transform: translateY(20px);
  opacity: 0;
  transition: all .25s ease;
  pointer-events: none;
  box-shadow: var(--shadow);
}
.toast.show { transform: translateY(0); opacity: 1; }
.toast.error { border-left-color: var(--danger); }

/* ─── Scrollbar ─────────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--surface3); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--border); }

/* ─── Expenses / CSV Tab ─────────────────────────────────────────────────── */

/* Sub-tab bar */
.subtab-bar {
  display: flex;
  gap: 4px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 4px;
  margin-bottom: 24px;
  width: fit-content;
}
.subtab {
  padding: 7px 18px;
  border-radius: calc(var(--radius) - 4px);
  font-size: .88rem;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  transition: all var(--transition);
  border: none;
  background: transparent;
  font-family: inherit;
}
.subtab:hover { color: var(--text); background: var(--surface3); }
.subtab.active { background: var(--accent); color: #fff; }

/* Upload drop zone */
.drop-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 40px 32px;
  text-align: center;
  cursor: pointer;
  transition: border-color var(--transition), background var(--transition);
  margin-bottom: 20px;
}
.drop-zone:hover, .drop-zone.drag-over {
  border-color: var(--accent);
  background: rgba(99,102,241,.05);
}
.drop-zone-icon { color: var(--text-dim); margin-bottom: 12px; }
.drop-zone-label { font-size: 1rem; font-weight: 500; color: var(--text-muted); margin-bottom: 6px; }
.drop-zone-hint  { font-size: .83rem; color: var(--text-dim); }

/* Statement months list */
.statement-month {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin-bottom: 8px;
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition);
}
.statement-month:hover { background: var(--surface3); border-color: var(--accent); }
.statement-month.active { border-color: var(--accent); background: rgba(99,102,241,.08); }
.statement-month-name { font-weight: 600; flex: 1; }
.statement-month-meta { font-size: .82rem; color: var(--text-muted); }
.statement-badge {
  font-size: .75rem;
  padding: 2px 8px;
  border-radius: 20px;
  background: var(--surface3);
  color: var(--text-muted);
}

/* Per-statement rows inside a month group */
.stmt-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px 10px 28px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface3);
  margin-bottom: 6px;
  font-size: .88rem;
}
.stmt-item-name  { font-weight: 600; flex: 1; }
.stmt-item-bank  { font-size: .78rem; color: var(--accent-light); background: rgba(99,102,241,.1); padding: 1px 7px; border-radius: 10px; white-space: nowrap; }
.stmt-item-meta  { font-size: .78rem; color: var(--text-muted); white-space: nowrap; }
.stmt-viewer {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface2);
  margin: 0 0 12px 28px;
  overflow: hidden;
}
.stmt-viewer-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 16px;
  background: var(--surface3);
  border-bottom: 1px solid var(--border);
  font-size: .85rem; font-weight: 600;
}

/* Mapping rules */
.mapping-rule {
  display: grid;
  grid-template-columns: 1fr 1.6fr 1fr auto auto;
  gap: 10px;
  align-items: start;
  padding: 12px 14px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin-bottom: 8px;
}
.mapping-rule.rule-ignored { opacity: .55; }
.mapping-rule-label { font-size: .8rem; color: var(--text-muted); margin-bottom: 4px; }
.rule-ignore-wrap {
  display: flex; flex-direction: column; align-items: center; justify-content: flex-start;
  padding-top: 18px; gap: 4px;
}
.rule-ignore-wrap label { font-size: .72rem; color: var(--text-muted); }
.mapping-select {
  background: var(--surface3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: inherit;
  font-size: .88rem;
  padding: 6px 10px;
  width: 100%;
  transition: border-color var(--transition);
}
.mapping-select:focus { outline: none; border-color: var(--accent); }
.mapping-keywords-input {
  background: var(--surface3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: 'Inter', monospace;
  font-size: .83rem;
  padding: 6px 10px;
  width: 100%;
  transition: border-color var(--transition);
}
.mapping-keywords-input:focus { outline: none; border-color: var(--accent); }
.keyword-hint { font-size: .75rem; color: var(--text-dim); margin-top: 3px; }

/* CSV column config */
.col-config-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}
.col-config-field {
  display: flex;
  flex-direction: column;
  gap: 5px;
}
.col-num-input {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: inherit;
  font-size: .9rem;
  padding: 7px 10px;
  width: 100%;
  transition: border-color var(--transition);
}
.col-num-input:focus { outline: none; border-color: var(--accent); }

/* Transactions table */
.txn-table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.txn-table {
  width: 100%;
  border-collapse: collapse;
  font-size: .875rem;
}
.txn-table th {
  text-align: left;
  padding: 10px 14px;
  font-size: .78rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .05em;
  background: var(--surface2);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.txn-table td {
  padding: 9px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.txn-table tr:last-child td { border-bottom: none; }
.txn-table tr:hover td { background: var(--surface2); }
.txn-table tr.unmatched td { background: rgba(244,63,94,.05); }
.txn-table tr.unmatched:hover td { background: rgba(244,63,94,.09); }
.txn-table tr.transfer td { background: rgba(96,165,250,.04); }
.txn-table tr.transfer:hover td { background: rgba(96,165,250,.09); }
.txn-table tr.ignored td { opacity: .4; }

.txn-amount.debit    { color: var(--danger);  font-weight: 600; }
.txn-amount.credit   { color: var(--success); font-weight: 600; }
.txn-amount.transfer { color: #60a5fa;        font-weight: 600; }
.txn-assign-select {
  font-size: .78rem;
  padding: 3px 6px;
  background: var(--surface3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: inherit;
  width: 100%;
  cursor: pointer;
  transition: border-color var(--transition);
}
.txn-assign-select:hover { border-color: var(--accent); }

.card-payments-box {
  border: 1px solid rgba(96,165,250,.3);
  background: rgba(96,165,250,.06);
}
.card-payments-box .card-title { color: #60a5fa; }

.cat-tag {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: .78rem;
  padding: 2px 8px;
  border-radius: 20px;
  background: var(--surface3);
  color: var(--text-muted);
  white-space: nowrap;
}
.cat-tag.matched { background: rgba(99,102,241,.18); color: var(--accent-light); }
.cat-tag.unmatched { background: rgba(244,63,94,.15); color: var(--danger); }

/* Budget vs Actual table */
.bva-table {
  width: 100%;
  border-collapse: collapse;
  font-size: .9rem;
}
.bva-table th {
  text-align: left;
  padding: 9px 14px;
  font-size: .78rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .05em;
  border-bottom: 1px solid var(--border);
}
.bva-table td { padding: 10px 14px; border-bottom: 1px solid rgba(255,255,255,.04); }
.bva-table tr.parent-row td { background: var(--surface2); font-weight: 600; }
.bva-table tr.child-row td { padding-left: 32px; }
.bva-table tr:last-child td { border-bottom: none; }

.progress-bar-wrap {
  height: 6px;
  background: var(--surface3);
  border-radius: 3px;
  overflow: hidden;
  min-width: 80px;
}
.progress-bar {
  height: 100%;
  border-radius: 3px;
  transition: width .4s ease;
}
.progress-bar.under  { background: var(--success); }
.progress-bar.over   { background: var(--danger); }
.progress-bar.near   { background: var(--warning); }

.variance.positive { color: var(--success); }
.variance.negative { color: var(--danger);  }

/* ─── Responsive ────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  #app { flex-direction: column; }
  #sidebar { width: 100%; flex-direction: row; padding: 10px 12px; border-right: none; border-bottom: 1px solid var(--border); }
  .sidebar-brand { padding: 0 14px 0 0; border-bottom: none; margin-bottom: 0; border-right: 1px solid var(--border); }
  .nav-links { display: flex; gap: 4px; padding: 0 0 0 12px; }
  .nav-links li + li { margin-top: 0; }
  #content { padding: 18px 16px; }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .income-fields { grid-template-columns: 1fr; }
  .mapping-rule { grid-template-columns: 1fr; }
}
