:root {
  --paper: #EEEAE0;
  --paper-raised: #FAF8F2;
  --ink: #23262B;
  --ink-soft: #5B5F66;
  --navy: #2B3A4A;
  --stamp: #B23A2E;
  --stamp-dark: #8F2E24;
  --green: #3E6259;
  --gold: #C9A227;
  --line: #D6D0C2;

  --font-display: "Special Elite", monospace;
  --font-body: "Inter", system-ui, sans-serif;
  --font-mono: "IBM Plex Mono", monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-body);
}

body {
  padding-bottom: 3rem;
}

button, select, input {
  font-family: inherit;
}

/* ---------- Topbar ---------- */

.topbar {
  background: var(--navy);
  color: #F2EFE6;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.9rem 1.25rem;
  position: sticky;
  top: 0;
  z-index: 20;
  box-shadow: 0 2px 10px rgba(0,0,0,0.15);
}

.brand { display: flex; align-items: center; gap: 0.5rem; }
.brand-mark { font-size: 1.3rem; }
.brand-name {
  font-family: var(--font-display);
  font-size: 1.25rem;
  letter-spacing: 0.03em;
}

.tabs { display: flex; gap: 1.5rem; }
.tab {
  background: none;
  border: none;
  color: #C9CDD6;
  font-size: 0.92rem;
  font-weight: 600;
  padding: 0.35rem 0.1rem;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: color 0.15s, border-color 0.15s;
}
.tab:hover { color: #fff; }
.tab.active { color: #fff; border-bottom-color: var(--stamp); }

main {
  max-width: 780px;
  margin: 0 auto;
  padding: 1.5rem 1.1rem 3rem;
}

.view { display: none; }
.view.active { display: block; animation: fadein 0.25s ease; }

@keyframes fadein {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: none; }
}

/* ---------- Scan hero ---------- */

.scan-hero {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 2.5rem 1rem 1.5rem;
}

.stamp-button { cursor: pointer; }

.stamp-ring {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 168px;
  height: 168px;
  border-radius: 50%;
  border: 3px dashed var(--stamp);
  color: var(--stamp);
  transition: transform 0.15s ease, background 0.15s ease;
  background: var(--paper-raised);
}
.stamp-button:hover .stamp-ring {
  transform: scale(1.03) rotate(-2deg);
  background: #fff;
}
.stamp-button:active .stamp-ring { transform: scale(0.98) rotate(-2deg); }

.stamp-icon { font-size: 2rem; margin-bottom: 0.2rem; }
.stamp-text {
  font-family: var(--font-display);
  font-size: 0.95rem;
  line-height: 1.3;
  letter-spacing: 0.06em;
}

.scan-hint {
  max-width: 32rem;
  color: var(--ink-soft);
  margin: 1.4rem 0 0.6rem;
  line-height: 1.5;
  font-size: 0.95rem;
}

.link-button {
  background: none;
  border: none;
  color: var(--navy);
  text-decoration: underline;
  cursor: pointer;
  font-size: 0.88rem;
  padding: 0.4rem;
}

.scan-status {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.7rem;
  color: var(--ink-soft);
  padding: 1rem;
}
.scan-status.hidden { display: none; }

.spinner {
  width: 18px; height: 18px;
  border: 2px solid var(--line);
  border-top-color: var(--stamp);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Receipt card (signature element) ---------- */

.receipt-card {
  position: relative;
  background: var(--paper-raised);
  margin: 1.4rem 0.4rem;
  padding: 1.4rem 1.3rem 1.1rem;
  box-shadow: 0 3px 10px rgba(35,38,43,0.1);
}

.receipt-card::before,
.receipt-card::after {
  content: "";
  position: absolute;
  left: 0; right: 0;
  height: 9px;
  background:
    linear-gradient(135deg, var(--paper) 50%, transparent 50%) 0 0 / 14px 14px repeat-x,
    linear-gradient(45deg, var(--paper) 50%, transparent 50%) 0 0 / 14px 14px repeat-x;
}
.receipt-card::before { top: -1px; }
.receipt-card::after { bottom: -1px; transform: rotate(180deg); }

.receipt-card .field-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.8rem;
  padding: 0.5rem 0;
  border-bottom: 1px dashed var(--line);
}
.receipt-card .field-row:last-of-type { border-bottom: none; }

.field-label {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ink-soft);
  white-space: nowrap;
}

