/* ── Variables ──────────────────────────────────────────────────────────── */
:root {
  --bg: #f6f5f3;
  --surface: #ffffff;
  --surface-2: #f0eeeb;
  --border: #e5e2dc;
  --border-hover: #c8c4bc;

  --text: #1a1917;
  --text-2: #6b6560;
  --text-3: #9c9690;

  --green: #2d6a4f;
  --green-bg: #edf5f1;
  --red: #c0392b;
  --red-bg: #fdf0ee;
  --amber: #92590a;
  --amber-bg: #fdf4e7;
  --blue: #1a4480;
  --blue-bg: #eef2f9;

  --accent: #1a1917;
  --accent-hover: #333;

  --radius: 10px;
  --radius-lg: 16px;
  --shadow: 0 1px 3px rgba(0,0,0,.06), 0 1px 2px rgba(0,0,0,.04);
  --shadow-md: 0 4px 12px rgba(0,0,0,.08), 0 2px 4px rgba(0,0,0,.04);

  --font-display: 'DM Serif Display', Georgia, serif;
  --font-body: 'DM Sans', system-ui, sans-serif;

  --sidebar-w: 220px;
}

/* ── Reset ──────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 15px; }
body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}
input, select, button, textarea {
  font-family: inherit;
  font-size: inherit;
}
a { text-decoration: none; color: inherit; }

/* ── Screens ────────────────────────────────────────────────────────────── */
.screen { min-height: 100vh; }
.hidden { display: none !important; }

/* ── Auth ───────────────────────────────────────────────────────────────── */
#auth-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: var(--bg);
}

.auth-container {
  width: 100%;
  max-width: 380px;
  padding: 2rem;
}

.auth-brand {
  text-align: center;
  margin-bottom: 2.5rem;
}
.brand-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 48px; height: 48px;
  background: var(--text);
  color: #fff;
  font-family: var(--font-display);
  font-size: 1.2rem;
  border-radius: 12px;
  margin-bottom: .75rem;
}
.auth-brand h1 {
  font-family: var(--font-display);
  font-size: 1.8rem;
  font-weight: 400;
  letter-spacing: -0.02em;
}
.auth-brand p {
  color: var(--text-2);
  font-size: .85rem;
  margin-top: .25rem;
}

.auth-tabs {
  display: flex;
  gap: 0;
  background: var(--surface-2);
  border-radius: var(--radius);
  padding: 3px;
  margin-bottom: 1.5rem;
}
.tab-btn {
  flex: 1;
  padding: .5rem;
  border: none;
  background: transparent;
  border-radius: calc(var(--radius) - 2px);
  cursor: pointer;
  font-size: .875rem;
  font-weight: 500;
  color: var(--text-2);
  transition: all .15s;
}
.tab-btn.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
}

.auth-form { display: flex; flex-direction: column; gap: 1rem; }

.auth-error {
  font-size: .8rem;
  color: var(--red);
  min-height: 1rem;
  text-align: center;
}

/* ── App Layout ─────────────────────────────────────────────────────────── */
#app-screen {
  display: flex;
  min-height: 100vh;
}

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

.sidebar-top { flex: 1; padding: 1.5rem 1rem; }

.brand-small {
  display: flex;
  align-items: center;
  gap: .6rem;
  font-family: var(--font-display);
  font-size: 1.1rem;
  margin-bottom: 2rem;
  padding: 0 .4rem;
}
.brand-mark-sm {
  width: 30px; height: 30px;
  background: var(--text);
  color: #fff;
  border-radius: 7px;
  display: flex; align-items: center; justify-content: center;
  font-size: .8rem;
}

.nav-links { display: flex; flex-direction: column; gap: .25rem; }
.nav-item {
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: .6rem .8rem;
  border-radius: var(--radius);
  color: var(--text-2);
  font-size: .875rem;
  font-weight: 500;
  transition: all .15s;
  cursor: pointer;
}
.nav-item svg {
  width: 16px; height: 16px;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex-shrink: 0;
}
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.active { background: var(--text); color: #fff; }

.sidebar-bottom {
  padding: 1rem;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: .5rem;
}
.user-chip {
  display: flex;
  align-items: center;
  gap: .6rem;
  font-size: .8rem;
  color: var(--text-2);
}
.user-avatar {
  width: 28px; height: 28px;
  background: var(--surface-2);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-weight: 600;
  font-size: .75rem;
  color: var(--text);
  flex-shrink: 0;
}
.btn-logout {
  width: 100%;
  padding: .45rem;
  border: 1px solid var(--border);
  background: transparent;
  border-radius: var(--radius);
  font-size: .8rem;
  color: var(--text-2);
  cursor: pointer;
  transition: all .15s;
}
.btn-logout:hover { border-color: var(--red); color: var(--red); background: var(--red-bg); }

/* ── Main Content ───────────────────────────────────────────────────────── */
#main-content {
  margin-left: var(--sidebar-w);
  flex: 1;
  min-height: 100vh;
  padding: 2rem 2.5rem;
  max-width: 1100px;
}

