/* =====================================================================
   Airloop — design system
   Mobile d'abord : les règles de base visent le téléphone, les media
   queries min-width enrichissent pour les écrans plus larges.
   Tokens sémantiques uniquement dans les composants : aucune couleur
   brute hors de :root (thème clair) et du bloc thème sombre.
   ===================================================================== */
@font-face {
  font-family: "Familjen Grotesk";
  src: url("/assets/polices/familjen-grotesk.woff2") format("woff2");
  font-weight: 400 700; font-style: normal; font-display: swap;
}

:root {
  color-scheme: light dark;
  /* Studio clair : papier gris-bleu, encre, un seul accent outremer. */
  --bg: #EDF0F4;
  --bg-elev: #F6F7FA;
  --surface: #FFFFFF;
  --surface-2: #F3F5F8;
  --surface-3: #E6EAF0;
  --field: #F7F8FA;
  --overlay: rgba(14, 19, 32, .42);
  --border: #E1E5EB;
  --border-strong: #CDD3DC;
  --text: #0E1320;
  --text-2: #4F5868;
  --text-3: #858E9E;
  --on-primary: #FFFFFF;
  --topbar-bg: rgba(237, 240, 244, .88);

  --primary: #2C2FE0;
  --primary-hover: #2124C4;
  --primary-text: #2C2FE0;
  --primary-soft: rgba(44, 47, 224, .08);
  --primary-ring: rgba(44, 47, 224, .3);

  /* « À l'antenne » : réservé à ce qui diffuse réellement. */
  --success: #0A9459;   --success-soft: rgba(10, 148, 89, .1);
  --on-success: #FFFFFF;
  --warning: #A86400;   --warning-soft: rgba(214, 138, 0, .13);
  --info: #2468D0;      --info-soft: rgba(36, 104, 208, .1);
  --violet: #6648D6;    --violet-soft: rgba(102, 72, 214, .1);
  --danger: #CC2F2A;    --danger-soft: rgba(204, 47, 42, .08);
  --neutral-soft: rgba(79, 88, 104, .09);

  /* Vignettes et journaux restent sombres dans les deux thèmes. */
  --media-bg: #0E1320;
  --log-bg: #0E1320;
  --log-text: #C3CBD9;
  --glass-bg: rgba(10, 13, 20, .64);
  --glass-text: #FFFFFF;

  /* Bouton Google : couleurs imposées par la charte « Sign in with Google ». */
  --google-bg: #FFFFFF;
  --google-bg-hover: #F2F4F7;
  --google-text: #1F1F1F;
  --google-border: #DADCE0;

  --r-xs: 6px; --r-sm: 10px; --r: 12px; --r-lg: 16px; --r-xl: 22px; --r-full: 999px;
  --shadow-sm: 0 1px 2px rgba(14, 19, 32, .06);
  --shadow: 0 8px 24px -12px rgba(14, 19, 32, .22);
  --shadow-lg: 0 28px 56px -20px rgba(14, 19, 32, .32);

  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-display: "Familjen Grotesk", var(--font);
  --mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;
  --ease: cubic-bezier(.2, .8, .2, 1);
  --safe-b: env(safe-area-inset-bottom, 0px);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0A0D14;
    --bg-elev: #0F131C;
    --surface: #131824;
    --surface-2: #1A2030;
    --surface-3: #242B3C;
    --field: #0F131C;
    --overlay: rgba(3, 5, 10, .72);
    --border: rgba(255, 255, 255, .07);
    --border-strong: rgba(255, 255, 255, .14);
    --text: #E9EDF5;
    --text-2: #A0A9BA;
    --text-3: #6E778A;
    --topbar-bg: rgba(10, 13, 20, .84);

    --primary: #5B5EF4;
    --primary-hover: #6F72FF;
    --primary-text: #9C9EFF;
    --primary-soft: rgba(110, 113, 255, .14);
    --primary-ring: rgba(110, 113, 255, .42);

    --success: #34D399;   --success-soft: rgba(52, 211, 153, .13);
    --on-success: #05231A;
    --warning: #F5B544;   --warning-soft: rgba(245, 181, 68, .13);
    --info: #60A5FA;      --info-soft: rgba(96, 165, 250, .13);
    --violet: #A78BFA;    --violet-soft: rgba(167, 139, 250, .13);
    --danger: #FF6B6B;    --danger-soft: rgba(255, 107, 107, .11);
    --neutral-soft: rgba(160, 169, 186, .1);
    --media-bg: #05070B;
    --log-bg: #070A10;

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
    --shadow: 0 8px 24px -8px rgba(0, 0, 0, .6);
    --shadow-lg: 0 28px 60px -16px rgba(0, 0, 0, .75);
  }
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; -webkit-tap-highlight-color: transparent; }
body {
  margin: 0; font-family: var(--font); background: var(--bg); color: var(--text);
  font-size: 15px; line-height: 1.5; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale;
}
a { color: inherit; }
h1, h2, h3, h4 { font-family: var(--font-display); letter-spacing: -.015em; margin: 0; font-weight: 650; }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; border-radius: 6px; }
::selection { background: var(--primary-soft); }
.num, .tabular { font-variant-numeric: tabular-nums; }

