/**
 * styles.css — GroceryTracker Dashboard
 *
 * Organization:
 *   1. Reset & Design Tokens (CSS custom properties)
 *   2. Scrollbar
 *   3. Shell / Layout
 *   4. Header & Filter Bar
 *   5. Navigation Tabs
 *   6. Main Content Area
 *   7. Card & Bento Grid
 *   8. Stat Cards
 *   9. Grid Layouts
 *  10. Charts
 *  11. Tables
 *  12. Expandable Receipt Rows
 *  13. Badges (quality, source, category, store)
 *  14. Search Input
 *  15. Pagination
 *  16. Progress Bars (Insights tab)
 *  17. Trend Mini Bars (Insights tab)
 *  18. Store Pill
 *  19. Skeleton Loading Animation
 *  20. State Boxes (empty, error, loading)
 *  21. Responsive Breakpoints
 *
 * Design system: OLED dark-mode glassmorphism + bento grid
 * Fonts: Fira Sans (body) + Fira Code (monospace/numbers)
 * Accent: Indigo #6366f1
 */

/* =============================================================================
   1. RESET & DESIGN TOKENS
   ============================================================================= */

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

:root {
  /* Backgrounds */
  --bg:        #0a0d14;   /* Page background */
  --bg2:       #0f1117;   /* Slightly lighter surface */

  /* Glass surfaces */
  --surface:   rgba(255, 255, 255, 0.04);
  --surface-h: rgba(255, 255, 255, 0.07);  /* Hover state */

  /* Borders */
  --border:    rgba(255, 255, 255, 0.08);
  --border-h:  rgba(255, 255, 255, 0.16);  /* Hover / focus */

  /* Text */
  --text:   #f1f5f9;   /* Primary */
  --text-2: #94a3b8;   /* Secondary / labels */
  --text-3: #475569;   /* Muted / placeholders */

  /* Accent colours */
  --primary:   #6366f1;
  --primary-g: linear-gradient(135deg, #6366f1, #8b5cf6);
  --success:   #22c55e;
  --warning:   #f59e0b;
  --danger:    #ef4444;

  /* Spacing & shape */
  --radius:    16px;
  --radius-sm: 8px;
}

/* Respect user's motion preference */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration:  .01ms !important;
    transition-duration: .01ms !important;
  }
}

html { color-scheme: dark; }

body {
  font-family: 'Fira Sans', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.6;
  min-height: 100vh;
}

/* =============================================================================
   2. SCROLLBAR
   ============================================================================= */

::-webkit-scrollbar          { width: 6px; height: 6px; }
::-webkit-scrollbar-track    { background: transparent; }
::-webkit-scrollbar-thumb    { background: var(--border-h); border-radius: 999px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-3); }

/* =============================================================================
   3. SHELL / LAYOUT
   ============================================================================= */

.shell {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* =============================================================================
   4. HEADER & FILTER BAR
   ============================================================================= */

.header {
  position: sticky;
  top: 0;
  z-index: 50;
  background: rgba(10, 13, 20, 0.88);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  min-height: 60px;
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 16px;
  font-weight: 700;
  white-space: nowrap;
  text-decoration: none;
  color: inherit;
}

.logo-icon {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: var(--primary-g);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.logo-icon svg { width: 18px; height: 18px; }

.logo-text span { color: var(--primary); }

.filter-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
  flex-wrap: wrap;
}

.filter-bar select,
.filter-bar input[type="date"] {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: inherit;
  font-size: 13px;
  padding: 6px 10px;
  cursor: pointer;
  transition: border-color .2s;
  appearance: none;
  -webkit-appearance: none;
}

.filter-bar select:hover,
.filter-bar input[type="date"]:hover  { border-color: var(--border-h); }

.filter-bar select:focus,
.filter-bar input[type="date"]:focus  { outline: none; border-color: var(--primary); }

.filter-bar select option { background: #1e2030; }

.filter-label {
  font-size: 11px;
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: .5px;
  white-space: nowrap;
}

/* Primary action button */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 16px;
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: all .2s;
}

.btn-primary {
  background: var(--primary-g);
  color: #fff;
}

.btn-primary:hover  { transform: translateY(-1px); box-shadow: 0 4px 20px rgba(99, 102, 241, .4); }
.btn-primary:active { transform: translateY(0); }

/* =============================================================================
   5. NAVIGATION TABS
   ============================================================================= */

.nav {
  background: rgba(10, 13, 20, 0.7);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  border-bottom: 1px solid var(--border);
  display: flex;
  padding: 0 24px;
  overflow-x: auto;          /* Horizontal scroll on small screens */
}

.nav-btn {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 14px 18px;
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-2);
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  white-space: nowrap;
  transition: color .2s, border-color .2s;
}

.nav-btn svg    { width: 15px; height: 15px; flex-shrink: 0; }
.nav-btn:hover  { color: var(--text); }
.nav-btn.active { color: var(--primary); border-bottom-color: var(--primary); }

/* =============================================================================
   6. MAIN CONTENT AREA & TABS
   ============================================================================= */

