:root {
  color-scheme: light dark;

  --bg:           #f6f7f9;
  --bg-elev:      #ffffff;
  --bg-elev-2:    #f1f2f5;
  --fg:           #1d2330;
  --fg-muted:     #5a6577;
  --border:       #e3e6ec;
  --border-strong:#cbd1da;
  --accent:       #1f6feb;
  --accent-fg:    #ffffff;
  --accent-soft:  #e7f0ff;
  --danger:       #d33b3b;
  --success:      #1e8e57;
  --ah:           #009ee3; /* AH blauw */
  --jumbo:        #fdc300; /* Jumbo geel */
  --jumbo-fg:     #1d2330;

  --radius:       12px;
  --radius-sm:    8px;
  --shadow-sm:    0 1px 2px rgba(15, 23, 42, .06);
  --shadow-md:    0 4px 14px rgba(15, 23, 42, .08);
  --shadow-lg:    0 10px 28px rgba(15, 23, 42, .18);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg:           #0e1117;
    --bg-elev:      #161b22;
    --bg-elev-2:    #1c222b;
    --fg:           #e7ecf3;
    --fg-muted:     #8b94a3;
    --border:       #262d37;
    --border-strong:#39414d;
    --accent:       #4c8dff;
    --accent-fg:    #ffffff;
    --accent-soft:  #1b2a44;
    --shadow-sm:    0 1px 2px rgba(0, 0, 0, .3);
    --shadow-md:    0 4px 14px rgba(0, 0, 0, .4);
    --shadow-lg:    0 10px 28px rgba(0, 0, 0, .55);
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--fg);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

.hidden { display: none !important; }

button {
  font: inherit;
  cursor: pointer;
}

input, button {
  font: inherit;
  color: inherit;
}

/* ── Login ───────────────────────────────────────────────────── */

.login-screen {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(ellipse at top, var(--accent-soft) 0%, var(--bg) 60%);
  padding: 16px;
  z-index: 10;
}

.login-card {
  background: var(--bg-elev);
  padding: 32px 28px 24px;
  border-radius: 16px;
  box-shadow: var(--shadow-md);
  width: min(360px, 100%);
  display: flex;
  flex-direction: column;
  gap: 12px;
  text-align: center;
  border: 1px solid var(--border);
}

.login-emoji {
  font-size: 56px;
  line-height: 1;
}

.login-card h1 {
  margin: 0;
  font-size: 24px;
  letter-spacing: -0.01em;
}

.login-hint {
  margin: 0;
  color: var(--fg-muted);
  font-size: 14px;
}