/* ---------- Icônes et logo ---------- */
.i { width: 18px; height: 18px; flex: 0 0 auto; display: inline-block; vertical-align: middle; }
.i-sm { width: 16px; height: 16px; }
.i-xs { width: 13px; height: 13px; }
.i-lg { width: 22px; height: 22px; }
.i-xl { width: 28px; height: 28px; }
.logo { display: inline-flex; align-items: center; gap: 9px; font: 650 1.12rem/1 var(--font-display); letter-spacing: -.02em; text-decoration: none; }
.logo-mark { border-radius: 30%; display: block; }

/* ---------- Boutons : 44 px de cible tactile sur mobile ---------- */
.btn {
  --h: 44px;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: var(--h); padding: 0 16px; border-radius: var(--r-sm); border: 1px solid transparent;
  font: 600 .9rem/1 var(--font); color: var(--text); background: var(--surface-2); cursor: pointer;
  white-space: nowrap; text-decoration: none; user-select: none; touch-action: manipulation;
  transition: background .15s var(--ease), border-color .15s var(--ease), transform .1s var(--ease), opacity .15s;
}
.btn:active:not(:disabled) { transform: scale(.98); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: var(--on-primary); }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn-secondary { background: var(--surface); border-color: var(--border-strong); }
.btn-secondary:hover:not(:disabled) { background: var(--surface-2); }
.btn-ghost { background: transparent; color: var(--text-2); }
.btn-ghost:hover:not(:disabled) { background: var(--surface-2); color: var(--text); }
.btn-success { background: var(--success-soft); color: var(--success); }
.btn-success:hover:not(:disabled) { filter: brightness(.97); }
.btn-danger { background: var(--danger-soft); color: var(--danger); }
.btn-danger:hover:not(:disabled) { filter: brightness(.97); }
.btn-google { background: var(--google-bg); color: var(--google-text); border-color: var(--google-border); }
.btn-google:hover { background: var(--google-bg-hover); }
.btn-sm { --h: 36px; padding: 0 12px; font-size: .82rem; gap: 6px; }
.btn-lg { --h: 50px; padding: 0 22px; font-size: .98rem; border-radius: var(--r); }
.btn-icon { width: var(--h); padding: 0; }
.btn-block { width: 100%; }
.separateur { display: flex; align-items: center; gap: 12px; margin: 18px 0 2px; color: var(--text-3); font-size: .8rem; }
.separateur::before, .separateur::after { content: ""; flex: 1; height: 1px; background: var(--border); }

