/* Wallet : une pile de cartes au format carte bancaire, un ticket blanc pour le code en caisse */
:root {
  --bg: #F3F1EC; --surface: #FFFFFF; --ink: #16181D; --muted: #6B6E78; --line: #E2DFD8;
  --accent: #1F6F5C; --accent-ink: #FFFFFF; --danger: #C23A2B; --field: #ECE9E2;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Helvetica Neue", system-ui, sans-serif;
  --display: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Helvetica Neue", system-ui, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, monospace;
  --safe-t: env(safe-area-inset-top, 0px); --safe-b: env(safe-area-inset-bottom, 0px);
  --gutter-l: max(16px, env(safe-area-inset-left, 0px)); --gutter-r: max(16px, env(safe-area-inset-right, 0px));
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121418; --surface: #1C1F25; --ink: #EEF0F3; --muted: #9298A3; --line: #2B2F37;
    --accent: #5CC6A6; --accent-ink: #0E1A16; --danger: #F07A6A; --field: #23272E;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 16px/1.4 var(--font); -webkit-font-smoothing: antialiased; overscroll-behavior-y: none; }
[hidden] { display: none !important; }
h1, h2, h3 { font-family: var(--display); margin: 0; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.muted { color: var(--muted); }
.small { font-size: .86rem; }
.error { color: var(--danger); font-size: .9rem; margin: 0; }

.btn { border: 0; border-radius: 12px; padding: 12px 16px; background: var(--field); font-weight: 600; text-align: center; display: inline-flex; align-items: center; justify-content: center; gap: 6px; }
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.ghost { background: transparent; color: var(--ink); }
.btn.danger { background: transparent; color: var(--danger); }
.btn.link { background: transparent; padding: 8px 4px; color: var(--accent); font-weight: 500; }
.btn.link.strong { font-weight: 700; }
.btn:active { opacity: .7; }
.icon-btn { border: 0; background: transparent; padding: 8px; border-radius: 50%; color: var(--ink); display: grid; place-items: center; }
.icon-btn.on-color { color: inherit; background: rgba(255,255,255,.18); }

input[type=text], input[type=search], select, .code-input {
  width: 100%; border: 1px solid transparent; background: var(--field); border-radius: 12px; padding: 12px 14px; min-width: 0; font-size: 16px; }
input:focus, select:focus { outline: none; border-color: var(--accent); }
select { -webkit-appearance: none; appearance: none; padding-right: 36px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 10 6'%3E%3Cpath d='M1 1l4 4 4-4' fill='none' stroke='%23888' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 14px center; background-size: 10px 6px; }

/* Écrans */
.screen { min-height: 100%; padding: calc(var(--safe-t) + 8px) var(--gutter-r) calc(var(--safe-b) + 96px) var(--gutter-l); }
.bar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 6px 0 10px; }
.bar h1 { font-size: 2rem; font-weight: 700; letter-spacing: -.02em; }
.search-wrap { padding-bottom: 14px; }
.sync-note { font-size: .82rem; color: var(--muted); padding: 0 2px 10px; }

/* Grille de cartes au format ISO (85,6 × 54 mm) */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.tile { position: relative; aspect-ratio: 85.6 / 54; border-radius: 14px; border: 0; padding: 12px 13px; text-align: left; display: flex; flex-direction: column; justify-content: space-between;
  box-shadow: 0 1px 0 rgba(255,255,255,.18) inset, 0 6px 16px -10px rgba(0,0,0,.45); overflow: hidden; max-width: 100%; }
.tile::after { content: ""; position: absolute; inset: 0; background: linear-gradient(135deg, rgba(255,255,255,.16), rgba(255,255,255,0) 55%); pointer-events: none; }
.tile .t-name { font-family: var(--display); font-weight: 700; font-size: 1.08rem; line-height: 1.15; letter-spacing: -.01em; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.tile .t-holder { font-size: .78rem; opacity: .82; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile .t-num { font-family: var(--mono); font-size: .72rem; opacity: .75; letter-spacing: .04em; }
.tile:active { transform: scale(.97); }
.empty { grid-column: 1 / -1; text-align: center; color: var(--muted); padding: 48px 12px; line-height: 1.6; }

.fab { position: fixed; right: calc(var(--gutter-r) + 4px); bottom: calc(var(--safe-b) + 20px); width: 58px; height: 58px; border-radius: 50%; border: 0;
  background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; box-shadow: 0 10px 24px -8px rgba(0,0,0,.5); z-index: 5; }

/* Feuilles plein écran */
.sheet { position: fixed; inset: 0; z-index: 10; background: var(--bg); overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: calc(var(--safe-t) + 4px) var(--gutter-r) calc(var(--safe-b) + 24px) var(--gutter-l); animation: up .22s ease-out; }
@keyframes up { from { transform: translateY(24px); opacity: .4; } to { transform: none; opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .sheet { animation: none; } .tile:active { transform: none; } }
.sheet-bar { position: sticky; top: calc(-1 * var(--safe-t) - 4px); background: var(--bg); padding-top: calc(var(--safe-t) + 8px); margin-top: calc(-1 * var(--safe-t) - 4px); z-index: 2; }
.sheet-bar h2 { font-size: 1.05rem; font-weight: 600; }
.form { display: grid; gap: 16px; max-width: 560px; margin: 0 auto; padding-top: 8px; }
.field { display: grid; gap: 6px; }
.field > span { font-size: .82rem; color: var(--muted); font-weight: 500; padding-left: 2px; }
.scan-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.swatches { display: grid; grid-template-columns: repeat(6, 1fr); gap: 10px; }
.swatch { aspect-ratio: 1; border-radius: 50%; border: 0; box-shadow: 0 0 0 1px rgba(0,0,0,.08) inset; }
.swatch[aria-pressed=true] { box-shadow: 0 0 0 3px var(--bg), 0 0 0 5px var(--ink); }
.preview-wrap { display: grid; gap: 6px; }

/* Carte en caisse */
.show-sheet { display: flex; flex-direction: column; gap: 16px; justify-content: center; }
.show-card { border-radius: 22px; padding: 18px 16px 16px; display: grid; gap: 16px; max-width: 520px; width: 100%; margin: 0 auto; box-shadow: 0 20px 40px -20px rgba(0,0,0,.6); }
.show-head { display: flex; justify-content: space-between; align-items: start; gap: 12px; }
.show-name { font-family: var(--display); font-weight: 700; font-size: 1.6rem; letter-spacing: -.02em; line-height: 1.1; }
.show-holder { font-size: .9rem; opacity: .85; margin-top: 2px; }
.ticket { background: #FFFFFF; color: #111; border-radius: 14px; padding: 18px 16px 14px; display: grid; gap: 10px; justify-items: center; }
.code { width: 100%; display: grid; place-items: center; min-height: 40px; }
.code svg { width: 100%; height: auto; max-height: 140px; display: block; }
.code.qr svg { width: min(68vw, 240px); max-height: none; }
.number { font-family: var(--mono); font-size: 1.05rem; letter-spacing: .08em; text-align: center; word-break: break-all; user-select: all; }
.number.big { font-size: 1.6rem; }
.show-actions { display: flex; justify-content: center; gap: 8px; }

/* Scanner */
.scan-sheet { background: #000; padding: 0; display: grid; place-items: center; }
.scan-sheet video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.scan-frame { position: relative; width: min(84vw, 420px); aspect-ratio: 2 / 1; border: 3px solid rgba(255,255,255,.9); border-radius: 18px; box-shadow: 0 0 0 100vmax rgba(0,0,0,.45); }
.scan-hint { position: absolute; top: calc(var(--safe-t) + 24px); left: 0; right: 0; text-align: center; color: #fff; font-weight: 600; margin: 0; }
.scan-close { position: absolute; bottom: calc(var(--safe-b) + 28px); left: 50%; transform: translateX(-50%); background: rgba(255,255,255,.92); color: #111; }

/* Réglages */
.group { display: grid; gap: 10px; background: var(--surface); border-radius: 16px; padding: 16px; }
.group h3 { font-size: 1rem; font-weight: 600; }
.group p { margin: 0; }
.new-code { font-family: var(--mono); font-size: 2.4rem; font-weight: 700; letter-spacing: .3em; text-align: center; padding: 10px 0 2px; }
.new-code small { display: block; font-family: var(--font); font-size: .82rem; font-weight: 400; letter-spacing: 0; color: var(--muted); }
.devices { list-style: none; margin: 0; padding: 0; display: grid; }
.devices li { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 10px 0; border-top: 1px solid var(--line); }
.devices li:first-child { border-top: 0; }
.devices .d-name { font-weight: 600; }
.devices .d-meta { font-size: .8rem; color: var(--muted); }
.devices .btn { padding: 8px 10px; font-size: .9rem; }

/* Appairage */
.pair-box { max-width: 380px; margin: 12vh auto 0; display: grid; gap: 14px; text-align: center; }
.pair-icon { margin: 0 auto; border-radius: 16px; }
.pair-box h1 { font-size: 1.8rem; }
.pair-box p { margin: 0; }
.stack { display: grid; gap: 10px; margin-top: 8px; }
.code-input { font-family: var(--mono); font-size: 2rem; letter-spacing: .4em; text-align: center; padding: 14px; }

.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--safe-b) + 92px); background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: .92rem; z-index: 30; max-width: calc(100vw - 32px); text-align: center; }

/* Cartes avec logo : le logo (sur fond de sa couleur) remplit la carte, comme sur la carte physique */
.tile.has-logo { padding: 10px; justify-content: center; align-items: center; }
.tile.has-logo::after { display: none; }
.t-logo { max-width: 78%; max-height: 72%; object-fit: contain; display: block; margin: auto; }
.t-corner { position: absolute; top: 8px; right: 10px; font-size: .72rem; }
.show-logo { display: block; max-height: 64px; max-width: 70%; object-fit: contain; }

/* Onglets Cartes / Voyage */
.tabs { display: inline-flex; background: var(--field); border-radius: 12px; padding: 3px; gap: 2px; }
.tabs button { border: 0; background: transparent; padding: 8px 16px; border-radius: 10px; font-weight: 600; font-size: 1rem; color: var(--muted); }
.tabs button[aria-selected=true] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,.18); }

/* Voyage : billets groupés par jour */
.trip { display: grid; gap: 6px; margin-bottom: 18px; }
.trip h2 { font-size: 1.5rem; font-weight: 700; letter-spacing: -.02em; padding: 4px 2px 2px; }
.day { font-size: .8rem; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; padding: 12px 2px 4px; }
.day.today { color: var(--accent); }
.tk-row { display: grid; grid-template-columns: 56px 1fr auto; gap: 12px; align-items: center; width: 100%; text-align: left; border: 0; background: var(--surface); border-radius: 14px; padding: 12px 14px; }
.tk-row:active { opacity: .7; }
.tk-row .time { font-family: var(--mono); font-weight: 600; font-size: .95rem; }
.tk-row .time.none { color: var(--muted); font-family: var(--font); font-weight: 500; font-size: .8rem; }
.tk-row .what { min-width: 0; }
.tk-row .t, .tk-row .s { display: block; }
.tk-row .t { font-weight: 600; }
.tk-row .s { font-size: .85rem; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip { font-size: .78rem; font-weight: 600; padding: 4px 10px; border-radius: 999px; background: var(--accent); color: var(--accent-ink); white-space: nowrap; }

.ticket-view { display: grid; gap: 14px; max-width: 620px; margin: 0 auto; padding-top: 6px; }
.tk-when { font-size: .85rem; color: var(--muted); font-weight: 600; }
.tk-title { font-family: var(--display); font-size: 1.5rem; font-weight: 700; letter-spacing: -.02em; line-height: 1.15; }
.tk-sub { color: var(--muted); }
.tk-warn { margin: 0; font-size: .86rem; color: var(--muted); }
.tk-image { background: #fff; border-radius: 14px; overflow: hidden; display: grid; place-items: center; }
.tk-image img { display: block; width: 100%; height: auto; }
.tk-image img.qr-only { width: min(86vw, 360px); image-rendering: pixelated; padding: 18px; }
.tk-image .loading { color: #666; padding: 40px; font-size: .9rem; }
.small-preview img { max-height: 220px; width: auto; max-width: 100%; }
.check { display: flex; gap: 10px; align-items: center; font-size: .92rem; }
.check input { width: 20px; height: 20px; accent-color: var(--accent); }
