:root {
  --bg: #0a0f14;
  --surface: #111820;
  --surface-2: #161f2a;
  --border: rgba(255, 255, 255, 0.06);
  --text: #e8edf2;
  --muted: #6b7d8f;
  --accent: #2dd4bf;
  --accent-dim: rgba(45, 212, 191, 0.15);
  --down: #f87171;
  --stable: #94a3b8;
  --ring-size: 180px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  min-height: 100%;
}

body {
  font-family: "DM Sans", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100%;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
  overflow-y: auto;
}

.bg-glow {
  position: fixed;
  inset: 0;
  background:
    radial-gradient(ellipse 60% 40% at 50% -10%, rgba(45, 212, 191, 0.12), transparent),
    radial-gradient(ellipse 40% 30% at 80% 100%, rgba(56, 189, 248, 0.06), transparent);
  pointer-events: none;
  z-index: 0;
}

/* ── Dashboard shell ── */

.dashboard {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-rows: auto auto 1fr auto;
  gap: 1rem;
  min-height: 100dvh;
  max-width: 1280px;
  margin: 0 auto;
  padding: 1.25rem 1.5rem 1.5rem;
}

/* ── Top bar ── */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-shrink: 0;
}

.topbar-brand h1 {
  font-size: 1.25rem;
  font-weight: 500;
  letter-spacing: -0.02em;
}

.subtitle {
  font-size: 0.8rem;
  color: var(--muted);
  margin-top: 0.1rem;
}

.topbar-status {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-shrink: 0;
}

.badge {
  font-size: 0.65rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--accent);
  background: var(--accent-dim);
  padding: 0.25rem 0.6rem;
  border-radius: 999px;
  animation: pulse 2.5s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.6; }
}

.updated {
  font-size: 0.75rem;
  color: var(--muted);
  white-space: nowrap;
}

/* ── Tabs ── */

.tabs {
  display: flex;
  gap: 0.25rem;
  background: var(--surface-2);
  padding: 3px;
  border-radius: 10px;
  width: fit-content;
  margin: 0 auto;
  flex-shrink: 0;
}

.tab {
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--muted);
  text-decoration: none;
  padding: 0.4rem 0.9rem;
  border-radius: 8px;
  white-space: nowrap;
  transition: color 0.2s, background 0.2s;
}

.tab:hover {
  color: var(--text);
}

.tab.active {
  color: var(--text);
  background: var(--surface);
}

/* ── Views ── */

.view {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  min-width: 0;
}

.view[hidden] {
  display: none;
}

.view-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-areas: "next week";
  gap: 1rem;
  align-content: start;
  min-width: 0;
}

.view-grid > .panel {
  min-width: 0;
}

.panel-next { grid-area: next; }
.panel-week { grid-area: week; }

/* ── Rangée 1 : En ce moment · Dernière heure · À venir · Créneau calme ── */

.home-cards {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 1rem;
  min-width: 0;
}

.home-cards > .panel {
  min-width: 0;
}

/* Dernière heure + À venir empilées, se partageant la hauteur de la rangée. */
.home-stack {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  min-width: 0;
}

.home-stack > .panel {
  flex: 1;
  min-width: 0;
}

/* Le titre reste en haut à gauche ; le corps se centre dans l'espace restant. */
.trend-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.best-slot-cal {
  margin-top: 0.6rem;
}

.top-slot-cal[hidden] {
  display: none;
}

/* En dessous de 3 colonnes confortables : une carte par ligne. */
@media (max-width: 1080px) {
  .home-cards {
    grid-template-columns: minmax(0, 1fr);
  }
}

.trend-big {
  font-size: 1.15rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  line-height: 1.35;
}

/* Plus de monde = rouge, moins de monde = teal : lecture "bon pour nager". */
.trend-big.up { color: var(--down); }
.trend-big.down { color: var(--accent); }
.trend-big.stable { color: var(--stable); }

.trend-detail {
  font-size: 0.78rem;
  color: var(--muted);
  margin-top: 0.3rem;
  line-height: 1.45;
}


.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: visible;
}

.panel-next,
.panel-week {
  min-height: 260px;
}

.panel-label {
  font-size: 0.7rem;
  font-weight: 500;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 0.75rem;
  flex-shrink: 0;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
  flex-shrink: 0;
}

.panel-header h2 {
  font-size: 0.7rem;
  font-weight: 500;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.panel-hint {
  font-size: 0.68rem;
  color: var(--muted);
  flex-shrink: 0;
}

/* ── Current occupancy ── */

.panel-current {
  --ring-size: 128px;
  overflow: visible;
  min-height: auto;
}

.current-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.65rem;
  flex: 1;
  justify-content: center;
  padding: 0.35rem 0;
}

.current-meta {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.3rem;
  text-align: center;
  min-width: 0;
}