/* ---------- Formulaires (16 px : pas de zoom automatique sur iOS) ---------- */
.field { display: flex; flex-direction: column; gap: 7px; margin-top: 16px; }
.field > label, .label { font-size: .82rem; font-weight: 600; color: var(--text-2); }
.label .opt, .field > label .opt { font-weight: 400; color: var(--text-3); }
.input, .select, textarea.input {
  width: 100%; height: 46px; padding: 0 13px; border-radius: var(--r-sm);
  border: 1px solid var(--border-strong); background: var(--field); color: var(--text);
  font: 400 16px var(--font); transition: border-color .15s, box-shadow .15s;
}
.select { appearance: none; padding-right: 36px; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23858E9E' stroke-width='2' stroke-linecap='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center; }
.input::placeholder { color: var(--text-3); }
.input:focus, .select:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.input-icon { position: relative; }
.input-icon .i { position: absolute; left: 13px; top: 50%; transform: translateY(-50%); color: var(--text-3); pointer-events: none; }
.input-icon .input { padding-left: 40px; }
.hint { font-size: .8rem; color: var(--text-3); }
.hint.warn { color: var(--warning); }
.check { display: flex; align-items: center; gap: 10px; font-size: .9rem; color: var(--text); cursor: pointer; min-height: 32px; }
.check input { width: 18px; height: 18px; accent-color: var(--primary); }
.grid-2 { display: grid; grid-template-columns: 1fr; gap: 0 14px; }

/* Contrôle segmenté */
.seg { display: inline-flex; gap: 2px; padding: 3px; background: var(--surface-3); border-radius: 12px; }
.seg button { display: inline-flex; align-items: center; justify-content: center; gap: 7px; min-height: 38px; padding: 0 12px; border: 0; border-radius: 9px;
  background: transparent; color: var(--text-2); font: 600 .84rem var(--font); cursor: pointer; transition: background .15s, color .15s; flex: 1; white-space: nowrap; }
.seg button:hover { color: var(--text); }
.seg button.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }
.seg.block { display: flex; width: 100%; }
.seg.block button { white-space: normal; line-height: 1.25; padding: 6px 10px; }

/* Choix en cartes (type de source, encodage) */
.choices { display: grid; grid-template-columns: 1fr; gap: 8px; }
.choice { text-align: left; display: flex; gap: 12px; align-items: flex-start; padding: 13px 14px; border-radius: var(--r); border: 1px solid var(--border-strong);
  background: var(--surface); color: var(--text); cursor: pointer; font: inherit; transition: border-color .15s, background .15s; }
.choice:hover { border-color: var(--text-3); }
.choice .ci { width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; background: var(--surface-3); color: var(--text-2); flex: 0 0 auto; }
.choice b { display: block; font-size: .9rem; }
.choice span.d { display: block; font-size: .78rem; color: var(--text-3); margin-top: 2px; line-height: 1.4; }
.choice.active { border-color: var(--primary); background: var(--primary-soft); box-shadow: 0 0 0 1px var(--primary); }
.choice.active .ci { background: var(--primary); color: var(--on-primary); }

/* ---------- Badges, puces, points ---------- */
.badge { display: inline-flex; align-items: center; gap: 6px; height: 22px; padding: 0 9px; border-radius: var(--r-full);
  font-size: .7rem; font-weight: 650; letter-spacing: .02em; white-space: nowrap; }
.badge-live { background: var(--success-soft); color: var(--success); }
.badge-onair { background: var(--success); color: var(--on-success); }
.badge-stopped { background: var(--neutral-soft); color: var(--text-2); }
.badge-restarting { background: var(--warning-soft); color: var(--warning); }
.badge-preparing { background: var(--info-soft); color: var(--info); }
.badge-error { background: var(--danger-soft); color: var(--danger); }
.badge-pending { background: var(--violet-soft); color: var(--violet); }
.chip { display: inline-flex; align-items: center; gap: 5px; height: 26px; padding: 0 9px; border-radius: 8px; font-size: .76rem; font-weight: 500;
  background: var(--surface-2); color: var(--text-2); white-space: nowrap; max-width: 100%; }