.page { display: block; }
.page.hidden { display: none; }

/* ── Page Header ─────────────────────────────────────────────────────────── */
.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 1.75rem;
  gap: 1rem;
}
.page-header h2 {
  font-family: var(--font-display);
  font-size: 1.8rem;
  font-weight: 400;
  letter-spacing: -0.02em;
  line-height: 1.2;
}
.subtext { color: var(--text-2); font-size: .85rem; margin-top: .2rem; }
.header-actions { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }

/* ── Form Elements ──────────────────────────────────────────────────────── */
.field { display: flex; flex-direction: column; gap: .4rem; }
.field label {
  font-size: .8rem;
  font-weight: 600;
  color: var(--text-2);
  letter-spacing: .02em;
  text-transform: uppercase;
}
.field .hint { font-weight: 400; text-transform: none; color: var(--text-3); }
.field input, .field select {
  padding: .65rem .85rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  transition: border-color .15s;
  outline: none;
}
.field input:focus, .field select:focus { border-color: var(--text); }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: .75rem; }

.select-pill {
  padding: .45rem .8rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  font-size: .85rem;
  cursor: pointer;
  outline: none;
  transition: border-color .15s;
}
.select-pill:focus { border-color: var(--text); }

/* ── Buttons ────────────────────────────────────────────────────────────── */
.btn-primary {
  padding: .6rem 1.2rem;
  background: var(--text);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  font-weight: 600;
  font-size: .875rem;
  cursor: pointer;
  transition: background .15s, opacity .15s;
  white-space: nowrap;
}
.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:disabled { opacity: .5; cursor: not-allowed; }
.btn-secondary {
  padding: .6rem 1.2rem;
  background: transparent;
  color: var(--text-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: .875rem;
  cursor: pointer;
  transition: all .15s;
}
.btn-secondary:hover { border-color: var(--text); color: var(--text); }

/* ── Cards ──────────────────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  box-shadow: var(--shadow);
}
.card h3 {
  font-size: .875rem;
  font-weight: 600;
  color: var(--text-2);
  text-transform: uppercase;
  letter-spacing: .04em;
  margin-bottom: 1rem;
}

/* ── Stats Grid ─────────────────────────────────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1rem;
  margin-bottom: 1.5rem;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.25rem 1.5rem;
  box-shadow: var(--shadow);
}
.stat-card.income { border-left: 3px solid var(--green); }
.stat-card.expense { border-left: 3px solid var(--red); }
.stat-card.net { border-left: 3px solid var(--blue); }
.stat-label {
  font-size: .78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--text-2);
  margin-bottom: .4rem;
}
.stat-amount {
  font-family: var(--font-display);
  font-size: 1.6rem;
  font-weight: 400;
  letter-spacing: -0.02em;
}
.stat-card.income .stat-amount { color: var(--green); }
.stat-card.expense .stat-amount { color: var(--red); }
.stat-card.net .stat-amount { color: var(--blue); }

/* ── Dashboard Grid ─────────────────────────────────────────────────────── */
.dashboard-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

/* ── Chart ──────────────────────────────────────────────────────────────── */
.chart-container { display: flex; flex-direction: column; gap: .6rem; }
.chart-bar-item { display: flex; flex-direction: column; gap: .25rem; }
.chart-bar-label {
  display: flex;
  justify-content: space-between;
  font-size: .8rem;
  color: var(--text-2);
}
.chart-bar-track {
  height: 6px;
  background: var(--surface-2);
  border-radius: 999px;
  overflow: hidden;
}
.chart-bar-fill {
  height: 100%;
  background: var(--text);
  border-radius: 999px;
  transition: width .4s ease;
}

/* ── Transaction List ───────────────────────────────────────────────────── */
.tx-list { display: flex; flex-direction: column; gap: .5rem; }
.tx-list--full { margin-top: .5rem; }

.tx-item {
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: .75rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  transition: border-color .15s;
}
.tx-item:hover { border-color: var(--border-hover); }
.tx-icon {
  width: 34px; height: 34px;
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-size: .9rem;
  flex-shrink: 0;
}
.tx-icon.income { background: var(--green-bg); }
.tx-icon.expense { background: var(--red-bg); }
.tx-info { flex: 1; min-width: 0; }
.tx-desc {
  font-size: .875rem;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.tx-meta { font-size: .75rem; color: var(--text-2); display: flex; gap: .5rem; align-items: center; }
.tx-cat-badge {
  background: var(--surface-2);
  border-radius: 999px;
  padding: .1rem .5rem;
  font-size: .7rem;
  font-weight: 500;
  white-space: nowrap;
}
.tx-amount {
  font-weight: 600;
  font-size: .9rem;
  white-space: nowrap;
}
.tx-amount.income { color: var(--green); }
.tx-amount.expense { color: var(--red); }
.tx-delete {
  opacity: 0;
  padding: .2rem .4rem;
  border: none;
  background: transparent;
  color: var(--text-3);
  cursor: pointer;
  border-radius: 4px;
  font-size: .8rem;
  transition: all .15s;
}
.tx-item:hover .tx-delete { opacity: 1; }
.tx-delete:hover { background: var(--red-bg); color: var(--red); }

.tx-empty, .empty-state {
  text-align: center;
  color: var(--text-3);
  font-size: .875rem;
  padding: 2rem 0;
}

/* ── Filter Bar ─────────────────────────────────────────────────────────── */
.filter-bar {
  display: flex;
  gap: .5rem;
  margin-bottom: 1.25rem;
  flex-wrap: wrap;
}

/* ── Budget ─────────────────────────────────────────────────────────────── */
.budget-grid { display: flex; flex-direction: column; gap: .75rem; }
.budget-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1rem 1.25rem;
}
.budget-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: .6rem; }
.budget-cat { font-weight: 600; font-size: .875rem; }
.budget-amounts { font-size: .8rem; color: var(--text-2); }
.budget-track {
  height: 8px;
  background: var(--surface-2);
  border-radius: 999px;
  overflow: hidden;
}
.budget-fill {
  height: 100%;
  border-radius: 999px;
  transition: width .4s ease, background .3s;
}
.budget-fill.ok { background: var(--green); }
.budget-fill.warn { background: var(--amber); }
.budget-fill.over { background: var(--red); }

