/* ============================================================
   GROCERY ANALYTICS — DASHBOARD STYLES
   ============================================================ */

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

/* Accessibility — visible keyboard focus ring */
:focus { outline: none; }
:focus-visible {
  outline: 2px solid var(--accent, #E05A3A);
  outline-offset: 2px;
  border-radius: 4px;
}

:root {

  /* ── Chris Frost Design System v1.0 ─────────────────────── */

  /* Colour palette */
  --color-ink:            #1A2636;
  --color-deep:           #2E3E52;
  --color-mid:            #4A627A;
  --color-muted:          #7A8FA6;
  --color-border:         #C2D0DC;
  --color-surface:        #EEF2F7;
  --color-canvas:         #F7F9FC;
  --color-accent:         #E05A3A;
  --color-accent-bg:      rgba(224, 90, 58, 0.10);
  --color-accent-text:    #B03D22;
  --color-accent-dark-text: #F0927A;

  /* Typography */
  --font-sans:      -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  --text-display:   32px;
  --text-heading:   20px;
  --text-body:      15px;
  --text-label:     13px;
  --text-meta:      12px;
  --text-micro:     11px;
  --weight-regular: 400;
  --weight-medium:  500;
  --tracking-display: -0.6px;
  --tracking-heading: -0.2px;
  --leading-tight:  1.2;
  --leading-body:   1.6;

  /* Spacing */
  --space-1:  4px;
  --space-2:  8px;
  --space-3:  12px;
  --space-4:  16px;
  --space-5:  20px;
  --space-6:  24px;
  --space-8:  32px;
  --space-10: 40px;
  --space-12: 48px;

  /* Border radius */
  --radius-sm:   6px;
  --radius-md:   8px;
  --radius-lg:   12px;
  --radius-xl:   16px;
  --radius-full: 9999px;

  /* Borders */
  --border-light:  0.5px solid var(--color-border);
  --border-dark:   1px solid var(--color-mid);
  --border-accent: 1px solid var(--color-accent);

  /* Shadows */
  --shadow-card:  0 1px 3px rgba(26, 38, 54, 0.08), 0 1px 2px rgba(26, 38, 54, 0.04);
  --shadow-modal: 0 8px 30px rgba(26, 38, 54, 0.16);

  /* ── App-level aliases (keep existing component styles working) ── */

  --bg:           #F7F9FC;   /* canvas — page background */
  --surface:      #FFFFFF;   /* white — cards, panels, header */
  --surface2:     #EEF2F7;   /* surface — inner elements, rows, stat blocks */
  --border:       #C2D0DC;
  --text:         #1A2636;   /* ink */
  --text-muted:   #7A8FA6;   /* muted */
  --accent:       #E05A3A;   /* coral */
  --accent-hover: #C94E30;
  --muted:        var(--color-muted);             /* alias — fixes var(--muted) refs */
  --hover:        rgba(26, 38, 54, 0.04);         /* subtle hover on white surfaces */
  --green:        #16a34a;   /* semantic: savings, positive deltas */
  --red:          #dc2626;   /* semantic: errors, flags */
  --yellow:       #d97706;   /* semantic: warnings */
  --radius:       12px;
  --shadow:       var(--shadow-card);

  /* Category colour palette */
  --c-fruit:         #f97316;
  --c-vegetables:    #22c55e;
  --c-dairy:         #facc15;
  --c-meat:          #ef4444;
  --c-fish:          #06b6d4;
  --c-deli:          #f59e0b;
  --c-bakery:        #d97706;
  --c-cereals:       #fbbf24;
  --c-dry_goods:     #a16207;
  --c-tins_jars:     #fb923c;
  --c-condiments:    #84cc16;
  --c-snacks:        #a855f7;
  --c-beverages:     #3b82f6;
  --c-alcohol:       #8b5cf6;
  --c-frozen:        #67e8f9;
  --c-household:     #94a3b8;
  --c-personal_care: #f472b6;
  --c-baby:          #fda4af;
  --c-pet:           #86efac;
  --c-supplements:   #10b981;
  --c-other:         #6b7280;
}

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

/* ============================================================
   HEADER
   ============================================================ */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

/* CF logomark — 44×44 rounded square, Ink bg, Coral text */
.cf-logo {
  width: 34px;
  height: 34px;
  background: var(--color-ink);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--color-accent);
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0.01em;
  flex-shrink: 0;
  font-family: var(--font-sans);
}
.header h1 { font-size: 1.2rem; font-weight: 500; letter-spacing: -0.02em; }
.header-right { display: flex; gap: 10px; align-items: center; }

/* User avatar / dropdown */
.user-menu { position: relative; }
.user-avatar-btn {
  background: none; border: none; cursor: pointer; padding: 0;
  display: flex; align-items: center;
}
.user-avatar {
  width: 28px; height: 28px; border-radius: 50%;
  border: 2px solid var(--border); object-fit: cover;
}
.user-dropdown {
  position: absolute; top: calc(100% + 8px); right: 0;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; padding: 0.5rem 0; min-width: 200px;
  box-shadow: var(--shadow-modal); z-index: 200;
}
.user-dropdown-name  { font-weight: 600; font-size: 0.9rem; padding: 0.4rem 1rem 0.1rem; }
.user-dropdown-email { font-size: 0.8rem; color: var(--color-mid); padding: 0 1rem 0.4rem; }
.user-dropdown-divider { border: none; border-top: 1px solid var(--border); margin: 0.25rem 0; }
.user-dropdown-item {
  display: block; width: 100%; text-align: left; background: none; border: none;
  padding: 0.45rem 1rem; font-size: 0.875rem; color: var(--text); cursor: pointer;
}
.user-dropdown-item:hover { background: var(--hover); }
.user-dropdown-section-label { font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--color-muted); padding: 0.4rem 1rem 0.1rem; }
.user-dropdown-household-name { font-size: 0.85rem; font-weight: 600; padding: 0 1rem 0.2rem; }
.user-dropdown-members { padding: 0 1rem 0.3rem; }
.household-member { font-size: 0.8rem; color: var(--color-mid); padding: 0.1rem 0; }
.member-role { font-size: 0.7rem; background: var(--accent); color: #fff; border-radius: 3px; padding: 0 4px; margin-left: 4px; }
.household-invite-btn { color: var(--accent) !important; }

/* ============================================================
   FILTER BAR
   ============================================================ */
.filter-bar {
  display: flex;
  align-items: flex-end;
  gap: 12px;
  padding: 14px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.filter-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.filter-group label {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}
.filter-group input,
.filter-group select {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  padding: 7px 11px;
  font-size: 0.875rem;
  outline: none;
  transition: border-color 0.15s;
}
.filter-group input:focus,
.filter-group select:focus { border-color: var(--accent); }

.filter-group--presets { gap: 6px; }

.date-presets {
  display: flex;
  gap: 5px;
  flex-wrap: wrap;
}

.preset-chip {
  padding: 5px 11px;
  border-radius: 20px;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text-muted);
  transition: background 0.15s, color 0.15s, border-color 0.15s;
  white-space: nowrap;
}
.preset-chip:hover {
  background: var(--border);
  color: var(--text);
}
.preset-chip.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

/* ============================================================
   BUTTONS
   ============================================================ */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: 8px;
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: background 0.15s, opacity 0.15s;
  white-space: nowrap;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }

