/* TIVALA — interface de gestion des panneaux d'arret */

/* La police des panneaux est embarquee dans le projet : le navigateur ne peut
 * donc pas piocher une autre « Century Gothic » installee sur la machine, et
 * le rendu est identique partout. Fichier = GOTHICB.TTF (Century Gothic Bold).
 * Nom de famille prive pour eviter toute collision avec les polices systeme. */
@font-face {
  font-family: 'TivalaGothic';
  src: url('polices/CenturyGothic-Bold.ttf') format('truetype');
  font-weight: 700;
  font-style: normal;
  font-display: block;
}

:root {
  --nuit: #000126;
  --nuit-2: #0a0c33;
  --nuit-3: #151845;
  --bord: #262a5e;
  --texte: #eef0f8;
  --texte-2: #a7adcd;
  --clair: #f5f5f5;
  --accent: #2f8fff;
  --rouge: #ff3b3b;
  --vert: #34c759;
  --orange: #dc904d;
  --r: 12px;
  --police: 'Nunito', 'Avenir Next', 'Segoe UI', system-ui, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--nuit);
  color: var(--texte);
  font-family: var(--police);
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); }

/* ------------------------------------------------------------- en-tete */

header.appli {
  display: flex;
  align-items: center;
  gap: 22px;
  padding: 14px 24px;
  background: var(--nuit-2);
  border-bottom: 1px solid var(--bord);
  position: sticky;
  top: 0;
  z-index: 20;
  flex-wrap: wrap;
}

.marque { display: flex; align-items: center; gap: 14px; }
.marque .logo { height: 30px; width: auto; display: block; }
.marque small {
  font-weight: 700; color: var(--texte-2); font-size: 12px;
  padding-left: 14px; border-left: 1px solid var(--bord);
}
@media (max-width: 720px) { .marque small { display: none; } }

nav.onglets { display: flex; gap: 8px; }
nav.onglets a {
  padding: 8px 16px;
  border-radius: 999px;
  text-decoration: none;
  color: var(--texte-2);
  font-weight: 700;
  border: 1px solid transparent;
}
nav.onglets a:hover { background: var(--nuit-3); color: var(--texte); }
nav.onglets a.actif { background: var(--texte); color: var(--nuit); }

.etat-mode {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 12px;
  color: var(--texte-2);
}
.puce {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 10px; border-radius: 999px;
  background: var(--nuit-3); border: 1px solid var(--bord);
}
.puce::before {
  content: ''; width: 7px; height: 7px; border-radius: 50%; background: var(--texte-2);
}
.puce.ok::before { background: var(--vert); }
.puce.attention::before { background: var(--orange); }

/* --------------------------------------------------------------- layout */

main { padding: 24px; max-width: 1500px; margin: 0 auto; }

.grille-edition {
  display: grid;
  grid-template-columns: minmax(360px, 440px) 1fr;
  gap: 22px;
  align-items: start;
}
/* sans cela, le canvas 4000 px de large fait grossir la colonne */
.grille-edition > * { min-width: 0; }
@media (max-width: 1080px) { .grille-edition { grid-template-columns: 1fr; } }

.carte {
  background: var(--nuit-2);
  border: 1px solid var(--bord);
  border-radius: var(--r);
  padding: 18px;
  margin-bottom: 18px;
}
.carte > h2 {
  margin: 0 0 14px;
  font-size: 15px;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  color: var(--texte-2);
}
.carte > h2 .compte { color: var(--texte); text-transform: none; letter-spacing: 0; }

.colle { position: sticky; top: 84px; }

/* ------------------------------------------------------------ controles */

label.champ { display: block; margin-bottom: 14px; }
label.champ > span {
  display: block; font-size: 12px; font-weight: 700;
  color: var(--texte-2); margin-bottom: 6px; text-transform: uppercase; letter-spacing: .6px;
}

input[type='text'], input[type='number'], select, textarea {
  width: 100%;
  padding: 10px 12px;
  border-radius: 9px;
  border: 1px solid var(--bord);
  background: var(--nuit-3);
  color: var(--texte);
  font-family: inherit;
  font-size: 15px;
  font-weight: 600;
}
input[type='text']:focus, select:focus, textarea:focus {
  outline: 2px solid var(--accent); outline-offset: -1px; border-color: var(--accent);
}
input[type='color'] {
  width: 44px; height: 38px; padding: 2px; border-radius: 8px;
  border: 1px solid var(--bord); background: var(--nuit-3); cursor: pointer;
}
input[type='range'] { width: 100%; accent-color: var(--accent); }

