/* ── Theme variables ── */

:root, [data-theme="dark"] {
  --bg: #0f1117;
  --surface: #1a1d27;
  --surface2: #22263a;
  --border: #2e3350;
  --accent: #4f7ef8;
  --accent-hover: #3d6be0;
  --text: #e8eaf0;
  --text-muted: #7b82a0;
  --error: #f87171;
  --warning-bg: #2a2210;
  --warning-text: #fbbf24;
  --success: #4ade80;
  --radius: 10px;
  --font: 'Inter', system-ui, sans-serif;

  --cell-green-bg:  rgba(74, 222, 128, 0.12);
  --cell-yellow-bg: rgba(251, 191, 36, 0.12);
  --cell-red-bg:    rgba(248, 113, 113, 0.14);
}

[data-theme="light"] {
  --bg: #f5f6fa;
  --surface: #ffffff;
  --surface2: #eef0f7;
  --border: #d8dbe8;
  --accent: #3b6ef4;
  --accent-hover: #2a5de0;
  --text: #1a1d2e;
  --text-muted: #5b6278;
  --error: #c0392b;
  --warning-bg: #fff8e1;
  --warning-text: #b45309;
  --success: #16a34a;
  --radius: 10px;
  --font: 'Inter', system-ui, sans-serif;

  --cell-green-bg:  rgba(22, 163, 74, 0.10);
  --cell-yellow-bg: rgba(180, 83, 9, 0.08);
  --cell-red-bg:    rgba(192, 57, 43, 0.10);
}

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

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  min-height: 100vh;
  transition: background 0.2s, color 0.2s;
}

/* ── Header ── */
header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 32px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.logo { font-weight: 700; font-size: 16px; letter-spacing: 0.02em; }
.header-actions { display: flex; gap: 12px; align-items: center; }
.logout { color: var(--text-muted); text-decoration: none; font-size: 13px; }
.logout:hover { color: var(--text); }

/* Theme toggle */
.theme-toggle {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 5px 10px;
  cursor: pointer;
  font-size: 14px;
  color: var(--text-muted);
  transition: background 0.15s, color 0.15s;
  line-height: 1;
}
.theme-toggle:hover { color: var(--text); background: var(--border); }

[data-theme="dark"]  .theme-icon-light { display: none; }
[data-theme="dark"]  .theme-icon-dark  { display: inline; }
[data-theme="light"] .theme-icon-dark  { display: none; }
[data-theme="light"] .theme-icon-light { display: inline; }

/* ── Nav ── */
.main-nav { display: flex; gap: 4px; }
.nav-link {
  padding: 7px 16px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  text-decoration: none;
  color: var(--text-muted);
  transition: background 0.15s, color 0.15s;
}
.nav-link:hover { background: var(--surface2); color: var(--text); }
.nav-link.active { background: var(--accent); color: #fff; }

/* ── Layout ── */
.center { display: flex; justify-content: center; align-items: center; min-height: 100vh; }
.container { max-width: 1200px; margin: 0 auto; padding: 32px; }

/* ── Card ── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 40px;
  max-width: 420px;
  width: 100%;
}
.card.center { margin: auto; }
h1 { font-size: 22px; font-weight: 700; margin-bottom: 4px; }
h2 { font-size: 18px; font-weight: 600; margin-bottom: 8px; }
.subtitle { color: var(--text-muted); font-size: 13px; margin-bottom: 24px; }

/* ── Forms ── */
form { display: flex; flex-direction: column; gap: 14px; }
label { font-size: 13px; color: var(--text-muted); margin-bottom: 4px; display: block; }
input[type="password"], input[type="text"] {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px 14px;
  color: var(--text);
  font-size: 14px;
  outline: none;
  transition: border-color 0.15s;
}
input:focus { border-color: var(--accent); }

button[type="submit"], button#analyzeBtn {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 11px 20px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}
button:hover:not(:disabled) { background: var(--accent-hover); }
button:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-secondary {
  background: var(--surface2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 9px 16px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  display: inline-block;
  transition: background 0.15s;
}
.btn-secondary:hover { background: var(--border); }
.btn-secondary.small { padding: 6px 12px; font-size: 12px; }

/* ── Alerts ── */
.alert {
  padding: 10px 14px;
  border-radius: 6px;
  font-size: 13px;
  margin-bottom: 12px;
}
.alert.error   { background: rgba(192,57,43,0.10); color: var(--error); border: 1px solid rgba(192,57,43,0.25); }
.alert.warning { background: var(--warning-bg); color: var(--warning-text); border: 1px solid rgba(180,83,9,0.2); }
.budget-update-banner { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.btn-dismiss-banner { flex-shrink: 0; padding: 4px 10px; font-size: 12px; border: 1px solid rgba(180,83,9,0.4); background: transparent; color: var(--warning-text); border-radius: 4px; cursor: pointer; }
.btn-dismiss-banner:hover { background: rgba(180,83,9,0.12); }

/* ── Drop zone ── */
.drop-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 40px 20px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  color: var(--text-muted);
}
.drop-zone.drag-over { border-color: var(--accent); background: rgba(79,126,248,0.05); }
.drop-zone svg { opacity: 0.5; }
.drop-zone .hint { font-size: 12px; }
.file-name { font-size: 13px; color: var(--accent); font-weight: 500; min-height: 18px; }

/* ── File info ── */
.file-info {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
  font-size: 14px;
}
.badge {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 2px 10px;
  font-size: 12px;
  color: var(--text-muted);
}
.badge.warning { color: var(--warning-text); background: var(--warning-bg); border-color: rgba(180,83,9,0.2); }

/* ── Table ── */
.table-wrapper {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 32px;
}
table { width: 100%; border-collapse: collapse; font-size: 13px; }
thead { background: var(--surface2); }
th {
  padding: 10px 14px;
  text-align: left;
  font-weight: 600;
  color: var(--text-muted);
  white-space: nowrap;
  border-bottom: 1px solid var(--border);
}
td {
  padding: 9px 14px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  max-width: 240px;
  overflow: hidden;
  text-overflow: ellipsis;
}
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--surface2); }

