/* ===========================================================
   Retro Brocante — design system
   Direction : étiquette de prix de brocante / ticket manuscrit.
   Graphite + jaune moutarde (ambre CRT), monospace pour les prix
   (effet ticket de caisse / étiquette à main), sans-serif condensé
   pour les titres (effet tampon).
   =========================================================== */

@import url('https://fonts.googleapis.com/css2?family=Barlow+Condensed:wght@600;700;800&family=JetBrains+Mono:wght@400;500;700&family=Inter:wght@400;500;600&display=swap');

:root {
  /* Couleurs */
  --bg: #14161b;
  --surface: #1d2027;
  --surface-raised: #262a33;
  --border: #2f3440;
  --text: #edeef0;
  --text-muted: #9096a3;
  --text-faint: #5b6270;

  --accent: #e4b03e;         /* jaune moutarde — accent principal, prix/CTA */
  --accent-dim: #7a5f22;
  --accent-text: #1a1508;

  --kept: #4caf6d;           /* vert — gardé / validé */
  --kept-bg: rgba(76, 175, 109, 0.14);
  --not-kept: #e15a4f;       /* rouge — pas gardé / annulé */
  --not-kept-bg: rgba(225, 90, 79, 0.14);
  --masked-bg: rgba(255, 255, 255, 0.03);

  /* Typo */
  --font-display: 'Barlow Condensed', sans-serif;
  --font-body: 'Inter', system-ui, sans-serif;
  --font-price: 'JetBrains Mono', monospace;

  --radius: 10px;
  --radius-sm: 6px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: contain;
}

body {
  display: flex;
  flex-direction: column;
  max-width: 560px;
  margin: 0 auto;
  min-height: 100vh;
}

h1, h2, h3 {
  font-family: var(--font-display);
  font-weight: 800;
  letter-spacing: 0.01em;
  margin: 0;
  text-transform: uppercase;
}

button {
  font-family: var(--font-body);
  cursor: pointer;
  border: none;
  background: none;
  color: inherit;
}

button:focus-visible, a:focus-visible, input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

input, select {
  font-family: var(--font-body);
  background: var(--surface-raised);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 15px;
}

/* ---------- Header ---------- */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 16px 8px;
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 10;
}
.app-header h1 {
  font-size: 22px;
}
.header-badge {
  font-family: var(--font-price);
  font-size: 12px;
  color: var(--accent);
  border: 1px solid var(--accent-dim);
  border-radius: 999px;
  padding: 4px 10px;
  white-space: nowrap;
}

/* ---------- Main content area ---------- */
.screen {
  flex: 1;
  padding: 8px 16px 24px;
  overflow-y: auto;
}
.screen[hidden] { display: none; }

/* ---------- Bottom nav ---------- */
.bottom-nav {
  position: sticky;
  bottom: 0;
  display: flex;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
  z-index: 20;
}
.bottom-nav button {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 8px 4px;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 600;
}
.bottom-nav button .icon { font-size: 20px; line-height: 1; }
.bottom-nav button.active { color: var(--accent); }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 13px 18px;
  border-radius: var(--radius);
  font-weight: 600;
  font-size: 15px;
  width: 100%;
}
.btn-primary { background: var(--accent); color: var(--accent-text); }
.btn-primary:active { background: #c99727; }
.btn-secondary { background: var(--surface-raised); color: var(--text); border: 1px solid var(--border); }

.rafale-toggle-row { display: flex; justify-content: center; margin: 8px 0; }
#btn-toggle-rafale.active { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.btn-danger { background: transparent; color: var(--not-kept); border: 1px solid var(--not-kept); }
.btn-ghost { background: transparent; color: var(--text-muted); }
.btn-sm { padding: 8px 12px; font-size: 13px; width: auto; }
.btn:disabled { opacity: 0.4; pointer-events: none; }

/* ---------- Scan screen ---------- */
.scan-viewport {
  position: relative;
  width: 100%;
  aspect-ratio: 3/4;
  background: #000;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--border);
}
.scan-viewport video { width: 100%; height: 100%; object-fit: cover; }
.scan-reticle {
  position: absolute;
  inset: 20% 10%;
  border: 2px solid var(--accent);
  border-radius: var(--radius);
  box-shadow: 0 0 0 999px rgba(0,0,0,0.35);
  pointer-events: none;
}
.scan-hint {
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
  margin-top: 10px;
}

.manual-search-toggle {
  margin-top: 14px;
  text-align: center;
}
.manual-search-toggle button {
  color: var(--accent);
  font-size: 13px;
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.search-results {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 12px;
}

/* ---------- Price tag badge (élément signature) ---------- */
/* Forme évoquant une étiquette de prix de brocante : rectangle à coin
   tronqué avec un "trou" pour la ficelle, effet ticket écrit à la main. */
.price-tag {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-family: var(--font-price);
  font-weight: 700;
  font-size: 15px;
  color: var(--accent-text);
  background: var(--accent);
  padding: 5px 12px 5px 16px;
  clip-path: polygon(10px 0, 100% 0, 100% 100%, 10px 100%, 0 50%);
}
.price-tag::before {
  content: '';
  position: absolute;
  left: 4px;
  top: 50%;
  transform: translateY(-50%);
  width: 3px;
  height: 3px;
  border-radius: 50%;
  background: var(--accent-text);
  opacity: 0.5;
}
.price-tag.muted {
  background: var(--surface-raised);
  color: var(--text-muted);
  border: 1px dashed var(--border);
}
.price-tag.max {
  background: transparent;
  color: var(--accent);
  border: 1px solid var(--accent-dim);
}

/* ---------- Game card / basket item ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
}

.game-row {
  display: flex;
  gap: 12px;
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px;
  margin-bottom: 8px;
  transition: opacity 0.15s ease, background 0.15s ease;
}
.game-row.is-masked {
  background: var(--masked-bg);
  opacity: 0.5;
}
.game-row.status-kept { border-color: var(--kept); }
.game-row.status-not-kept { border-color: var(--not-kept); opacity: 0.6; }

.game-row .cover {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-sm);
  background: var(--surface-raised);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
  overflow: hidden;
}
.game-row .cover img { width: 100%; height: 100%; object-fit: cover; }

.game-row .info { flex: 1; min-width: 0; }
.game-row .title {
  font-weight: 600;
  font-size: 14.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.game-row .meta {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}
.game-row .prices {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 3px;
}
.game-row .actions {
  display: flex;
  gap: 4px;
}
.icon-btn {
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  background: var(--surface-raised);
  font-size: 15px;
  flex-shrink: 0;
}
.icon-btn:active { background: var(--border); }

/* ---------- Sticky basket totals bar ---------- */
.basket-totals {
  position: sticky;
  bottom: 0;
  background: var(--surface);
  border-top: 1px solid var(--border);
  border-radius: var(--radius) var(--radius) 0 0;
  padding: 12px 14px;
  margin: 12px -16px 0;
  box-shadow: 0 -6px 16px rgba(0,0,0,0.3);
}
.basket-totals .row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 4px;
}
.basket-totals .row strong {
  font-family: var(--font-price);
  color: var(--text);
  font-size: 16px;
}
.basket-totals .row.max strong { color: var(--accent); }
.basket-actions {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}
.basket-actions .btn { flex: 1; }

.basket-counter-pill {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 8px 14px;
  margin-top: 12px;
  font-size: 13px;
  color: var(--text-muted);
}
.basket-counter-pill strong { color: var(--text); font-family: var(--font-price); }
.basket-counter-pill button {
  margin-left: auto;
  color: var(--accent);
  font-weight: 600;
  font-size: 12px;
}

/* ---------- Empty states ---------- */
.empty-state {
  text-align: center;
  padding: 40px 16px;
  color: var(--text-muted);
}
.empty-state .icon { font-size: 32px; margin-bottom: 10px; opacity: 0.6; }
.empty-state p { font-size: 14px; margin: 0; }

/* ---------- Tabs (historique) ---------- */
.tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 14px;
  background: var(--surface);
  border-radius: var(--radius-sm);
  padding: 3px;
}
.tabs button {
  flex: 1;
  padding: 8px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  border-radius: 5px;
}
.tabs button.active { background: var(--surface-raised); color: var(--text); }

