/* ══ VA — feuille de style. iPhone d'abord, thème sombre par défaut. ══ */
:root {
  --bg: #0b0e14;
  --surface: #141924;
  --surface-2: #1c2331;
  --line: #262f40;
  --text: #e8ecf4;
  --muted: #8b97ad;
  --accent: #4c8dff;
  --accent-2: #7b4cff;
  --accent-ink: #fff;
  --ok: #35c96b;
  --warn: #ffb020;
  --danger: #ff5d5d;
  --radius: 14px;
  --tabh: 58px;
}
@media (prefers-color-scheme: light) {
  :root {
    --bg: #f4f6fa; --surface: #fff; --surface-2: #eef1f7; --line: #dfe4ee;
    --text: #101725; --muted: #64708a;
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
/* L'attribut `hidden` n'est qu'une regle par defaut du navigateur : la moindre
   regle d'auteur qui pose un `display` (ex. .gate{display:grid}) l'ecrase et
   l'element reste visible. On lui redonne le dernier mot, une fois pour toutes. */
[hidden] { display: none !important; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, system-ui, sans-serif;
  -webkit-font-smoothing: antialiased; overscroll-behavior-y: none;
}
h1, h2 { margin: 0; font-weight: 650; letter-spacing: -0.01em; }
h1 { font-size: 22px; }
h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
p { margin: 8px 0 0; }
.muted { color: var(--muted); }
.error { color: var(--danger); font-size: 14px; }
.note { font-weight: 400; text-transform: none; letter-spacing: 0; color: var(--muted); }
.hint { font-size: 13px; color: var(--muted); }

.logo {
  display: inline-grid; place-items: center; width: 56px; height: 56px; border-radius: 16px;
  background: linear-gradient(145deg, var(--accent), var(--accent-2));
  color: #fff; font-weight: 800; font-size: 22px; letter-spacing: -.02em;
}
.logo.sm { width: 28px; height: 28px; border-radius: 9px; font-size: 12px; }

/* ══ Portail ══ */
.gate { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: 24px; }
.gate-box { width: 100%; max-width: 340px; text-align: center; }
.gate-box h1 { margin: 16px 0 4px; }
#login-form { display: grid; gap: 10px; margin-top: 22px; }

input[type="password"], input[type="number"] {
  width: 100%; padding: 14px 16px; font-size: 16px; /* 16px : pas de zoom auto iOS */
  color: var(--text); background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); outline: none;
}
input:focus { border-color: var(--accent); }

button { font: inherit; cursor: pointer; border: none; border-radius: var(--radius); }
.primary {
  padding: 14px 18px; font-weight: 650; color: var(--accent-ink); background: var(--accent);
  transition: transform .08s ease, opacity .15s ease;
}
.primary:active { transform: scale(.985); }
.primary:disabled { opacity: .4; cursor: default; }
.primary.big { width: 100%; padding: 16px; font-size: 17px; }
/* Hauteur minimale 44 px : recommandation tactile d'Apple. En dessous, on rate
   la cible au doigt — et un « Ajouter » manque revient a une appli cassee. */
.ghost {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 44px; padding: 8px 14px; font-size: 14px;
  color: var(--muted); background: var(--surface-2); border: 1px solid var(--line);
}
.ghost.sm { min-height: 44px; padding: 6px 14px; font-size: 13px; }
.ghost.upload { cursor: pointer; color: var(--accent); border-color: color-mix(in srgb, var(--accent) 45%, var(--line)); }

/* Televersement : le champ natif est pose PAR-DESSUS le bouton, transparent.
   Le doigt touche donc l'input lui-meme. C'est le seul montage fiable sur
   iOS : Safari refuse d'ouvrir le selecteur pour un input en display:none,
   meme via un .click() programme ou un <label> englobant. */
.uploader { position: relative; display: inline-block; }
.uploader input[type="file"] {
  position: absolute; inset: 0; width: 100%; height: 100%;
  opacity: 0; font-size: 0; cursor: pointer;
}

/* ══ Structure ══ */
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: max(10px, env(safe-area-inset-top)) 16px 10px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(180%) blur(14px); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; font-size: 17px; }
.build { margin-left: auto; margin-right: 8px; font-size: 10.5px; color: var(--muted); font-variant-numeric: tabular-nums; }
main { padding: 16px 16px calc(var(--tabh) + 96px + env(safe-area-inset-bottom)); }
.block { margin-bottom: 22px; }
.block > h2 { margin-bottom: 10px; }
.row-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.row-head h2 { margin: 0; }

/* ══ Pastilles ══ */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chips.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); }
.chip {
  flex: 0 0 auto; min-height: 44px; padding: 11px 14px;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font-size: 15px; color: var(--text); background: var(--surface);
  border: 1px solid var(--line); border-radius: 12px;
  transition: background .12s ease, border-color .12s ease;
}
.chip:active { background: var(--surface-2); }
.chip.on {
  background: color-mix(in srgb, var(--accent) 18%, var(--surface));
  border-color: var(--accent); font-weight: 600;
}
.chips.flags .flag { font-size: 19px; line-height: 1; }
.custom { margin-top: 8px; }
.chip.newtag { color: var(--accent); border-style: dashed; }
.chip.small { min-height: 38px; padding: 8px 12px; font-size: 14px; }