.main {
  flex: 1;
  padding: 24px;
  max-width: 1280px;
  width: 100%;
  margin: 0 auto;
}

.tab-pane         { display: none; animation: fadeIn .25s ease; }
.tab-pane.active  { display: block; }

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* =============================================================================
   7. CARD
   ============================================================================= */

.card {
  background: var(--surface);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}

.card-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-2);
  text-transform: uppercase;
  letter-spacing: .6px;
  margin-bottom: 16px;
}

/* =============================================================================
   8. STAT CARDS (BENTO GRID)
   ============================================================================= */

/* 4-column bento grid — responsive via media queries below */
.bento {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 20px;
}

.stat-card {
  background: var(--surface);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 22px 18px;
  position: relative;
  overflow: hidden;
  transition: border-color .2s, transform .2s;
  cursor: default;
}

.stat-card:hover {
  border-color: var(--border-h);
  transform: translateY(-2px);
}

/* Coloured top highlight line using --accent-color per card */
.stat-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--accent-color, var(--primary)), transparent);
  opacity: .6;
}

.stat-card .icon {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: color-mix(in srgb, var(--accent-color, var(--primary)) 15%, transparent);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 12px;
}

.stat-card .icon svg { width: 18px; height: 18px; color: var(--accent-color, var(--primary)); }

.stat-card .label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .6px;
  color: var(--text-3);
  font-weight: 600;
}

.stat-card .value {
  font-family: 'Fira Code', monospace;
  font-size: 26px;
  font-weight: 600;
  color: var(--text);
  margin: 6px 0 4px;
  line-height: 1.1;
}

.stat-card .sub { font-size: 11px; color: var(--text-2); }

/* =============================================================================
   9. GRID LAYOUTS
   ============================================================================= */

/* Two-column grid for side-by-side cards */
.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 16px;
}

/* =============================================================================
   10. CHARTS
   ============================================================================= */

.chart-wrap      { position: relative; height: 260px; }
.chart-wrap-tall { position: relative; height: 320px; }
.cat-chart-wrap  { position: relative; height: 200px; }

/* =============================================================================
   11. TABLES
   ============================================================================= */

.table-wrap { overflow-x: auto; }

table { width: 100%; border-collapse: collapse; }