button {
  font-family: inherit;
  font-weight: 800;
  font-size: 14px;
  padding: 10px 16px;
  border-radius: 9px;
  border: 1px solid var(--bord);
  background: var(--nuit-3);
  color: var(--texte);
  cursor: pointer;
}
button:hover { border-color: var(--accent); }
button.principal { background: var(--accent); border-color: var(--accent); color: #fff; }
button.principal:hover { filter: brightness(1.1); }
button.discret { background: transparent; color: var(--texte-2); }
button.danger:hover { border-color: var(--rouge); color: var(--rouge); }
button.mini { padding: 5px 9px; font-size: 12px; border-radius: 7px; }
button:disabled { opacity: .45; cursor: not-allowed; }

.rangee { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.rangee.fin { justify-content: flex-end; }
.separateur { height: 1px; background: var(--bord); margin: 16px 0; }

.interrupteur { display: flex; align-items: center; gap: 10px; font-weight: 700; cursor: pointer; }
.interrupteur input { width: 18px; height: 18px; accent-color: var(--accent); }

/* --------------------------------------------------- segments (type arret) */

.segments { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.segments label {
  border: 1px solid var(--bord); border-radius: 10px; padding: 12px;
  cursor: pointer; text-align: center; font-weight: 800;
  background: var(--nuit-3);
}
.segments label small { display: block; font-weight: 600; color: var(--texte-2); font-size: 11px; }
.segments input { display: none; }
.segments input:checked + span { color: var(--accent); }
.segments label:has(input:checked) { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }

/* ---------------------------------------------------------------- lignes */

table.lignes { width: 100%; border-collapse: collapse; }
table.lignes th {
  text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .8px;
  color: var(--texte-2); padding: 0 10px 10px; font-weight: 800;
}
table.lignes td { padding: 8px 10px; border-top: 1px solid var(--bord); vertical-align: middle; }
table.lignes tr:hover td { background: rgba(255, 255, 255, .02); }
table.lignes td.actions { text-align: right; white-space: nowrap; }
table.lignes input[type='text'] { padding: 8px 10px; }
.col-etroite { width: 90px; }
.col-picto { width: 74px; }

.vignette {
  width: 46px; height: 46px; border-radius: 6px; object-fit: cover; display: block;
  background: var(--nuit-3); border: 1px solid var(--bord);
}
.vignette-auto {
  width: 46px; height: 46px; border-radius: 6px; display: grid; place-items: center;
  font-weight: 800; color: #fff; font-size: 20px;
}

.vide { color: var(--texte-2); text-align: center; padding: 26px 10px; font-weight: 600; }

/* ------------------------------------------------------- lignes du panneau */

.dispo { display: flex; flex-wrap: wrap; gap: 8px; }
.jeton {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 5px 12px 5px 5px; border-radius: 999px;
  border: 1px solid var(--bord); background: var(--nuit-3);
  cursor: pointer; font-weight: 800;
}
.jeton:hover { border-color: var(--accent); }
.jeton img, .jeton .carre {
  width: 26px; height: 26px; border-radius: 5px; display: grid; place-items: center;
  font-size: 13px; color: #fff; font-weight: 800;
}

ul.desservi { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
ul.desservi li {
  display: grid;
  grid-template-columns: 40px 1fr auto;
  gap: 10px; align-items: center;
  padding: 8px; border: 1px solid var(--bord); border-radius: 10px;
  background: var(--nuit-3);
}
ul.desservi li.survol { border-color: var(--accent); }
ul.desservi li.glisse { opacity: .4; }
ul.desservi li .poignee { cursor: grab; }
ul.desservi img.mini-picto, ul.desservi .carre {
  width: 40px; height: 40px; border-radius: 6px; display: grid; place-items: center;
  color: #fff; font-weight: 800;
}
ul.desservi input[type='text'], ul.desservi select { padding: 7px 10px; font-size: 14px; }
ul.desservi .num { font-size: 11px; color: var(--texte-2); font-weight: 800; }
.aide-lien {
  display: inline-block; margin-top: 5px; font-size: 11px; font-weight: 800;
  color: var(--orange); text-decoration: none;
}
.aide-lien:hover { text-decoration: underline; }

/* -------------------------------------------------------------- apercu */

.zone-apercu {
  background: repeating-conic-gradient(#e9e9ee 0% 25%, #ffffff 0% 50%) 50% / 24px 24px;
  border-radius: 10px;
  padding: 18px;
  display: grid;
  place-items: center;
  border: 1px solid var(--bord);
}
#apercu { max-width: 100%; height: auto; display: block; border-radius: 4px; }

.apercu-reel { display: flex; gap: 22px; align-items: flex-start; flex-wrap: wrap; }
.apercu-reel figure {
  margin: 0; display: flex; flex-direction: column; gap: 8px; align-items: flex-start;
  max-width: 100%;
  /* le zoom x2 d'un abribus fait 1200 px : il defile dans son propre cadre
     plutot que d'etre reduit (ce qui fausserait le controle de lisibilite) */
  overflow-x: auto;
}
.apercu-reel canvas { flex: none; }
.apercu-reel figcaption { font-size: 11px; color: var(--texte-2); font-weight: 800; letter-spacing: .5px; }
.apercu-reel canvas {
  background: repeating-conic-gradient(#e9e9ee 0% 25%, #ffffff 0% 50%) 50% / 12px 12px;
  border: 1px solid var(--bord); border-radius: 4px;
  image-rendering: pixelated;
}

.alerte {
  margin: 0 0 14px; padding: 11px 14px; border-radius: 10px;
  background: rgba(220, 144, 77, .13); border: 1px solid rgba(220, 144, 77, .5);
  color: #ffd9b3; font-size: 13px; font-weight: 600;
}
.alerte.erreur { background: rgba(255, 59, 59, .13); border-color: rgba(255, 59, 59, .5); color: #ffc9c9; }
.alerte code { background: rgba(0, 0, 0, .3); padding: 1px 5px; border-radius: 4px; }
.alerte.cache { display: none; }

/* --------------------------------------------------------------- liste */

ul.panneaux { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
ul.panneaux li {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px; border: 1px solid var(--bord); border-radius: 10px; background: var(--nuit-3);
}
ul.panneaux li.actif { border-color: var(--accent); }
ul.panneaux li .nom { font-weight: 800; }
ul.panneaux li .type {
  font-size: 10px; text-transform: uppercase; letter-spacing: .8px;
  padding: 3px 8px; border-radius: 999px; background: var(--nuit); color: var(--texte-2); font-weight: 800;
}
ul.panneaux li .grandir { flex: 1; }

/* --------------------------------------------------------------- toast */

#toast {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%) translateY(140%);
  background: var(--texte); color: var(--nuit);
  padding: 12px 20px; border-radius: 999px; font-weight: 800;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .45);
  transition: transform .25s ease; z-index: 100; max-width: 90vw; text-align: center;
}
#toast.visible { transform: translateX(-50%) translateY(0); }
#toast.ko { background: var(--rouge); color: #fff; }

/* ------------------------------------------------- etat d'enregistrement */

.etat-sauvegarde {
  display: flex; align-items: center; gap: 9px;
  font-size: 13px; font-weight: 800; color: var(--texte-2);
  padding: 10px 13px; margin-bottom: 12px;
  border: 1px solid var(--bord); border-radius: 9px; background: var(--nuit-3);
}
.etat-sauvegarde::before {
  content: ''; width: 9px; height: 9px; border-radius: 50%;
  background: var(--texte-2); flex: none;
}
.etat-sauvegarde.ok { color: var(--vert); border-color: rgba(52, 199, 89, .4); }
.etat-sauvegarde.ok::before { background: var(--vert); }
.etat-sauvegarde.modifie { color: var(--orange); border-color: rgba(220, 144, 77, .45); }
.etat-sauvegarde.modifie::before { background: var(--orange); }
.etat-sauvegarde.encours::before { background: var(--accent); animation: pulse 1s infinite; }
.etat-sauvegarde.erreur { color: #ffc9c9; border-color: rgba(255, 59, 59, .5); }
.etat-sauvegarde.erreur::before { background: var(--rouge); }
@keyframes pulse { 50% { opacity: .25; } }

.aide { font-size: 12px; color: var(--texte-2); font-weight: 600; line-height: 1.5; }
.aide code {
  background: var(--nuit-3); padding: 1px 6px; border-radius: 5px;
  border: 1px solid var(--bord); font-size: 11px;
}
details.reglages summary {
  cursor: pointer; font-weight: 800; color: var(--texte-2);
  text-transform: uppercase; font-size: 12px; letter-spacing: 1px;
}
details.reglages[open] summary { margin-bottom: 14px; }
.deux { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.valeur-curseur { float: right; color: var(--texte); font-weight: 800; }
