:root {
  --primary: #6366f1;
  --primary-dark: #4f46e5;
  --primary-light: #e0e7ff;
  --success: #10b981;
  --danger: #ef4444;
  --warning: #f59e0b;
  --bg: #f1f5f9;
  --card: #ffffff;
  --border: #e2e8f0;
  --text: #1e293b;
  --text-muted: #64748b;
  --nav-height: 64px;
  --header-height: 56px;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.06);
  --shadow-md: 0 4px 6px rgba(0,0,0,.07), 0 2px 4px rgba(0,0,0,.06);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ── Login ─────────────────────────────────────────────────────── */
#view-login {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
}

.login-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 36px 28px;
  width: 100%;
  max-width: 380px;
  box-shadow: var(--shadow-md);
}

.login-card h1 {
  font-size: 1.5rem;
  font-weight: 700;
  text-align: center;
  margin-bottom: 6px;
}

.login-card p {
  text-align: center;
  color: var(--text-muted);
  margin-bottom: 28px;
  font-size: 0.875rem;
}

/* ── Layout ─────────────────────────────────────────────────────── */
#app { display: flex; flex-direction: column; min-height: 100dvh; }

header {
  height: var(--header-height);
  background: var(--card);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 16px;
  position: sticky;
  top: 0;
  z-index: 100;
  gap: 12px;
}

header h2 {
  font-size: 1rem;
  font-weight: 600;
  flex: 1;
}

.header-user {
  font-size: 0.8rem;
  color: var(--text-muted);
}

main {
  flex: 1;
  padding: 16px;
  padding-bottom: calc(var(--nav-height) + 16px);
  overflow-y: auto;
}

/* ── Bottom Nav ─────────────────────────────────────────────────── */
.bottom-nav {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: var(--nav-height);
  background: var(--card);
  border-top: 1px solid var(--border);
  display: flex;
  z-index: 100;
}

.nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  font-size: 0.65rem;
  font-weight: 500;
  transition: color .15s;
  padding: 8px 4px;
}

.nav-item svg { width: 22px; height: 22px; }

.nav-item.active { color: var(--primary); }

/* ── Forms ──────────────────────────────────────────────────────── */
.form-group { margin-bottom: 16px; }

label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: .04em;
}

input, select, textarea {
  width: 100%;
  padding: 10px 14px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  font-size: 0.95rem;
  font-family: inherit;
  color: var(--text);
  background: var(--card);
  transition: border-color .15s;
  -webkit-appearance: none;
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
}

/* ── Buttons ────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 20px;
  border-radius: 8px;
  font-size: 0.9rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  border: none;
  transition: opacity .15s, transform .1s;
  text-decoration: none;
}

.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-success { background: var(--success); color: #fff; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-ghost { background: var(--bg); color: var(--text); }
.btn-block { width: 100%; }
.btn-sm { padding: 6px 14px; font-size: 0.8rem; }

/* ── Cards ──────────────────────────────────────────────────────── */
.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}

.card + .card { margin-top: 12px; }

/* ── Summary cards grid ─────────────────────────────────────────── */
.summary-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 16px;
}

.summary-grid .card.full { grid-column: 1 / -1; }

.summary-card { text-align: center; }
.summary-card .label { font-size: 0.7rem; font-weight: 600; text-transform: uppercase; color: var(--text-muted); letter-spacing: .05em; margin-bottom: 4px; }
.summary-card .value { font-size: 1.4rem; font-weight: 700; }
.summary-card .value.income { color: var(--success); }
.summary-card .value.expense { color: var(--danger); }
.summary-card .value.positive { color: var(--success); }
.summary-card .value.negative { color: var(--danger); }

/* ── Upload ─────────────────────────────────────────────────────── */
.upload-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 40px 20px;
  text-align: center;
  cursor: pointer;
  transition: border-color .2s, background .2s;
  background: var(--card);
}

.upload-zone:hover, .upload-zone.drag-over {
  border-color: var(--primary);
  background: var(--primary-light);
}

.upload-zone svg { width: 48px; height: 48px; color: var(--primary); margin-bottom: 12px; }
.upload-zone p { color: var(--text-muted); font-size: 0.9rem; }
.upload-zone strong { color: var(--text); }

/* ── Spinner ────────────────────────────────────────────────────── */
.spinner {
  width: 40px; height: 40px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin .7s linear infinite;
  margin: 24px auto;
}

@keyframes spin { to { transform: rotate(360deg); } }

.loading-box { text-align: center; padding: 32px; }
.loading-box p { color: var(--text-muted); font-size: 0.875rem; margin-top: 8px; }

/* ── Modal ──────────────────────────────────────────────────────── */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  z-index: 200;
  display: flex;
  align-items: flex-end;
  padding: 0;
}

@media (min-width: 600px) {
  .modal-backdrop { align-items: center; justify-content: center; padding: 24px; }
}

.modal-box {
  background: var(--card);
  border-radius: var(--radius) var(--radius) 0 0;
  width: 100%;
  max-height: 90dvh;
  overflow-y: auto;
  padding: 20px;
}

@media (min-width: 600px) {
  .modal-box { border-radius: var(--radius); max-width: 520px; max-height: 85vh; }
}

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

.modal-header h3 { font-size: 1rem; font-weight: 700; }

.modal-close {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  padding: 4px;
  border-radius: 6px;
}