/* ── Insights ───────────────────────────────────────────────────────────── */
.insight-area { display: flex; flex-direction: column; gap: 1rem; }
.insight-empty {
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: var(--radius-lg);
  padding: 3rem;
  text-align: center;
  color: var(--text-2);
}
.insight-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
}
.insight-card h3 {
  font-size: .75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--text-3);
  margin-bottom: .75rem;
  display: flex;
  align-items: center;
  gap: .4rem;
}
.insight-card h3 .badge {
  background: var(--surface-2);
  border-radius: 4px;
  padding: .1rem .4rem;
}
.insight-text {
  font-size: .9rem;
  line-height: 1.7;
  color: var(--text);
}
.insight-loading {
  display: flex;
  align-items: center;
  gap: .75rem;
  color: var(--text-2);
  font-size: .875rem;
  padding: 1.5rem;
}
.spinner {
  width: 18px; height: 18px;
  border: 2px solid var(--border);
  border-top-color: var(--text);
  border-radius: 50%;
  animation: spin .6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Modal ──────────────────────────────────────────────────────────────── */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.3);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 1rem;
  backdrop-filter: blur(2px);
}
.modal-box {
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  width: 100%;
  max-width: 460px;
  box-shadow: var(--shadow-md);
  animation: slideUp .2s ease;
}
@keyframes slideUp { from { opacity:0; transform: translateY(10px); } to { opacity:1; transform: translateY(0); } }
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.25rem;
}
.modal-header h3 {
  font-family: var(--font-display);
  font-size: 1.2rem;
  font-weight: 400;
}
.modal-close {
  border: none;
  background: transparent;
  color: var(--text-2);
  font-size: 1rem;
  cursor: pointer;
  padding: .2rem .4rem;
  border-radius: 4px;
  transition: all .15s;
}
.modal-close:hover { background: var(--surface-2); color: var(--text); }
.modal-footer {
  display: flex;
  gap: .75rem;
  justify-content: flex-end;
  margin-top: 1.25rem;
}
form { display: flex; flex-direction: column; gap: .9rem; }

/* ── Toast ──────────────────────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  background: var(--text);
  color: #fff;
  padding: .7rem 1.2rem;
  border-radius: var(--radius);
  font-size: .85rem;
  font-weight: 500;
  z-index: 9999;
  box-shadow: var(--shadow-md);
  animation: fadeIn .2s ease;
  max-width: 320px;
}
.toast.error { background: var(--red); }
.toast.success { background: var(--green); }
@keyframes fadeIn { from { opacity:0; transform: translateY(6px); } to { opacity:1; transform: translateY(0); } }

/* ── Responsive ─────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  :root { --sidebar-w: 0px; }
  #sidebar {
    width: 100%;
    height: auto;
    position: static;
    flex-direction: row;
    border-right: none;
    border-bottom: 1px solid var(--border);
    padding: .5rem;
  }
  .sidebar-top { padding: .5rem; }
  .nav-links { flex-direction: row; flex-wrap: wrap; }
  .brand-small, .sidebar-bottom { display: none; }
  #main-content { margin-left: 0; padding: 1rem; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .dashboard-grid { grid-template-columns: 1fr; }
  .field-row { grid-template-columns: 1fr; }
}