.chip .nm { overflow: hidden; text-overflow: ellipsis; }
.chip-success { color: var(--success); background: var(--success-soft); }
.chip-warning { color: var(--warning); background: var(--warning-soft); }
.chip-info { color: var(--info); background: var(--info-soft); }
.chip-violet { color: var(--violet); background: var(--violet-soft); }
.chip-off { color: var(--text-3); }
.dot { width: 7px; height: 7px; border-radius: 50%; display: inline-block; flex: 0 0 auto; background: var(--text-3); }
.dot-live { background: var(--success); animation: respire 2.4s ease-in-out infinite; }
.dot-onair { background: var(--on-success); animation: respire 2.4s ease-in-out infinite; }
.dot-restarting { background: var(--warning); animation: respire 1.6s ease-in-out infinite; }
.dot-preparing { background: var(--info); animation: respire 1.6s ease-in-out infinite; }
.dot-error { background: var(--danger); }
.dot-pending { background: var(--violet); }
@keyframes respire { 0%, 100% { opacity: 1; } 50% { opacity: .35; } }

/* ---------- Signature : la boucle ----------
   Un anneau dont l'arc dit la part de chaînes à l'antenne (--p, 0 à 100),
   et un point qui en fait le tour sans s'arrêter, comme le flux. */
.boucle { --p: 100; --taille: 88px; --trait: 5px; --c: var(--success);
  position: relative; width: var(--taille); height: var(--taille); flex: 0 0 auto; display: grid; place-items: center; text-align: center; }
