:root {
  --bg: #0f1220;
  --bg-elev: #181c2e;
  --bg-elev-2: #202542;
  --line: #2b3157;
  --text: #eef0fb;
  --text-dim: #9aa0c4;
  --accent: #5b7cff;
  --accent-2: #8a5bff;
  --now: #ff5b7c;
  --hover-bg: #2a3160;
  --stripe: rgba(255, 255, 255, .015);
  --radius: 12px;
  --ch-w: 176px;        /* largeur colonne chaîne */
  --px-hour: 160px;     /* échelle horaire, pilotée par JS */
  --row-h: 62px;
  --axis-h: 34px;
  color-scheme: dark;
}

:root[data-theme="light"] {
  --bg: #f4f6fc;
  --bg-elev: #ffffff;
  --bg-elev-2: #eef1fa;
  --line: #d6dbef;
  --text: #171a2b;
  --text-dim: #5b6180;
  --accent: #3d5bef;
  --accent-2: #7a3bef;
  --now: #e11d48;
  --hover-bg: #e3e9ff;
  --stripe: rgba(0, 0, 0, .022);
  color-scheme: light;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 15px;
  line-height: 1.4;
  -webkit-text-size-adjust: 100%;
}

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

/* ---------- Barre unifiée (titre + filtres + actions) ---------- */
.bar {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 12px 20px;
  padding: 10px clamp(12px, 3vw, 28px);
  background: linear-gradient(120deg, var(--bg-elev), var(--bg));
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 30;
}
.bar__brand { display: flex; align-items: center; gap: 9px; padding-bottom: 2px; }
.app-logo { font-size: 26px; line-height: 1; }
.bar h1 { margin: 0; font-size: clamp(1rem, 3vw, 1.3rem); white-space: nowrap; }
.bar__actions {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-left: auto;      /* pousse les actions à droite */
  padding-bottom: 2px;
}
.updated { color: var(--text-dim); font-size: .78rem; white-space: nowrap; }

.control-block { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.control-block--grow { flex: 1 1 300px; }
.slots-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; }

/* Intégration en iframe : barre non fixe pour ne pas gêner la navigation */
:root.embedded .bar {
  position: static;
  top: auto;
}

/* Vue "tableau seul" (gepgtv-full.html) : uniquement la grille, sur Maintenant */
:root.table-only .bar,
:root.table-only .app-footer { display: none; }
.control-label {
  font-size: .72rem;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text-dim);
  font-weight: 600;
}

.days, .chips { display: flex; flex-wrap: wrap; gap: 6px; }

.btn {
  border: 1px solid var(--line);
  background: var(--bg-elev-2);
  color: var(--text);
  border-radius: 9px;
  padding: 7px 12px;
  font-size: .86rem;
  cursor: pointer;
  white-space: nowrap;
  transition: background .12s, border-color .12s, color .12s;
}
.btn:hover { border-color: var(--accent); }
.btn--ghost { background: transparent; }

.day-btn, .chip {
  border: 1px solid var(--line);
  background: var(--bg-elev-2);
  color: var(--text);
  border-radius: 9px;
  padding: 7px 12px;
  font-size: .86rem;
  cursor: pointer;
  white-space: nowrap;
  transition: background .12s, border-color .12s;
}
.day-btn small { display: block; font-size: .7rem; color: var(--text-dim); }
.day-btn:hover, .chip:hover { border-color: var(--accent); }
.day-btn.is-active, .chip.is-active {
  background: linear-gradient(120deg, var(--accent), var(--accent-2));
  border-color: transparent;
  color: #fff;
}
.day-btn.is-active small { color: rgba(255,255,255,.85); }

