/* ==========================================================================
   Portail eperso — feuille de style unique.
   Thème clair et sombre, du téléphone au grand écran.
   ========================================================================== */

:root {
  --indigo: #4f46e5;
  --indigo-soft: #eef2ff;
  --red: #ef4444;
  --green: #10b981;

  --bg: #f1f5f9;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #e2e8f0;
  --text: #0f172a;
  --text-soft: #64748b;
  --text-faint: #94a3b8;

  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .04), 0 8px 24px -12px rgba(15, 23, 42, .12);
  --shadow-lg: 0 12px 40px -12px rgba(15, 23, 42, .25);

  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1120;
    --surface: #111827;
    --surface-2: #1a2233;
    --border: #1f2937;
    --text: #f1f5f9;
    --text-soft: #94a3b8;
    --text-faint: #64748b;
    --indigo-soft: #1e1b4b;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px -12px rgba(0, 0, 0, .6);
    --shadow-lg: 0 12px 40px -12px rgba(0, 0, 0, .8);
  }
}

*, *::before, *::after { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
}

h1, h2 { margin: 0; font-weight: 700; letter-spacing: -.01em; }
a { color: var(--indigo); }
code { font-family: ui-monospace, 'Cascadia Mono', Menlo, monospace; font-size: .92em; }

.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;
}
.spacer { flex: 1; }
.inline-form { margin: 0; display: inline-flex; }

/* ---------- Boutons ----------
   Deux details font l'essentiel du confort sur mobile, avant toute esthetique :
     · le survol est enferme dans @media (hover: hover). Sans cela, un doigt
       laisse le bouton en etat survole apres le tap — il a l'air bloque ;
     · -webkit-tap-highlight-color coupe le rectangle gris que le navigateur
       peint sur chaque appui, et touch-action supprime le delai de 300 ms.
   La profondeur vient ensuite d'ombres douces superposees plutot que d'une
   arete franche, et l'appui repond par un enfoncement court et elastique. */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 11px 18px; border: none; border-radius: 14px;
  font: inherit; font-weight: 600; letter-spacing: .005em;
  cursor: pointer; text-decoration: none;
  min-height: 46px;
  position: relative; isolation: isolate; overflow: hidden;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  user-select: none; -webkit-user-select: none;
  transition: transform .16s cubic-bezier(.2, .9, .3, 1.3),
              box-shadow .16s ease, filter .16s ease;
}

/* Voile lumineux en haut : donne le galbe sans alourdir. */
.btn-primary::after {
  content: ""; position: absolute; inset: 0; border-radius: inherit;
  pointer-events: none; z-index: -1;
  background: linear-gradient(180deg, rgba(255, 255, 255, .22) 0%, rgba(255, 255, 255, 0) 58%);
}