.field-row input,
.field-row select {
  border: none;
  background: transparent;
  border-bottom: 1px solid transparent;
  text-align: right;
  font-family: var(--font-mono);
  font-size: 0.95rem;
  color: var(--ink);
  padding: 0.15rem 0.1rem;
  flex: 1;
  min-width: 0;
}
.field-row input:focus,
.field-row select:focus {
  outline: none;
  border-bottom-color: var(--stamp);
}

.field-row.amount-row input {
  font-size: 1.3rem;
  font-weight: 600;
  color: var(--stamp-dark);
}

.receipt-thumb {
  width: 100%;
  max-height: 220px;
  object-fit: contain;
  background: var(--paper);
  margin-bottom: 0.8rem;
  border: 1px solid var(--line);
}

.receipt-actions {
  display: flex;
  gap: 0.7rem;
  margin-top: 1rem;
}

.btn {
  flex: 1;
  border: none;
  padding: 0.65rem 1rem;
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
  border-radius: 3px;
}
.btn-primary { background: var(--stamp); color: #fff; }
.btn-primary:hover { background: var(--stamp-dark); }
.btn-secondary { background: transparent; color: var(--ink-soft); border: 1px solid var(--line); }
.btn-secondary:hover { border-color: var(--ink-soft); color: var(--ink); }
.btn-ghost {
  flex: none;
  background: transparent;
  border: none;
  color: var(--ink-soft);
  cursor: pointer;
  font-size: 0.85rem;
  text-decoration: underline;
  padding: 0.3rem;
}

.ai-note {
  font-size: 0.78rem;
  color: var(--stamp-dark);
  margin: -0.3rem 0 0.6rem;
}

/* ---------- Dashboard ---------- */

.period-tabs { display: flex; gap: 1.2rem; margin-bottom: 1.3rem; }
.ptab {
  background: none;
  border: none;
  padding: 0.4rem 0.1rem;
  font-weight: 600;
  color: var(--ink-soft);
  border-bottom: 2px solid transparent;
  cursor: pointer;
}
.ptab.active { color: var(--ink); border-bottom-color: var(--green); }

.totals-row { margin-bottom: 1.6rem; }
.total-label { font-size: 0.85rem; color: var(--ink-soft); text-transform: uppercase; letter-spacing: 0.05em; }
.total-amount {
  font-family: var(--font-display);
  font-size: 2.4rem;
  color: var(--navy);
  margin: 0.15rem 0;
}
.total-sub { font-size: 0.85rem; color: var(--ink-soft); }

.charts-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.2rem;
}
@media (max-width: 680px) {
  .charts-grid { grid-template-columns: 1fr; }
}

.chart-card {
  background: var(--paper-raised);
  border: 1px solid var(--line);
  padding: 1rem 1rem 1.4rem;
  border-radius: 4px;
  position: relative;
}
.chart-card h3 {
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--ink-soft);
  margin: 0 0 0.8rem;
}

.empty-note { color: var(--ink-soft); font-size: 0.85rem; text-align: center; margin-top: 1rem; }
.empty-note.hidden { display: none; }

/* ---------- History ---------- */

.history-filters { margin-bottom: 0.6rem; }
#filterCategory {
  border: 1px solid var(--line);
  background: var(--paper-raised);
  padding: 0.5rem 0.7rem;
  border-radius: 3px;
  font-size: 0.85rem;
  color: var(--ink);
}

.receipt-list { display: flex; flex-direction: column; }

.receipt-list-item {
  background: var(--paper-raised);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 0.8rem 1rem;
  margin: 0.5rem 0.4rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.8rem;
  cursor: pointer;
}
.receipt-list-item:hover { border-color: var(--ink-soft); }

.rli-main { min-width: 0; }
.rli-merchant { font-weight: 600; font-size: 0.95rem; }
.rli-meta {
  font-size: 0.78rem;
  color: var(--ink-soft);
  margin-top: 0.15rem;
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}
.rli-tag {
  background: var(--paper);
  border-radius: 20px;
  padding: 0.1rem 0.55rem;
  font-family: var(--font-mono);
}
.rli-amount {
  font-family: var(--font-mono);
  font-weight: 600;
  color: var(--stamp-dark);
  white-space: nowrap;
  font-size: 1.05rem;
}
