:root {
  --primary: #2563EB;
  --primary-light: #EFF6FF;
  --bg: #F1F5F9;
  --card: #FFFFFF;
  --text: #0F172A;
  --muted: #64748B;
  --border: #E2E8F0;
  --success: #10B981;
  --danger: #EF4444;
  --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.05);
  --radius: 12px;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
}

/* ---- Auth Overlay ---- */
.auth-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
}
.auth-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 8px 32px rgba(0,0,0,0.1);
  padding: 40px;
  width: 100%;
  max-width: 420px;
}
.auth-logo {
  font-size: 1.4rem;
  font-weight: 700;
  text-align: center;
  margin-bottom: 6px;
}
.auth-tagline {
  font-size: 0.875rem;
  color: var(--muted);
  text-align: center;
  margin-bottom: 28px;
}
.auth-tabs {
  display: flex;
  background: var(--bg);
  border-radius: 8px;
  padding: 3px;
  gap: 2px;
  margin-bottom: 24px;
}
.auth-tab {
  flex: 1;
  padding: 8px;
  border: none;
  border-radius: 6px;
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  background: transparent;
  color: var(--muted);
  transition: background 0.15s, color 0.15s;
}
.auth-tab.active {
  background: var(--card);
  color: var(--text);
  box-shadow: var(--shadow);
}
.auth-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.form-group {
  display: flex;
  flex-direction: column;
  gap: 5px;
}
.form-group label {
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--muted);
}
.form-group input {
  padding: 9px 13px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.9rem;
  outline: none;
  transition: border-color 0.15s;
}
.form-group input:focus { border-color: var(--primary); }
.auth-error {
  background: #FEE2E2;
  color: #991B1B;
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 0.82rem;
}
.btn-full { width: 100%; padding: 11px; font-size: 0.9rem; }

/* ---- Header ---- */
header {
  background: var(--card);
  border-bottom: 1px solid var(--border);
  padding: 18px 0;
}
.header-content {
  max-width: 920px;
  margin: 0 auto;
  padding: 0 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
header h1 { font-size: 1.4rem; font-weight: 700; }
header p  { color: var(--muted); font-size: 0.875rem; margin-top: 3px; }
.header-user {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}
.user-email {
  font-size: 0.82rem;
  color: var(--muted);
}

/* ---- Layout ---- */
main {
  max-width: 920px;
  margin: 0 auto;
  padding: 24px 20px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}
footer {
  text-align: center;
  padding: 20px;
  color: var(--muted);
  font-size: 0.8rem;
}

/* ---- Card ---- */
.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
}
.card h2 {
  font-size: 1.05rem;
  font-weight: 600;
  margin-bottom: 16px;
}
.section-desc {
  color: var(--muted);
  font-size: 0.875rem;
  margin-bottom: 14px;
}

/* ---- Buttons ---- */
.btn {
  padding: 9px 18px;
  border: none;
  border-radius: 8px;
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s;
  white-space: nowrap;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: #1D4ED8; }
.btn-secondary { background: var(--border); color: var(--text); }
.btn-secondary:hover { background: #CBD5E1; }

/* ---- API Key ---- */
.input-row {
  display: flex;
  gap: 8px;
}
.input-row input {
  flex: 1;
  padding: 9px 13px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.875rem;
  outline: none;
  transition: border-color 0.15s;
  font-family: monospace;
}
.input-row input:focus { border-color: var(--primary); }

.key-status {
  margin-top: 10px;
  font-size: 0.8rem;
  padding: 7px 12px;
  border-radius: 6px;
}
.key-status.success { background: #D1FAE5; color: #065F46; }
.key-status.error   { background: #FEE2E2; color: #991B1B; }

/* ---- Upload Zone ---- */
.upload-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 52px 24px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
}
.upload-zone:hover,
.upload-zone.dragover {
  border-color: var(--primary);
  background: var(--primary-light);
}
.upload-icon {
  font-size: 2.8rem;
  margin-bottom: 12px;
  line-height: 1;
}
.upload-title {
  font-size: 1rem;
  font-weight: 500;
}
.upload-sub {
  color: var(--muted);
  font-size: 0.875rem;
  margin-top: 5px;
}
.upload-link { color: var(--primary); text-decoration: underline; }

.file-info {
  margin-top: 14px;
  padding: 10px 14px;
  background: var(--primary-light);
  border-radius: 8px;
  font-size: 0.875rem;
  color: var(--primary);
  font-weight: 500;
}

/* ---- Processing ---- */
.processing-card {
  text-align: center;
  padding: 48px 24px;
}
.spinner {
  width: 38px;
  height: 38px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.75s linear infinite;
  margin: 0 auto 14px;
}
@keyframes spin { to { transform: rotate(360deg); } }

#processing-text {
  font-weight: 600;
  font-size: 1rem;
  color: var(--text);
}
.processing-sub {
  color: var(--muted);
  font-size: 0.82rem;
  margin-top: 4px;
  min-height: 1.2em;
}
.processing-steps {
  list-style: none;
  display: flex;
  justify-content: center;
  gap: 0;
  margin-top: 24px;
  padding: 0;
  counter-reset: step;
}
.processing-steps li {
  counter-increment: step;
  display: flex;
  flex-direction: column;
  align-items: center;
  font-size: 0.78rem;
  color: var(--muted);
  position: relative;
  min-width: 110px;
}
.processing-steps li::before {
  content: counter(step);
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2px solid var(--border);
  background: var(--card);
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 600;
  margin-bottom: 6px;
  transition: all 0.2s;
  z-index: 1;
}
.processing-steps li + li::after {
  content: '';
  position: absolute;
  top: 14px;
  right: 50%;
  width: 100%;
  height: 2px;
  background: var(--border);
  z-index: 0;
}
.processing-steps li.active {
  color: var(--primary);
}
.processing-steps li.active::before {
  border-color: var(--primary);
  background: var(--primary-light);
  color: var(--primary);
}
.processing-steps li.done {
  color: var(--success);
}
.processing-steps li.done::before {
  content: '\2713';
  border-color: var(--success);
  background: #D1FAE5;
  color: var(--success);
}

/* ---- Summary Cards ---- */
.summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 16px;
}
.summary-card { padding: 20px; }
.summary-label {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.summary-value {
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--text);
  margin-top: 6px;
  line-height: 1.2;
}
.summary-value--sm { font-size: 1.1rem; }
.val-income { color: var(--success); }
.val-spend  { color: var(--danger); }

/* ---- Tabs ---- */
.chart-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  gap: 12px;
}
.chart-card-header h2 { margin-bottom: 0; }
.tabs {
  display: flex;
  background: var(--bg);
  border-radius: 8px;
  padding: 3px;
  gap: 2px;
}
.tab {
  padding: 5px 14px;
  border: none;
  border-radius: 6px;
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  background: transparent;
  color: var(--muted);
  transition: background 0.15s, color 0.15s;
}
.tab.active {
  background: var(--card);
  color: var(--text);
  box-shadow: var(--shadow);
}
.tab:not(.active):hover { color: var(--text); }

