*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0f1117;
  --surface: #1a1d27;
  --surface2: #22263a;
  --border: #2e3250;
  --accent: #6c63ff;
  --accent-light: #8b85ff;
  --green: #22c55e;
  --yellow: #f59e0b;
  --red: #ef4444;
  --text: #e8eaf6;
  --muted: #8892b0;
  --radius: 14px;
}

body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

/* Screens */
.screen { display: none; min-height: 100vh; }
.screen.active { display: block; }

/* Upload Screen */
#upload-screen {
  align-items: center;
  justify-content: center;
  background: radial-gradient(ellipse at top, #1a1040 0%, var(--bg) 60%);
}

.hero { text-align: center; max-width: 520px; padding: 2rem; margin: 0 auto;}

.logo { font-size: 3.5rem; margin-bottom: 1rem; }

h1 {
  font-size: 2.2rem;
  font-weight: 700;
  background: linear-gradient(135deg, #fff 0%, var(--accent-light) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  margin-bottom: 0.75rem;
}

.subtitle { color: var(--muted); font-size: 1.05rem; margin-bottom: 2.5rem; line-height: 1.6; }

.drop-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 2.5rem;
  transition: all 0.2s ease;
  cursor: pointer;
  background: var(--surface);
}

.drop-zone.dragover {
  border-color: var(--accent);
  background: #1e1a40;
  transform: scale(1.01);
}

.drop-icon { font-size: 2.5rem; margin-bottom: 1rem; }
.drop-text { font-size: 1.1rem; font-weight: 500; margin-bottom: 0.4rem; }
.drop-sub { color: var(--muted); font-size: 0.875rem; margin-bottom: 1.5rem; }

.btn-primary {
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 0.75rem 2rem;
  border-radius: 8px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
}
.btn-primary:hover { background: var(--accent-light); transform: translateY(-1px); }

.btn-secondary {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
  padding: 0.6rem 1.25rem;
  border-radius: 8px;
  font-size: 0.9rem;
  cursor: pointer;
  transition: border-color 0.2s;
}
.btn-secondary:hover { border-color: var(--accent); color: var(--accent-light); }

.privacy-note { color: var(--muted); font-size: 0.8rem; margin-top: 1.5rem; }

/* Loading Screen */
#loading-screen {
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 1.5rem;
}

.loading-content { text-align: center; }
.loading-content h2 { font-size: 1.5rem; margin-bottom: 0.5rem; }
.loading-content p { color: var(--muted); }

.spinner {
  width: 52px;
  height: 52px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto 1.5rem;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Results Screen */
#results-screen { flex-direction: column; }

.results-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 2rem;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  position: sticky;
  top: 0;
  z-index: 10;
}

.header-left { display: flex; align-items: center; gap: 0.5rem; font-weight: 600; }
.logo-sm { font-size: 1.4rem; }

.results-main { max-width: 1100px; margin: 0 auto; padding: 2rem; width: 100%; }

.file-info {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.5rem;
  margin-bottom: 2rem;
  font-size: 0.9rem;
  color: var(--muted);
  display: flex;
  gap: 2rem;
  flex-wrap: wrap;
}
.file-info strong { color: var(--text); }

/* Summary Cards */
.summary-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem;
  margin-bottom: 2rem;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  transition: border-color 0.2s;
}
.card:hover { border-color: var(--accent); }
.card-label { color: var(--muted); font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 0.5rem; }
.card-value { font-size: 1.9rem; font-weight: 700; }
.card-value.green { color: var(--green); }
.card-value.yellow { color: var(--yellow); }
.card-value.accent { color: var(--accent-light); }

/* Insights */
.insights-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius);
  padding: 1.5rem;
  margin-bottom: 2rem;
}
.insights-section h2 { font-size: 1rem; margin-bottom: 1rem; color: var(--accent-light); }
.insight-item {
  display: flex;
  gap: 0.75rem;
  align-items: flex-start;
  margin-bottom: 0.6rem;
  font-size: 0.95rem;
  color: var(--muted);
  line-height: 1.5;
}
.insight-item::before { content: '→'; color: var(--accent); flex-shrink: 0; }

/* Table */
.table-section { }
.section-title { font-size: 1.2rem; font-weight: 600; margin-bottom: 1rem; }

.table-wrapper { overflow-x: auto; border-radius: var(--radius); border: 1px solid var(--border); }