.btn-primary {
  background: linear-gradient(145deg,
              color-mix(in srgb, var(--indigo) 78%, #fff) 0%,
              var(--indigo) 45%,
              color-mix(in srgb, var(--indigo) 84%, #000) 100%);
  color: #fff;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, .28),
    inset 0 -1px 0 rgba(0, 0, 0, .18),
    0 6px 18px -6px color-mix(in srgb, var(--indigo) 78%, transparent),
    0 2px 6px -2px rgba(15, 23, 42, .28);
}

.btn-ghost {
  background: var(--surface);
  color: var(--text-soft);
  box-shadow:
    inset 0 0 0 1px var(--border),
    0 2px 6px -3px rgba(15, 23, 42, .3);
}

.btn-danger {
  background: color-mix(in srgb, var(--red) 10%, var(--surface));
  color: var(--red);
  box-shadow:
    inset 0 0 0 1px color-mix(in srgb, var(--red) 28%, transparent),
    0 2px 6px -3px color-mix(in srgb, var(--red) 40%, transparent);
}

/* Le survol n'existe que la ou il y a un curseur. */
@media (hover: hover) {
  .btn-primary:hover:not(:disabled) {
    transform: translateY(-1px);
    box-shadow:
      inset 0 1px 0 rgba(255, 255, 255, .32),
      inset 0 -1px 0 rgba(0, 0, 0, .18),
      0 10px 24px -8px color-mix(in srgb, var(--indigo) 82%, transparent),
      0 3px 8px -3px rgba(15, 23, 42, .3);
  }
  .btn-ghost:hover:not(:disabled) {
    color: var(--text); transform: translateY(-1px);
    box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--indigo) 40%, var(--border)),
                0 6px 14px -6px rgba(15, 23, 42, .35);
  }
  .btn-danger:hover:not(:disabled) {
    transform: translateY(-1px);
    background: color-mix(in srgb, var(--red) 16%, var(--surface));
  }
}

/* L'appui : court, net, elastique. */
.btn:active:not(:disabled) {
  transform: translateY(1px) scale(.975);
  transition-duration: .06s;
}
.btn-primary:active:not(:disabled) {
  box-shadow:
    inset 0 2px 5px rgba(0, 0, 0, .28),
    0 2px 6px -3px color-mix(in srgb, var(--indigo) 70%, transparent);
  filter: brightness(.97);
}
.btn-ghost:active:not(:disabled),
.btn-danger:active:not(:disabled) {
  box-shadow: inset 0 2px 5px rgba(15, 23, 42, .14), inset 0 0 0 1px var(--border);
}

.btn:disabled { opacity: .42; cursor: not-allowed; transform: none; box-shadow: inset 0 0 0 1px var(--border); }

/* Pleine largeur : un libelle long passe a la ligne au lieu de deborder. */
.btn-block { display: flex; width: 100%; white-space: normal; }
.btn-sm { padding: 7px 13px; font-size: 13px; min-height: 40px; border-radius: 11px; }

@media (prefers-color-scheme: dark) {
  .btn-ghost { background: var(--surface-2); box-shadow: inset 0 0 0 1px var(--border), 0 2px 6px -3px rgba(0, 0, 0, .7); }
  .btn-ghost:active:not(:disabled),
  .btn-danger:active:not(:disabled) { box-shadow: inset 0 2px 6px rgba(0, 0, 0, .5), inset 0 0 0 1px var(--border); }
}

/* ---------- Champs ---------- */
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field > span {
  font-size: 12.5px; font-weight: 600; color: var(--text-soft); letter-spacing: .01em;
}
.field > span em { font-weight: 400; font-style: normal; color: var(--text-faint); }
.field-narrow { flex: 0 0 96px; }
.field-row { display: flex; gap: 12px; }
.field-check { flex-direction: row; align-items: center; gap: 10px; }
.field-check input { width: 20px; height: 20px; accent-color: var(--indigo); }
.field-check span { font-size: 14px; color: var(--text); font-weight: 500; }

input[type="text"], input[type="email"], input[type="password"], input[type="url"] {
  width: 100%; padding: 11px 13px; min-height: 44px;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text); font: inherit;
  transition: border-color .15s ease, box-shadow .15s ease;
}
input:focus-visible {
  outline: none; border-color: var(--indigo);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--indigo) 22%, transparent);
}
/* Les boutons portent leur relief dans box-shadow : une bague de focus ecrite
   la l'effacerait. On passe donc par outline, qui se superpose sans rien oter. */
.btn:focus-visible, a:focus-visible, summary:focus-visible, .app-card:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--indigo) 55%, transparent);
  outline-offset: 2px;
}
.hint { font-size: 12.5px; color: var(--text-faint); margin: 0; }
.stack { display: flex; flex-direction: column; gap: 14px; }