/* ---- Chart Grid ---- */
.chart-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}
@media (max-width: 620px) {
  .chart-grid { grid-template-columns: 1fr; }
}
.chart-container {
  height: 270px;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ---- Category List ---- */
#category-list {
  display: flex;
  flex-direction: column;
  gap: 11px;
  max-height: 290px;
  overflow-y: auto;
  padding-right: 4px;
}
.cat-item {
  display: flex;
  align-items: center;
  gap: 9px;
}
.cat-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  flex-shrink: 0;
}
.cat-name {
  flex: 1;
  font-size: 0.875rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.cat-bar-wrap {
  flex: 2;
  background: var(--bg);
  border-radius: 4px;
  height: 5px;
  overflow: hidden;
}
.cat-bar {
  height: 100%;
  border-radius: 4px;
  transition: width 0.5s ease;
}
.cat-amount {
  font-size: 0.82rem;
  font-weight: 600;
  min-width: 75px;
  text-align: right;
}

/* ---- Table ---- */
.table-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  flex-wrap: wrap;
  gap: 10px;
}
.table-controls { display: flex; gap: 8px; flex-wrap: wrap; }
.search-input,
.filter-select {
  padding: 7px 11px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.84rem;
  outline: none;
  background: var(--card);
  transition: border-color 0.15s;
}
.search-input:focus,
.filter-select:focus { border-color: var(--primary); }

.table-wrapper { overflow-x: auto; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}
th {
  text-align: left;
  padding: 9px 12px;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}
th:hover { color: var(--text); }
th.sorted-asc::after  { content: ' \2191'; }
th.sorted-desc::after { content: ' \2193'; }

td {
  padding: 11px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
tr:last-child td { border-bottom: none; }
tr:hover td { background: #FAFAFA; }

.amount-col { text-align: right; }
td.amount-col {
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
td.pos { color: var(--success); }
td.neg { color: var(--danger); }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  border-radius: 20px;
  font-size: 0.78rem;
  font-weight: 500;
}
.badge.editable {
  cursor: pointer;
  transition: box-shadow 0.15s, opacity 0.15s;
}
.badge.editable:hover {
  box-shadow: 0 0 0 2px currentColor;
}
.cat-select {
  padding: 3px 6px;
  border: 2px solid var(--primary);
  border-radius: 6px;
  font-size: 0.8rem;
  outline: none;
  background: var(--card);
  color: var(--text);
  cursor: pointer;
}

/* ---- Results Actions ---- */
.results-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  padding: 16px 24px;
}
.save-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.save-status {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--success);
}

/* ---- Previous Reports ---- */
.reports-heading {
  margin-bottom: 14px;
}
.reports-heading h2 {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text);
}
.reports-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 14px;
}
.report-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 6px;
  transition: box-shadow 0.15s;
}
.report-card:hover {
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}
.report-card-name {
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.report-card-range {
  font-size: 0.8rem;
  color: var(--muted);
}
.report-card-stats {
  display: flex;
  gap: 12px;
  font-size: 0.85rem;
  font-weight: 600;
  margin-top: 2px;
}
.report-card-meta {
  font-size: 0.75rem;
  color: var(--muted);
  margin-top: 2px;
}
.report-card-actions {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}
.btn-sm {
  padding: 5px 12px;
  font-size: 0.8rem;
}
.btn-ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
}
.btn-ghost:hover {
  background: #FEE2E2;
  color: var(--danger);
  border-color: #FECACA;
}

.hidden { display: none !important; }

/* ---- Subscription Wall ---- */
#subscription-wall {
  max-width: 480px;
  margin: 0 auto;
}
.sub-wall-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
  text-align: center;
}
.sub-wall-icon { font-size: 48px; line-height: 1; }
.sub-wall-title { font-size: 1.5rem; font-weight: 700; }
.sub-wall-desc  { color: var(--muted); }
.sub-price      { font-size: 2.25rem; font-weight: 800; color: var(--primary); }
.sub-features {
  list-style: none;
  text-align: left;
  width: 100%;
  max-width: 340px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.sub-features li::before { content: '✓  '; color: var(--success); font-weight: 700; }
.btn-lg { padding: 14px 40px; font-size: 1.05rem; }

/* ---- Subscription badge ---- */
.sub-badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.sub-badge--active  { background: #d1fae5; color: #065f46; }
.sub-badge--warning { background: #fef3c7; color: #92400e; }
