/* Ledger Lens — design tokens + components
   Dark enterprise: near-black, teal accent, borders over shadows, Inter. */

:root {
  /* Color */
  --bg: #0a0a0b;
  --panel: #111113;
  --panel-hover: #141418;
  --border: #26262a;
  --border-row: #1c1c20;
  --text: #f2f2ee;
  --text-2: #a0a0a8;
  --text-3: #6b6b73;
  --accent: #2dd4bf;
  --accent-hover: #4adec8;
  --accent-ink: #062a26;
  --danger: #f87171;
  --warn: #fbbf24;
  --good: #34d399;

  /* Type */
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --t-xs: 11px;
  --t-sm: 12px;
  --t-md: 14px;
  --t-lg: 16px;
  --t-xl: 20px;
  --t-2xl: 28px;
  --t-3xl: 40px;

  /* Space (4px base) */
  --s-1: 4px;  --s-2: 8px;  --s-3: 12px; --s-4: 16px;
  --s-5: 24px; --s-6: 32px; --s-7: 48px; --s-8: 64px;

  /* Shape */
  --r-sm: 8px;
  --r-md: 10px;
  --r-lg: 12px;
}

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

html { color-scheme: dark; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: var(--t-md);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ============ Top bar ============ */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: rgba(10, 10, 11, 0.92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
  height: 64px;
}
.topbar-inner {
  max-width: 1160px;
  margin: 0 auto;
  padding: 0 var(--s-5);
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-4);
}
.brand {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  text-decoration: none;
  color: var(--text);
}
.brand-mark { flex-shrink: 0; }
.brand-name { font-size: var(--t-lg); font-weight: 600; letter-spacing: -0.02em; }
.topbar-actions { display: flex; align-items: center; gap: var(--s-2); flex-wrap: wrap; }
.period-chip {
  font-size: var(--t-sm);
  color: var(--text-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px 12px;
  margin-right: var(--s-2);
  white-space: nowrap;
}

/* ============ Buttons ============ */
.btn {
  font-family: var(--font);
  font-size: var(--t-md);
  font-weight: 600;
  border-radius: var(--r-md);
  padding: 9px 14px;
  cursor: pointer;
  border: 1px solid transparent;
  transition: background 120ms ease, border-color 120ms ease, color 120ms ease;
  white-space: nowrap;
}
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }
.btn-secondary {
  background: transparent;
  color: var(--text);
  border-color: var(--border);
}
.btn-secondary:hover:not(:disabled) { background: var(--panel-hover); border-color: #34343a; }
.btn-danger {
  background: transparent;
  color: var(--danger);
  border-color: var(--border);
}
.btn-danger:hover:not(:disabled) { background: rgba(248, 113, 113, 0.08); border-color: #4a2a2a; }

/* ============ Page / layout ============ */
.page {
  flex: 1;
  width: 100%;
  max-width: 1160px;
  margin: 0 auto;
  padding: var(--s-7) var(--s-5) var(--s-8);
}

.foot {
  border-top: 1px solid var(--border);
  padding: var(--s-5);
  text-align: center;
}
.foot p { font-size: var(--t-sm); color: var(--text-3); }

/* ============ Empty state ============ */
.empty { padding: var(--s-8) 0; }
.empty-inner {
  max-width: 640px;
  margin: 0 auto;
  text-align: center;
}
.empty-title {
  font-size: var(--t-3xl);
  font-weight: 700;
  letter-spacing: -0.04em;
  line-height: 1.05;
  margin-bottom: var(--s-4);
}
.empty-sub {
  font-size: var(--t-lg);
  color: var(--text-2);
  line-height: 1.6;
  margin-bottom: var(--s-6);
  max-width: 52ch;
  margin-left: auto;
  margin-right: auto;
}

.dropzone {
  border: 1px dashed #34343a;
  border-radius: var(--r-lg);
  background: var(--panel);
  padding: var(--s-7) var(--s-5);
  cursor: pointer;
  transition: border-color 120ms ease, background 120ms ease;
}
.dropzone:hover { border-color: var(--accent); background: var(--panel-hover); }
.dropzone:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.dropzone.dragover { border-color: var(--accent); background: rgba(45, 212, 191, 0.05); }
.dropzone.busy { pointer-events: none; opacity: 0.65; border-color: var(--accent); border-style: dashed; animation: dz-pulse 1.2s ease-in-out infinite; }
@keyframes dz-pulse { 0%, 100% { border-color: var(--accent); } 50% { border-color: var(--accent-3); } }
.dropzone-icon { color: var(--text-3); margin: 0 auto var(--s-3); width: 28px; height: 28px; }
.dropzone-icon svg { display: block; margin: 0 auto; }
.dropzone-title { font-size: var(--t-lg); font-weight: 600; }
.dropzone-hint { font-size: var(--t-md); color: var(--text-3); margin-top: var(--s-1); }
.dropzone-browse { color: var(--accent); }
.dropzone-browse:hover { color: var(--accent-hover); }

.empty-foot { margin-top: var(--s-6); display: flex; flex-direction: column; align-items: center; gap: var(--s-3); }
.privacy-note { font-size: var(--t-sm); color: var(--text-3); max-width: 44ch; line-height: 1.6; }

/* Parse status line (shown while processing / errors) */
.parse-status {
  margin-top: var(--s-4);
  font-size: var(--t-md);
  min-height: 22px;
}
.parse-status.error { color: var(--danger); }
.parse-status.ok { color: var(--good); }

/* ============ Report ============ */
.report-head { margin-bottom: var(--s-5); }
.report-title { font-size: var(--t-2xl); font-weight: 700; letter-spacing: -0.03em; }
.report-sub { color: var(--text-2); font-size: var(--t-md); margin-top: var(--s-1); }

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: var(--s-3);
  margin-bottom: var(--s-5);
}
.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: var(--s-4) var(--s-4);
}
.card-label {
  font-size: var(--t-sm);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-3);
  margin-bottom: var(--s-2);
}
.card-value {
  font-size: var(--t-xl);
  font-weight: 700;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}
