:root {
  --bg: #0E0F11;
  --surface: #17191D;
  --surface-2: #141619;
  --line: #23262C;
  --line-2: #2A2E35;
  --text: #F2F3F5;
  --text-2: #E8EAED;
  --muted: #A3A9B3;
  --muted-2: #8C929C;
  --faint: #6E747E;
  --lime: #C8F031;
  --lime-ink: #0E0F11;
  --amber: #FFB547;
  --amber-ink: #1A1204;
  --blue: #7FA7E0;
  --grey-dot: #5B616B;
  --ys-bg: #2A2340;
  --ys-text: #C9B8FF;
  --display: "Barlow Condensed", "Arial Narrow", system-ui, sans-serif;
  --body: Barlow, system-ui, -apple-system, "Segoe UI", sans-serif;
  --radius: 16px;
  --tabbar-h: 76px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--body);
  -webkit-font-smoothing: antialiased;
}
button { font: inherit; color: inherit; }
a { color: var(--lime); }
[hidden] { display: none !important; }
.sr-only {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}
:focus-visible { outline: 2px solid var(--lime); outline-offset: 2px; }

/* ---------- Mise en page (mobile d'abord) ---------- */
.app {
  max-width: 1360px;
  margin: 0 auto;
  padding: calc(16px + env(safe-area-inset-top)) 16px calc(var(--tabbar-h) + 24px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.top { display: flex; flex-direction: column; gap: 14px; }
.top-title { display: flex; flex-direction: column; gap: 2px; }
.eyebrow {
  font-size: 12px; font-weight: 600; letter-spacing: .14em;
  text-transform: uppercase; color: var(--lime);
}
h1 {
  margin: 0; font-family: var(--display); font-weight: 800;
  font-size: 40px; line-height: 1; text-transform: uppercase;
}
.h1-desktop { display: none; }
.meta { margin: 4px 0 0; font-size: 13px; color: var(--muted-2); }
.meta.stale { color: var(--amber); }

.top-actions { display: flex; gap: 8px; align-items: center; }
.search {
  flex: 1; min-width: 0; display: flex; align-items: center; gap: 10px;
  height: 48px; padding: 0 14px; border-radius: 14px;
  background: var(--surface); border: 1px solid var(--line-2); color: var(--muted-2);
}
.search:focus-within { border-color: var(--lime); }
.search input {
  flex: 1; min-width: 0; height: 100%; border: 0; outline: none;
  background: transparent; color: var(--text); font: 500 16px var(--body);
}
.search input::placeholder { color: var(--faint); }
.icon-btn {
  flex: none; display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-width: 48px; height: 48px; padding: 0 12px; border-radius: 14px;
  border: 1px solid var(--line-2); background: var(--surface); color: var(--text-2);
  font-weight: 600; font-size: 15px; cursor: pointer;
}
.icon-btn:hover { border-color: #3A3F48; }
.icon-btn .btn-label { display: none; }
.fav-filter[aria-pressed="true"] { background: var(--amber); border-color: var(--amber); color: var(--amber-ink); }
.fav-filter[aria-pressed="true"] svg path { fill: currentColor; }
#refresh.loading svg { animation: spin .8s linear infinite; }
.filter-btn { position: relative; }
.filter-btn.is-active, .filter-btn[aria-expanded="true"] { border-color: var(--lime); color: var(--lime); }
.badge {
  position: absolute; top: -6px; right: -6px; min-width: 20px; height: 20px; padding: 0 5px;
  display: inline-flex; align-items: center; justify-content: center; border-radius: 999px;
  background: var(--lime); color: var(--lime-ink); font-size: 12px; font-weight: 700;
}

/* ---------- Panneau de filtres ---------- */
.filters {
  display: flex; flex-direction: column; gap: 16px;
  padding: 16px; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--line-2);
}
.filter-group { display: flex; flex-direction: column; gap: 10px; }
.filter-title {
  margin: 0; font-size: 12px; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; color: var(--muted);
}
.chips { display: flex; flex-wrap: wrap; gap: 8px; max-height: 40vh; overflow-y: auto; }
.chip {
  display: inline-flex; align-items: center; gap: 8px; min-height: 40px; padding: 0 14px;
  border-radius: 999px; border: 1px solid var(--line-2); background: var(--surface-2);
  color: var(--text-2); font-size: 14px; font-weight: 600; cursor: pointer;
}
.chip:hover { border-color: #3A3F48; }
.chip-count { font-size: 12px; font-weight: 600; color: var(--faint); }
.chip[aria-pressed="true"] { background: var(--lime); border-color: var(--lime); color: var(--lime-ink); }
.chip[aria-pressed="true"] .chip-count { color: var(--lime-ink); opacity: .7; }
.filter-actions { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.link-btn {
  min-height: 44px; padding: 0 4px; border: 0; background: none; cursor: pointer;
  color: var(--muted); font-size: 14px; font-weight: 600; text-decoration: underline; text-underline-offset: 3px;
}
.link-btn:hover { color: var(--text); }
.apply-btn {
  min-height: 44px; padding: 0 18px; border: 0; border-radius: 12px; cursor: pointer;
  background: var(--lime); color: var(--lime-ink); font-size: 15px; font-weight: 700;
}
.active-filters { margin: -4px 0 0; font-size: 13px; font-weight: 600; color: var(--lime); }
@keyframes spin { to { transform: rotate(360deg); } }

.tab-desc { margin: -4px 0 0; font-size: 14px; line-height: 1.4; color: var(--muted); }

.kpis { display: none; }

.columns { display: flex; flex-direction: column; gap: 10px; }
.col { display: flex; flex-direction: column; gap: 10px; }
.col-head { display: none; }
.app[data-tab="ouvertes"] .col:not(#col-ouvertes),
.app[data-tab="bientot"] .col:not(#col-bientot),
.app[data-tab="autres"] .col:not(#col-autres) { display: none; }

.list { display: flex; flex-direction: column; gap: 10px; }

/* ---------- Cartes ---------- */
.card {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 12px 12px 14px; border-radius: var(--radius);
  background: var(--surface); border: 1px solid var(--line);
}
.card.is-fav { border-color: #4A3B1E; }
.card-quiet { background: var(--surface-2); padding-block: 10px; }
.code {
  width: 52px; height: 52px; flex: none; border-radius: 12px; background: var(--line);
  display: flex; align-items: center; justify-content: center;
  font-family: var(--display); font-weight: 700; font-size: 18px; letter-spacing: .04em;
}
.card-quiet .code { width: 44px; height: auto; background: none; justify-content: flex-start; color: var(--muted); font-size: 17px; }
.info { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.name { display: flex; flex-wrap: wrap; align-items: center; gap: 2px 6px; min-width: 0; }
.city { font-weight: 700; font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card-quiet .city { font-weight: 600; font-size: 15px; }
.ys {
  flex: none; font-size: 10px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase;
  padding: 3px 6px; border-radius: 6px; background: var(--ys-bg); color: var(--ys-text);
}
.sub { font-size: 13px; color: var(--muted); }
.card-quiet .sub { color: var(--muted-2); }

.star {
  flex: none; width: 44px; height: 44px; display: inline-flex; align-items: center; justify-content: center;
  border: 0; border-radius: 12px; background: transparent; color: var(--faint); cursor: pointer;
}
.star svg path { fill: none; }
.star:hover { color: var(--text-2); }
.star[aria-pressed="true"] { color: var(--amber); }
.star[aria-pressed="true"] svg path { fill: currentColor; }

.buy {
  flex: none; display: inline-flex; align-items: center; gap: 4px;
  min-height: 44px; padding: 0 14px; border-radius: 12px;
  background: var(--lime); color: var(--lime-ink); font-weight: 700; font-size: 14px; text-decoration: none;
}
.buy:hover { background: #D8FF55; color: var(--lime-ink); }

.time { width: 58px; flex: none; display: flex; flex-direction: column; }
.hh { font-family: var(--display); font-weight: 700; font-size: 24px; line-height: 1; color: var(--amber); }
.tz { font-size: 11px; color: var(--muted-2); }
.card.is-past .hh { color: var(--lime); font-size: 18px; }

/* ---------- Groupes ---------- */
.group-head {
  display: flex; align-items: baseline; justify-content: space-between; gap: 8px;
  margin: 10px 0 0;
}
.group-head:first-child { margin-top: 0; }
.group-title {
  display: flex; align-items: center; gap: 8px; margin: 0;
  font-size: 13px; font-weight: 700; letter-spacing: .1em; text-transform: uppercase; color: var(--text-2);
}
.group-rel { font-size: 13px; font-weight: 600; color: var(--amber); white-space: nowrap; }
.group-count { font-size: 13px; color: var(--muted-2); }
.dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }

.notif {
  display: flex; align-items: center; gap: 12px;
  padding: 14px; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--line-2);
}
.notif.is-on { border-color: #3A2A10; }
.notif-icon { flex: none; color: var(--amber); }
.notif-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.notif-title { font-size: 15px; font-weight: 700; }
.notif-sub { font-size: 13px; line-height: 1.35; color: var(--muted); }
.notif-btn {
  flex: none; min-height: 44px; padding: 0 14px; border-radius: 12px; cursor: pointer;
  border: 0; background: var(--amber); color: var(--amber-ink); font-size: 14px; font-weight: 700;
}
.notif.is-on .notif-btn { background: none; border: 1px solid var(--line-2); color: var(--muted); }
.notif-btn:disabled { opacity: .6; cursor: progress; }

.next {
  padding: 16px; border-radius: 18px; background: var(--amber); color: var(--amber-ink);
  display: flex; flex-direction: column; gap: 6px;
}
.next-label { font-size: 12px; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; }
.next-title { font-family: var(--display); font-weight: 800; font-size: 30px; line-height: 1; text-transform: uppercase; }
.next-sub { font-size: 14px; font-weight: 500; }

.empty { padding: 36px 12px; text-align: center; color: var(--muted-2); font-size: 15px; }

.foot { font-size: 12px; color: var(--faint); text-align: center; }

/* ---------- Barre d'onglets ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: flex; gap: 6px;
  padding: 8px 12px calc(12px + env(safe-area-inset-bottom));
  background: var(--surface-2); border-top: 1px solid var(--line);
}
.tab {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  min-height: 56px; border: 0; border-radius: 14px; background: none; cursor: pointer;
  color: var(--muted-2); font: 600 11px/1.1 var(--body); letter-spacing: .04em; text-transform: uppercase;
}
.tab[aria-current="page"] { background: var(--lime); color: var(--lime-ink); }

.toast {
  position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + 20px + env(safe-area-inset-bottom)); z-index: 20;
  transform: translateX(-50%); max-width: calc(100% - 32px);
  padding: 12px 16px; border-radius: 12px; background: var(--text-2); color: var(--bg);
  font-size: 14px; font-weight: 600; box-shadow: 0 8px 24px rgba(0, 0, 0, .4);
}

/* ---------- Desktop ---------- */
@media (min-width: 900px) {
  .app { padding: 32px 24px 48px; gap: 28px; }
  .top { flex-direction: row; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 20px; }
  h1 { font-size: 56px; }
  .h1-mobile { display: none; }
  .h1-desktop { display: inline; }
  .meta { font-size: 15px; color: var(--muted); }
  .top-actions { flex-wrap: wrap; }
  .search { width: 320px; flex: none; }
  .icon-btn { padding: 0 18px; }
  .icon-btn .btn-label { display: inline; }
  .filters { padding: 20px; }
  .chips { max-height: none; }
  .active-filters { margin: -16px 0 0; font-size: 14px; }
  .tab-desc, .tabbar { display: none; }
  .toast { bottom: 32px; }

  .kpis { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
  .kpi {
    display: flex; flex-direction: column; align-items: flex-start; gap: 6px;
    padding: 22px; border-radius: 20px; border: 1px solid transparent; text-align: left; cursor: pointer;
  }
  .kpi-label { font-size: 13px; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; }
  .kpi-num { font-family: var(--display); font-weight: 800; font-size: 64px; line-height: .9; }
  .kpi-sub { font-size: 14px; font-weight: 500; }
  .kpi-open { background: var(--lime); color: var(--lime-ink); }
  .kpi-dated { background: var(--amber); color: var(--amber-ink); }
  .kpi-other { background: var(--surface); border-color: var(--line-2); }
  .kpi-other .kpi-label, .kpi-other .kpi-sub { color: var(--muted); }

  .columns {
    display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 20px; align-items: stretch;
  }
  .app .col { display: flex !important; }
  .col {
    padding: 20px; border-radius: 20px; background: var(--surface-2); border: 1px solid var(--line);
    scroll-margin-top: 16px;
    /* hauteur identique pour les 3 colonnes ; chaque liste défile dans l’espace restant */
    height: max(520px, calc(100vh - 120px)); min-height: 0;
  }
  .col > :not(.list) { flex: none; }
  .col-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
  .col-head h2 { margin: 0; font-family: var(--display); font-weight: 700; font-size: 28px; text-transform: uppercase; }
  .pill { padding: 4px 10px; border-radius: 999px; font-size: 13px; font-weight: 700; }
  .pill-open { background: #2B3313; color: var(--lime); }
  .pill-dated { background: #3A2A10; color: var(--amber); }
  .pill-other { background: var(--line); color: #C4C9D1; }

  /* listes compactes, défilement interne pour garder les 3 colonnes alignées */
  .list { gap: 0; flex: 1; min-height: 0; overflow-y: auto; margin-right: -8px; padding-right: 8px; scrollbar-width: thin; }
  .list .card {
    background: none; border: 0; border-top: 1px solid var(--line); border-radius: 0;
    padding: 8px 0; gap: 10px;
  }
  .list .card.is-fav { border-top-color: var(--line); }
  .list .code { width: 44px; height: auto; background: none; justify-content: flex-start; color: var(--muted); font-size: 17px; }
  .list .city { font-size: 16px; }
  .list .group-head { margin: 14px 0 6px; }
  .list .group-head:first-child { margin-top: 0; }
  .next { padding: 14px; }
  .notif { padding: 12px; background: var(--surface); }
  .notif-title { font-size: 14px; }
  .next-title { font-size: 24px; }
}

@media (min-width: 900px) and (max-width: 1180px) {
  .columns { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (prefers-reduced-motion: reduce) {
  #refresh.loading svg { animation: none; }
}