/* ── Analysis panel ── */
.analysis-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
}
.analysis-panel h3 { font-size: 16px; font-weight: 600; margin-bottom: 16px; }
.question-row { display: flex; gap: 10px; }
.question-row input { flex: 1; }
.analysis-result { margin-top: 20px; }
.analysis-result.hidden { display: none; }

.spinner {
  width: 24px; height: 24px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  margin: 16px auto;
}
@keyframes spin { to { transform: rotate(360deg); } }

#analysisText { line-height: 1.7; color: var(--text); }
#analysisText p { margin-bottom: 10px; }
#analysisText h3, #analysisText h4 { margin: 16px 0 6px; font-weight: 600; color: var(--text); }
#analysisText ul { padding-left: 20px; margin-bottom: 10px; }
#analysisText li { margin-bottom: 4px; }
#analysisText strong { color: var(--text); }
#analysisText .error { color: var(--error); }

/* ── Import / Review page ── */
.radio-group { display: flex; gap: 20px; }
.radio-label { display: flex; align-items: center; gap: 8px; cursor: pointer; font-size: 14px; }
.radio-label input { accent-color: var(--accent); }

.period-row { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.period-label { color: var(--text-muted); font-size: 13px; min-width: 70px; }
.period-row input[type="date"] { background: var(--surface2); border: 1px solid var(--border); border-radius:6px; padding:8px 12px; color:var(--text); font-size:13px; outline:none; }
.period-row input[type="date"]:focus { border-color: var(--accent); }
.btn-remove { background:none; border:none; color:var(--text-muted); cursor:pointer; font-size:16px; padding:4px 8px; }
.btn-remove:hover { color:var(--error); }

/* Stats bar */
.stats-bar { display:flex; gap:16px; margin-bottom:20px; flex-wrap:wrap; }
.stat-item { background:var(--surface); border:1px solid var(--border); border-radius:var(--radius); padding:14px 20px; min-width:140px; }
.stat-item.high   { border-color: rgba(74,222,128,0.35); }
.stat-item.medium { border-color: rgba(251,191,36,0.35); }
.stat-item.low    { border-color: rgba(248,113,113,0.35); }
.stat-value { display:block; font-size:24px; font-weight:700; }
.stat-label { font-size:12px; color:var(--text-muted); }

/* Filter bar */
.filter-bar { display:flex; gap:8px; margin-bottom:14px; }
.filter-btn { background:var(--surface2); border:1px solid var(--border); border-radius:20px; padding:6px 14px; font-size:12px; color:var(--text-muted); cursor:pointer; transition:all 0.15s; }
.filter-btn:hover { color:var(--text); }
.filter-btn.active { background:var(--accent); border-color:var(--accent); color:#fff; }

/* Confidence badges */
.conf-badge { display:inline-block; padding:2px 8px; border-radius:12px; font-size:12px; font-weight:600; }
.conf-badge.high   { background: var(--cell-green-bg);  color:var(--success); }
.conf-badge.medium { background: var(--cell-yellow-bg); color:var(--warning-text); }
.conf-badge.low    { background: var(--cell-red-bg);    color:var(--error); }

/* Method badges */
.method-badge { display:inline-block; padding:2px 8px; border-radius:12px; font-size:11px; }
.method-badge.vacation     { background:rgba(79,126,248,0.15); color:var(--accent); }
.method-badge.label_rule   { background: var(--cell-green-bg);  color:var(--success); }
.method-badge.bank_mapping { background: var(--cell-yellow-bg); color:var(--warning-text); }
.method-badge.claude       { background:rgba(167,139,250,0.15); color:#a78bfa; }
.method-badge.unclassified { background: var(--cell-red-bg);    color:var(--error); }

/* Category select */
.cat-select { background:var(--surface2); border:1px solid var(--border); border-radius:5px; padding:4px 8px; color:var(--text); font-size:12px; outline:none; cursor:pointer; }
.cat-select:focus { border-color:var(--accent); }
tr.edited .cat-select { border-color:var(--accent); }

/* Amount colors */
.amount-neg { color: var(--error); }
.amount-pos { color: var(--success); }

/* Label cell */
.label-cell { max-width: 280px; overflow:hidden; text-overflow:ellipsis; }
.bank-cat { color:var(--text-muted); font-size:12px; max-width:160px; overflow:hidden; text-overflow:ellipsis; }

/* Confirm bar */
.confirm-bar { display:flex; align-items:center; justify-content:flex-end; gap:16px; padding:16px 0; border-top:1px solid var(--border); }
.btn-confirm { background:var(--success); color:#fff; border:none; border-radius:6px; padding:12px 24px; font-size:14px; font-weight:700; cursor:pointer; transition:opacity 0.15s; }
[data-theme="light"] .btn-confirm { color: #fff; }
.btn-confirm:hover:not(:disabled) { opacity:0.85; }
.btn-confirm:disabled { opacity:0.5; cursor:not-allowed; }
.success { color:var(--success); font-weight:600; }

/* ── Format warning banner ── */
.format-banner {
  display: flex;
  gap: 14px;
  background: var(--warning-bg);
  border: 1px solid rgba(180,83,9,0.3);
  border-radius: var(--radius);
  padding: 16px 20px;
  margin-bottom: 20px;
  align-items: flex-start;
}
.format-banner-icon { font-size: 18px; color: var(--warning-text); flex-shrink: 0; margin-top: 2px; }
.format-banner-body { flex: 1; }
.format-banner-body strong { color: var(--warning-text); display: block; margin-bottom: 8px; }
.format-detail {
  font-family: monospace;
  font-size: 12px;
  color: var(--text-muted);
  white-space: pre-wrap;
  margin: 0;
  line-height: 1.6;
}

/* ── Budget page ── */

.budget-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
  flex-wrap: wrap;
  gap: 12px;
}
.year-tabs { display: flex; gap: 8px; }
.year-tab {
  padding: 7px 18px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 600;
  text-decoration: none;
  color: var(--text-muted);
  border: 1px solid var(--border);
  background: var(--surface2);
  transition: all 0.15s;
}
.year-tab:hover { color: var(--text); }
.year-tab.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.budget-subtitle { font-size: 12px; color: var(--text-muted); }

/* Scrollable table */
.budget-scroll { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); }

.budget-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.budget-table thead th {
  background: var(--surface2);
  padding: 8px 10px;
  text-align: right;
  font-weight: 600;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.budget-table thead th.col-cat { text-align: left; }
.th-sub { font-weight: 400; font-size: 10px; }

/* Column widths */
.col-cat    { width: 160px; min-width: 140px; text-align: left !important; }
.col-budget { width: 72px; }
.col-ytd    { width: 72px; }
.col-var    { width: 72px; font-weight: 600; }
.col-bar    { width: 110px; }
.col-month  { width: 46px; min-width: 40px; text-align: right; }

/* Month highlight */
.month-current { background: rgba(79,126,248,0.08) !important; }
.month-future  { opacity: 0.35; }

/* Group rows */
.group-header {
  background: var(--surface2);
  cursor: pointer;
  user-select: none;
}
.group-header:hover { background: var(--border); }
.group-name {
  padding: 9px 12px;
  font-weight: 700;
  font-size: 12px;
  color: var(--text);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.group-chevron { margin-right: 8px; font-size: 10px; color: var(--text-muted); }
.group-total { font-weight: 600; color: var(--text-muted); padding: 8px 6px; }
.group-spacer td { height: 6px; background: var(--bg); border: none; }

/* Category rows */
.cat-row td {
  padding: 7px 10px;
  border-bottom: 1px solid var(--border);
  text-align: right;
}
.cat-row:last-child td { border-bottom: none; }
.cat-row:hover td { background: rgba(79,126,248,0.04); }
.cat-name { text-align: left !important; color: var(--text); }

/* Editable budget input */
.budget-input {
  width: 58px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 4px;
  padding: 3px 5px;
  color: var(--text);
  font-size: 12px;
  text-align: right;
  outline: none;
  transition: border-color 0.15s, background 0.15s;
}
.budget-input:hover { border-color: var(--border); background: var(--surface2); }
.budget-input:focus { border-color: var(--accent); background: var(--surface2); }
.budget-input.saving { opacity: 0.5; }
.budget-input.saved  { border-color: var(--success); }

/* Variance / status colors — bold text for readability in both themes */
.green   { color: var(--success); font-weight: 600; }
.yellow  { color: var(--warning-text); font-weight: 600; }
.red     { color: var(--error); font-weight: 600; }
.neutral { color: var(--text-muted); }

.cell-green  { background: var(--cell-green-bg)  !important; }
.cell-yellow { background: var(--cell-yellow-bg) !important; }
.cell-red    { background: var(--cell-red-bg)    !important; }

/* Progress bar */
.progress-wrap {
  position: relative;
  background: var(--surface2);
  border-radius: 3px;
  height: 5px;
  overflow: hidden;
  margin-bottom: 3px;
}
.progress-bar {
  height: 100%;
  border-radius: 3px;
  transition: width 0.3s;
}
.progress-bar.green   { background: var(--success); }
.progress-bar.yellow  { background: var(--warning-text); }
.progress-bar.red     { background: var(--error); }
.progress-bar.neutral { background: var(--text-muted); }
.progress-over {
  position: absolute;
  top: 0; right: 0;
  height: 100%;
  background: var(--error);
  opacity: 0.6;
  border-radius: 0 3px 3px 0;
}
.progress-pct { font-size: 10px; }

/* ── Modals ── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 20px;
}
.modal-overlay.hidden { display: none; }
.modal-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  width: 100%;
  max-width: 760px;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.modal-box.modal-wide { max-width: 940px; }
.modal-box.modal-xl   { max-width: 1160px; }
.modal-hd {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  font-size: 14px;
}
.modal-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 18px;
  cursor: pointer;
  padding: 2px 8px;
  border-radius: 4px;
  line-height: 1;
}
.modal-close:hover { background: var(--surface2); color: var(--text); }
.modal-bd { flex: 1; overflow-y: auto; padding: 16px 20px; }
.modal-ft {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  padding: 10px 20px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}
.modal-msg { font-size: 13px; }
.modal-empty { color: var(--text-muted); font-size: 13px; padding: 24px 0; text-align: center; }
.modal-table-wrap { overflow-x: auto; }
.modal-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.modal-table th, .modal-table td {
  padding: 7px 10px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  white-space: nowrap;
}
.modal-table thead th {
  background: var(--surface2);
  font-weight: 600;
  color: var(--text-muted);
  position: sticky;
  top: 0;
}
.modal-table tbody tr:hover td { background: var(--surface2); }
.modal-table tr.edited td { background: rgba(79,126,248,0.07); }

/* Clickable budget cell */
.cell-link { cursor: pointer; }
.cell-link:hover { text-decoration: underline; opacity: 0.85; }

/* Category management */
.cats-input {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 4px 8px;
  color: var(--text);
  font-size: 12px;
  width: 100%;
  outline: none;
}
.cats-input:focus { border-color: var(--accent); }
.cats-num { width: 70px; text-align: right; }
.cats-actions { display: flex; gap: 6px; white-space: nowrap; }
.cats-add-panel {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px;
  margin-bottom: 14px;
}
.cats-add-row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.cats-check-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  white-space: nowrap;
  color: var(--text-muted);
}
.cats-msg { font-size: 12px; margin-top: 8px; color: var(--text-muted); }

/* ── Login page (standalone, no nav) ── */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; }