.status-pill {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  padding: 3px 8px;
  border-radius: 999px;
}
.status-pill.validated { background: var(--kept-bg); color: var(--kept); }
.status-pill.not_taken { background: var(--not-kept-bg); color: var(--not-kept); }
.status-pill.kept { background: var(--kept-bg); color: var(--kept); }
.status-pill.not_kept { background: var(--not-kept-bg); color: var(--not-kept); }

.basket-history-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 10px;
}
.basket-history-card .top-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
}
.basket-history-card .date { font-size: 12px; color: var(--text-faint); }
.basket-history-card .figures {
  display: flex;
  gap: 16px;
  margin-top: 8px;
  font-size: 12px;
  color: var(--text-muted);
}
.basket-history-card .figures strong { color: var(--text); font-family: var(--font-price); }

/* ---------- Modal (fiche jeu détaillée) ---------- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 50;
  display: flex;
  align-items: flex-end;
}
.modal-backdrop[hidden] { display: none; }
.modal-sheet {
  background: var(--surface);
  border-radius: 16px 16px 0 0;
  width: 100%;
  max-width: 560px;
  margin: 0 auto;
  max-height: 88vh;
  overflow-y: auto;
  padding: 20px 18px calc(20px + env(safe-area-inset-bottom));
}
.modal-sheet .handle {
  width: 36px;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  margin: 0 auto 14px;
}
.detail-cover {
  width: 100%;
  max-height: 160px;
  object-fit: contain;
  border-radius: var(--radius);
  background: var(--surface-raised);
  margin-bottom: 12px;
}
.cote-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin: 14px 0;
}
.cote-grid .cell {
  background: var(--surface-raised);
  border-radius: var(--radius-sm);
  padding: 10px 8px;
  text-align: center;
}
.cote-grid .cell .label { font-size: 11px; color: var(--text-muted); text-transform: uppercase; }
.cote-grid .cell .value { font-family: var(--font-price); font-weight: 700; font-size: 16px; margin-top: 4px; }

.reliability-note {
  font-size: 12px;
  color: var(--text-faint);
  background: var(--surface-raised);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  margin-top: 10px;
  line-height: 1.5;
}

.field-row {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 12px;
}
.field-row label { font-size: 12px; color: var(--text-muted); font-weight: 600; }

.condition-selector {
  display: flex;
  gap: 6px;
}
.condition-selector button {
  flex: 1;
  padding: 9px 4px;
  font-size: 12px;
  font-weight: 600;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  background: var(--surface-raised);
}
.condition-selector button.active {
  border-color: var(--accent);
  color: var(--accent);
  background: rgba(228, 176, 62, 0.08);
}

.advanced-toggle-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}
.advanced-toggle-row .chip {
  font-size: 12px;
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--text-muted);
  background: var(--surface-raised);
}
.advanced-toggle-row .chip.active {
  border-color: var(--not-kept);
  color: var(--not-kept);
  background: var(--not-kept-bg);
}

.toast {
  position: fixed;
  bottom: 90px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface-raised);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 13px;
  z-index: 100;
  box-shadow: 0 4px 16px rgba(0,0,0,0.4);
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