.card-value.neg { color: var(--danger); }
.card-value.pos { color: var(--good); }
.card-foot { font-size: var(--t-sm); color: var(--text-3); margin-top: var(--s-1); }

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--s-4);
  margin-bottom: var(--s-4);
}
.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: var(--s-5);
  margin-bottom: var(--s-4);
}
.grid-2 .panel { margin-bottom: 0; }
.panel-title { font-size: var(--t-lg); font-weight: 600; letter-spacing: -0.01em; }
.panel-sub { font-size: var(--t-sm); color: var(--text-3); margin: var(--s-1) 0 var(--s-4); }

/* ============ Category bars ============ */
.cat-bars { display: flex; flex-direction: column; gap: var(--s-3); }
.cat-row { display: grid; grid-template-columns: 130px 1fr auto; gap: var(--s-3); align-items: center; }
.cat-name { font-size: var(--t-md); color: var(--text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cat-track { height: 8px; background: #1a1a1e; border-radius: 999px; overflow: hidden; }
.cat-fill { height: 100%; background: var(--accent); border-radius: 999px; }
.cat-fill.alt { background: #1f8a80; }
.cat-val {
  font-size: var(--t-md);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.cat-pct { color: var(--text-3); font-weight: 400; margin-left: var(--s-1); }

/* ============ Trend chart ============ */
.trend-wrap { display: flex; flex-direction: column; gap: var(--s-2); }
.trend-row {
  display: grid;
  grid-template-columns: 72px 1fr 110px;
  gap: var(--s-3);
  align-items: center;
  font-size: var(--t-sm);
}
.trend-month { color: var(--text-2); text-transform: capitalize; font-variant-numeric: tabular-nums; }
.trend-bar {
  height: 14px;
  background: #1a1a1e;
  border-radius: 4px;
  display: flex;
  overflow: hidden;
}
.trend-fill-spend { background: var(--accent); }
.trend-fill-income { background: #1f8a80; }
.trend-val { text-align: right; font-variant-numeric: tabular-nums; color: var(--text-2); white-space: nowrap; }
.trend-val .neg { color: var(--danger); }
.trend-legend { display: flex; gap: var(--s-4); margin-top: var(--s-3); font-size: var(--t-xs); color: var(--text-3); }
.legend-dot { display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 6px; vertical-align: baseline; }

/* ============ Subscriptions ============ */
.sub-list { display: flex; flex-direction: column; }
.sub-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-3);
  padding: var(--s-3) 0;
  border-bottom: 1px solid var(--border-row);
}
.sub-row:last-child { border-bottom: none; }
.sub-merchant { font-weight: 600; font-size: var(--t-md); }
.sub-detail { font-size: var(--t-sm); color: var(--text-3); margin-top: 2px; }
.sub-amt { text-align: right; font-variant-numeric: tabular-nums; }
.sub-amt .per { color: var(--text-3); font-size: var(--t-sm); }
.sub-amt .yr { color: var(--warn); font-size: var(--t-sm); font-weight: 600; }
.sub-empty { color: var(--text-3); font-size: var(--t-md); padding: var(--s-3) 0; }

/* ============ Opportunities ============ */
.opp-list { display: flex; flex-direction: column; gap: var(--s-3); }
.opp {
  border: 1px solid var(--border);
  border-left: 2px solid var(--accent);
  border-radius: var(--r-sm);
  padding: var(--s-3) var(--s-4);
  background: #0e0e10;
}
.opp.high { border-left-color: var(--warn); }
.opp.info { border-left-color: var(--text-3); }
.opp-title { font-weight: 600; font-size: var(--t-md); display: flex; align-items: center; gap: var(--s-2); }
.opp-badge {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding: 2px 7px;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--text-2);
}
.opp.high .opp-badge { color: var(--warn); border-color: #4a3a1a; }
.opp-body { font-size: var(--t-sm); color: var(--text-2); margin-top: var(--s-1); line-height: 1.5; }
.opp-empty { color: var(--text-3); font-size: var(--t-md); }

/* ============ Tables ============ */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: var(--t-md); }
.table th {
  font-size: var(--t-xs);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-3);
  text-align: left;
  font-weight: 600;
  padding: var(--s-2) var(--s-3);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.table td {
  padding: var(--s-2) var(--s-3);
  border-bottom: 1px solid var(--border-row);
  font-variant-numeric: tabular-nums;
}
.table tbody tr { transition: background 100ms ease; }
.table tbody tr:hover { background: var(--panel-hover); }
.table .num { text-align: right; }
.table .merchant-cell { font-weight: 600; white-space: nowrap; }
.table .cat-cell { color: var(--text-2); }
.table .muted { color: var(--text-3); }
.status-ok { color: var(--good); font-size: var(--t-sm); }
.status-warn { color: var(--warn); font-size: var(--t-sm); }

/* ============ Responsive ============ */
@media (max-width: 860px) {
  .grid-2 { grid-template-columns: 1fr; }
  .page { padding: var(--s-5) var(--s-4) var(--s-7); }
  .empty { padding: var(--s-6) 0; }
  .empty-title { font-size: var(--t-2xl); }
  .cat-row { grid-template-columns: 96px 1fr auto; }
}
@media (max-width: 560px) {
  .topbar { height: auto; }
  .topbar-inner { flex-wrap: wrap; padding: var(--s-2) var(--s-4); gap: var(--s-2); }
  .cards { grid-template-columns: 1fr 1fr; }
  .trend-row { grid-template-columns: 56px 1fr 92px; }
  .period-chip { margin-right: 0; }
}