thead th {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: .6px;
  color: var(--text-3);
  font-weight: 600;
  padding: 10px 14px 8px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

tbody tr {
  border-bottom: 1px solid var(--border);
  transition: background .15s;
}

tbody tr:last-child { border-bottom: none; }
tbody tr:hover td  { background: var(--surface-h); }

td {
  padding: 11px 14px;
  font-size: 13px;
  vertical-align: middle;
}

/* =============================================================================
   12. EXPANDABLE RECEIPT ROWS
   ============================================================================= */

.row-expand { cursor: pointer; }

/* Animated expand arrow in first cell */
.row-expand td:first-child::before {
  content: '▶';
  font-size: 8px;
  color: var(--text-3);
  margin-right: 8px;
  display: inline-block;
  transition: transform .2s;
}

.row-expand.open td:first-child::before { transform: rotate(90deg); }

/* Items sub-row */
.row-items td  { padding: 0; }
.items-inner   { padding: 16px 20px 16px 40px; }
.items-inner table     { font-size: 12px; }
.items-inner thead th  { font-size: 10px; }
.items-inner td        { padding: 7px 10px; }

/* Height animation for smooth expand/collapse */
.expand-anim      { overflow: hidden; transition: max-height .3s ease; max-height: 0; }
.expand-anim.open { max-height: 600px; }

/* Cheapest-store row highlight */
.cheapest-row td                    { background: rgba(34, 197, 94, .06) !important; }
.cheapest-row td:first-child        { border-left: 2px solid var(--success); }

/* =============================================================================
   13. BADGES
   ============================================================================= */

.badge {
  display: inline-flex;
  align-items: center;
  font-size: 10px;
  font-weight: 600;
  border-radius: 6px;
  padding: 2px 7px;
  white-space: nowrap;
}

/* Parse quality */
.badge-high   { background: rgba(34, 197, 94, .15);  color: #86efac; }
.badge-medium { background: rgba(245, 158, 11, .15); color: #fcd34d; }
.badge-low    { background: rgba(239, 68, 68, .15);  color: #fca5a5; }

/* Receipt source */
.badge-gmail  { background: rgba(99, 102, 241, .15); color: #a5b4fc; }
.badge-tg     { background: rgba(14, 165, 233, .15); color: #7dd3fc; }

/* Sale indicator */
.badge-sale   { background: rgba(34, 197, 94, .15);  color: #86efac; }

/* Product categories — colours defined in config.js, applied inline */

/* =============================================================================
   14. SEARCH INPUT
   ============================================================================= */

.search-wrap { position: relative; margin-bottom: 16px; }

.search-input {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  padding: 10px 14px 10px 40px;  /* Left padding for icon */
  transition: border-color .2s;
}

.search-input:focus       { outline: none; border-color: var(--primary); }
.search-input::placeholder { color: var(--text-3); }

.search-icon {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  width: 16px;
  height: 16px;
  color: var(--text-3);
  pointer-events: none;  /* Don't block clicks on input */
}

/* =============================================================================
   15. PAGINATION
   ============================================================================= */

.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.page-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 6px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
  font-size: 12px;
  cursor: pointer;
  transition: all .2s;
}

.page-btn:hover:not(:disabled) { border-color: var(--primary); color: var(--primary); }
.page-btn:disabled             { opacity: .3; cursor: not-allowed; }

.page-info {
  font-size: 12px;
  color: var(--text-3);
  font-family: 'Fira Code', monospace;
}

/* =============================================================================
   16. PROGRESS BARS (Insights tab — top items)
   ============================================================================= */

.progress-row    { margin-bottom: 10px; }

.progress-header {
  display: flex;
  justify-content: space-between;
  margin-bottom: 5px;
}

.progress-name { font-size: 13px; }

.progress-meta {
  font-size: 11px;
  color: var(--text-2);
  font-family: 'Fira Code', monospace;
}

.progress-track {
  height: 6px;
  background: rgba(255, 255, 255, .07);
  border-radius: 999px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  border-radius: 999px;
  background: var(--primary-g);
  width: 0%;
  /* Animate from 0 → target width on mount */
  transition: width .8s cubic-bezier(.16, 1, .3, 1);
}

/* =============================================================================
   17. TREND MINI BARS (Insights tab — spend trend)
   ============================================================================= */

.trend-bars {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  height: 80px;
  padding-top: 20px;
}

.trend-bar-col {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.trend-bar-amt {
  font-size: 9px;
  color: var(--text-3);
  font-family: 'Fira Code', monospace;
  text-align: center;
}

.trend-bar-fill {
  width: 100%;
  border-radius: 4px 4px 0 0;
  background: var(--primary-g);
  min-height: 4px;
  /* Animate height on mount */
  transition: height .8s cubic-bezier(.16, 1, .3, 1);
}

.trend-bar-lbl { font-size: 10px; color: var(--text-3); }

/* =============================================================================
   18. STORE PILL
   ============================================================================= */

.store-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 5px;
}

/* Coloured dot — colour set via --store-color CSS variable in JS */
.store-pill::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--store-color, var(--text-3));
}

/* =============================================================================
   19. SKELETON LOADING ANIMATION
   ============================================================================= */

.skeleton {
  background: linear-gradient(
    90deg,
    rgba(255, 255, 255, .04) 25%,
    rgba(255, 255, 255, .08) 50%,
    rgba(255, 255, 255, .04) 75%
  );
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: 6px;
}

@keyframes shimmer {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

.skel-line { height: 14px; margin-bottom: 8px; }

/* =============================================================================
   20. STATE BOXES (empty / error / loading)
   ============================================================================= */

.state-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px 20px;
  text-align: center;
  gap: 10px;
  color: var(--text-3);
}

.state-box svg { width: 40px; height: 40px; opacity: .4; }
.state-box p   { font-size: 13px; }

.retry-btn {
  font-size: 12px;
  color: var(--primary);
  background: none;
  border: 1px solid var(--primary);
  border-radius: var(--radius-sm);
  padding: 5px 12px;
  cursor: pointer;
  font-family: inherit;
  transition: background .2s;
}

.retry-btn:hover { background: rgba(99, 102, 241, .1); }

/* =============================================================================
   21. RESPONSIVE BREAKPOINTS
   ============================================================================= */

/* Tablet: stack header vertically, hide filter labels */
@media (max-width: 768px) {
  .header {
    flex-direction: column;
    align-items: flex-start;
    padding: 10px 16px;
    min-height: auto;
    gap: 8px;
  }

  .filter-bar {
    margin-left: 0;
    width: 100%;
  }

  .filter-bar select,
  .filter-bar input[type="date"] {
    flex: 1;
    min-width: 100px;
  }

  /* Hide "Von" / "Bis" / "Geschäft" labels to save space */
  .filter-label { display: none; }

  .grid-2 { grid-template-columns: 1fr; }
}

/* Bento grid: 4 → 2 columns */
@media (max-width: 900px) {
  .bento { grid-template-columns: repeat(2, 1fr); }
}

/* Small phones: compact nav, hide icon SVGs in nav */
@media (max-width: 640px) {
  .main  { padding: 12px; }
  .nav   { padding: 0 8px; }
  .nav-btn { padding: 12px 10px; font-size: 12px; gap: 4px; }
  .nav-btn svg { display: none; }
}

/* Bento grid: 2 → 1 column, compact cards */
@media (max-width: 500px) {
  .bento { grid-template-columns: 1fr; }
  .stat-card .value { font-size: 20px; }
  .stat-card { padding: 14px 16px 12px; }
  .card  { padding: 14px; }
  td     { padding: 8px 10px; font-size: 12px; }
}

/* Shorter charts on mobile to reduce vertical scroll */
@media (max-width: 600px) {
  .chart-wrap      { height: 200px; }
  .chart-wrap-tall { height: 220px; }
  .cat-chart-wrap  { height: 200px; }
}
