/* ── Reset & tokens ─────────────────────────────── */
:root {
  --bg:           #f4f4f5;
  --surface:      #ffffff;
  --border:       #e4e4e7;
  --border-focus: #3b82f6;
  --text:         #18181b;
  --text-muted:   #71717a;
  --accent:       #2563eb;
  --accent-hover: #1d4ed8;
  --accent-light: #eff6ff;
  --success:      #16a34a;
  --success-bg:   #f0fdf4;
  --success-border:#bbf7d0;
  --error:        #dc2626;
  --error-bg:     #fef2f2;
  --error-border: #fecaca;
  --shadow-sm:    0 1px 2px rgba(0,0,0,.06);
  --shadow:       0 1px 4px rgba(0,0,0,.10);
  --radius:       10px;
  --radius-sm:    6px;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  font-size: 15px;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

[x-cloak] { display: none !important; }

/* ── Nav ────────────────────────────────────────── */
.nav {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}
.nav-inner {
  max-width: 900px;
  margin: 0 auto;
  padding: 0 1.25rem;
  height: 56px;
  display: flex;
  align-items: center;
}
.nav-brand {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text);
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: .4rem;
}
.nav-brand:hover { color: var(--accent); }

/* ── Layout ─────────────────────────────────────── */
.container {
  max-width: 900px;
  margin: 0 auto;
  padding: 2rem 1.25rem;
  flex: 1;
}

/* ── Cards ──────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 1.5rem;
}
.card + .card { margin-top: 1rem; }
.card-title {
  font-size: .875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--text-muted);
  margin-bottom: 1rem;
}

/* ── Buttons ────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .4rem;
  padding: .55rem 1.1rem;
  border-radius: var(--radius-sm);
  font-size: .9rem;
  font-weight: 500;
  border: none;
  cursor: pointer;
  text-decoration: none;
  transition: background .15s, opacity .15s;
}
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary {
  background: var(--accent);
  color: #fff;
}
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }
.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-secondary:hover:not(:disabled) { background: var(--bg); }

/* ── Hero ───────────────────────────────────────── */
.hero { margin-bottom: 1.5rem; }
.hero-title {
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: -.02em;
}
.hero-subtitle {
  color: var(--text-muted);
  margin-top: .25rem;
}

/* ── Upload zone ────────────────────────────────── */
.upload-card { padding: 1.5rem; }

.upload-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 2.5rem 1rem;
  text-align: center;
  cursor: pointer;
  transition: border-color .15s, background .15s;
  user-select: none;
}
.upload-zone:hover,
.upload-zone.drag-over {
  border-color: var(--accent);
  background: var(--accent-light);
}
.upload-icon { font-size: 2.5rem; margin-bottom: .5rem; }
.upload-hint {
  color: var(--text-muted);
  font-size: .9rem;
  line-height: 1.5;
}
.upload-hint-small {
  font-size: .8rem;
  color: var(--text-muted);
}
.upload-filename {
  font-size: .95rem;
  font-weight: 500;
  color: var(--accent);
  word-break: break-all;
}

.upload-actions {
  margin-top: 1rem;
  display: flex;
  justify-content: flex-end;
}

.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  white-space: nowrap;
  border: 0;
}

/* ── Analysis result / error cards ─────────────── */
.result-card {
  margin-top: 1.25rem;
  border-radius: var(--radius);
  padding: 1.25rem;
  border: 1px solid;
}
.success-card {
  background: var(--success-bg);
  border-color: var(--success-border);
}
.error-card {
  background: var(--error-bg);
  border-color: var(--error-border);
}
.result-header {
  display: flex;
  align-items: center;
  gap: .5rem;
  margin-bottom: .75rem;
}
.result-icon { font-size: 1.1rem; }
.result-title { font-size: 1rem; font-weight: 600; }
.result-body { display: flex; flex-direction: column; gap: .4rem; margin-bottom: 1rem; }
.result-row {
  display: flex;
  justify-content: space-between;
  font-size: .9rem;
}
.result-row-total { padding-top: .4rem; border-top: 1px solid var(--border); }
.result-label { color: var(--text-muted); }
.result-total { font-weight: 700; font-size: 1.05rem; }
.result-cta { width: 100%; }

.error-msg { font-size: .9rem; color: var(--error); margin-bottom: .5rem; }
.error-hint { font-size: .8rem; color: var(--text-muted); }