/* ---------- Alertes ---------- */
.alert {
  padding: 12px 14px; border-radius: var(--radius-sm); font-size: 14px;
  margin: 0 0 18px; border: 1px solid transparent; line-height: 1.5;
}
.alert-error { background: color-mix(in srgb, var(--red) 12%, transparent); color: #b91c1c; border-color: color-mix(in srgb, var(--red) 30%, transparent); }
.alert-ok { background: color-mix(in srgb, var(--green) 12%, transparent); color: #047857; border-color: color-mix(in srgb, var(--green) 30%, transparent); }
@media (prefers-color-scheme: dark) {
  .alert-error { color: #fca5a5; }
  .alert-ok { color: #6ee7b7; }
}

/* ==========================================================================
   La porte
   ========================================================================== */
.gate-body {
  min-height: 100dvh; display: grid; place-items: center; padding: 24px;
  background:
    radial-gradient(1000px 500px at 15% -10%, color-mix(in srgb, var(--indigo) 18%, transparent), transparent 60%),
    var(--bg);
}
.gate-card {
  width: 100%; max-width: 360px; background: var(--surface);
  border: 1px solid var(--border); border-radius: 22px;
  padding: 32px 26px; box-shadow: var(--shadow-lg);
}
/* Ni titre, ni nom, ni indice : un visiteur de passage ne doit rien déduire. */
.gate-logo { font-size: 38px; line-height: 1; text-align: center; margin-bottom: 20px; opacity: .85; }
.gate-form { display: flex; flex-direction: column; gap: 14px; }

/* ---------- Le pavé de la porte ----------
   Quatre chiffres ne justifient pas d'ouvrir le clavier du système, qui
   recouvre la moitié d'un écran de téléphone. */

/* Les pastilles : combien de chiffres sont saisis, jamais lesquels. */
.pin { display: flex; justify-content: center; gap: 14px; margin: 4px 0 22px; }
.pin i {
  width: 14px; height: 14px; border-radius: 50%;
  background: transparent;
  box-shadow: inset 0 0 0 2px color-mix(in srgb, var(--text-faint) 60%, transparent);
  transition: transform .18s cubic-bezier(.2, .9, .3, 1.6), background .18s ease, box-shadow .18s ease;
}
.pin i.is-on {
  background: var(--indigo);
  box-shadow: inset 0 0 0 2px var(--indigo),
              0 3px 10px -3px color-mix(in srgb, var(--indigo) 80%, transparent);
  transform: scale(1.18);
}
/* Code refusé : les pastilles le disent d'un mouvement, sans phrase de plus. */
.pin.is-wrong i {
  box-shadow: inset 0 0 0 2px color-mix(in srgb, var(--red) 70%, transparent);
}
.pin.is-wrong { animation: pin-shake .42s cubic-bezier(.36, .07, .19, .97); }
@keyframes pin-shake {
  10%, 90% { transform: translateX(-2px); }
  20%, 80% { transform: translateX(4px); }
  30%, 50%, 70% { transform: translateX(-7px); }
  40%, 60% { transform: translateX(7px); }
}

.keypad {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px;
  margin-top: 4px;
}
.keypad.is-busy { opacity: .55; pointer-events: none; }
.key-hole { display: block; }

.key {
  display: grid; place-items: center;
  aspect-ratio: 1 / 1; width: 100%; max-height: 74px;
  border: none; border-radius: 20px;
  background: var(--surface);
  color: var(--text);
  font: inherit; font-size: 25px; font-weight: 600;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  user-select: none; -webkit-user-select: none;
  box-shadow:
    inset 0 0 0 1px var(--border),
    0 4px 12px -6px rgba(15, 23, 42, .4);
  transition: transform .13s cubic-bezier(.2, .9, .3, 1.4),
              box-shadow .13s ease, background .13s ease;
}
@media (hover: hover) {
  .key:hover {
    transform: translateY(-2px);
    background: color-mix(in srgb, var(--indigo) 6%, var(--surface));
    box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--indigo) 35%, var(--border)),
                0 8px 18px -8px rgba(15, 23, 42, .45);
  }
}
/* L'appui doit se voir tout de suite : c'est le seul retour dont on dispose. */
.key:active {
  transform: scale(.93);
  transition-duration: .05s;
  background: color-mix(in srgb, var(--indigo) 14%, var(--surface));
  box-shadow: inset 0 2px 8px rgba(15, 23, 42, .18),
              inset 0 0 0 1px color-mix(in srgb, var(--indigo) 45%, var(--border));
}
.key-del { font-size: 21px; color: var(--text-soft); }

@media (prefers-color-scheme: dark) {
  .key { background: var(--surface-2); box-shadow: inset 0 0 0 1px var(--border), 0 4px 12px -6px rgba(0, 0, 0, .8); }
  .key:active { box-shadow: inset 0 2px 8px rgba(0, 0, 0, .6), inset 0 0 0 1px color-mix(in srgb, var(--indigo) 45%, var(--border)); }
}

/* Sur un petit ecran, le pave prend la place qu'il merite. */
@media (max-width: 620px) {
  .keypad { gap: 14px; }
  .key { font-size: 28px; border-radius: 24px; max-height: none; }
  .pin { gap: 16px; margin-bottom: 26px; }
  .pin i { width: 16px; height: 16px; }
}

/* ==========================================================================
   Barre et page
   ========================================================================== */
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: saturate(180%) blur(14px);
  border-bottom: 1px solid var(--border);
}
.topbar-inner {
  max-width: 900px; margin: 0 auto; min-height: 60px;
  padding: 8px 16px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 9px; text-decoration: none; color: var(--text); }
.brand-mark { font-size: 21px; }
.brand-text { font-weight: 700; font-size: 15.5px; letter-spacing: -.01em; }

.wrap { max-width: 900px; margin: 0 auto; padding: 24px 16px 60px; }
.wrap-narrow { max-width: 640px; }

/* ---------- Grille du portail ---------- */
.grid {
  display: grid; gap: 14px;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
}
/* La carte est le vrai bouton du portail : meme logique que les boutons —
   survol reserve aux pointeurs, appui court et elastique, aucun rectangle gris. */
.app-card {
  display: flex; align-items: center; gap: 14px; padding: 18px;
  background: var(--surface); border: none; border-radius: 18px;
  text-decoration: none; color: var(--text);
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  box-shadow:
    inset 0 0 0 1px var(--border),
    0 4px 14px -8px rgba(15, 23, 42, .45);
  transition: transform .16s cubic-bezier(.2, .9, .3, 1.3), box-shadow .16s ease;
}
@media (hover: hover) {
  .app-card:hover {
    transform: translateY(-3px);
    box-shadow:
      inset 0 0 0 1px color-mix(in srgb, var(--indigo) 45%, var(--border)),
      0 14px 28px -12px rgba(15, 23, 42, .5);
  }
}
.app-card:active {
  transform: translateY(1px) scale(.985);
  transition-duration: .06s;
  box-shadow: inset 0 0 0 1px var(--border), inset 0 2px 6px rgba(15, 23, 42, .1);
}
@media (prefers-color-scheme: dark) {
  .app-card { box-shadow: inset 0 0 0 1px var(--border), 0 4px 14px -8px rgba(0, 0, 0, .8); }
  .app-card:active { box-shadow: inset 0 0 0 1px var(--border), inset 0 2px 6px rgba(0, 0, 0, .5); }
}
.app-icon {
  display: grid; place-items: center; flex-shrink: 0;
  width: 46px; height: 46px; border-radius: 13px;
  background: linear-gradient(180deg,
              color-mix(in srgb, var(--indigo) 80%, #fff) 0%, var(--indigo) 60%,
              color-mix(in srgb, var(--indigo) 86%, #000) 100%);
  color: #fff; font-size: 19px; font-weight: 700;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .38),
              0 3px 8px -3px color-mix(in srgb, var(--indigo) 75%, transparent);
}
.app-icon-sm { width: 34px; height: 34px; border-radius: 10px; font-size: 15px; }
.app-body { display: flex; flex-direction: column; min-width: 0; }
.app-name { font-weight: 700; font-size: 15px; }
.app-desc {
  font-size: 13px; color: var(--text-soft);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.app-host { font-size: 11.5px; color: var(--text-faint); }

.foot-note { margin: 28px 0 0; font-size: 12.5px; color: var(--text-faint); line-height: 1.7; }

.empty { text-align: center; padding: 46px 20px; color: var(--text-faint); }
.empty-icon { font-size: 34px; display: block; margin-bottom: 10px; }
.empty p { margin: 0 0 16px; }

/* ---------- Cartes de configuration ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 20px; margin-bottom: 18px;
}
.card-title { font-size: 16px; margin-bottom: 6px; }
.card-note { margin: 0 0 16px; font-size: 13px; color: var(--text-soft); line-height: 1.6; }

.row { border: 1px solid var(--border); border-radius: var(--radius-sm); margin-bottom: 10px; }
.row[data-off="1"] { opacity: .62; }
.row-head {
  display: flex; align-items: center; gap: 12px; padding: 12px;
  cursor: pointer; list-style: none;
}
.row-head::-webkit-details-marker { display: none; }
.row-head::after { content: "▾"; margin-left: auto; color: var(--text-faint); }
.row[open] .row-head::after { content: "▴"; }
.row-main { display: flex; flex-direction: column; min-width: 0; }
.row-name { font-weight: 600; font-size: 14px; }
.row-name em { font-style: normal; font-weight: 400; color: var(--text-faint); font-size: 12.5px; }
.row-url {
  font-size: 12px; color: var(--text-faint);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.row-form { padding: 4px 12px 12px; border-top: 1px solid var(--border); }
.row-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row-actions-sep { padding: 0 12px 12px; }

.discover {
  display: flex; gap: 8px; align-items: center; flex-wrap: wrap;
  padding: 10px 0; border-top: 1px solid var(--border);
}
.discover input { flex: 1 1 150px; }

/* ==========================================================================
   Petits écrans
   ========================================================================== */
@media (max-width: 620px) {
  .grid { grid-template-columns: 1fr; }
  .btn { min-height: 50px; border-radius: 16px; font-size: 15.5px; }
  .btn-sm { min-height: 42px; border-radius: 12px; }
  .field-row { flex-direction: column; }
  .field-narrow { flex: 1 1 auto; }
  .brand-text { font-size: 14.5px; }
  .wrap { padding: 18px 12px 50px; }
  .card { padding: 16px; }
  .discover input { flex-basis: 100%; }
  .discover .btn { width: 100%; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important; transition-duration: .01ms !important;
  }
}
