:root {
  --bg: #f7f7f8;
  --card-bg: #ffffff;
  --text: #1a1a1a;
  --muted: #6b7280;
  --border: #e5e7eb;
  --accent: #2563eb;
  --accent-light: #eff6ff;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.navbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 2rem;
  background: var(--card-bg);
  border-bottom: 1px solid var(--border);
}

.navbar .brand {
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--text);
  text-decoration: none;
}

.nav-links a {
  margin-left: 1.5rem;
  color: var(--muted);
  text-decoration: none;
  font-weight: 500;
}

.nav-links a:hover { color: var(--accent); }

.container {
  max-width: 960px;
  margin: 0 auto;
  padding: 2rem;
}

h1 { margin-top: 0; }

.stats {
  display: flex;
  gap: 1rem;
  margin-bottom: 2rem;
}

.stat-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1rem 1.5rem;
  flex: 1;
}

.stat-value { font-size: 1.8rem; font-weight: 700; }
.stat-label { color: var(--muted); font-size: 0.85rem; }

table {
  width: 100%;
  border-collapse: collapse;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}

th, td {
  text-align: left;
  padding: 0.6rem 0.9rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
}

th { background: #fafafa; color: var(--muted); font-weight: 600; }
tr:last-child td { border-bottom: none; }

.muted { color: var(--muted); font-size: 0.85em; }

.badge {
  background: var(--accent-light);
  color: var(--accent);
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 600;
}

.filter-bar {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
}
.filter-bar select,
.filter-bar input[type="text"] {
  padding: 0.5rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--card-bg);
  color: var(--text);
  font-size: 0.9rem;
}
.filter-bar input[type="text"] {
  flex: 1;
  min-width: 160px;
}
.filter-bar button {
  padding: 0.5rem 1rem;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 6px;
  font-weight: 600;
  cursor: pointer;
  font-size: 0.9rem;
}
.clear-filters {
  color: var(--muted);
  text-decoration: none;
  font-size: 0.85rem;
}
.clear-filters:hover { color: #dc2626; }

.add-form {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 2rem;
  flex-wrap: wrap;
}
.add-form input {
  flex: 1;
  min-width: 160px;
  padding: 0.6rem 0.9rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.95rem;
}
.add-form input.size-value {
  flex: 0 0 100px;
  min-width: 0;
}
.add-form select {
  padding: 0.6rem 0.9rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--card-bg);
  color: var(--text);
  font-size: 0.95rem;
}
.add-form button, .page-header button {
  padding: 0.6rem 1.2rem;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 6px;
  font-weight: 600;
  cursor: pointer;
}

.watchlist-item {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1rem 1.5rem;
  margin-bottom: 1rem;
}
.watchlist-item-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.watchlist-item-header h3 { margin: 0.2rem 0; }