.chip--now { border-color: var(--now); color: var(--now); }
.chip--now::first-letter { color: var(--now); }
.chip--now.is-active { background: linear-gradient(120deg, var(--now), #b23); border-color: transparent; color: #fff; }

.range { display: flex; gap: 12px; align-items: center; font-size: .82rem; color: var(--text-dim); }
.hour-select {
  background: var(--bg-elev-2);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 5px 8px;
  font-size: .85rem;
}

.channels-row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.search {
  flex: 1 1 200px;
  min-width: 150px;
  background: var(--bg-elev-2);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 9px;
  padding: 8px 12px;
  font-size: .9rem;
}
.search::placeholder { color: var(--text-dim); }

.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 9px; overflow: hidden; }
.seg__btn {
  background: var(--bg-elev-2);
  color: var(--text-dim);
  border: 0;
  padding: 8px 14px;
  font-size: .84rem;
  cursor: pointer;
}
.seg__btn.is-active { background: linear-gradient(120deg, var(--accent), var(--accent-2)); color: #fff; }
.zoom { display: inline-flex; gap: 4px; }

/* ---------- Guide / timeline ---------- */
.guide-wrap { padding: 0; }
.status {
  padding: 40px 20px;
  text-align: center;
  color: var(--text-dim);
}
.status.is-error { color: var(--now); }

.guide {
  overflow-x: auto;
  overflow-y: visible;
  -webkit-overflow-scrolling: touch;
  scrollbar-color: var(--accent) transparent;
}

.time-axis {
  z-index: 12;
  display: grid;
  grid-template-columns: var(--ch-w) 1fr;
  height: var(--axis-h);
  background: var(--bg);
  border-bottom: 1px solid var(--line);
  min-width: max-content;
}
.time-axis__corner {
  position: sticky;
  left: 0;
  z-index: 2;
  background: var(--bg);
  border-right: 1px solid var(--line);
  display: flex;
  align-items: center;
  padding: 0 12px;
  font-size: .72rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: .05em;
}
.time-axis__track { position: relative; }
.tick {
  position: absolute;
  top: 0;
  height: 100%;
  border-left: 1px solid var(--line);
  padding-left: 6px;
  font-size: .74rem;
  color: var(--text-dim);
  display: flex;
  align-items: center;
}

.rows { min-width: max-content; }

.row {
  display: grid;
  grid-template-columns: var(--ch-w) 1fr;
  height: var(--row-h);
  border-bottom: 1px solid var(--line);
}
.row:nth-child(even) .row__track { background: var(--stripe); }

.row__ch {
  position: sticky;
  left: 0;
  z-index: 6;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 10px;
  background: var(--bg-elev);
  border-right: 1px solid var(--line);
  overflow: hidden;
}
.row__ch img {
  width: 38px;
  height: 38px;
  object-fit: contain;
  border-radius: 8px;
  background: #fff1;
  flex: 0 0 auto;
}
.row__ch span {
  font-size: .84rem;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Piste en flux : les blocs se suivent et poussent les voisins (axe horaire approx.) */
.row__track { position: relative; display: flex; align-items: stretch; }

.prog {
  position: relative;
  flex: 0 0 auto;
  min-width: 80px;                /* largeur mini des blocs courts */
  margin: 5px 1px;
  border-radius: 8px;
  background: var(--bg-elev-2);
  border: 1px solid var(--line);
  padding: 5px 8px;
  overflow: hidden;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 2px;
  transition: background .12s, border-color .12s;
}
.gap { flex: 0 0 auto; }          /* espace = créneau sans programme */
.prog:hover { background: var(--hover-bg); border-color: var(--accent); z-index: 4; }
.prog.is-now { border-color: var(--now); box-shadow: 0 0 0 1px var(--now) inset; }
.prog.is-past { opacity: .55; }
.prog.is-empty { min-width: 0; cursor: default; opacity: .4; }
.prog__time { font-size: .7rem; color: var(--text-dim); }
.prog__title {
  font-size: .82rem;
  font-weight: 600;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  -webkit-box-orient: vertical;
}

/* Survol : infobulle affichant le titre entier (utile pour les programmes courts) */
.prog:hover { overflow: visible; z-index: 20; }
.prog.is-empty:hover::after { content: none; }
.prog:hover::after {
  content: attr(data-t);
  position: absolute;
  left: 0;
  top: calc(100% + 6px);
  z-index: 40;
  width: max-content;
  max-width: 280px;
  white-space: normal;
  background: var(--bg-elev);
  border: 1px solid var(--accent);
  color: var(--text);
  padding: 7px 10px;
  border-radius: 8px;
  font-size: .82rem;
  font-weight: 600;
  line-height: 1.3;
  box-shadow: 0 10px 26px rgba(0,0,0,.55);
  pointer-events: none;
}

.nowline {
  position: absolute;
  top: 0;
  width: 2px;
  background: var(--now);
  z-index: 5;
  pointer-events: none;
}
.nowline::before {
  content: "";
  position: absolute;
  top: -4px;
  left: -3px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--now);
}

/* ---------- Modal ---------- */
.modal { position: fixed; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center; padding: 16px; }
.modal[hidden] { display: none; }
.modal__backdrop { position: absolute; inset: 0; background: rgba(4,6,16,.72); backdrop-filter: blur(2px); }
.modal__card {
  position: relative;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 22px;
  max-width: 460px;
  width: 100%;
  box-shadow: 0 20px 60px rgba(0,0,0,.5);
}
.modal__close {
  position: absolute; top: 12px; right: 12px;
  background: transparent; border: 0; color: var(--text-dim);
  font-size: 1rem; cursor: pointer;
}
.modal__head { display: flex; gap: 12px; align-items: center; margin-bottom: 14px; }
.modal__logo { width: 48px; height: 48px; object-fit: contain; border-radius: 10px; background: #fff1; }
.modal__channel { font-weight: 700; }
.modal__time { color: var(--text-dim); font-size: .85rem; }
.modal__title { margin: 0 0 8px; font-size: 1.25rem; }
.modal__sub { margin: 0; color: var(--text-dim); }
.modal__sub:empty { display: none; }

/* ---------- Bouton retour en haut ---------- */
.to-top {
  position: fixed;
  right: 16px;
  bottom: 16px;
  width: 46px;
  height: 46px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--bg-elev-2);
  color: var(--text);
  font-size: 1.3rem;
  line-height: 1;
  cursor: pointer;
  box-shadow: 0 6px 20px rgba(0, 0, 0, .35);
  opacity: 0;
  visibility: hidden;
  transform: translateY(10px);
  transition: opacity .18s, transform .18s, visibility .18s;
  z-index: 45;
}
.to-top.is-visible { opacity: 1; visibility: visible; transform: none; }
.to-top:hover { border-color: var(--accent); background: var(--hover-bg); }

/* ---------- Footer ---------- */
.app-footer {
  padding: 18px clamp(12px, 3vw, 28px);
  color: var(--text-dim);
  font-size: .78rem;
  border-top: 1px solid var(--line);
  text-align: center;
}

/* ---------- Responsive ---------- */
@media (max-width: 720px) {
  :root { --ch-w: 120px; --row-h: 58px; }
  .row__ch img { width: 30px; height: 30px; }
  .bar { padding: 8px 12px; gap: 10px 14px; }
}
@media (max-width: 480px) {
  :root { --ch-w: 104px; }
  .bar h1 { display: none; }            /* garde juste le logo 📺 pour gagner de la place */
  .control-block--grow { flex-basis: 100%; }
}

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