/* =========================================================
   LoyaltyOS — design tokens
   Ancrage : un outil de comptoir (café, boulangerie, salon...).
   Le vert "tampon encreur" est la seule couleur d'accent utilisée
   pour les actions et l'identité ; l'ambre sert uniquement aux
   points/montants, en monospace, comme un ticket de caisse.
   ========================================================= */

:root {
  --paper: #f7f6f2;
  --surface: #ffffff;
  --surface-sunken: #f0eee8;
  --ink: #1f2421;
  --ink-soft: #6b6b62;
  --ink-faint: #707065;
  --border: #e5e2d9;
  --border-strong: #d3cfc2;

  --stamp: #2f6f4e;
  --stamp-dark: #234f39;
  --stamp-pale: #e3eee7;

  --amber: #ad7a1f;
  --amber-pale: #f5ebd6;

  --danger: #a8402a;
  --danger-pale: #f7e6e1;

  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-pill: 999px;

  --shadow-card: 0 1px 2px rgba(31,36,33,0.04), 0 8px 24px rgba(31,36,33,0.06);
  --shadow-pop: 0 4px 10px rgba(31,36,33,0.08), 0 16px 40px rgba(31,36,33,0.12);

  --font-ui: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-num: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

  font-size: 16px;
  color-scheme: light;
}

* { box-sizing: border-box; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}

body {
  margin: 0;
  font-family: var(--font-ui);
  background: var(--paper);
  color: var(--ink);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; }
:focus-visible { outline: 2px solid var(--stamp); outline-offset: 2px; }

/* Contenu present pour les lecteurs d'ecran mais retire du rendu visuel
   (labels de champs dont l'intitule est deja porte par le contexte visuel). */
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

.num { font-family: var(--font-num); font-variant-numeric: tabular-nums; }

.container {
  width: 100%;
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 20px;
}

.container-narrow {
  width: 100%;
  max-width: 460px;
  margin: 0 auto;
  padding: 0 20px;
}

/* ---------- Boutons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 46px;
  padding: 12px 20px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-size: 0.95rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  text-decoration: none;
  transition: transform 0.08s ease, opacity 0.15s ease, background-color 0.15s ease;
  width: 100%;
}
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; transform: none; }

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

.btn-secondary { background: var(--surface); color: var(--ink); border-color: var(--border-strong); }
.btn-secondary:hover:not(:disabled) { background: var(--surface-sunken); }

.btn-danger { background: var(--danger); color: #fff; }
.btn-block { width: 100%; }
.btn-auto { width: auto; min-height: 40px; padding: 9px 16px; }

/* ---------- Formulaires ---------- */

.field { margin-bottom: 16px; text-align: left; }
.field label { display: block; font-size: 0.85rem; font-weight: 600; margin-bottom: 6px; color: var(--ink-soft); }
.field input[type="text"],
.field input[type="email"],
.field input[type="password"],
.field input[type="number"],
.field input[type="color"],
.field textarea,
.field select {
  width: 100%;
  min-height: 44px;
  padding: 11px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  /* 16px (pas 0.95rem/15.2px) : sous 16px, Safari iOS zoome automatiquement
     la page a la mise au point d'un champ, ce qui casse la mise en page. */
  font-size: 16px;
  font-family: inherit;
  background: var(--surface);
  color: var(--ink);
  transition: border-color 0.15s ease;
}
.field input:focus, .field textarea:focus, .field select:focus {
  border-color: var(--stamp);
}
.field textarea { resize: vertical; min-height: 90px; }
.field-checkbox { display: flex; align-items: flex-start; gap: 8px; font-size: 0.85rem; color: var(--ink-soft); }
.field-checkbox input { margin-top: 3px; width: 18px; height: 18px; }

.error-box {
  background: var(--danger-pale);
  color: var(--danger);
  border: 1px solid #ecc9bd;
  padding: 11px 14px;
  border-radius: var(--radius-sm);
  font-size: 0.88rem;
  margin-bottom: 16px;
}
.success-box {
  background: var(--stamp-pale);
  color: var(--stamp-dark);
  border: 1px solid #c9dfd0;
  padding: 11px 14px;
  border-radius: var(--radius-sm);
  font-size: 0.88rem;
  margin-bottom: 16px;
}

/* ---------- Cartes / panneaux ---------- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-card);
  padding: 24px;
}

.auth-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background:
    radial-gradient(circle at 15% 10%, var(--stamp-pale) 0%, transparent 45%),
    var(--paper);
}

/* ---------- Layout admin / commercant ---------- */

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