table { width: 100%; border-collapse: collapse; background: var(--surface); }

thead tr { background: var(--surface2); }
th {
  padding: 0.85rem 1rem;
  text-align: left;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  font-weight: 600;
  white-space: nowrap;
}

tbody tr {
  border-top: 1px solid var(--border);
  transition: background 0.15s;
}
tbody tr:hover { background: var(--surface2); }

td {
  padding: 0.9rem 1rem;
  font-size: 0.95rem;
  vertical-align: middle;
}

.merchant-name { font-weight: 600; }

.badge {
  display: inline-block;
  padding: 0.2rem 0.65rem;
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 500;
  text-transform: capitalize;
}

.badge-streaming  { background: #1e3a5f; color: #60a5fa; }
.badge-software   { background: #1e3a1e; color: #4ade80; }
.badge-fitness    { background: #3a1e1e; color: #f87171; }
.badge-news       { background: #3a3a1e; color: #fbbf24; }
.badge-food       { background: #3a2a1e; color: #fb923c; }
.badge-cloud      { background: #1e2e3a; color: #38bdf8; }
.badge-gaming     { background: #2e1e3a; color: #c084fc; }
.badge-finance    { background: #1e3a2e; color: #34d399; }
.badge-other      { background: var(--surface2); color: var(--muted); }

.freq-badge {
  background: var(--surface2);
  color: var(--text);
  font-size: 0.78rem;
  padding: 0.2rem 0.6rem;
  border-radius: 20px;
  border: 1px solid var(--border);
}

.confidence-bar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.bar-track {
  width: 60px;
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  overflow: hidden;
}
.bar-fill {
  height: 100%;
  border-radius: 3px;
  background: var(--green);
}
.bar-fill.medium { background: var(--yellow); }
.bar-fill.low    { background: var(--red); }
.confidence-pct { font-size: 0.8rem; color: var(--muted); }

.amount-cell { font-weight: 600; font-variant-numeric: tabular-nums; }
.annual-cell { color: var(--yellow); font-weight: 600; }

/* File Counter */
.file-counter {
  margin-top: 1rem;
  font-size: 0.85rem;
  color: var(--yellow);
  font-weight: 500;
  min-height: 1.2rem;
}

/* File List */
.file-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-top: 0.75rem;
  max-height: 260px;
  overflow-y: auto;
  width: 100%;
}

.file-item {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.55rem 0.85rem;
  font-size: 0.875rem;
  text-align: left;
}

.file-icon { font-size: 1rem; flex-shrink: 0; }

.file-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text);
}

.file-size { color: var(--muted); font-size: 0.78rem; flex-shrink: 0; }

.file-remove {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 0.8rem;
  padding: 0.1rem 0.3rem;
  border-radius: 4px;
  flex-shrink: 0;
  transition: color 0.15s, background 0.15s;
}
.file-remove:hover { color: var(--red); background: rgba(239,68,68,0.1); }

/* Analyze Button */
.btn-analyze {
  margin-top: 1.25rem;
  width: 100%;
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 0.85rem;
  border-radius: 10px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s, opacity 0.2s;
}
.btn-analyze:hover:not(:disabled) { background: var(--accent-light); transform: translateY(-1px); }
.btn-analyze:disabled { cursor: not-allowed; }

/* Toast Notifications */
.toast {
  position: fixed;
  bottom: 2rem;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.75rem 1.5rem;
  border-radius: 8px;
  font-size: 0.9rem;
  opacity: 0;
  transition: opacity 0.3s, transform 0.3s;
  z-index: 100;
  white-space: nowrap;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast-warn  { border-color: var(--yellow); color: var(--yellow); }
.toast-error { border-color: var(--red);    color: var(--red);    }

/* ── Header user pill ─────────────────────────────────────────────────────── */
.header-right {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.user-pill {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 40px;
  padding: 0.35rem 0.85rem 0.35rem 0.35rem;
}

.user-pill-avatar {
  width: 26px; height: 26px;
  background: var(--accent);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.75rem;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
}

.user-pill-name {
  font-size: 0.82rem;
  color: var(--text);
  font-weight: 500;
  max-width: 160px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

@media (max-width: 600px) {
  .user-pill-name { display: none; }
}

@media (max-width: 600px) {
  .results-main { padding: 1rem; }
  h1 { font-size: 1.7rem; }
  .summary-cards { grid-template-columns: 1fr 1fr; }
}