.login-card input {
  padding: 14px 16px;
  border-radius: 10px;
  border: 1px solid var(--border-strong);
  background: var(--bg-elev-2);
  font-size: 16px; /* avoids iOS zoom-on-focus */
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.login-card input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

.login-card button {
  padding: 12px 16px;
  border-radius: 10px;
  border: 0;
  background: var(--accent);
  color: var(--accent-fg);
  font-weight: 600;
  font-size: 16px;
}
.login-card button:hover { filter: brightness(1.05); }
.login-card button:active { transform: translateY(1px); }

.login-error {
  color: var(--danger);
  font-size: 14px;
  min-height: 1em;
}

/* ── App shell ───────────────────────────────────────────────── */

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

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 16px;
  background: var(--bg-elev);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 5;
  padding-top: max(10px, env(safe-area-inset-top));
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  letter-spacing: -0.01em;
  min-width: 0;
}
.brand-emoji { font-size: 22px; }
.brand-name  {
  font-size: 18px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-actions { display: flex; gap: 8px; align-items: center; }

.ghost-btn {
  background: transparent;
  border: 1px solid var(--border-strong);
  color: var(--fg);
  padding: 8px 12px;
  border-radius: 10px;
  font-size: 14px;
}
.ghost-btn:hover { background: var(--bg-elev-2); }

.danger-btn {
  background: transparent;
  color: var(--danger);
  border: 1px solid transparent;
  padding: 8px 12px;
  border-radius: 10px;
  font-size: 14px;
}
.danger-btn:not([disabled]):hover { background: color-mix(in srgb, var(--danger) 12%, transparent); }
.danger-btn[disabled] { opacity: .4; cursor: not-allowed; }

.primary-btn {
  background: var(--accent);
  color: var(--accent-fg);
  border: 0;
  padding: 10px 16px;
  border-radius: 10px;
  font-weight: 600;
}
.primary-btn:hover { filter: brightness(1.05); }
.block-btn { width: 100%; padding: 14px 16px; font-size: 16px; }

.icon-btn {
  background: transparent;
  border: 0;
  width: 36px;
  height: 36px;
  border-radius: 10px;
  font-size: 22px;
  color: var(--fg-muted);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.icon-btn:hover { background: var(--bg-elev-2); color: var(--fg); }

.count-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 24px;
  height: 22px;
  padding: 0 8px;
  border-radius: 11px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
}

/* ── Lijstje (main view) ───────────────────────────────────── */

.lijstje-main {
  flex: 1;
  overflow-y: auto;
  min-height: 0;
  padding: 16px 16px calc(24px + env(safe-area-inset-bottom));
  position: relative;
}

.lijstje-grid {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 16px;
}

.empty-hint {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  color: var(--fg-muted);
  pointer-events: none;
  padding: 24px;
}
.empty-emoji { font-size: 64px; margin-bottom: 12px; }
.empty-hint p { margin: 0; line-height: 1.4; }
.muted { color: var(--fg-muted); font-size: 13px; }

/* Tile — the primary unit. The whole tile is a button: tap to vink, tap
   again to un-vink. Smaller controls (qty stepper, delete) live on the
   tile and stop propagation. */
.lijstje-tile {
  position: relative;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  transition: transform .12s, box-shadow .12s, opacity .15s, border-color .12s;
  overflow: hidden;
}
.lijstje-tile:hover { transform: translateY(-1px); box-shadow: var(--shadow-md); border-color: var(--border-strong); }
.lijstje-tile:active { transform: translateY(0); }

.tile-image {
  position: relative;
  aspect-ratio: 1;
  background: var(--bg-elev-2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 88px;
  overflow: hidden;
}
.tile-image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.tile-store {
  position: absolute;
  top: 8px;
  left: 8px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .04em;
  padding: 2px 6px;
  border-radius: 4px;
  text-transform: uppercase;
}
.tile-store[data-store="ah"]    { background: var(--ah);    color: white; }
.tile-store[data-store="jumbo"] { background: var(--jumbo); color: var(--jumbo-fg); }

.tile-qty {
  position: absolute;
  top: 8px;
  right: 8px;
  background: var(--fg);
  color: var(--bg);
  border-radius: 999px;
  min-width: 28px;
  height: 28px;
  padding: 0 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 14px;
  box-shadow: var(--shadow-sm);
}

.tile-delete {
  position: absolute;
  bottom: 8px;
  right: 8px;
  width: 32px;
  height: 32px;
  border-radius: 999px;
  border: 0;
  background: rgba(0, 0, 0, .55);
  color: white;
  font-size: 18px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity .12s, background .12s;
}
.lijstje-tile:hover .tile-delete,
.lijstje-tile:focus-within .tile-delete { opacity: 1; }
.tile-delete:hover { background: var(--danger); }
/* Touch devices have no hover, so always show — but keep it subtle. */
@media (hover: none) {
  .tile-delete { opacity: .9; }
}

/* Vinked overlay — sits above the image and visually marks the tile as
   completed without removing it from the list. */
.tile-check {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(30, 142, 87, .8);
  color: white;
  font-size: 64px;
  font-weight: 800;
  opacity: 0;
  transition: opacity .15s;
  pointer-events: none;
}
.lijstje-tile.completed .tile-check { opacity: 1; }
.lijstje-tile.completed .tile-name { text-decoration: line-through; color: var(--fg-muted); }
.lijstje-tile.completed { border-color: var(--success); }

/* Unavailable overlay — red cross. Mirrors .tile-check structurally so the
   same image area can host either; mutual exclusion with completed is
   enforced server-side, so both classes never appear together in practice. */
.tile-unavailable {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(211, 59, 59, .8);
  color: white;
  font-size: 80px;
  font-weight: 800;
  opacity: 0;
  transition: opacity .15s;
  pointer-events: none;
}
.lijstje-tile.unavailable .tile-unavailable { opacity: 1; }
.lijstje-tile.unavailable .tile-name { text-decoration: line-through; color: var(--fg-muted); }
.lijstje-tile.unavailable { border-color: var(--danger); }

.tile-body {
  padding: 10px 12px 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
  flex: 1;
}
.tile-name {
  font-size: 15px;
  font-weight: 600;
  line-height: 1.25;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  word-break: break-word;
}

.tile-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 12px 10px;
}

.qty-stepper {
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  overflow: hidden;
  background: var(--bg-elev-2);
}
.qty-stepper button {
  background: transparent;
  border: 0;
  width: 32px;
  height: 32px;
  font-size: 18px;
  color: var(--fg);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.qty-stepper button:hover { background: var(--bg-elev); }
.qty-stepper .qty-value {
  min-width: 26px;
  text-align: center;
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  font-size: 14px;
}

/* ── Add tile (ghost; in-grid replacement for the old FAB) ─── */

.lijstje-tile.add-tile {
  background: transparent;
  border: 2px dashed var(--border-strong);
  box-shadow: none;
  color: var(--fg-muted);
}
.lijstje-tile.add-tile:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
  transform: translateY(-1px);
  box-shadow: var(--shadow-sm);
}
.add-tile-image {
  background: transparent;
  font-size: 88px;
  font-weight: 200;
  line-height: 1;
  color: inherit;
}
.add-tile-name {
  color: inherit;
  text-align: center;
  font-weight: 600;
}

/* ── Tile comment (free-text note attached to an item) ─────── */

.tile-comment {
  font-size: 12px;
  color: var(--danger);
  font-weight: 700;
  font-style: italic;
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  word-break: break-word;
}
.lijstje-tile.completed .tile-comment,
.lijstje-tile.unavailable .tile-comment { text-decoration: line-through; }

.tile-tool-cluster {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.tile-comment-btn,
.tile-unavailable-btn {
  background: transparent;
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  width: 32px;
  height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  line-height: 1;
  opacity: .55;
  transition: opacity .12s, background .12s, border-color .12s;
}
.tile-comment-btn:hover,
.tile-unavailable-btn:hover { opacity: 1; background: var(--bg-elev-2); }
.tile-comment-btn.has-comment {
  opacity: 1;
  border-color: var(--accent);
  background: var(--accent-soft);
}
.tile-unavailable-btn.is-unavailable {
  opacity: 1;
  border-color: var(--danger);
  background: color-mix(in srgb, var(--danger) 15%, transparent);
}

/* ── Comment editor modal ──────────────────────────────────── */

.comment-modal-card {
  gap: 14px;
}
.comment-product-name {
  font-weight: 600;
  font-size: 15px;
  color: var(--fg);
  word-break: break-word;
}
#comment-input {
  width: 100%;
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid var(--border-strong);
  background: var(--bg-elev-2);
  font: inherit;
  font-size: 16px; /* avoids iOS zoom-on-focus */
  color: var(--fg);
  resize: vertical;
  min-height: 80px;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
#comment-input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

.comment-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

/* ── Modal ─────────────────────────────────────────────────── */

.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .5);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 0;
  z-index: 20;
  animation: modal-fade .15s ease-out;
}
@media (min-width: 640px) {
  .modal { align-items: center; padding: 16px; }
}
@keyframes modal-fade {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.modal-card {
  background: var(--bg-elev);
  border-radius: 16px 16px 0 0;
  padding: 16px;
  width: 100%;
  max-width: 560px;
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding-bottom: max(16px, env(safe-area-inset-bottom));
  max-height: 90dvh;
  min-height: 0;
}
@media (min-width: 640px) {
  .modal-card { border-radius: 16px; }
}

.catalog-modal-card {
  height: 90dvh;
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.modal-head h3 { margin: 0; font-size: 18px; flex: 1; }

/* ── Catalog view (inside the modal) ───────────────────────── */

#search-input {
  width: 100%;
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid var(--border-strong);
  background: var(--bg-elev-2);
  font-size: 16px; /* avoids iOS zoom-on-focus */
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
#search-input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

.product-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 10px;
  overflow-y: auto;
  flex: 1;
  min-height: 0;
  padding: 4px 2px;
}

.product-card {
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  cursor: pointer;
  user-select: none;
  position: relative;
  transition: transform .12s, box-shadow .12s, border-color .12s;
  -webkit-tap-highlight-color: transparent;
}
.product-card:hover { transform: translateY(-1px); box-shadow: var(--shadow-md); border-color: var(--border-strong); }
.product-card:active { transform: translateY(0); }

.product-image {
  aspect-ratio: 1;
  border-radius: var(--radius-sm);
  background: var(--bg-elev);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  font-size: 36px;
  border: 1px solid var(--border);
}
.product-image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.product-store {
  position: absolute;
  top: 12px;
  right: 12px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .04em;
  padding: 2px 6px;
  border-radius: 4px;
  text-transform: uppercase;
}
.product-store[data-store="ah"]    { background: var(--ah);    color: white; }
.product-store[data-store="jumbo"] { background: var(--jumbo); color: var(--jumbo-fg); }

.product-name {
  font-size: 12px;
  font-weight: 500;
  line-height: 1.25;
  flex: 1;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* ── Toast stack ───────────────────────────────────────────── */

/* The stack is a fixed column above the FAB. Pills fade in via the .shown
   class (added in the frame after insertion) and out via .leaving so a
   burst of polled "Toegevoegd" notifications doesn't drop any. */
.toast-stack {
  position: fixed;
  bottom: calc(24px + env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  z-index: 30;
  pointer-events: none;
  max-width: calc(100% - 32px);
}

.toast-pill {
  background: var(--success);
  color: #ffffff;
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 500;
  box-shadow: var(--shadow-md);
  text-align: center;
  max-width: 100%;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity .15s, transform .15s;
}
.toast-pill.shown   { opacity: 1; transform: translateY(0); }
.toast-pill.leaving { opacity: 0; transform: translateY(-4px); }
.toast-pill.danger  { background: var(--danger); }

/* Brief visual confirmation on a tapped catalog card — the modal stays
   open for rapid multi-add, so the user needs feedback that the tap
   registered without losing their search context. */
.product-card-added {
  animation: card-pulse .6s ease-out;
}
@keyframes card-pulse {
  0%   { box-shadow: 0 0 0 0 var(--success); }
  60%  { box-shadow: 0 0 0 8px transparent; border-color: var(--success); }
  100% { box-shadow: 0 0 0 0 transparent; }
}

/* ── Narrow viewports ──────────────────────────────────────── */

@media (max-width: 480px) {
  .lijstje-grid {
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 12px;
  }
  .brand-name { font-size: 16px; }
  .topbar { padding: 10px 12px; padding-top: max(10px, env(safe-area-inset-top)); }
  .lijstje-main { padding: 12px 12px calc(24px + env(safe-area-inset-bottom)); }
  .tile-image { font-size: 72px; }
  .add-tile-image { font-size: 72px; }
}