/* ── Receipt list ───────────────────────────────── */
.receipts-section { margin-top: 2.5rem; }
.section-title {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: .75rem;
}
.receipts-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: .5rem;
}
.receipt-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  transition: box-shadow .15s, border-color .15s;
}
.receipt-card:hover { box-shadow: var(--shadow); border-color: #d4d4d8; }
.receipt-card-link {
  display: block;
  padding: .9rem 1.1rem;
  text-decoration: none;
  color: inherit;
}
.receipt-card-main {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 1rem;
}
.receipt-store { font-weight: 500; }
.receipt-total { font-weight: 600; white-space: nowrap; }
.receipt-card-meta {
  display: flex;
  justify-content: space-between;
  font-size: .8rem;
  color: var(--text-muted);
  margin-top: .2rem;
}

#load-more-container {
  margin-top: 1rem;
  display: flex;
  justify-content: center;
}
.load-more { min-width: 120px; }

.empty-state {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--text-muted);
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
}

/* ── Detail page ────────────────────────────────── */
.detail-header { margin-bottom: 1.5rem; }
.back-link {
  color: var(--accent);
  text-decoration: none;
  font-size: .875rem;
  display: inline-block;
  margin-bottom: .5rem;
}
.back-link:hover { text-decoration: underline; }
.detail-title {
  font-size: 1.6rem;
  font-weight: 700;
  letter-spacing: -.02em;
}
.detail-subtitle { color: var(--text-muted); margin-top: .2rem; }

.detail-grid {
  display: grid;
  grid-template-columns: 1fr 280px;
  gap: 1.25rem;
  align-items: start;
}
@media (max-width: 680px) {
  .detail-grid { grid-template-columns: 1fr; }
}

.detail-main { display: flex; flex-direction: column; gap: 1rem; }
.detail-sidebar { display: flex; flex-direction: column; gap: 1rem; }

/* Meta grid */
.meta-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: .75rem;
}
.meta-label { font-size: .75rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: .04em; display: block; }
.meta-value { font-size: .95rem; font-weight: 500; }

/* Items table */
.items-card {}
.table-wrapper { overflow-x: auto; }
.items-table {
  width: 100%;
  border-collapse: collapse;
  font-size: .875rem;
}
.items-table th {
  text-align: left;
  padding: .5rem .75rem;
  font-size: .75rem;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
}
.items-table td {
  padding: .6rem .75rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.items-table tbody tr:last-child td { border-bottom: none; }
.items-table tfoot td {
  padding: .6rem .75rem;
  border-top: 1px solid var(--border);
}
.items-table .num { text-align: right; }
.num-label { color: var(--text-muted); font-size: .875rem; }
.total-row td { font-size: .95rem; }

.category-badge {
  display: inline-block;
  font-size: .75rem;
  padding: .1rem .45rem;
  border-radius: 99px;
  background: var(--accent-light);
  color: var(--accent);
  font-weight: 500;
}
.text-muted { color: var(--text-muted); }

/* Spending breakdown */
.breakdown-list { list-style: none; display: flex; flex-direction: column; gap: .6rem; }
.breakdown-item { display: flex; align-items: center; gap: .5rem; }
.breakdown-label {
  font-size: .8rem;
  width: 80px;
  flex-shrink: 0;
  text-overflow: ellipsis;
  overflow: hidden;
  white-space: nowrap;
}
.breakdown-bar-wrap {
  flex: 1;
  height: 6px;
  background: var(--border);
  border-radius: 99px;
  overflow: hidden;
}
.breakdown-bar {
  height: 100%;
  background: var(--accent);
  border-radius: 99px;
  min-width: 4px;
  transition: width .3s ease;
}
.breakdown-amount {
  font-size: .8rem;
  font-weight: 500;
  white-space: nowrap;
  width: 54px;
  text-align: right;
}

/* Receipt image */
.image-link { display: block; }
.receipt-image {
  width: 100%;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  display: block;
}

/* Error page */
.error-page { text-align: center; }
.error-code { font-size: 3rem; font-weight: 700; color: var(--text-muted); }

/* Footer */
.footer {
  text-align: center;
  padding: 1.5rem;
  font-size: .8rem;
  color: var(--text-muted);
  border-top: 1px solid var(--border);
}

/* ── htmx loading indicator ─────────────────────── */
.htmx-request .htmx-indicator { display: inline-block !important; }
