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

:root {
  --green: #16a34a;
  --green-light: #dcfce7;
  --green-dark: #15803d;
  --red: #dc2626;
  --red-light: #fee2e2;
  --red-dark: #b91c1c;
  --gray-50: #f9fafb;
  --gray-100: #f3f4f6;
  --gray-200: #e5e7eb;
  --gray-400: #9ca3af;
  --gray-600: #4b5563;
  --gray-800: #1f2937;
  --gray-900: #111827;
  --blue-50: #eff6ff;
  --blue-600: #2563eb;
  --amber-50: #fffbeb;
  --amber-600: #d97706;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 4px 16px rgba(0,0,0,.06);
  --shadow-lg: 0 4px 6px rgba(0,0,0,.07), 0 10px 40px rgba(0,0,0,.1);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--gray-50);
  color: var(--gray-800);
  line-height: 1.6;
  min-height: 100vh;
}

/* ── HEADER ── */
.header {
  background: #fff;
  border-bottom: 1px solid var(--gray-200);
  padding: 14px 24px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.logo { font-weight: 700; font-size: 1.1rem; color: var(--green); }
.logo span { color: var(--gray-800); }

/* ── HERO ── */
.hero {
  background: linear-gradient(135deg, #f0fdf4 0%, #eff6ff 100%);
  padding: 64px 24px 56px;
  text-align: center;
}
.hero h1 {
  font-size: clamp(1.75rem, 4vw, 2.75rem);
  font-weight: 800;
  color: var(--gray-900);
  line-height: 1.2;
  max-width: 680px;
  margin: 0 auto 16px;
}
.hero h1 em { font-style: normal; color: var(--green); }
.hero p { font-size: 1.1rem; color: var(--gray-600); max-width: 480px; margin: 0 auto 32px; }
.trust-badges { display: flex; justify-content: center; flex-wrap: wrap; gap: 12px; margin-top: 20px; }
.badge {
  background: #fff; border: 1px solid var(--gray-200); border-radius: 999px;
  padding: 6px 14px; font-size: .82rem; color: var(--gray-600);
  display: flex; align-items: center; gap: 5px;
}
.badge .icon { color: var(--green); font-size: .9rem; }

/* ── UPLOAD SECTION ── */
.upload-section { max-width: 680px; margin: -28px auto 0; padding: 0 24px 48px; }
.upload-card { background: #fff; border-radius: var(--radius); box-shadow: var(--shadow-lg); padding: 40px 32px; }
.upload-card h2 { font-size: 1.15rem; font-weight: 700; margin-bottom: 6px; }
.upload-card p  { color: var(--gray-600); font-size: .9rem; margin-bottom: 24px; }

.drop-zone {
  border: 2px dashed var(--gray-200); border-radius: var(--radius);
  padding: 36px 20px; text-align: center; cursor: pointer;
  transition: border-color .2s, background .2s; position: relative;
}
.drop-zone:hover, .drop-zone.drag-over { border-color: var(--green); background: var(--green-light); }
.drop-zone input[type=file] { position: absolute; inset: 0; opacity: 0; cursor: pointer; width: 100%; height: 100%; }
.drop-icon { font-size: 2.4rem; margin-bottom: 10px; }
.drop-zone strong { display: block; font-size: 1rem; color: var(--gray-800); margin-bottom: 4px; }
.drop-zone small  { color: var(--gray-400); font-size: .82rem; }

.btn-primary {
  display: inline-flex; align-items: center; gap: 8px;
  background: var(--green); color: #fff; border: none;
  border-radius: 8px; padding: 13px 28px; font-size: 1rem; font-weight: 600;
  cursor: pointer; transition: background .15s, transform .1s;
  margin-top: 20px; width: 100%; justify-content: center;
}
.btn-primary:hover { background: var(--green-dark); transform: translateY(-1px); }
.btn-primary:active { transform: translateY(0); }

/* ── LOADING ── */
#loading { display: none; text-align: center; padding: 32px 0 8px; }
.spinner {
  width: 40px; height: 40px;
  border: 3px solid var(--gray-200); border-top-color: var(--green);
  border-radius: 50%; animation: spin .7s linear infinite; margin: 0 auto 12px;
}
@keyframes spin { to { transform: rotate(360deg); } }
#loading p { color: var(--gray-600); font-size: .9rem; }

/* ── ERROR ── */
#error-box {
  display: none; background: #fef2f2; border: 1px solid #fecaca;
  border-radius: 8px; padding: 14px 18px; color: #b91c1c; font-size: .9rem; margin-top: 16px;
}

/* ── RESULTS ── */
#results { display: none; max-width: 900px; margin: 0 auto; padding: 0 24px 64px; }
.results-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 28px; flex-wrap: wrap; gap: 12px;
}
.results-header h2 { font-size: 1.35rem; font-weight: 800; }
.btn-secondary {
  background: #fff; border: 1px solid var(--gray-200); border-radius: 8px;
  padding: 9px 18px; font-size: .9rem; font-weight: 600; cursor: pointer;
  color: #374151; transition: border-color .15s;
}
.btn-secondary:hover { border-color: var(--green); color: var(--green); }

/* ── METRIC CARDS ── */
.metrics-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
.metric-card { background: #fff; border-radius: var(--radius); padding: 22px 20px; box-shadow: var(--shadow); }
.metric-card .label { font-size: .75rem; text-transform: uppercase; letter-spacing: .06em; color: var(--gray-400); margin-bottom: 6px; }
.metric-card .value { font-size: 1.55rem; font-weight: 800; color: var(--gray-900); line-height: 1; }
.metric-card .sub   { font-size: .75rem; color: var(--gray-400); margin-top: 5px; }

/* Income card — green */
.metric-card.income  { background: var(--green); }
.metric-card.income  .label { color: rgba(255,255,255,.75); }
.metric-card.income  .value { color: #fff; }
.metric-card.income  .sub   { color: rgba(255,255,255,.65); }

/* Expense card — red */
.metric-card.expense { background: var(--red); }
.metric-card.expense .label { color: rgba(255,255,255,.75); }
.metric-card.expense .value { color: #fff; }
.metric-card.expense .sub   { color: rgba(255,255,255,.65); }

/* Net card — green when surplus, red when deficit */
.metric-card.surplus { background: var(--green-light); border: 1px solid #bbf7d0; }
.metric-card.surplus .label { color: var(--green-dark); }
.metric-card.surplus .value { color: var(--green-dark); }
.metric-card.surplus .sub   { color: var(--green); }
.metric-card.deficit { background: var(--red-light); border: 1px solid #fecaca; }
.metric-card.deficit .label { color: var(--red-dark); }
.metric-card.deficit .value { color: var(--red-dark); }
.metric-card.deficit .sub   { color: var(--red); }

/* fallback highlight */
.metric-card.highlight { background: var(--green); }
.metric-card.highlight .label { color: rgba(255,255,255,.75); }
.metric-card.highlight .value { color: #fff; }

/* ── CHARTS ROW ── */
.charts-row { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin-bottom: 24px; }
@media (max-width: 600px) { .charts-row { grid-template-columns: 1fr; } }
.chart-card { background: #fff; border-radius: var(--radius); box-shadow: var(--shadow); padding: 24px; }
.chart-card h3 { font-size: .82rem; font-weight: 700; color: var(--gray-600); margin-bottom: 16px; text-transform: uppercase; letter-spacing: .05em; }
.chart-card canvas { max-height: 220px; }

/* ── TOP TRANSACTIONS ── */
.top-expenses-card { background: #fff; border-radius: var(--radius); box-shadow: var(--shadow); padding: 24px; margin-bottom: 24px; }
.top-expenses-card h3 { font-size: .82rem; font-weight: 700; color: var(--gray-600); margin-bottom: 16px; text-transform: uppercase; letter-spacing: .05em; }
.expense-item { display: flex; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--gray-100); gap: 12px; }
.expense-item:last-child { border-bottom: none; }
.expense-label  { font-size: .9rem; color: var(--gray-800); flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.expense-bar-wrap { flex: 0 0 120px; height: 6px; background: var(--gray-100); border-radius: 99px; overflow: hidden; }
.expense-bar        { height: 100%; border-radius: 99px; transition: width .6s ease; }
.expense-bar.red    { background: var(--red); }
.expense-bar.green  { background: var(--green); }
.expense-bar.blue   { background: var(--blue-600); }
.expense-amount     { font-size: .9rem; font-weight: 700; color: var(--gray-900); min-width: 80px; text-align: right; }
.expense-type-badge {
  font-size: .68rem; font-weight: 700; padding: 2px 7px; border-radius: 99px;
  text-transform: uppercase; letter-spacing: .04em; flex-shrink: 0;
}
.expense-type-badge.income  { background: var(--green-light); color: var(--green-dark); }
.expense-type-badge.expense { background: var(--red-light);   color: var(--red-dark); }

/* ── AI INSIGHTS ── */
.insights-card {
  background: linear-gradient(135deg, #f0fdf4, #eff6ff);
  border: 1px solid var(--green-light); border-radius: var(--radius);
  padding: 28px; margin-bottom: 24px; box-shadow: var(--shadow);
}
.insights-header { display: flex; align-items: center; gap: 10px; margin-bottom: 16px; }
.insights-header h3 { font-size: 1rem; font-weight: 700; color: var(--gray-900); }
.insights-badge { background: var(--green); color: #fff; font-size: .7rem; font-weight: 700; padding: 3px 9px; border-radius: 99px; letter-spacing: .05em; }
.insights-body  { color: var(--gray-800); font-size: .95rem; line-height: 1.75; white-space: pre-line; }

/* ── FOOTER ── */
footer { background: var(--gray-900); color: var(--gray-400); text-align: center; padding: 40px 24px; font-size: .85rem; }
footer p + p { margin-top: 6px; }
footer a { color: var(--gray-400); text-decoration: underline; }
.footer-trust { color: var(--green); margin-top: 12px; font-size: .8rem; }