/* ══ Aperçu VCF ══ */
.sample { list-style: none; margin: 0; padding: 0; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.sample li {
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  padding: 11px 14px; background: var(--surface); border-bottom: 1px solid var(--line); font-size: 14px;
}
.sample li:last-child { border-bottom: none; }
.sample .tel { color: var(--muted); font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 13px; white-space: nowrap; }

/* ══ Repli (stats + limites) ══ */
.fold { border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); overflow: hidden; }
.fold summary {
  padding: 14px; font-size: 14px; font-weight: 600; cursor: pointer; list-style: none;
  display: flex; justify-content: space-between; align-items: center;
}
.fold summary::-webkit-details-marker { display: none; }
.fold summary::after { content: "▾"; color: var(--muted); transition: transform .2s ease; }
.fold[open] summary::after { transform: rotate(180deg); }
.fold-body { padding: 0 14px 14px; }
.kv { display: grid; grid-template-columns: 1fr auto; gap: 2px 12px; }
.kv div { padding: 9px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.kv div:nth-child(odd) { color: var(--muted); }
.kv div:nth-child(even) { text-align: right; font-variant-numeric: tabular-nums; }

/* ══ Cartes de compteur ══ */
.stat-cards { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.stat-card {
  padding: 14px 10px; text-align: center; background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--radius);
}
.stat-card .n { display: block; font-size: 24px; font-weight: 700; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.stat-card .l { display: block; margin-top: 2px; font-size: 11.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.stat-card.free .n { color: var(--ok); }

/* ══ Liste de fichiers ══ */
.filelist { list-style: none; margin: 0; padding: 0; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.filelist li {
  display: flex; align-items: center; gap: 12px; padding: 12px 14px;
  background: var(--surface); border-bottom: 1px solid var(--line);
}
.filelist li:last-child { border-bottom: none; }
.filelist li.sel { background: color-mix(in srgb, var(--accent) 14%, var(--surface)); }
.filelist .meta { flex: 1; min-width: 0; }
.filelist .fname {
  display: block; font-size: 14.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
}
.filelist .fsub { display: block; margin-top: 2px; font-size: 12px; color: var(--muted); }
.tag { padding: 3px 8px; font-size: 11px; border-radius: 20px; white-space: nowrap; }
.empty { padding: 28px 16px; text-align: center; color: var(--muted); font-size: 14px;
  border: 1px dashed var(--line); border-radius: var(--radius); }

/* ══ Grille photos ══ */
.grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
@media (min-width: 620px) { .grid { grid-template-columns: repeat(5, 1fr); } }
.cell { position: relative; aspect-ratio: 1; border-radius: 10px; overflow: hidden; background: var(--surface-2); border: 1px solid var(--line); }
.cell img { width: 100%; height: 100%; object-fit: cover; display: block; }
.cell.sel { outline: 3px solid var(--accent); outline-offset: -3px; }
.cell .badge {
  position: absolute; top: 5px; right: 5px; width: 20px; height: 20px; border-radius: 50%;
  display: grid; place-items: center; font-size: 12px; color: #fff;
  background: color-mix(in srgb, #000 55%, transparent);
}
.cell.sel .badge { background: var(--accent); }
.cell .fallback { display: grid; place-items: center; height: 100%; padding: 6px; font-size: 10px;
  color: var(--muted); text-align: center; word-break: break-all; }
/* Téléchargement direct d'une vignette : cible tactile confortable, en surimpression. */
.cell .dl {
  position: absolute; left: 5px; bottom: 5px; width: 30px; height: 30px; padding: 0;
  display: grid; place-items: center; font-size: 15px; line-height: 1; border-radius: 50%;
  color: #fff; background: color-mix(in srgb, #000 55%, transparent);
  backdrop-filter: blur(4px);
}
.cell .dl:active { background: var(--accent); }

/* ══ Progression ══ */
/* Retour visuel du glisser-deposer (Mac) */
.page.drop { outline: 2px dashed var(--accent); outline-offset: 6px; border-radius: var(--radius); }

.progress { margin-bottom: 10px; font-size: 13px; color: var(--muted); }
.progress .bar { height: 4px; margin-top: 6px; border-radius: 4px; background: var(--surface-2); overflow: hidden; }
.progress .bar i { display: block; height: 100%; background: var(--accent); transition: width .2s ease; }

/* ══ Barre d'action ══ */
.action {
  position: fixed; left: 0; right: 0; bottom: calc(var(--tabh) + env(safe-area-inset-bottom));
  padding: 12px 16px; z-index: 4;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: saturate(180%) blur(14px); border-top: 1px solid var(--line);
}
.action-note { margin: 6px 0 0; min-height: 15px; font-size: 12px; color: var(--muted); text-align: center; }
.action-note.err { color: var(--danger); }
.action-note.ok { color: var(--ok); }

/* ══ Onglets ══ */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 6;
  display: grid; grid-template-columns: repeat(3, 1fr);
  padding-bottom: env(safe-area-inset-bottom);
  background: color-mix(in srgb, var(--bg) 94%, transparent);
  backdrop-filter: saturate(180%) blur(14px); border-top: 1px solid var(--line);
}
.tab { display: grid; gap: 2px; place-items: center; height: var(--tabh); padding: 0; border-radius: 0;
  background: none; color: var(--muted); font-size: 11px; }
.tab span { font-size: 17px; line-height: 1; }
.tab.on { color: var(--accent); }

/* ══ Occupé ══ */
.primary.busy { position: relative; color: transparent; }
.primary.busy::after {
  content: ""; position: absolute; inset: 0; margin: auto; width: 18px; height: 18px;
  border-radius: 50%; border: 2px solid color-mix(in srgb, var(--accent-ink) 40%, transparent);
  border-top-color: var(--accent-ink); animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .primary.busy::after { animation-duration: 2s; } }