.sidebar {
  width: 232px;
  flex-shrink: 0;
  background: var(--ink);
  color: #fff;
  padding: 20px 14px;
  display: flex;
  flex-direction: column;
}
.sidebar .brand { font-weight: 700; font-size: 1.05rem; padding: 8px 10px 22px; letter-spacing: -0.01em; }
.sidebar nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.sidebar nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 12px;
  border-radius: var(--radius-sm);
  text-decoration: none;
  color: rgba(255,255,255,0.72);
  font-size: 0.9rem;
  font-weight: 500;
  transition: background-color 0.12s ease, color 0.12s ease;
}
.sidebar nav a svg { flex-shrink: 0; opacity: 0.85; }
.sidebar nav a.active { background: var(--stamp); color: #fff; }
.sidebar nav a.active svg { opacity: 1; }
.sidebar nav a:hover:not(.active) { background: rgba(255,255,255,0.08); color: #fff; }
.sidebar form { margin-top: auto; }
.sidebar .logout-btn {
  width: 100%;
  min-height: 40px;
  padding: 10px 12px;
  background: transparent;
  border: 1px solid rgba(255,255,255,0.18);
  color: rgba(255,255,255,0.8);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 0.85rem;
  font-family: inherit;
}
.sidebar .logout-btn:hover { background: rgba(255,255,255,0.08); }

.main-area { flex: 1; min-width: 0; }
.topbar {
  display: none;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  padding: 14px 20px;
  background: var(--ink);
  color: #fff;
}
.topbar .brand { font-weight: 700; }
.topbar button {
  background: transparent;
  border: 1px solid rgba(255,255,255,0.3);
  color: #fff;
  padding: 7px 12px;
  border-radius: var(--radius-sm);
  font-family: inherit;
  min-height: 38px;
}

.content { padding: 28px 24px 80px; max-width: 1100px; margin: 0 auto; }

.page-title { font-size: 1.5rem; margin: 0 0 4px; letter-spacing: -0.01em; }
.page-subtitle { color: var(--ink-soft); margin: 0 0 24px; font-size: 0.92rem; }

/* ---------- Grille de stats ---------- */

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
  margin-bottom: 28px;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 18px;
}
.stat-card .value {
  font-family: var(--font-num);
  font-variant-numeric: tabular-nums;
  font-size: 1.7rem;
  font-weight: 600;
  color: var(--ink);
}
.stat-card .label { color: var(--ink-soft); font-size: 0.8rem; margin-top: 4px; }

/* ---------- Tableaux ---------- */

.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-md); }
table { width: 100%; border-collapse: collapse; font-size: 0.88rem; min-width: 560px; }
th, td { text-align: left; padding: 13px 16px; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { color: var(--ink-soft); font-weight: 600; font-size: 0.76rem; letter-spacing: 0.02em; }
tr:last-child td { border-bottom: none; }
tbody tr { transition: background-color 0.1s ease; }
tbody tr:hover { background: var(--surface-sunken); }
.table-link { color: var(--stamp-dark); font-weight: 600; text-decoration: none; }
.table-link:hover { text-decoration: underline; }
td.num, th.num { font-family: var(--font-num); }

.badge { display: inline-block; padding: 3px 10px; border-radius: var(--radius-pill); font-size: 0.74rem; font-weight: 600; }
.badge-active { background: var(--stamp-pale); color: var(--stamp-dark); }
.badge-suspended { background: var(--danger-pale); color: var(--danger); }

/* ---------- Menu deroulant (profil, menu mobile) ---------- */

.dropdown { position: relative; }
.dropdown-trigger {
  display: flex; align-items: center; gap: 8px; cursor: pointer; background: none; border: none;
  font-family: inherit; color: inherit; padding: 0;
}
.dropdown-trigger .chev { transition: transform 0.15s ease; opacity: 0.7; }
.dropdown.open .dropdown-trigger .chev { transform: rotate(180deg); }
.dropdown-panel {
  position: absolute; top: calc(100% + 10px); right: 0; min-width: 210px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-md);
  box-shadow: var(--shadow-pop); padding: 8px; z-index: 60;
  display: none;
}
.dropdown.open .dropdown-panel { display: block; }
.dropdown-panel a, .dropdown-panel .dropdown-item {
  display: block; width: 100%; text-align: left; padding: 10px 12px; border-radius: var(--radius-sm);
  font-size: 0.88rem; color: var(--ink); text-decoration: none; background: none; border: none;
  cursor: pointer; font-family: inherit;
}
.dropdown-panel a:hover, .dropdown-panel .dropdown-item:hover { background: var(--surface-sunken); }
.dropdown-panel .dropdown-item.danger { color: var(--danger); }
.dropdown-panel .divider { height: 1px; background: var(--border); margin: 6px 4px; }