.current-meta .status {
  font-size: 1.05rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  line-height: 1.35;
}

.home-grid {
  display: grid;
  grid-template-columns: minmax(0, 2fr) minmax(0, 1fr);
  gap: 1rem;
  min-width: 0;
  align-items: stretch;
}

.home-grid > .panel {
  min-width: 0;
}

.ring-wrap {
  position: relative;
  width: var(--ring-size);
  height: var(--ring-size);
  flex-shrink: 0;
}

.ring {
  width: 100%;
  height: 100%;
  transform: rotate(-90deg);
}

.ring-bg {
  fill: none;
  stroke: var(--surface-2);
  stroke-width: 6;
}

.ring-fill {
  fill: none;
  stroke: var(--accent);
  stroke-width: 6;
  stroke-linecap: round;
  stroke-dasharray: 326.73;
  stroke-dashoffset: 326.73;
  transition: stroke-dashoffset 0.8s cubic-bezier(0.4, 0, 0.2, 1), stroke 0.4s;
}

.count-block {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.count {
  font-size: 2.25rem;
  font-weight: 300;
  letter-spacing: -0.04em;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.count-closed {
  font-size: 1.35rem;
  font-weight: 500;
  letter-spacing: 0.04em;
  font-variant-numeric: normal;
}

.count-label {
  font-size: 0.75rem;
  color: var(--muted);
  margin-top: 0.2rem;
}

.status {
  font-size: 0.85rem;
  font-weight: 500;
}

/* Code couleur unique (cf. légende heatmap) : ≤20 / 21–60 / 61–100 / >100. */
.status-low { color: var(--accent); }
.status-heat-0 { color: #2dd4bf; }
.status-heat-1 { color: #14b8a6; }
.status-heat-2 { color: #0d9488; }
.status-heat-3 { color: #fbbf24; }
.status-heat-4 { color: #f87171; }
.status-closed { color: var(--muted); }

.hero-today-hours {
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text);
  line-height: 1.35;
}

.capacity {
  font-size: 0.68rem;
  color: var(--muted);
  line-height: 1.35;
  max-width: 14rem;
}

.schedule-week {
  font-size: 0.68rem;
  color: var(--muted);
  line-height: 1.35;
  text-align: center;
  margin-bottom: 0.55rem;
  flex-shrink: 0;
}

.schedule-note {
  font-size: 0.68rem;
  color: var(--muted);
  text-align: center;
  margin-top: 0.75rem;
  flex-shrink: 0;
}

.schedule-days {
  list-style: none;
  display: flex;
  flex-direction: column;
  justify-content: space-evenly;
  flex: 1;
  min-height: 0;
  width: 100%;
  max-width: 22rem;
  margin: 0 auto;
}

.schedule-day {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  font-size: 0.85rem;
  padding: 0.45rem 0.65rem;
  border-radius: 8px;
}

.schedule-day:not(:last-child) {
  border-bottom: 1px solid var(--border);
}

.schedule-day-name {
  color: var(--text);
  text-transform: capitalize;
}

.schedule-day-hours {
  color: var(--accent);
  font-variant-numeric: tabular-nums;
  text-align: right;
  white-space: nowrap;
}

.schedule-day-hours.schedule-day-closed {
  color: var(--muted);
}

.schedule-day-today {
  background: rgba(45, 212, 191, 0.07);
}

.schedule-day-today .schedule-day-name,
.schedule-day-today .schedule-day-hours {
  font-weight: 600;
}

.schedule-day-today .schedule-day-hours:not(.schedule-day-closed) {
  color: #5eead4;
}

/* ── Trend & charts ── */

.panel-next,
.panel-week {
  min-height: 0;
  overflow: visible;
}

.today-comparison {
  font-size: 0.85rem;
  font-weight: 500;
  margin: 0 0 0.5rem;
  line-height: 1.4;
}

.today-comparison.quiet { color: var(--accent); }
.today-comparison.normal { color: var(--muted); }
.today-comparison.busy { color: var(--down); }

.today-unavailable {
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.5;
  text-align: center;
  padding: 0.75rem 0.5rem;
  margin: 0;
}

.today-unavailable[hidden],
#today-chart[hidden] {
  display: none;
}

.panel-today {
  min-height: 280px;
}

/* Hauteur fixe : un canvas Chart.js dans un conteneur élastique déclenche une
   boucle de redimensionnement visible au chargement. */
.panel-today .chart-wrap {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  flex: none;
  height: 320px;
}

.panel-today .today-unavailable:not([hidden]) {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
}

.panel-today #today-chart:not([hidden]) {
  flex: 1;
  align-self: stretch;
  width: 100%;
  min-height: 0;
}

.chart-wrap {
  flex: 1;
  min-height: 0;
  min-width: 0;
  position: relative;
  width: 100%;
  max-width: 100%;
}

/* ── Quand y aller ── */

.next-lead {
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--accent);
  margin: 0 0 0.65rem;
  line-height: 1.4;
}

.next-lead[hidden],
.next-empty[hidden] {
  display: none;
}

.next-empty {
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.5;
  text-align: center;
  padding: 0.75rem 0.5rem;
  margin: 0;
}

.next-slots {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
}

.next-slot {
  display: grid;
  grid-template-columns: 2.1rem 1fr 2.6rem;
  align-items: center;
  column-gap: 0.5rem;
  row-gap: 0;
  padding: 0.15rem 0.4rem;
  border-radius: 7px;
}

.next-slot.is-best {
  background: rgba(45, 212, 191, 0.07);
}

.next-slot.is-now {
  background: rgba(255, 255, 255, 0.03);
}

.next-hour {
  font-size: 0.72rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.next-slot.is-now .next-hour {
  color: var(--text);
}

.next-slot.is-best .next-hour,
.next-slot.is-best .next-value {
  color: var(--accent);
  font-weight: 500;
}

.next-bar {
  display: block;
  height: 8px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.04);
  overflow: hidden;
  min-width: 0;
}

/* Même palette que la heatmap : 4 paliers ≤20 / 21–60 / 61–100 / >100. */
.next-bar-fill {
  display: block;
  height: 100%;
  border-radius: 999px;
  background: rgba(107, 125, 143, 0.3);
  transition: width 0.4s ease;
}

.next-slot.heat-0 .next-bar-fill { background: rgba(45, 212, 191, 0.95); }
.next-slot.heat-1 .next-bar-fill { background: rgba(45, 212, 191, 0.6); }
.next-slot.heat-2 .next-bar-fill { background: rgba(45, 212, 191, 0.32); }
.next-slot.heat-3 .next-bar-fill { background: rgba(251, 191, 36, 0.72); }
.next-slot.heat-4 .next-bar-fill { background: rgba(248, 113, 113, 0.82); }

.next-value {
  font-size: 0.72rem;
  color: var(--text);
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.next-tag {
  grid-column: 2 / -1;
  font-size: 0.62rem;
  line-height: 1.2;
  color: var(--muted);
  letter-spacing: 0.04em;
}

.next-slot.is-best .next-tag {
  color: var(--accent);
}

.next-slot.is-drained {
  opacity: 0.45;
}

.next-slot.is-drained .next-bar-fill {
  background: rgba(107, 125, 143, 0.5);
}

/* ── Top 3 de la semaine ── */

.top-slots {
  list-style: none;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.75rem;
}

.top-slot {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.8rem 0.95rem;
  min-width: 0;
}

.top-slot.is-first {
  border-color: rgba(45, 212, 191, 0.35);
  background: rgba(45, 212, 191, 0.06);
}

.top-slot-rank {
  font-size: 0.62rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

.top-slot.is-first .top-slot-rank {
  color: var(--accent);
}

.top-slot-when {
  font-size: 0.95rem;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.top-slot-avg {
  font-size: 0.72rem;
  color: var(--muted);
}

.top-slot-cal {
  margin-top: 0.35rem;
  align-self: flex-start;
  font-size: 0.7rem;
  font-weight: 500;
  color: var(--accent);
  text-decoration: none;
  padding: 0.25rem 0.6rem;
  border: 1px solid rgba(45, 212, 191, 0.3);
  border-radius: 999px;
  transition: background 0.2s, border-color 0.2s;
}

.top-slot-cal:hover {
  background: var(--accent-dim);
  border-color: rgba(45, 212, 191, 0.5);
}

/* ── Semaine type ── */

.heatmap-wrap {
  position: relative;
  flex: 1;
  min-height: 0;
  min-width: 0;
  display: flex;
  align-items: stretch;
}

.heatmap {
  display: grid;
  grid-template-columns: 2rem repeat(var(--heat-cols, 13), minmax(0, 1fr));
  grid-template-rows: auto repeat(7, minmax(18px, 1fr));
  gap: 2px;
  width: 100%;
  height: 100%;
  align-content: stretch;
}

.heat-corner {
  display: block;
}

.heat-hour,
.heat-day {
  font-size: 0.6rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  text-align: center;
  line-height: 1.6;
}

.heat-day {
  display: flex;
  align-items: center;
  text-align: left;
  padding-right: 0.35rem;
}

.heat-day-today {
  color: var(--text);
  font-weight: 500;
}

.heat-cell {
  display: block;
  height: 100%;
  min-height: 18px;
  border-radius: 3px;
  background: rgba(255, 255, 255, 0.02);
  cursor: default;
}

.heat-cell:focus-visible {
  outline: 1px solid var(--accent);
  outline-offset: 1px;
}

.heat-cell-closed {
  background: repeating-linear-gradient(
    -45deg,
    rgba(107, 125, 143, 0.12),
    rgba(107, 125, 143, 0.12) 2px,
    transparent 2px,
    transparent 4px
  );
}

.heat-cell-empty {
  background: rgba(107, 125, 143, 0.1);
}

.heat-cell-now {
  box-shadow: inset 0 0 0 1.5px var(--text);
}

.heat-tip {
  position: absolute;
  transform: translate(-50%, calc(-100% - 6px));
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.4rem 0.6rem;
  font-size: 0.68rem;
  line-height: 1.35;
  color: var(--text);
  white-space: nowrap;
  pointer-events: none;
  z-index: 5;
}

.heat-tip[hidden] {
  display: none;
}

.heat-legend {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.25rem 0.75rem;
  margin-top: 0.75rem;
  font-size: 0.6rem;
  color: var(--muted);
  flex-shrink: 0;
}

.heat-legend li {
  display: flex;
  align-items: center;
  gap: 0.3rem;
}

.heat-swatch {
  width: 10px;
  height: 10px;
  border-radius: 2px;
  background: rgba(255, 255, 255, 0.04);
}

.heat-swatch-empty {
  background: rgba(107, 125, 143, 0.1);
}

.heat-swatch-closed {
  background: repeating-linear-gradient(
    -45deg,
    rgba(107, 125, 143, 0.12),
    rgba(107, 125, 143, 0.12) 2px,
    transparent 2px,
    transparent 4px
  );
}

/* ── Footer ── */

.footer {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.35rem;
  text-align: center;
  font-size: 0.68rem;
  color: var(--muted);
  flex-shrink: 0;
}

.credits a {
  color: var(--muted);
  text-decoration: none;
  transition: color 0.2s;
}

.credits a:hover {
  color: var(--accent);
}

.error-banner {
  background: rgba(248, 113, 113, 0.1);
  border: 1px solid rgba(248, 113, 113, 0.2);
  color: var(--down);
  font-size: 0.8rem;
  padding: 0.65rem 1rem;
  border-radius: 10px;
  text-align: center;
  flex-shrink: 0;
}

/* ── Mobile: stacked, scrollable ── */

@media (max-width: 768px) {
  .dashboard {
    width: 100%;
    max-width: 100%;
    padding: 1rem 0.875rem 2rem;
    gap: 0.875rem;
    overflow-x: hidden;
  }

  .topbar {
    flex-direction: column;
    align-items: flex-start;
    min-width: 0;
    width: 100%;
  }

  .topbar-status {
    flex-wrap: wrap;
    width: 100%;
  }

  .updated {
    white-space: normal;
  }

  .tabs {
    width: 100%;
  }

  .tab {
    flex: 1;
    text-align: center;
    padding: 0.4rem 0.5rem;
    white-space: normal;
    line-height: 1.25;
  }

  .view {
    gap: 0.875rem;
  }

  .view-grid {
    width: 100%;
    max-width: 100%;
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas:
      "next"
      "week";
    gap: 0.875rem;
  }

  .panel {
    width: 100%;
    max-width: 100%;
    padding: 1rem;
  }

  .panel-header {
    flex-wrap: wrap;
    min-width: 0;
  }

  .panel-current {
    min-height: auto;
    --ring-size: 148px;
  }

  .home-grid {
    grid-template-columns: minmax(0, 1fr);
    gap: 0.875rem;
    width: 100%;
    max-width: 100%;
  }

  .home-cards {
    grid-template-columns: minmax(0, 1fr);
    gap: 0.875rem;
  }

  .home-stack {
    gap: 0.875rem;
  }

  .hero-today-hours,
  .capacity {
    max-width: 100%;
  }

  .schedule-days {
    max-height: none;
    max-width: 100%;
    width: 100%;
    overflow: visible;
    margin: 0 auto;
  }

  .schedule-day-hours {
    white-space: normal;
  }

  .chart-wrap {
    min-height: 200px;
    overflow: hidden;
  }

  .panel-today .chart-wrap {
    height: 240px;
  }

  .top-slots {
    grid-template-columns: minmax(0, 1fr);
    gap: 0.6rem;
  }

  .heat-hour-alt {
    visibility: hidden;
  }

  .heatmap {
    grid-template-columns: 1.7rem repeat(var(--heat-cols, 13), minmax(0, 1fr));
  }

  .heat-cell {
    min-height: 16px;
  }

  .heat-tip {
    white-space: normal;
    max-width: 12rem;
    text-align: center;
  }

  .next-slots {
    overflow-y: visible;
  }

  .count {
    font-size: 2.5rem;
  }
}

@media (max-width: 400px) {
  .panel-current {
    --ring-size: 132px;
  }

  .count {
    font-size: 2.25rem;
  }
}