/* ── Pending transaction item ───────────────────────────────────── */
.pending-item {
  border: 1.5px solid var(--border);
  border-radius: 10px;
  padding: 14px;
  margin-bottom: 12px;
}

.pending-item .row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.pending-item .merchant { font-weight: 600; }
.pending-item .amount { font-weight: 700; font-size: 1.05rem; color: var(--danger); }

.ai-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 0.7rem;
  background: #f0fdf4;
  color: #16a34a;
  border: 1px solid #bbf7d0;
  border-radius: 20px;
  padding: 2px 8px;
  margin-bottom: 8px;
}

/* ── Transaction list ───────────────────────────────────────────── */
.tx-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}

.tx-item:last-child { border-bottom: none; }

.tx-icon {
  width: 38px; height: 38px;
  border-radius: 10px;
  background: var(--primary-light);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  flex-shrink: 0;
}

.tx-info { flex: 1; min-width: 0; }
.tx-info .merchant { font-weight: 600; font-size: 0.9rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tx-info .meta { font-size: 0.75rem; color: var(--text-muted); }

.tx-right { text-align: right; flex-shrink: 0; }
.tx-right .amount { font-weight: 700; color: var(--danger); font-size: 0.95rem; }
.tx-right .actions { display: flex; gap: 6px; margin-top: 4px; justify-content: flex-end; }

/* ── Category pill ──────────────────────────────────────────────── */
.pill {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 20px;
  font-size: 0.7rem;
  font-weight: 600;
  background: var(--primary-light);
  color: var(--primary-dark);
}

/* ── Budget bar ─────────────────────────────────────────────────── */
.budget-item {
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}

.budget-item:last-child { border-bottom: none; }

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

.budget-bar-wrap { height: 8px; background: var(--border); border-radius: 4px; overflow: hidden; }
.budget-bar { height: 100%; border-radius: 4px; transition: width .4s; }
.budget-bar.ok { background: var(--success); }
.budget-bar.warn { background: var(--warning); }
.budget-bar.over { background: var(--danger); }

/* ── Filters ────────────────────────────────────────────────────── */
.filters {
  display: flex;
  gap: 8px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}

.filters select, .filters input { width: auto; flex: 1; min-width: 100px; padding: 8px 12px; font-size: 0.85rem; }

/* ── Section title ──────────────────────────────────────────────── */
.section-title {
  font-size: 1rem;
  font-weight: 700;
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

/* ── Month selector ─────────────────────────────────────────────── */
.month-nav {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
  background: var(--card);
  border-radius: var(--radius);
  padding: 10px 14px;
  box-shadow: var(--shadow);
}

.month-nav span { flex: 1; text-align: center; font-weight: 600; }

.month-nav button {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--primary);
  padding: 4px;
  border-radius: 6px;
  font-size: 1.2rem;
}

/* ── Chart containers ───────────────────────────────────────────── */
.chart-wrap {
  position: relative;
  height: 220px;
}

.chart-wrap.tall { height: 280px; }

/* ── Empty state ────────────────────────────────────────────────── */
.empty {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-muted);
  font-size: 0.875rem;
}

.empty svg { width: 48px; height: 48px; margin-bottom: 12px; opacity: .4; }

/* ── Toast ──────────────────────────────────────────────────────── */
#toast {
  position: fixed;
  bottom: calc(var(--nav-height) + 12px);
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: #1e293b;
  color: #fff;
  padding: 10px 20px;
  border-radius: 8px;
  font-size: 0.875rem;
  font-weight: 500;
  opacity: 0;
  transition: opacity .2s, transform .2s;
  z-index: 300;
  white-space: nowrap;
  pointer-events: none;
}

#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#toast.error { background: var(--danger); }
#toast.success { background: var(--success); }

/* ── Utilities ──────────────────────────────────────────────────── */
.hidden { display: none !important; }
.mt-8 { margin-top: 8px; }
.mt-12 { margin-top: 12px; }
.mt-16 { margin-top: 16px; }
.text-muted { color: var(--text-muted); font-size: 0.875rem; }
.text-center { text-align: center; }

/* ── Desktop sidebar ────────────────────────────────────────────── */
@media (min-width: 768px) {
  #app { flex-direction: row; }

  .bottom-nav {
    position: sticky;
    top: 0;
    bottom: auto;
    left: 0;
    width: 200px;
    height: 100dvh;
    flex-direction: column;
    border-top: none;
    border-right: 1px solid var(--border);
    padding: 16px 8px;
    justify-content: flex-start;
    gap: 4px;
    align-self: flex-start;
  }

  .nav-item {
    flex-direction: row;
    justify-content: flex-start;
    gap: 10px;
    padding: 10px 14px;
    border-radius: 8px;
    font-size: 0.875rem;
    width: 100%;
  }

  .nav-brand {
    padding: 8px 14px 16px;
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--primary);
    border-bottom: 1px solid var(--border);
    margin-bottom: 8px;
    display: flex;
    align-items: center;
    gap: 8px;
  }

  .nav-item.active { background: var(--primary-light); }

  header { display: none; }

  main { padding: 24px; padding-bottom: 24px; max-width: 900px; }

  .summary-grid { grid-template-columns: repeat(4, 1fr); }
  .summary-grid .card.full { grid-column: auto; }
}