/* ---------- Liste fine depliable (remplace les tableaux qui debordent sur mobile) ---------- */

.slim-list { border: 1px solid var(--border); border-radius: var(--radius-md); background: var(--surface); overflow: hidden; }
.slim-row {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 13px 16px; border-bottom: 1px solid var(--border); cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.slim-row:focus-visible { outline-offset: -2px; }
.slim-list > .slim-row:last-of-type { border-bottom: none; }
.slim-row-left { display: flex; align-items: center; gap: 10px; min-width: 0; flex: 1; }
.slim-title { font-size: 0.9rem; font-weight: 500; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.slim-sub { font-size: 0.76rem; color: var(--ink-soft); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.slim-right { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.slim-cost { font-family: var(--font-num); font-size: 0.85rem; color: var(--ink-soft); }
.slim-chev { transition: transform 0.2s ease; color: var(--ink-soft); flex-shrink: 0; }
.slim-row.open .slim-chev { transform: rotate(180deg); }
.slim-detail { max-height: 0; overflow: hidden; transition: max-height 0.22s ease; background: var(--surface-sunken); }
.slim-row.open + .slim-detail { max-height: 400px; }
.slim-detail-inner { padding: 14px 16px 16px; font-size: 0.85rem; }
.slim-detail-row { display: flex; justify-content: space-between; gap: 10px; padding: 5px 0; border-bottom: 1px solid var(--border); }
.slim-detail-row:last-of-type { border-bottom: none; }
.slim-detail-row .k { color: var(--ink-soft); }
.slim-detail-row .v { color: var(--ink); text-align: right; word-break: break-word; }
.slim-field { margin-bottom: 10px; }
.slim-field label { display: block; font-size: 0.72rem; color: var(--ink-soft); margin-bottom: 4px; }
.slim-field input, .slim-field textarea {
  /* 16px, pas 0.85rem : evite le zoom automatique de Safari iOS au focus. */
  width: 100%; padding: 8px 10px; border: 1px solid var(--border-strong); border-radius: 7px; font-size: 16px; box-sizing: border-box; font-family: inherit;
}
.slim-actions { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }
.slim-actions form { flex: 1; margin: 0; }
.slim-actions button, .slim-actions .btn {
  width: 100%; padding: 8px; border-radius: 7px; border: 1px solid var(--border-strong); background: var(--surface);
  font-size: 0.78rem; font-weight: 600; cursor: pointer; color: var(--ink); font-family: inherit;
}
.slim-actions button.save { background: var(--stamp); color: #fff; border-color: var(--stamp); }
.slim-actions button.danger, .slim-actions .btn.danger { color: var(--danger); }
.slim-empty { padding: 20px 16px; color: var(--ink-soft); font-size: 0.85rem; text-align: center; }

/* ---------- Carte de recompense (catalogue, sur mobile comme sur PC) ---------- */

.reward-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-md); padding: 14px 16px; margin-bottom: 10px; }
.reward-card-top { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 10px; }
.reward-card-top input.title-input { border: none; background: none; font-weight: 600; font-size: 16px; color: var(--ink); padding: 0; flex: 1; min-width: 0; font-family: inherit; }
.reward-card-fields { display: flex; gap: 10px; align-items: flex-end; margin-bottom: 12px; }
.reward-card-fields label { font-size: 0.72rem; color: var(--ink-soft); display: block; margin-bottom: 3px; }
.reward-card-fields input.cost-input { width: 90px; padding: 7px 9px; border: 1px solid var(--border-strong); border-radius: 6px; font-family: var(--font-num); font-size: 16px; }
.reward-card-actions { display: flex; gap: 8px; }
.reward-card-actions button, .reward-card-actions .btn { flex: 1; padding: 8px; border-radius: 8px; border: 1px solid var(--border-strong); background: var(--surface); font-size: 0.78rem; font-weight: 600; cursor: pointer; color: var(--ink); font-family: inherit; }
.reward-card-actions button.save { background: var(--stamp); color: #fff; border-color: var(--stamp); }
.reward-card-actions button.danger { color: var(--danger); }
.dropdown-panel form { margin: 0; }

.profile-chip { display: flex; align-items: center; gap: 10px; padding: 8px; border-radius: var(--radius-sm); }
.profile-avatar {
  width: 32px; height: 32px; border-radius: 50%; background: var(--stamp); color: #fff;
  display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 0.85rem; flex-shrink: 0;
}
.profile-name { font-size: 0.85rem; font-weight: 600; text-align: left; line-height: 1.3; max-width: 130px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- Raccourcis rapides (tableau de bord) ---------- */

.quick-actions { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin-bottom: 26px; }
.quick-action {
  display: flex; align-items: center; gap: 10px; padding: 14px 16px; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius-md); text-decoration: none; color: var(--ink);
  font-size: 0.85rem; font-weight: 600; transition: border-color 0.15s ease, transform 0.1s ease;
}
.quick-action svg { color: var(--stamp); flex-shrink: 0; }
.quick-action:hover { border-color: var(--stamp); }
.quick-action:active { transform: scale(0.98); }

/* ---------- Scanner ---------- */

#qr-reader { width: 100%; max-width: 420px; margin: 0 auto; border-radius: var(--radius-md); overflow: hidden; }
.scan-result { margin-top: 18px; }

/* ---------- Page client ---------- */

.hero { text-align: center; padding: 60px 20px 40px; }
.hero h1 { font-size: 2rem; margin-bottom: 8px; letter-spacing: -0.02em; }
.hero p { color: var(--ink-soft); }
.merchant-logo { width: 72px; height: 72px; border-radius: var(--radius-md); object-fit: cover; margin: 0 auto 16px; display: block; box-shadow: var(--shadow-card); }
.wallet-buttons { display: flex; flex-direction: column; gap: 12px; margin-top: 20px; }
.btn-apple { background: #000; color: #fff; }
.btn-apple:hover:not(:disabled) { background: #1a1a1a; }
.btn-google { background: var(--surface); color: var(--ink); border: 1px solid var(--border-strong); }
.btn-google:hover:not(:disabled) { background: var(--surface-sunken); }

footer.site-footer {
  text-align: center;
  padding: 24px;
  color: var(--ink-faint);
  font-size: 0.8rem;
}
footer.site-footer a { color: var(--ink-soft); }

/* ---------- Responsive ---------- */

@media (max-width: 820px) {
  .sidebar { display: none; }
  .topbar { display: flex; }
  .content { padding: 20px 16px 90px; }
  .btn { min-height: 48px; }
}

@media (min-width: 821px) {
  .mobile-nav { display: none; }
}

@media (max-width: 480px) {
  .hero { padding: 40px 16px 28px; }
  .hero h1 { font-size: 1.6rem; }
  .page-title { font-size: 1.3rem; }
}

/* ---------- Tutoriel guide (nouveaux comptes) ---------- */

.tour-dim {
  position: fixed; inset: 0; z-index: 900; background: rgba(20, 22, 20, 0.55);
  opacity: 0; transition: opacity 0.25s ease;
}
.tour-dim.tour-visible { opacity: 1; }

.tour-highlight {
  position: fixed; z-index: 901; border-radius: 12px; pointer-events: none;
  box-shadow: 0 0 0 9999px rgba(20, 22, 20, 0.55), 0 0 0 3px var(--stamp);
  transition: top 0.3s ease, left 0.3s ease, width 0.3s ease, height 0.3s ease, opacity 0.2s ease;
  opacity: 0;
}
.tour-highlight.tour-visible { opacity: 1; }

.tour-tooltip {
  position: fixed; z-index: 902; width: min(320px, calc(100vw - 32px)); background: #fff;
  border-radius: var(--radius-md); box-shadow: 0 20px 50px rgba(0,0,0,0.3); padding: 18px 20px;
  opacity: 0; transform: translateY(6px); transition: opacity 0.2s ease, transform 0.2s ease, top 0.3s ease, left 0.3s ease;
}
.tour-tooltip.tour-visible { opacity: 1; transform: translateY(0); }
.tour-tooltip .tour-step-count { font-size: 0.72rem; font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase; color: var(--stamp); margin-bottom: 6px; }
.tour-tooltip h3 { font-size: 1rem; margin: 0 0 8px; }
.tour-tooltip p { font-size: 0.86rem; color: var(--ink-soft); margin: 0 0 16px; line-height: 1.5; }
.tour-tooltip-actions { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.tour-skip { background: none; border: none; color: var(--ink-faint); font-size: 0.8rem; cursor: pointer; padding: 6px 0; }
.tour-skip:hover { color: var(--ink-soft); }
.tour-nav-btns { display: flex; gap: 8px; margin-left: auto; }
.tour-nav-btns button { min-height: 36px; padding: 0 14px; font-size: 0.82rem; }

.tour-relaunch { font-size: 0.82rem; color: var(--ink-soft); background: none; border: none; cursor: pointer; padding: 0; text-decoration: underline; text-underline-offset: 2px; }
.tour-relaunch:hover { color: var(--ink); }