.boucle::before { content: ""; position: absolute; inset: 0; border-radius: 50%;
  background: conic-gradient(var(--c) calc(var(--p) * 1%), var(--surface-3) 0);
  -webkit-mask: radial-gradient(farthest-side, transparent calc(100% - var(--trait)), #000 calc(100% - var(--trait) + .5px));
  mask: radial-gradient(farthest-side, transparent calc(100% - var(--trait)), #000 calc(100% - var(--trait) + .5px)); }
.boucle::after { content: ""; position: absolute; inset: 0; border-radius: 50%;
  background: radial-gradient(circle at 50% calc(var(--trait) / 2), var(--c) calc(var(--trait) * .9), transparent calc(var(--trait) * .9 + 1px));
  animation: orbite 14s linear infinite; }
.boucle.arret::after { display: none; }
.boucle.alerte { --c: var(--warning); }
.boucle > * { position: relative; z-index: 1; }
@keyframes orbite { to { transform: rotate(360deg); } }

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

/* ---------- Surfaces ---------- */
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); }
.panel-pad { padding: 18px; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.panel-head h3 { font-size: 1rem; }
.empty { text-align: center; color: var(--text-2); padding: 44px 20px; border: 1px dashed var(--border-strong); border-radius: var(--r-lg); background: var(--surface); }
.empty .ei { width: 52px; height: 52px; border-radius: 50%; display: grid; place-items: center; margin: 0 auto 14px; background: var(--surface-2); color: var(--text-2); }
.empty h3 { font-size: 1.15rem; color: var(--text); margin-bottom: 6px; }
.empty p { margin: 0 auto 18px; max-width: 420px; font-size: .9rem; }

/* ---------- Tableaux : défilement horizontal sur mobile ---------- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; border: 1px solid var(--border); border-radius: var(--r-lg); background: var(--surface); }
table.table { width: 100%; border-collapse: collapse; font-size: .86rem; }
.table th { text-align: left; font-size: .72rem; font-weight: 600; color: var(--text-3);
  padding: 11px 14px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.table td { padding: 12px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: var(--surface-2); }
.table .r { text-align: right; }

/* ---------- Modales : feuille montante sur mobile, fenêtre au-delà ---------- */
.overlay { position: fixed; inset: 0; z-index: 60; background: var(--overlay); display: none;
  align-items: flex-end; justify-content: center; padding: 0; overflow: hidden; }
.overlay.show { display: flex; animation: fade .18s var(--ease); }
.modal { width: 100%; background: var(--surface); border-radius: var(--r-xl) var(--r-xl) 0 0; box-shadow: var(--shadow-lg);
  animation: monte .26s var(--ease); }
.modal, .modal > form { display: flex; flex-direction: column; max-height: 94dvh; min-height: 0; }
.modal-head { padding: 22px 18px 0; flex-shrink: 0; position: relative; }
.modal-head::before { content: ""; position: absolute; top: 8px; left: 50%; width: 36px; height: 4px; margin-left: -18px; border-radius: 4px; background: var(--surface-3); }
.modal-head h2 { font-size: 1.3rem; }
.modal-head p { margin: 5px 0 0; color: var(--text-2); font-size: .88rem; }
.modal-body { padding: 6px 18px 22px; overflow-y: auto; flex: 1; min-height: 0; overscroll-behavior: contain; }
.modal-foot { display: flex; gap: 10px; padding: 12px 18px calc(12px + var(--safe-b)); border-top: 1px solid var(--border); flex-shrink: 0; background: var(--surface); }
.modal-foot .btn { flex: 1; }
.modal-section { padding-top: 20px; margin-top: 20px; border-top: 1px solid var(--border); }
.modal-section:first-child { border-top: 0; margin-top: 4px; padding-top: 12px; }
.modal-section > h4 { font-size: 1.02rem; display: flex; align-items: center; gap: 10px; }
.modal-section > h4 .step { width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center; border: 1.5px solid var(--border-strong);
  color: var(--text-2); font: 600 .74rem var(--font); }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes monte { from { transform: translateY(24px); opacity: .6; } to { transform: none; opacity: 1; } }

/* ---------- Notifications ---------- */
#toasts { position: fixed; left: 12px; right: 12px; bottom: calc(84px + var(--safe-b)); z-index: 100; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
.toast { display: flex; gap: 10px; align-items: flex-start; background: var(--text); color: var(--bg); border-radius: var(--r);
  padding: 12px 15px; font-size: .88rem; box-shadow: var(--shadow-lg); max-width: 420px; width: 100%; animation: slidein .25s var(--ease); pointer-events: auto; }
.toast .i { margin-top: 1px; }
.toast.ok .i { color: var(--success); } .toast.err .i { color: var(--danger); } .toast.info .i { color: var(--primary-text); }
@keyframes slidein { from { transform: translateY(12px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ---------- Barres de progression ---------- */
.bar { height: 6px; background: var(--surface-3); border-radius: var(--r-full); overflow: hidden; }
.bar i { display: block; height: 100%; width: 0; background: var(--success); border-radius: inherit; transition: width .4s var(--ease); }
.bar i.mid { background: var(--warning); } .bar i.high { background: var(--danger); } .bar i.brand { background: var(--primary); }

/* ---------- Utilitaires ---------- */
.accent-text { color: var(--primary-text); }
.muted { color: var(--text-2); } .faint { color: var(--text-3); }
.mono { font-family: var(--mono); }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); border: 0; }

/* ---------- Écrans plus larges ---------- */
@media (min-width: 640px) {
  body { font-size: 14.5px; }
  .btn { --h: 40px; font-size: .875rem; }
  .btn-sm { --h: 32px; font-size: .8rem; }
  .btn-lg { --h: 48px; }
  .input, .select, textarea.input { height: 42px; font-size: .92rem; }
  .grid-2 { grid-template-columns: 1fr 1fr; }
  .choices { grid-template-columns: 1fr 1fr; gap: 10px; }
  .panel-pad { padding: 20px; }
  .overlay { align-items: flex-start; padding: 6vh 16px; overflow-y: auto; }
  .modal { max-width: 680px; border-radius: var(--r-xl); border: 1px solid var(--border); animation: monte .22s var(--ease); }
  .modal, .modal > form { max-height: 88vh; }
  .modal-head { padding: 24px 24px 0; }
  .modal-head::before { display: none; }
  .modal-body { padding: 6px 24px 24px; }
  .modal-foot { justify-content: flex-end; padding: 14px 24px; border-radius: 0 0 var(--r-xl) var(--r-xl); }
  .modal-foot .btn { flex: 0 0 auto; }
  #toasts { left: auto; right: 20px; bottom: 20px; align-items: flex-end; }
  .toast { width: auto; }
}