.btn-secondary {
  background: var(--surface2);
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-secondary:hover:not(:disabled) { background: var(--border); }

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
}
.btn-ghost:hover:not(:disabled) { color: var(--text); border-color: var(--text-muted); }

.btn-danger { background: var(--red); color: #fff; }
.btn-sm { padding: 5px 10px; font-size: 0.8rem; }

/* ============================================================
   MAIN LAYOUT
   ============================================================ */
.main {
  max-width: 1400px;
  margin: 0 auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* ============================================================
   STAT CARDS
   ============================================================ */
.stat-cards {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 16px;
}

@media (max-width: 1200px) { .stat-cards { grid-template-columns: repeat(3, 1fr); } }
@media (max-width: 700px)  { .stat-cards { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 500px)  { .stat-cards { grid-template-columns: 1fr; } }

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 22px;
}
.stat-label {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-bottom: 8px;
}
.stat-value {
  font-size: 1.9rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  color: var(--text);
}
.stat-card--discount .stat-value { color: #22c55e; }
.stat-card--organic .stat-value  { color: #4ade80; }
.premium-positive { color: #f87171; font-weight: 600; }
.premium-negative { color: #4ade80; font-weight: 600; }
.chart-subtext { font-size: 0.8rem; color: var(--color-mid); margin: -8px 0 12px; }
.stat-sub {
  font-size: 0.7rem;
  color: var(--color-mid);
  margin-top: 4px;
}

/* ============================================================
   CHART CARDS
   ============================================================ */
.chart-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 22px;
}
.chart-wide { width: 100%; }
.chart-row { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
@media (max-width: 800px) { .chart-row { grid-template-columns: 1fr; } }

.chart-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 18px;
  flex-wrap: wrap;
  gap: 8px;
}
.chart-header h2 { font-size: 1rem; font-weight: 600; }
.chart-header-controls { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

/* Chart mode toggle (Total / Category / Item Type) */
.chart-mode-toggle { display: flex; border: 1px solid var(--border); border-radius: 6px; overflow: hidden; }
.chart-mode-btn {
  background: var(--surface2); border: none; padding: 5px 10px;
  font-size: 0.78rem; font-weight: 500; color: var(--text-muted);
  cursor: pointer; transition: background 0.15s, color 0.15s;
  border-right: 1px solid var(--border);
}
.chart-mode-btn:last-child { border-right: none; }
.chart-mode-btn.active { background: var(--accent); color: #fff; }
.chart-mode-btn:hover:not(.active) { background: var(--surface3, #2a2d3e); color: var(--text); }

/* Segmented toggle (By Name / By Item Type) */
.toggle-group { display: flex; border: 1px solid var(--border); border-radius: 6px; overflow: hidden; }
.toggle-btn {
  background: var(--surface2); border: none; padding: 5px 12px;
  font-size: 0.78rem; font-weight: 500; color: var(--text-muted);
  cursor: pointer; transition: background 0.15s, color 0.15s;
  border-right: 1px solid var(--border);
}
.toggle-btn:last-child { border-right: none; }
.toggle-btn:hover { background: var(--border); color: var(--text); }
.toggle-btn.active { background: var(--accent); color: #fff; }

/* Classify banner */
.classify-banner {
  display: flex; align-items: center; gap: 10px;
  background: rgba(224, 90, 58, 0.06); border: 1px solid rgba(224, 90, 58, 0.20);
  border-radius: 6px; padding: 8px 12px; margin-bottom: 14px;
  font-size: 0.82rem; color: var(--color-mid);
}
.btn-classify {
  background: rgba(224, 90, 58, 0.10); border: 1px solid rgba(224, 90, 58, 0.30);
  color: var(--color-accent-text); padding: 4px 10px; font-size: 0.78rem;
  border-radius: 5px; cursor: pointer; white-space: nowrap;
}
.btn-classify:hover { background: rgba(224, 90, 58, 0.18); }
.btn-classify:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-sm { padding: 4px 10px; font-size: 0.78rem; }

.weeks-select {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  padding: 5px 9px;
  font-size: 0.8rem;
  outline: none;
}

.chart-container { position: relative; height: 260px; }
.chart-donut { height: 300px; }

.chart-empty {
  text-align: center;
  color: var(--text-muted);
  padding: 40px 0;
  font-size: 0.875rem;
}

/* ============================================================
   RECEIPTS TABLE
   ============================================================ */
.table-wrap { overflow-x: auto; }

.receipts-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}
.receipts-table th {
  text-align: left;
  padding: 10px 12px;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.receipts-table td {
  padding: 11px 12px;
  border-bottom: 1px solid var(--border);
  color: var(--text);
}
.receipts-table tbody tr:hover { background: var(--surface2); }
.receipts-table tbody tr:last-child td { border-bottom: none; }

.loading-cell { text-align: center; color: var(--text-muted); padding: 32px; }

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.badge-processed { background: rgba(62, 207, 142, 0.15); color: var(--green); }
.badge-pending   { background: rgba(251, 191, 36, 0.15);  color: var(--yellow); }
.badge-failed    { background: rgba(248, 113, 113, 0.15); color: var(--red); }

.failed-retry-note {
  font-size: 0.68rem;
  color: var(--text-muted);
  margin-top: 3px;
  font-style: italic;
}

.receipts-count { font-size: 0.8rem; color: var(--color-mid); }

.action-btns { display: flex; gap: 6px; }

/* Pagination */
.pagination {
  display: flex;
  justify-content: center;
  gap: 6px;
  margin-top: 16px;
  flex-wrap: wrap;
}
.page-btn {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  padding: 5px 12px;
  font-size: 0.8rem;
  cursor: pointer;
}
.page-btn.active { background: var(--accent); border-color: var(--accent); }
.page-btn:hover:not(.active) { border-color: var(--text-muted); }

/* ============================================================
   MODALS
   ============================================================ */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.65);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 20px;
}
.modal-overlay.hidden { display: none; }

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  width: 100%;
  max-width: 520px;
  box-shadow: var(--shadow-modal);
  display: flex;
  flex-direction: column;
  max-height: 90vh;
}
.modal-large { max-width: 780px; }

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 22px;
  border-bottom: 1px solid var(--border);
}
.modal-header h2 { font-size: 1rem; font-weight: 600; }
.modal-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.4rem;
  cursor: pointer;
  line-height: 1;
  padding: 0 4px;
}
.modal-close:hover { color: var(--text); }

.modal-body { padding: 22px; overflow-y: auto; flex: 1 1 auto; }
.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 14px 22px;
  border-top: 1px solid var(--border);
}

/* Drop zone */
.drop-zone {
  border: 2px dashed var(--border);
  border-radius: 10px;
  padding: 32px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  min-height: 200px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.drop-zone.drag-over { border-color: var(--accent); background: rgba(224, 90, 58, 0.05); }

.drop-zone-inner { display: flex; flex-direction: column; align-items: center; gap: 10px; }
.drop-icon { font-size: 2.5rem; }
.drop-text { font-weight: 600; }
.drop-subtext { color: var(--color-mid); font-size: 0.8rem; }

.drop-preview { display: flex; flex-direction: column; align-items: center; gap: 10px; }
.drop-preview img { max-height: 200px; max-width: 100%; border-radius: 8px; object-fit: contain; }
.preview-name { font-size: 0.8rem; color: var(--color-mid); }

.upload-status {
  margin-top: 14px;
  padding: 12px 14px;
  border-radius: 8px;
  font-size: 0.875rem;
}
.upload-status.success { background: rgba(62, 207, 142, 0.1); color: var(--green); }
.upload-status.error   { background: rgba(248, 113, 113, 0.1); color: var(--red); }
.upload-status.loading { background: var(--surface2); color: var(--text-muted); }

/* Detail modal — layout */
.detail-layout { display: flex; gap: 20px; }
.detail-main { flex: 1; min-width: 0; }
.detail-layout--split .detail-main { flex: 0 0 55%; }

.detail-image-panel { flex: 0 0 42%; overflow-y: auto; max-height: 70vh; border-left: 1px solid var(--border); padding-left: 18px; }
.detail-image-wrap { display: flex; align-items: flex-start; }
.receipt-image { width: 100%; border-radius: 6px; box-shadow: var(--shadow); }

.detail-image-toggle { margin: 10px 0 14px; }

/* When split, widen the modal */
.modal-large.modal-xl { max-width: 1100px; }

/* Detail meta */
.detail-meta { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 20px; margin-bottom: 18px; }
.detail-meta-item { font-size: 0.8rem; }
.detail-meta-label { color: var(--text-muted); font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.05em; }
.detail-meta-value { font-weight: 600; margin-top: 2px; }

.items-table { width: 100%; border-collapse: collapse; font-size: 0.8rem; margin-top: 8px; }
.items-table th {
  text-align: left;
  padding: 7px 10px;
  font-size: 0.65rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
}
.items-table td { padding: 8px 10px; border-bottom: 1px solid var(--border); }
.items-table tbody tr:last-child td { border-bottom: none; }

.discount-summary {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  margin-top: 8px;
  background: rgba(34, 197, 94, 0.08);
  border: 1px solid rgba(34, 197, 94, 0.2);
  border-radius: var(--radius);
  font-size: 0.85rem;
}
.discount-summary-label { font-weight: 600; color: #22c55e; }
.discount-summary-value { color: var(--color-mid); }

/* Category dot */
.cat-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 5px;
}

/* ============================================================
   TOAST
   ============================================================ */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 18px;
  font-size: 0.875rem;
  box-shadow: var(--shadow);
  z-index: 300;
  transition: opacity 0.3s;
}
.toast.success { border-color: var(--green); color: var(--green); }
.toast.error   { border-color: var(--red);   color: var(--red); }
.toast.hidden  { display: none; }

/* ============================================================
   QUALITY BADGES & REPORT
   ============================================================ */

/* Inline quality badge in receipts table */
.quality-badge {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 12px;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  white-space: nowrap;
}
.quality-complete  { background: rgba(62,207,142,0.15); color: var(--green); border: 1px solid rgba(62,207,142,0.3); }
.quality-partial   { background: rgba(251,191,36,0.15);  color: var(--yellow); border: 1px solid rgba(251,191,36,0.3); }
.quality-incomplete { background: rgba(248,113,113,0.15); color: var(--red); border: 1px solid rgba(248,113,113,0.3); }
.quality-na        { background: transparent; color: var(--text-muted); border: none; }

/* Quality checklist in receipt detail modal */
.quality-detail-section { margin: 12px 0 18px; }
.quality-checklist { display: flex; gap: 8px; flex-wrap: wrap; }
.qc-row { display: flex; align-items: center; gap: 5px; font-size: 0.82rem; background: var(--surface2); border-radius: 8px; padding: 5px 10px; }
.qc-ok   { color: var(--green); font-weight: 700; }
.qc-fail { color: var(--red);   font-weight: 700; }
.qc-label { color: var(--text-muted); margin-right: 3px; }
.qc-value { color: var(--text); font-weight: 600; }
.qc-missing { color: var(--text-muted); font-style: italic; }

/* Scan quality report modal content */
.quality-summary-row {
  display: flex; gap: 12px; flex-wrap: wrap; margin-bottom: 20px;
  padding: 14px 16px; background: var(--surface2); border-radius: var(--radius);
}
.quality-summary-stat { display: flex; flex-direction: column; align-items: center; min-width: 60px; }
.qs-num   { font-size: 1.5rem; font-weight: 800; color: var(--text); }
.qs-label { font-size: 0.72rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.04em; }
.qss-complete .qs-num  { color: var(--green); }
.qss-partial .qs-num   { color: var(--yellow); }
.qss-incomplete .qs-num { color: var(--red); }

.quality-report-list { display: flex; flex-direction: column; gap: 6px; }
.quality-report-row {
  display: grid;
  grid-template-columns: 180px 1fr auto;
  grid-template-rows: auto auto;
  gap: 2px 12px;
  padding: 10px 14px;
  background: var(--surface2); border-radius: 8px; align-items: center;
}
.qr-filename { font-size: 0.82rem; color: var(--color-mid); font-family: monospace; grid-row: 1; }
.qr-meta     { font-size: 0.85rem; color: var(--text); grid-row: 1; }
.qr-badge    { grid-row: 1; text-align: right; }
.qr-checks   { grid-column: 1 / -1; grid-row: 2; display: flex; gap: 5px; flex-wrap: wrap; margin-top: 4px; }

/* Small check pills in quality report */
.qc-pill {
  font-size: 0.7rem; font-weight: 600; padding: 2px 8px;
  border-radius: 10px; white-space: nowrap; cursor: default;
}
.qcp-ok   { background: rgba(62,207,142,0.12); color: var(--green); }
.qcp-fail { background: rgba(248,113,113,0.12); color: var(--red); }

/* ============================================================
   TOP ITEMS LIST
   ============================================================ */
.top-items-list { border-top: 1px solid var(--border); margin-top: 12px; padding-top: 4px; }
.top-items-table { width: 100%; border-collapse: collapse; font-size: 0.8rem; }
.top-items-table th {
  text-align: left; padding: 6px 8px; font-size: 0.65rem; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-muted);
  border-bottom: 1px solid var(--border);
}
.top-items-table td { padding: 7px 8px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.top-items-table tbody tr:last-child td { border-bottom: none; }
.top-item-rank { color: var(--text-muted); font-size: 0.72rem; width: 24px; }
.top-item-name { font-weight: 500; }
.top-item-subtitle { font-size: 0.72rem; color: var(--color-mid); font-style: italic; }

/* Item flag button — compact */
.btn-xs { padding: 2px 6px !important; font-size: 0.72rem !important; line-height: 1.4; }
.item-flag-btn { opacity: 0.35; transition: opacity 0.15s; }
.item-flag-btn:hover, .item-flag-btn.has-flag { opacity: 1; }
.item-flag-btn.has-flag { color: var(--red) !important; }

/* Price per unit sub-label in receipt item rows */
.price-per-unit {
  display: inline-block;
  font-size: 0.7rem;
  color: var(--color-mid);
  letter-spacing: 0.01em;
}

/* Item type badge in receipt detail modal */
.item-type-tag {
  display: inline-block;
  font-size: 0.68rem;
  padding: 1px 6px;
  border-radius: 10px;
  background: rgba(224, 90, 58, 0.10);
  color: var(--color-accent-text);
  cursor: pointer;
  margin-top: 3px;
  transition: background 0.15s;
  user-select: none;
}
.item-type-tag:hover { background: rgba(224, 90, 58, 0.20); }
.item-type-tag.unclassified {
  background: var(--color-surface);
  color: var(--text-muted);
}
.item-type-tag.unclassified:hover { background: var(--border); color: var(--text); }

/* Category tag (receipt detail modal — clickable) */
.cat-tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 0.8rem;
  padding: 1px 6px 1px 4px;
  border-radius: 10px;
  background: color-mix(in srgb, var(--cat-color, #7b82a0) 15%, transparent);
  color: var(--text);
  cursor: pointer;
  transition: background 0.15s;
  user-select: none;
}
.cat-tag:hover { background: color-mix(in srgb, var(--cat-color, #7b82a0) 28%, transparent); }
.cat-tag--user { outline: 1px solid color-mix(in srgb, var(--cat-color, #7b82a0) 50%, transparent); }

/* Assign type button */
.assign-type-btn { opacity: 0.35; transition: opacity 0.15s; }
.assign-type-btn:hover, .assign-type-btn.has-type { opacity: 1; }
.assign-type-btn.has-type { color: var(--accent) !important; }

/* Assign-type modal split layout */
.assign-type-layout { display: flex; gap: 20px; }
.assign-type-form { flex: 1; min-width: 0; }
.assign-type-image-panel { flex: 0 0 45%; overflow-y: auto; max-height: 65vh; border-left: 1px solid var(--border); padding-left: 18px; }
.assign-type-image-panel .receipt-image { width: 100%; border-radius: 6px; box-shadow: var(--shadow); }
.assign-type-img-toggle { margin: 8px 0 14px; }
#assign-type-modal-inner.assign-type-split { max-width: 900px; }

/* Helper text below inputs */
.helper-text { font-size: 0.75rem; color: var(--color-mid); margin-top: 6px; line-height: 1.4; }

/* Item feedback subject line */
.item-feedback-subject { display: flex; align-items: center; gap: 7px; padding: 10px 12px;
  background: var(--surface2); border-radius: 6px; margin-bottom: 16px;
  font-size: 0.88rem; }

/* ============================================================
   FEEDBACK SYSTEM
   ============================================================ */
.feedback-intro { font-size: 0.8rem; color: var(--color-mid); margin-bottom: 16px; }
.feedback-intro code { background: var(--surface2); padding: 1px 5px; border-radius: 3px; font-size: 0.75rem; }

.feedback-flags { margin-bottom: 14px; }
.feedback-flag-label { display: block; font-size: 0.7rem; font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.06em; color: var(--text-muted); margin-bottom: 8px; }
.feedback-checkboxes { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.feedback-checkboxes label { display: flex; align-items: center; gap: 7px; font-size: 0.82rem;
  cursor: pointer; padding: 6px 8px; border-radius: 6px; transition: background 0.15s; }
.feedback-checkboxes label:hover { background: var(--surface2); }
.feedback-checkboxes input[type="checkbox"] { accent-color: var(--red); width: 14px; height: 14px; }

.feedback-notes-wrap { margin-top: 12px; }
.feedback-textarea { width: 100%; border: 1px solid var(--border); border-radius: 6px;
  padding: 9px 11px; font-size: 0.82rem; font-family: inherit; background: var(--bg);
  color: var(--text); resize: vertical; }
.feedback-textarea:focus { outline: none; border-color: var(--accent); }

/* Feedback modal split layout (with receipt image) */
.feedback-layout { display: flex; gap: 20px; }
.feedback-form { flex: 1; min-width: 0; }
.feedback-image-panel { flex: 0 0 44%; overflow-y: auto; max-height: 65vh;
  border-left: 1px solid var(--border); padding-left: 18px; }
.feedback-image-panel .receipt-image { width: 100%; border-radius: 6px; box-shadow: var(--shadow); }
.feedback-modal-wide { max-width: 900px; }

.btn-danger { background: var(--red); color: #fff; }
.btn-danger:hover { opacity: 0.88; }

/* Detail modal action row */
.detail-actions-row { display: flex; gap: 8px; margin: 10px 0 14px; flex-wrap: wrap; }
.feedback-open-btn.has-flag { color: var(--red) !important; }

/* Existing feedback display in detail modal */
.existing-feedback { background: rgba(248,113,113,0.06); border: 1px solid rgba(248,113,113,0.25);
  border-radius: 6px; padding: 10px 12px; margin-bottom: 14px; }
.existing-feedback-tags { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 4px; }
.existing-feedback-notes { font-size: 0.8rem; color: var(--color-mid); margin-top: 6px; }

/* Flag tag pill */
.flag-tag { display: inline-block; font-size: 0.7rem; font-weight: 600; padding: 2px 7px;
  border-radius: 10px; background: rgba(248,113,113,0.12); color: var(--red); text-transform: capitalize; }

/* Row flag in table */
.row-flag-icon { margin-left: 6px; font-size: 0.85rem; vertical-align: middle; }
.row-flagged td { background: rgba(248,113,113,0.03); }
.organic-badge { margin-left: 5px; font-size: 0.8rem; vertical-align: middle; opacity: 0.85; }
.item-actions-cell { white-space: nowrap; }
.item-delete-btn { opacity: 0.25; transition: opacity 0.15s; margin-left: 2px; }
.item-delete-btn:hover { opacity: 1; }
.item-delete-btn--armed { opacity: 1 !important; color: #f87171 !important; font-weight: 600; }

/* Receipt ID column */
.receipt-id-cell { color: var(--text-muted); font-size: 0.75rem; font-variant-numeric: tabular-nums; white-space: nowrap; }

/* Flagged receipts modal */
.flagged-row { padding: 14px 0; border-bottom: 1px solid var(--border); }
.flagged-row:last-child { border-bottom: none; }
.flagged-row-header { display: flex; gap: 12px; align-items: center; flex-wrap: wrap;
  font-size: 0.82rem; margin-bottom: 6px; }
.flagged-filename { font-weight: 600; font-family: monospace; font-size: 0.78rem; color: var(--text-muted); }
.flagged-tags { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 4px; }
.flagged-notes { font-size: 0.8rem; color: var(--color-mid); font-style: italic; margin-top: 5px; }

/* ============================================================
   UTILITY
   ============================================================ */
.hidden { display: none !important; }

/* Spinner used in buttons */
@keyframes spin { to { transform: rotate(360deg); } }
.spinner {
  width: 14px;
  height: 14px;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  display: inline-block;
}

/* ============================================================
   TAB NAVIGATION
   ============================================================ */
.tab-nav {
  display: flex;
  gap: 0;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
}
.tab-btn {
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--color-mid);
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 500;
  padding: 12px 18px;
  transition: color 0.15s, border-color 0.15s;
  margin-bottom: -1px;
}
.tab-btn:hover { color: var(--text); }
.tab-btn.active { color: var(--accent); border-bottom-color: var(--accent); }

/* ============================================================
   PLANNER TAB
   ============================================================ */
.planner-empty {
  color: var(--color-mid);
  padding: 24px 0;
  text-align: center;
  font-size: 0.9rem;
}

/* Plan item rows */
.plan-group { margin-bottom: 8px; }
.plan-group-title {
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin: 16px 0 8px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
}
.plan-group-title--overdue { color: var(--red); }
.plan-group-title--soon    { color: #facc15; }

.plan-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.plan-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: var(--surface2);
  border-radius: 6px;
  font-size: 0.875rem;
}
.plan-item-name { flex: 1; font-weight: 500; }
.plan-item-meta { color: var(--color-mid); font-size: 0.78rem; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* Small dismiss dropdown */
.dismiss-wrap { position: relative; }
.dismiss-menu {
  position: absolute;
  right: 0;
  top: calc(100% + 4px);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  z-index: 100;
  min-width: 140px;
  box-shadow: var(--shadow-modal);
}
.dismiss-option {
  display: block;
  width: 100%;
  background: none;
  border: none;
  color: var(--text);
  cursor: pointer;
  font-size: 0.8rem;
  padding: 8px 12px;
  text-align: left;
}
.dismiss-option:hover { background: var(--surface2); }

/* Export dropdown */
.export-wrap { position: relative; }
.export-menu {
  position: absolute;
  right: 0;
  top: calc(100% + 4px);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  z-index: 100;
  min-width: 160px;
  box-shadow: var(--shadow-modal);
}
.export-option {
  display: block;
  width: 100%;
  background: none;
  border: none;
  color: var(--text);
  cursor: pointer;
  font-size: 0.8rem;
  padding: 8px 12px;
  text-align: left;
}
.export-option:hover { background: var(--surface2); }

/* Cadence / confidence badges */
.badge {
  display: inline-block;
  padding: 2px 7px;
  border-radius: 10px;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.03em;
}
.badge-weekly    { background: rgba(224, 90, 58, 0.12); color: var(--color-accent-text); }
.badge-biweekly  { background: rgba(34,197,94,0.15);  color: #4ade80; }
.badge-monthly   { background: rgba(250,204,21,0.15); color: #fcd34d; }
.badge-adhoc     { background: rgba(123,130,160,0.15); color: var(--text-muted); }
.badge-paused    { background: rgba(248,113,113,0.15); color: var(--red); }
.badge-high      { background: rgba(34,197,94,0.12);  color: #4ade80; }
.badge-low       { background: rgba(250,204,21,0.12); color: #fcd34d; }
.badge-overdue   { background: rgba(248,113,113,0.18); color: var(--red); }
.badge-soon      { background: rgba(250,204,21,0.15); color: #fcd34d; }

/* Override select in cadence table */
.override-select {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text);
  font-size: 0.78rem;
  padding: 2px 6px;
}

/* Planner settings form */
.planner-settings { display: flex; flex-direction: column; gap: 16px; }
.setting-row {
  display: flex;
  align-items: center;
  gap: 16px;
}
.setting-row > label {
  width: 200px;
  font-size: 0.875rem;
  font-weight: 500;
  flex-shrink: 0;
}
.setting-control { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.setting-num-input {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text);
  font-size: 0.875rem;
  padding: 4px 8px;
}
.setting-select {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text);
  font-size: 0.875rem;
  padding: 4px 8px;
}
.setting-hint { color: var(--color-mid); font-size: 0.78rem; }

/* ============================================================
   UPLOAD MODAL — multi-file queue UI
   ============================================================ */
.upload-source-btns {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 10px;
  width: 100%;
  max-width: 260px;
}

/* Drop zone state when files have been queued */
.drop-zone--has-files {
  min-height: auto;
  padding: 14px;
  align-items: stretch;
  justify-content: flex-start;
  cursor: default;
}

/* Scrollable file queue */
.upload-queue {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 280px;
  overflow-y: auto;
}

.queue-item {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  padding: 9px 12px;
  background: var(--surface2);
  border-radius: 8px;
  font-size: 0.875rem;
}
.queue-item-icon { font-size: 1rem; flex-shrink: 0; }
.queue-item-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text);
}
.queue-item-status {
  font-size: 0.78rem;
  white-space: nowrap;
  flex-shrink: 0;
}
.queue-item-status.pending  { color: var(--text-muted); }
.queue-item-status.scanning { color: var(--accent); }
.queue-item-status.success  { color: var(--green); }
.queue-item-status.warning  { color: var(--yellow); }
.queue-item-status.error    { color: var(--red); }
.queue-item-status.skipped  { color: var(--text-muted); font-style: italic; }

/* Flag shortcut button inside queue item */
.queue-item-action { flex-shrink: 0; }

/* Semantic duplicate warning shown below a successfully scanned queue item */
.queue-item-duplicate-warning {
  flex-basis: 100%;
  margin-top: 0.35rem;
  padding: 0.3rem 0.5rem;
  border-radius: 4px;
  background: rgba(251, 191, 36, 0.1);
  border-left: 3px solid var(--yellow);
  font-size: 0.76rem;
  color: var(--text-muted);
  line-height: 1.4;
}
.queue-item-duplicate-warning a {
  color: var(--accent);
  text-decoration: underline;
}

/* Feedback + item-feedback modals float above the upload modal */
#feedback-modal,
#item-feedback-modal { z-index: 250; }

/* ============================================================
   WEEK-ON-WEEK ITEM TYPE TREND TABLE
   ============================================================ */
.trend-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.78rem;
  margin-top: 4px;
}
.trend-table th {
  text-align: right;
  padding: 6px 10px;
  font-size: 0.65rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.trend-table th.trend-name-col { text-align: left; }
.trend-table td { padding: 7px 10px; border-bottom: 1px solid var(--border); text-align: right; }
.trend-table tbody tr:last-child td { border-bottom: none; }
.trend-name-col { text-align: left !important; font-weight: 500; white-space: nowrap; min-width: 120px; }
.trend-val { min-width: 64px; font-variant-numeric: tabular-nums; }
.trend-zero { color: var(--text-muted); }
.trend-delta { min-width: 64px; font-weight: 600; }

/* Heat map — coral brand colour at increasing opacity */
.heat-0 { background: transparent; }
.heat-1 { background: rgba(224, 90, 58, 0.08); }
.heat-2 { background: rgba(224, 90, 58, 0.17); }
.heat-3 { background: rgba(224, 90, 58, 0.27); }
.heat-4 { background: rgba(224, 90, 58, 0.38); }

/* Delta badges */
.delta-up      { color: #22c55e; }
.delta-down    { color: #ef4444; }
.delta-neutral { color: var(--text-muted); }

/* ============================================================
   AI INSIGHTS PANEL
   ============================================================ */
.insights-panel .chart-header { align-items: flex-start; }
.insights-scope {
  display: block;
  font-size: 0.75rem;
  color: var(--color-mid);
  margin-top: 2px;
}
.insights-body {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 12px;
  margin-top: 16px;
}
.insight-card {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.insight-card--trend  { border-left: 3px solid var(--accent); }
.insight-card--outlier { border-left: 3px solid var(--yellow); }
.insight-card--price  { border-left: 3px solid var(--green); }
.insight-header {
  display: flex;
  align-items: flex-start;
  gap: 8px;
}
.insight-icon { font-size: 1rem; flex-shrink: 0; margin-top: 1px; }
.insight-headline { font-size: 0.9rem; line-height: 1.3; }
.insight-detail {
  font-size: 0.82rem;
  color: var(--color-mid);
  line-height: 1.4;
  margin: 0;
}
.insight-action {
  font-size: 0.8rem;
  color: var(--color-accent-text);
  font-weight: 500;
  margin: 0;
}
.insights-footer {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 12px;
  text-align: right;
}
.insight-feedback {
  display: flex;
  gap: 4px;
  margin-top: 6px;
  justify-content: flex-end;
}
.insight-rate-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 2px 6px;
  font-size: 0.8rem;
  cursor: pointer;
  opacity: 0.45;
  transition: opacity 0.15s, background 0.15s;
  line-height: 1.4;
}
.insight-rate-btn:hover { opacity: 0.8; }
.insight-rate-btn.active { opacity: 1; background: var(--surface3, var(--surface2)); border-color: var(--accent); }

.insight-rating-subject {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  margin-bottom: 14px;
  font-size: 0.85rem;
}
.insight-rating-subject .ir-headline { font-weight: 600; display: block; margin-bottom: 4px; }
.insight-rating-subject .ir-detail   { color: var(--color-mid); }

.insight-rating-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 6px;
}
.insight-rating-chip {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 5px 12px;
  font-size: 0.8rem;
  cursor: pointer;
  color: var(--text);
  transition: background 0.15s, border-color 0.15s;
}
.insight-rating-chip:hover { background: var(--surface3, var(--surface2)); }
.insight-rating-chip.selected {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

/* ============================================================
   MOBILE RESPONSIVE  (max-width: 640px — phones)
   ============================================================ */
@media (max-width: 640px) {

  /* Header: stack buttons below title on narrow screens */
  .header {
    flex-wrap: wrap;
    padding: 12px 16px;
    gap: 8px;
  }
  .header-left { flex: 1 1 auto; min-width: 0; }
  .header h1   { font-size: 1.05rem; }
  .header-right {
    flex: 0 0 100%;
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 6px;
  }

  /* Reduce page gutters */
  .filter-bar { padding: 10px 16px; gap: 8px; }
  .main       { padding: 14px 16px; gap: 14px; }
  .chart-card { padding: 14px 16px; }
  .tab-nav    { padding: 0 16px; }
  .tab-btn    { padding: 10px 12px; font-size: 0.85rem; }

  /* Modals: slide up from bottom edge, full width */
  .modal-overlay {
    padding: 0;
    align-items: flex-end;
  }
  .modal,
  .modal-large,
  .modal.modal-large,
  .modal-large.modal-xl {
    max-width: 100%;
    width: 100%;
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
    max-height: 92vh;
  }

  /* Detail modal split layout: stack panels */
  .detail-layout { flex-direction: column; }
  .detail-layout--split .detail-main { flex: none; width: 100%; }
  .detail-image-panel {
    flex: none;
    border-left: none;
    border-top: 1px solid var(--border);
    padding-left: 0;
    padding-top: 16px;
    max-height: none;
  }

  /* Assign-type split layout: stack panels */
  .assign-type-layout { flex-direction: column; }
  .assign-type-image-panel {
    flex: none;
    border-left: none;
    border-top: 1px solid var(--border);
    padding-left: 0;
    padding-top: 14px;
    max-height: none;
  }
  #assign-type-modal-inner.assign-type-split { max-width: 100%; }

  /* Feedback split layout: stack panels */
  .feedback-layout { flex-direction: column; }
  .feedback-image-panel {
    flex: none;
    border-left: none;
    border-top: 1px solid var(--border);
    padding-left: 0;
    padding-top: 14px;
    max-height: none;
  }
  .feedback-modal-wide { max-width: 100%; }

  /* Quality report rows: reflow from 3-col to 2-col */
  .quality-report-row {
    grid-template-columns: 1fr auto;
    grid-template-rows: auto auto auto;
  }
  .qr-filename { grid-column: 1;      grid-row: 1; }
  .qr-meta     { grid-column: 1;      grid-row: 2; }
  .qr-badge    { grid-column: 2;      grid-row: 1 / 3; align-self: center; }
  .qr-checks   { grid-column: 1 / -1; grid-row: 3; }

  /* Feedback checkboxes: single column */
  .feedback-checkboxes { grid-template-columns: 1fr; }

  /* Planner settings: stack label above control */
  .setting-row { flex-direction: column; align-items: flex-start; gap: 8px; }
  .setting-row > label { width: auto; }

  /* Slightly tighter stat values */
  .stat-value { font-size: 1.6rem; }

  /* Toast: full-width */
  .toast { left: 16px; right: 16px; bottom: 16px; }

  /* Upload modal queue: full height on mobile */
  .upload-queue { max-height: 240px; }
}

/* ── Very small phones (max-width: 400px) ─────────────────── */
@media (max-width: 400px) {
  .header h1  { font-size: 0.95rem; }
  .stat-value { font-size: 1.3rem; }
  .chart-card { padding: 12px; }
  .modal-body { padding: 16px; }
}

/* ── Shopping Agent tab ───────────────────────────────────── */
.agent-intro-list {
  padding-left: 20px;
  margin: 0 0 20px;
  line-height: 2;
  color: var(--color-mid);
}

.agent-activity { padding: 4px 0 8px; }

.agent-steps {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 420px;
  overflow-y: auto;
  padding-right: 4px;
}

.agent-step {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 14px;
  border-radius: 8px;
  background: var(--surface2);
  font-size: 0.875rem;
  line-height: 1.4;
  border-left: 3px solid transparent;
}
.agent-step--tool     { border-left-color: var(--accent); }
.agent-step--thinking { border-left-color: var(--yellow); opacity: 0.85; }
.agent-step--status   { border-left-color: var(--green); }
.agent-step--error    { border-left-color: var(--red); }
.agent-step--complete { opacity: 0.65; }

.agent-step-icon    { flex-shrink: 0; width: 20px; text-align: center; font-style: normal; }
.agent-step-text    { flex: 1; }
.agent-step-loading { flex-shrink: 0; display: flex; align-items: center; }
.agent-step-result  {
  display: block;
  margin-top: 3px;
  font-size: 0.8rem;
  color: var(--color-mid);
}

/* Smaller spinner variant */
.spinner--sm {
  width: 12px;
  height: 12px;
  border-width: 2px;
}

/* Agent result section */
.agent-result { margin-top: 24px; }

.agent-result-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 16px;
  gap: 12px;
}
.agent-result-summary { color: var(--color-mid); font-size: 0.9rem; }
.agent-result-total   { font-size: 1.25rem; font-weight: 700; color: var(--green); white-space: nowrap; }

.basket-items {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 20px;
}
.basket-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 12px;
  background: var(--surface2);
  border-radius: 6px;
  font-size: 0.875rem;
  text-decoration: none;
  cursor: pointer;
  transition: background 0.15s;
}
.basket-item:hover { background: var(--surface2); }
.basket-item-name  { color: var(--text); }
.basket-item-price { color: var(--color-mid); flex-shrink: 0; margin-left: 12px; }

.agent-result-actions { display: flex; gap: 12px; flex-wrap: wrap; }

/* ── Price drill-down modal ──────────────────────────────── */
.item-type-link {
  cursor: pointer;
  text-decoration: underline;
  text-decoration-style: dotted;
  text-underline-offset: 3px;
}
.item-type-link:hover { color: var(--accent); }

.price-drill-stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-bottom: 24px;
}
@media (max-width: 500px) { .price-drill-stats { grid-template-columns: repeat(2, 1fr); } }

.price-drill-stat {
  background: var(--surface2);
  border-radius: 10px;
  padding: 14px 16px;
}
.price-drill-stat-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 6px;
}
.price-drill-stat-val {
  font-size: 1.35rem;
  font-weight: 700;
  color: var(--text);
}
.price-drill-unit { font-size: 0.8rem; font-weight: 400; color: var(--color-mid); }

.price-drill-section-title {
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin: 0 0 10px;
}
.price-drill-chart-wrap {
  height: 200px;
  margin-bottom: 24px;
}

.price-drill-store-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}
.price-drill-store-table th {
  text-align: left;
  padding: 6px 10px;
  color: var(--text-muted);
  font-weight: 500;
  border-bottom: 1px solid var(--border);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.price-drill-store-table td {
  padding: 10px 10px;
  border-bottom: 1px solid rgba(255,255,255,0.04);
  color: var(--text);
}
.price-drill-store-table tr:last-child td { border-bottom: none; }
.price-drill-store-table tr:first-child td { color: #4ade80; }

/* ============================================================
   AI NARRATIVE SUMMARY
   ============================================================ */
.ai-summary-panel {
  border-left: 3px solid var(--accent);
  background: linear-gradient(135deg, rgba(224,90,58,0.05) 0%, rgba(224,90,58,0.01) 100%);
}
.ai-summary-body {
  display: flex;
  gap: 14px;
  align-items: flex-start;
}
.ai-summary-icon {
  font-size: 1.25rem;
  color: var(--color-accent-text);
  flex-shrink: 0;
  margin-top: 2px;
  line-height: 1;
}
.ai-summary-content { flex: 1; min-width: 0; }
.ai-summary-narrative {
  font-size: 0.95rem;
  line-height: 1.6;
  color: var(--text);
  margin: 0 0 12px;
}
.ai-summary-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.ai-action-chip {
  background: rgba(224, 90, 58, 0.08);
  border: 1px solid rgba(224, 90, 58, 0.25);
  border-radius: 20px;
  padding: 5px 14px;
  font-size: 0.8rem;
  color: var(--color-accent-text);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
  line-height: 1.4;
  text-align: left;
}
.ai-action-chip:hover {
  background: rgba(224, 90, 58, 0.15);
  border-color: rgba(224, 90, 58, 0.40);
}

/* ============================================================
   DATA CHAT PANEL
   ============================================================ */
.chat-panel { }
.chat-header { margin-bottom: 12px; }
.chat-header h2 { margin: 0; }
.chat-prompts {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 14px;
}
.chat-prompt-chip {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 6px 14px;
  font-size: 0.8rem;
  color: var(--text-muted);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
  line-height: 1.4;
}
.chat-prompt-chip:hover {
  background: rgba(224, 90, 58, 0.08);
  border-color: rgba(224, 90, 58, 0.30);
  color: var(--text);
}
.chat-input-row {
  display: flex;
  gap: 8px;
}
.chat-input {
  flex: 1;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 0.9rem;
  color: var(--text);
  outline: none;
  transition: border-color 0.15s;
  font-family: inherit;
}
.chat-input:focus { border-color: var(--accent); }
.chat-input::placeholder { color: var(--text-muted); }
.chat-send-btn { flex-shrink: 0; }
.chat-response {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  margin-top: 16px;
  padding: 14px 16px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: 10px;
}
.chat-response-icon {
  font-size: 1rem;
  color: var(--color-accent-text);
  flex-shrink: 0;
  margin-top: 2px;
  line-height: 1;
}
.chat-response-text {
  font-size: 0.9rem;
  line-height: 1.6;
  color: var(--text);
  margin: 0;
  max-height: 480px;
  overflow-y: auto;
  word-break: break-word;
}

@media (max-width: 640px) {
  .ai-summary-body { gap: 10px; }
  .ai-summary-narrative { font-size: 0.875rem; }
  .chat-prompts { gap: 6px; }
  .chat-prompt-chip { font-size: 0.75rem; padding: 5px 11px; }
}
