:root {
  --bg: #0b1e2d;
  --bg-panel: #12293d;
  --bg-card: #16324a;
  --border: #234258;
  --text: #e8eef2;
  --text-muted: #90a4b7;
  --accent: #4fb0c6;
  --income: #6bbf8a;
  --expense: #e07a5f;
  --danger: #d9534f;
  font-size: 16px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

.screen[hidden] { display: none !important; }

/* Login */
#login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 1rem;
}
.login-card {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 2rem;
  width: 100%;
  max-width: 320px;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  text-align: center;
}
.login-card h1 { margin: 0; font-size: 1.4rem; }
.muted { color: var(--text-muted); font-size: 0.9rem; margin: 0; }
.error-text { color: var(--danger); font-size: 0.85rem; margin: 0; }

input, select, button {
  font: inherit;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text);
  padding: 0.6rem 0.75rem;
}
input::placeholder { color: var(--text-muted); }

button { cursor: pointer; }
.primary-btn { background: var(--accent); color: #052a33; border: none; font-weight: 600; }
.ghost-btn { background: transparent; }
.danger-btn { background: transparent; color: var(--danger); border-color: var(--danger); }
.icon-btn { background: transparent; padding: 0.3rem 0.7rem; font-size: 1.1rem; }

/* App shell */
.topbar {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.75rem 1.25rem;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.topbar h1 { font-size: 1.1rem; margin: 0; margin-right: auto; }
.tabs { display: flex; gap: 0.4rem; flex-wrap: wrap; }
.tab-btn {
  background: transparent;
  border: 1px solid transparent;
  padding: 0.4rem 0.75rem;
  color: var(--text-muted);
}
.tab-btn.active { background: var(--bg-card); color: var(--text); border-color: var(--border); }

main { padding: 1.25rem; max-width: 1100px; margin: 0 auto; }
.view { display: none; }
.view.active { display: block; }

.panel {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.25rem;
  margin-bottom: 1.25rem;
}
.panel h2 { margin-top: 0; font-size: 1rem; }

.month-picker {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  margin-bottom: 1rem;
  font-size: 1.1rem;
  font-weight: 600;
}

.summary-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 0.75rem;
  margin-bottom: 1.25rem;
}
.card {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}
.card-label { color: var(--text-muted); font-size: 0.8rem; }
.card-value { font-size: 1.4rem; font-weight: 700; }
.card-value.income { color: var(--income); }
.card-value.expense { color: var(--expense); }

.dashboard-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.25rem;
}
@media (max-width: 800px) { .dashboard-grid { grid-template-columns: 1fr; } }

canvas { max-width: 100%; }

.legend { list-style: none; padding: 0; margin: 0.75rem 0 0; display: flex; flex-direction: column; gap: 0.35rem; font-size: 0.85rem; }
.legend li { display: flex; align-items: center; gap: 0.5rem; }
.legend .swatch { width: 10px; height: 10px; border-radius: 3px; flex-shrink: 0; }
.legend .amt { margin-left: auto; color: var(--text-muted); }

.budget-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 0.75rem; }
.budget-row-label { display: flex; justify-content: space-between; font-size: 0.85rem; margin-bottom: 0.25rem; }
.budget-bar-bg { background: var(--bg-card); border-radius: 6px; height: 8px; overflow: hidden; }
.budget-bar-fill { height: 100%; border-radius: 6px; }

.toolbar { display: flex; gap: 0.6rem; margin-bottom: 1rem; flex-wrap: wrap; align-items: center; }

.tx-table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.tx-table th, .tx-table td { text-align: left; padding: 0.5rem 0.6rem; border-bottom: 1px solid var(--border); }
.tx-table th.right, .tx-table td.right { text-align: right; }
.tx-table tbody tr { cursor: pointer; }
.tx-table tbody tr:hover { background: var(--bg-card); }
.amount-pos { color: var(--income); }
.amount-neg { color: var(--expense); }

.cat-pill { display: inline-flex; align-items: center; gap: 0.4rem; padding: 0.15rem 0.5rem; border-radius: 999px; background: var(--bg-card); font-size: 0.8rem; }
.cat-pill .swatch { width: 8px; height: 8px; border-radius: 50%; }

.category-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 0.5rem; }
.category-list li { display: flex; align-items: center; gap: 0.6rem; padding: 0.4rem 0; border-bottom: 1px solid var(--border); }
.category-list input[type="text"] { flex: 1; }
.category-list input[type="color"] { width: 36px; height: 36px; padding: 2px; }

.mapping-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0.75rem; margin: 1rem 0; }
.mapping-grid label { display: flex; flex-direction: column; gap: 0.3rem; font-size: 0.85rem; color: var(--text-muted); }
.checkbox-label { display: flex; align-items: center; gap: 0.5rem; font-size: 0.85rem; color: var(--text-muted); margin-bottom: 1rem; }
.checkbox-label input { width: auto; }

#import-preview { overflow-x: auto; margin-bottom: 1rem; }
#import-preview table { width: 100%; border-collapse: collapse; font-size: 0.8rem; }
#import-preview th, #import-preview td { padding: 0.35rem 0.5rem; border-bottom: 1px solid var(--border); white-space: nowrap; }

.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.5);
  display: flex; align-items: center; justify-content: center; padding: 1rem; z-index: 10;
}
.modal-overlay[hidden] { display: none; }
.modal {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.5rem;
  width: 100%;
  max-width: 420px;
}
.modal h2 { margin-top: 0; }
#tx-form { display: flex; flex-direction: column; gap: 0.75rem; }
#tx-form label { display: flex; flex-direction: column; gap: 0.3rem; font-size: 0.85rem; color: var(--text-muted); }
.modal-actions { display: flex; justify-content: flex-end; gap: 0.5rem; margin-top: 0.5rem; }