.btn-delete {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
  padding: 0.3rem 0.7rem;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.8rem;
}
.btn-delete:hover { color: #dc2626; border-color: #dc2626; }

table.preview { border: none; margin-top: 0.5rem; }
table.preview td { border-bottom: 1px solid var(--border); padding: 0.4rem 0; font-size: 0.85rem; }

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.empty { color: var(--muted); padding: 2rem 0; text-align: center; }

/* Unit price is the number that actually decides a deal, so it reads as
   emphasis rather than metadata - tabular figures keep the decimal points
   aligned down the column for scanning. */
.unit-price {
  font-variant-numeric: tabular-nums;
  color: var(--text);
  font-weight: 600;
  white-space: nowrap;
}

/* Discount layer: the effective price is the answer the app exists to give,
   so it outranks the shelf price visually without hiding it. */
.effective { white-space: nowrap; }
.effective-price {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  color: #15803d;
}
.saving {
  margin-left: 0.35rem;
  padding: 0.05rem 0.35rem;
  border-radius: 999px;
  background: #dcfce7;
  color: #15803d;
  font-size: 0.75rem;
  font-weight: 600;
}
.effective-unit {
  display: block;
  font-size: 0.8rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
/* The derivation stays visible but quiet - you should be able to check why a
   coupon was applied without clicking anything. */
.why { display: block; font-size: 0.72rem; max-width: 22rem; white-space: normal; }

/* The discount form has 11 fields, three of which are only meaningful in
   combination (scope + selector, mechanic + amount). The watchlist's flat
   flex row can't carry that - it produced an unlabelled wall of boxes where
   placeholders vanished the moment you typed. Labelled cells on a grid
   instead, so each field says what it is even once filled. */
.discount-form {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 0.9rem 1rem;
  align-items: end;
  margin-bottom: 2rem;
  padding: 1.2rem;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
}
.discount-form .field { display: flex; flex-direction: column; gap: 0.3rem; min-width: 0; }
.discount-form .field-wide { grid-column: span 2; }
.discount-form .field-narrow { max-width: 100%; }
.discount-form .field-submit { justify-content: flex-end; }
.discount-form label {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.02em;
}
.discount-form input,
.discount-form select {
  width: 100%;
  padding: 0.55rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.92rem;
  background: var(--bg, #fff);
  color: var(--text);
}
.discount-form .optional { font-weight: 400; text-transform: none; opacity: 0.7; }
.discount-form .field-note { font-size: 0.72rem; color: var(--muted); }
.discount-form .checkbox {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  text-transform: none;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text);
  letter-spacing: 0;
}
.discount-form .checkbox input { width: auto; }
/* A disabled selector still occupies its cell, so the grid doesn't reflow
   every time the scope changes. */
.discount-form .field-disabled { opacity: 0.45; }
.discount-form button { width: 100%; padding: 0.6rem 1.2rem; }
.intro { max-width: 46rem; }
.form-hint { font-size: 0.8rem; margin-top: -0.5rem; }
.form-error {
  padding: 0.6rem 0.8rem;
  border-radius: 6px;
  background: #fee2e2;
  color: #991b1b;
  font-size: 0.9rem;
}
.btn-warn { background: #f59e0b; color: #fff; border: none; padding: 0.25rem 0.6rem; border-radius: 4px; cursor: pointer; }
.btn-ok { background: #16a34a; color: #fff; border: none; padding: 0.25rem 0.6rem; border-radius: 4px; cursor: pointer; }

/* Live scope preview. Sits directly under the form because it's feedback on
   what you just typed, not a separate report. */
.scope-preview {
  margin: -1rem 0 2rem;
  padding: 0.9rem 1.1rem;
  border: 1px solid var(--border);
  border-left: 3px solid var(--border);
  border-radius: 6px;
  background: var(--card-bg);
}
.scope-preview-head { display: flex; align-items: baseline; gap: 0.6rem; flex-wrap: wrap; }
.preview-verdict { font-weight: 700; font-size: 0.95rem; }
.preview-ok    { color: #15803d; }
.preview-warn  { color: #b45309; }
.preview-broad { color: #b45309; }
.scope-preview:has(.preview-ok)    { border-left-color: #15803d; }
.scope-preview:has(.preview-warn),
.scope-preview:has(.preview-broad) { border-left-color: #f59e0b; }
.preview-table { margin-top: 0.7rem; font-size: 0.85rem; }
.preview-table td { padding: 0.25rem 0.6rem 0.25rem 0; border: none; }
.preview-table td:first-child { font-weight: 500; }

/* Coverage status. "Between leaflets" is deliberately not red: the connector
   is fine and the shop is coming back, which is a different situation from
   having no data source at all. */
.cov { padding: 0.1rem 0.5rem; border-radius: 999px; font-size: 0.75rem; font-weight: 600; white-space: nowrap; }
.cov-live    { background: #dcfce7; color: #15803d; }
.cov-between { background: #fef3c7; color: #92400e; }
.cov-stale   { background: #f1f5f9; color: #64748b; }

/* Compare -------------------------------------------------------------
   Written mobile-first, because the place this actually gets used is a
   shop aisle on a phone. The desktop table is the enhancement, not the
   base: at narrow widths a seven-column comparison table is ~500px wide
   and forces the whole page to scroll sideways, which is unusable one-
   handed while holding a basket. */

.compare-search { display: flex; gap: 0.6rem; margin-bottom: 1rem; flex-wrap: wrap; }
.compare-search input {
  flex: 1 1 12rem;
  min-width: 0;                 /* lets the field shrink instead of overflowing */
  padding: 0.85rem 1rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 1rem;              /* below 16px, iOS zooms the page on focus */
}
.compare-search button {
  padding: 0.85rem 1.5rem; background: var(--accent); color: #fff;
  border: none; border-radius: 8px; font-weight: 600; font-size: 1rem;
  cursor: pointer; min-height: 48px;   /* comfortable thumb target */
}

.cmp-status {
  display: flex; align-items: center; gap: 0.7rem; flex-wrap: wrap;
  margin-bottom: 1.2rem; font-size: 0.85rem;
}
.btn-refresh {
  padding: 0.5rem 0.9rem; border: 1px solid var(--border); border-radius: 999px;
  text-decoration: none; color: var(--text); font-weight: 600; min-height: 40px;
  display: inline-flex; align-items: center;
}

.cmp-group {
  margin-bottom: 1.2rem; padding: 0.9rem 1rem;
  border: 1px solid var(--border); border-radius: 10px; background: var(--card-bg);
}
.cmp-head { display: flex; align-items: baseline; gap: 0.6rem; flex-wrap: wrap; margin-bottom: 0.6rem; }
.cmp-head h2 { font-size: 1rem; margin: 0; line-height: 1.3; }
.cmp-spread {
  padding: 0.1rem 0.5rem; border-radius: 999px;
  background: #dcfce7; color: #15803d; font-size: 0.75rem; font-weight: 600;
}
.cmp-gtin { font-size: 0.7rem; margin: 0.4rem 0 0; }
.cmp-struck { text-decoration: line-through; }
.cmp-flag {
  margin-left: 0.4rem; padding: 0.05rem 0.4rem; border-radius: 999px;
  background: #15803d; color: #fff; font-size: 0.68rem; font-weight: 600;
  vertical-align: middle;
}

/* --- phone: each shop becomes a card ------------------------------- */
.cmp-table, .cmp-table tbody, .cmp-table tr, .cmp-table td { display: block; }
.cmp-table thead { display: none; }
.cmp-table { width: 100%; border-collapse: collapse; }
.cmp-table tr {
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-areas:
    "shop shop"
    "product product"
    "pay unit";
  gap: 0.15rem 0.6rem;
  align-items: baseline;
  padding: 0.7rem 0.6rem;
  border-top: 1px solid var(--border);
}
.cmp-table tr:first-child { border-top: none; }
/* The global `th, td` rule adds 0.6rem/0.9rem padding and a bottom border,
   which inside a card is 24px of dead space on every single line - it made
   each shop 158px tall instead of ~95px, roughly halving how many shops fit
   on screen. The card supplies its own padding. */
.cmp-table td {
  padding: 0;
  border-bottom: none;
  font-size: inherit;
}
.cmp-table { border: none; background: none; }
.c-shop    { grid-area: shop; font-weight: 700; font-size: 1rem; }
.c-product { grid-area: product; font-size: 0.85rem; color: var(--muted); }
.c-pay     { grid-area: pay; font-size: 1.35rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.c-unit    { grid-area: unit; text-align: right; font-weight: 600; white-space: nowrap; }
/* Size, original price and the coupon derivation are reference detail. On a
   phone they cost more attention than they earn, so only the two numbers
   that decide the choice survive.
   Scoped under .cmp-table on purpose: a bare `.c-size` loses to
   `.cmp-table td` on specificity (one class vs a class plus an element),
   so the columns stayed visible however far down the file this sat. */
.cmp-table .c-size,
.cmp-table .c-was,
.cmp-table .c-why { display: none; }
.cmp-best { background: rgba(22, 163, 74, 0.07); border-radius: 8px; }

/* --- desktop: back to a comparison table --------------------------- */
@media (min-width: 46em) {
  .cmp-table, .cmp-table tbody { display: table; width: 100%; }
  .cmp-table thead { display: table-header-group; }
  .cmp-table tr { display: table-row; padding: 0; border-top: none; }
  .cmp-table td { display: table-cell; padding: 0.35rem 0.7rem 0.35rem 0; vertical-align: top; }
  .cmp-table .c-size,
  .cmp-table .c-was,
  .cmp-table .c-why { display: table-cell; }
  .c-shop { white-space: nowrap; }
  .c-pay { font-size: 0.88rem; }
  .c-unit { text-align: left; }
  .cmp-table { font-size: 0.88rem; }
  .cmp-best td { background: rgba(22, 163, 74, 0.06); }
  .cmp-best { background: none; }
  .c-why { font-size: 0.72rem; max-width: 20rem; }
}

/* --- phone chrome ---------------------------------------------------
   Six nav links and 2rem gutters don't fit a 375px screen. The nav
   scrolls horizontally rather than wrapping into two rows, so the
   content above the fold stays content. */
@media (max-width: 46em) {
  .navbar { padding: 0.8rem 1rem; gap: 0.8rem; }
  .nav-links {
    display: flex;
    gap: 1.1rem;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .nav-links::-webkit-scrollbar { display: none; }
  .nav-links a { margin-left: 0; white-space: nowrap; padding: 0.4rem 0; }
  .container { padding: 1rem; }
  h1 { font-size: 1.4rem; }
  .intro { font-size: 0.88rem; }

  /* Compare is the only view redesigned for a phone. The rest keep their
     wide tables - Offers alone is ~870px across - so they scroll inside
     themselves rather than dragging the whole page sideways. Not as good
     as a real mobile layout, but it degrades instead of breaking, and
     these are desk views rather than aisle views. */
  table:not(.cmp-table) {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    white-space: nowrap;
  }

  .filter-bar, .discount-form { grid-template-columns: 1fr; }
  .filter-bar input, .filter-bar select, .filter-bar button { width: 100%; }
}

/* Long product names and German compounds must never widen the page. */
.cmp-group, .cmp-head h2, .c-product { overflow-wrap: anywhere; }
