:root {
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --header-h: 58px;
  --mobile-nav-h: 0px;

  --bg: #f8fafc;
  --surface: #ffffff;
  --surface-subtle: #f1f5f9;
  --surface-hover: #f8fafc;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;
  --text: #0f172a;
  --text-secondary: #334155;
  --text-muted: #64748b;

  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-soft: #eff6ff;

  --temp: #ea580c;
  --temp-hover: #c2410c;
  --temp-soft: #fff7ed;
  --temp-border: #fed7aa;

  --hum: #0284c7;
  --hum-hover: #0369a1;
  --hum-soft: #f0f9ff;
  --hum-border: #bae6fd;

  --online: #10b981;
  --online-dark: #059669;
  --online-soft: #ecfdf5;
  --online-border: #a7f3d0;

  --offline: #94a3b8;
  --offline-soft: #f1f5f9;

  --shadow-xs: 0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow-sm: 0 2px 6px rgba(15, 23, 42, 0.05), 0 1px 2px rgba(15, 23, 42, 0.03);
  --shadow-md: 0 8px 20px rgba(15, 23, 42, 0.07), 0 2px 6px rgba(15, 23, 42, 0.04);
  --shadow-lg: 0 18px 38px rgba(15, 23, 42, 0.16);

  --radius: 14px;
  --radius-sm: 9px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-variant-numeric: tabular-nums;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

/* =========================================================================
   PWA INSTALL BANNER & MODAL
   ========================================================================= */
.pwa-install-banner {
  position: fixed;
  left: 12px;
  right: 12px;
  bottom: calc(var(--mobile-nav-h) + var(--safe-bottom) + 10px);
  z-index: 65;
  background: #0f172a;
  color: #ffffff;
  border-radius: 14px;
  padding: 10px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  box-shadow: var(--shadow-lg);
  border: 1px solid rgba(255, 255, 255, 0.14);
  max-width: 520px;
  margin: 0 auto;
}

.pwa-banner-left {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.pwa-banner-icon {
  width: 38px;
  height: 38px;
  border-radius: 9px;
  flex-shrink: 0;
}

.pwa-banner-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.pwa-banner-text strong {
  font-size: 0.84rem;
  font-weight: 800;
}

.pwa-banner-text span {
  font-size: 0.72rem;
  color: #cbd5e1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.pwa-banner-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.pwa-banner-close {
  background: transparent;
  border: none;
  color: #94a3b8;
  font-size: 1.35rem;
  line-height: 1;
  padding: 2px 6px;
  cursor: pointer;
}

.pwa-modal-brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.pwa-modal-brand img {
  width: 38px;
  height: 38px;
  border-radius: 9px;
}

.muted-small {
  font-size: 0.74rem;
  color: var(--text-muted);
}

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

.pwa-step-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  background: var(--surface-subtle);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 0.82rem;
  color: var(--text-secondary);
}

.pwa-step-num {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--primary);
  color: #ffffff;
  font-size: 0.73rem;
  font-weight: 800;
  display: grid;
  place-items: center;
  flex-shrink: 0;
  margin-top: 1px;
}

/* =========================================================================
   HEADER COMPACT FIXE
   ========================================================================= */
.topbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: calc(var(--header-h) + var(--safe-top));
  padding: var(--safe-top) 22px 0 22px;
  z-index: 45;
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.topbar-left {
  display: flex;
  align-items: center;
  min-width: 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  user-select: none;
}

.brand-icon {
  width: 35px;
  height: 35px;
  border-radius: 10px;
  background: linear-gradient(135deg, #ea580c 0%, #2563eb 100%);
  color: #ffffff;
  display: grid;
  place-items: center;
  box-shadow: 0 3px 10px rgba(37, 99, 235, 0.22);
  flex-shrink: 0;
}

.brand-icon svg {
  width: 19px;
  height: 19px;
}

.brand-text h1 {
  font-size: 0.98rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1.15;
}

.brand-text .subtitle {
  display: block;
  font-size: 0.71rem;
  color: var(--text-muted);
  white-space: nowrap;
}

.topbar-nav {
  display: flex;
  align-items: center;
  gap: 4px;
  background: var(--surface-subtle);
  padding: 4px;
  border-radius: 11px;
  border: 1px solid var(--border);
}

.nav-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-size: 0.78rem;
  font-weight: 600;
  padding: 5px 11px;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.18s ease;
  white-space: nowrap;
}

.nav-pill:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.6);
}

.nav-pill.active {
  background: var(--surface);
  color: var(--primary);
  box-shadow: var(--shadow-xs);
}

.nav-num {
  display: inline-grid;
  place-items: center;
  width: 17px;
  height: 17px;
  border-radius: 5px;
  font-size: 0.68rem;
  font-weight: 700;
  background: #e2e8f0;
  color: #475569;
}

.nav-pill.active .nav-num {
  background: var(--primary);
  color: #ffffff;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 7px;
  flex-shrink: 0;
}

.export-group {
  display: flex;
  align-items: center;
  gap: 6px;
}

.mobile-export-wrap {
  display: none;
  position: relative;
}

.mobile-export-menu {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 11px;
  box-shadow: var(--shadow-lg);
  padding: 5px;
  min-width: 215px;
  z-index: 60;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.mobile-export-menu button {
  border: none;
  background: transparent;
  text-align: left;
  padding: 9px 11px;
  border-radius: 8px;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
}

.mobile-export-menu button:hover,
.mobile-export-menu button:active {
  background: var(--primary-soft);
  color: var(--primary);
}

.live-badge {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 5px 11px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  border: 1px solid var(--border);
  background: var(--surface);
  white-space: nowrap;
}

.live-badge.connected {
  background: var(--online-soft);
  color: #065f46;
  border-color: var(--online-border);
}

.live-badge.disconnected {
  background: #fef2f2;
  color: #991b1b;
  border-color: #fecaca;
}

.live-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--offline);
  flex-shrink: 0;
}

.live-badge.connected .live-dot {
  background: var(--online);
  animation: pulseEmerald 2s infinite;
}

@keyframes pulseEmerald {
  0% { box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.6); }
  70% { box-shadow: 0 0 0 7px rgba(16, 185, 129, 0); }
  100% { box-shadow: 0 0 0 0 rgba(16, 185, 129, 0); }
}

@keyframes spinOnce {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

.spinning {
  animation: spinOnce 0.55s ease;
}

/* =========================================================================
   BUTTONS & INPUTS
   ========================================================================= */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 7px 13px;
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
  font-weight: 600;
  border: 1px solid transparent;
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
  touch-action: manipulation;
}

.btn svg {
  width: 15px;
  height: 15px;
  flex-shrink: 0;
}

.btn-compact {
  padding: 6px 11px;
  font-size: 0.78rem;
}

.btn-sm {
  padding: 5px 10px;
  font-size: 0.76rem;
}

.btn:disabled {
  opacity: 0.42;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--primary);
  color: #ffffff;
  box-shadow: 0 2px 6px rgba(37, 99, 235, 0.22);
}
.btn-primary:hover:not(:disabled) {
  background: var(--primary-hover);
}

.btn-emerald {
  background: var(--online-dark);
  color: #ffffff;
  box-shadow: 0 2px 6px rgba(5, 150, 105, 0.25);
}
.btn-emerald:hover:not(:disabled) {
  background: #047857;
}

.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border);
}
.btn-secondary:hover:not(:disabled) {
  background: var(--surface-hover);
  border-color: var(--border-strong);
}

.btn-outline {
  background: transparent;
  color: var(--primary);
  border-color: #bfdbfe;
}
.btn-outline:hover:not(:disabled) {
  background: var(--primary-soft);
}

.show-mobile-inline,
.show-mobile-flex {
  display: none;
}

/* =========================================================================
   NAVIGATION LATÉRALE PAR POINTS (DESKTOP) & BARRE INFÉRIEURE (MOBILE/TABLETTE)
   ========================================================================= */
.side-dots {
  position: fixed;
  right: 14px;
  top: 50%;
  transform: translateY(-50%);
  z-index: 42;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: rgba(255, 255, 255, 0.88);
  backdrop-filter: blur(8px);
  border: 1px solid var(--border);
  padding: 10px 7px;
  border-radius: 999px;
  box-shadow: var(--shadow-sm);
}

.side-dot {
  position: relative;
  width: 18px;
  height: 18px;
  border: none;
  background: transparent;
  display: grid;
  place-items: center;
  cursor: pointer;
}

.dot-circle {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: #cbd5e1;
  transition: all 0.25s cubic-bezier(0.22, 1, 0.36, 1);
}

.side-dot:hover .dot-circle {
  background: #64748b;
  transform: scale(1.25);
}

.side-dot.active .dot-circle {
  width: 10px;
  height: 18px;
  background: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.16);
}

.dot-tooltip {
  position: absolute;
  right: 28px;
  top: 50%;
  transform: translateY(-50%) translateX(6px);
  background: #0f172a;
  color: #ffffff;
  font-size: 0.74rem;
  font-weight: 600;
  padding: 5px 10px;
  border-radius: 7px;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.18s ease, transform 0.18s ease;
  box-shadow: var(--shadow-md);
}

.side-dot:hover .dot-tooltip,
.side-dot:focus-visible .dot-tooltip {
  opacity: 1;
  transform: translateY(-50%) translateX(0);
}

.mobile-bottom-nav {
  display: none;
}

/* =========================================================================
   CONTENEUR FULL-SCREEN SNAP & TRANSITIONS EN FONDU
   ========================================================================= */
.snap-container {
  height: 100vh;
  height: 100dvh;
  width: 100%;
  overflow-y: auto;
  overflow-x: hidden;
  scroll-snap-type: y mandatory;
  scroll-behavior: smooth;
  scrollbar-width: none;
}

.snap-container::-webkit-scrollbar {
  display: none;
}

.screen {
  height: 100vh;
  height: 100dvh;
  width: 100%;
  scroll-snap-align: start;
  scroll-snap-stop: always;
  padding: calc(var(--header-h) + var(--safe-top) + 14px) 52px 16px 24px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.screen-inner {
  max-width: 1640px;
  width: 100%;
  height: 100%;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 0;
  opacity: 0.22;
  transform: translateY(16px) scale(0.992);
  transition: opacity 0.52s cubic-bezier(0.22, 1, 0.36, 1),
              transform 0.52s cubic-bezier(0.22, 1, 0.36, 1);
  will-change: opacity, transform;
}

.screen.is-active .screen-inner {
  opacity: 1;
  transform: translateY(0) scale(1);
}

/* =========================================================================
   SECTION HEADERS & SHARED CARDS
   ========================================================================= */
.section-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-shrink: 0;
}

.section-topbar.wrap-bar {
  flex-wrap: wrap;
}

.section-eyebrow {
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--primary);
}

.section-title {
  font-size: 1.15rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: var(--text);
}

.section-meta-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 5px 13px;
  font-size: 0.77rem;
  font-weight: 600;
  color: var(--text-secondary);
  box-shadow: var(--shadow-xs);
}

.meta-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}
.meta-dot.emerald { background: var(--online); }

.surface-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}

.flex-fill {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding: 14px 18px;
}

.card-header-compact {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
  flex-shrink: 0;
  flex-wrap: wrap;
}

.card-title-group h3 {
  font-size: 0.93rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 7px;
}

.card-title-group p {
  font-size: 0.76rem;
  color: var(--text-muted);
}

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

.swatch {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 3px;
  flex-shrink: 0;
}
.swatch.temp { background: var(--temp); }
.swatch.hum { background: var(--hum); }

.legend-inline {
  display: flex;
  align-items: center;
  gap: 8px;
}

.legend-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 999px;
}
.legend-chip.temp { background: var(--temp-soft); color: var(--temp); border: 1px solid var(--temp-border); }
.legend-chip.hum { background: var(--hum-soft); color: var(--hum); border: 1px solid var(--hum-border); }

/* =========================================================================
   ÉCRAN 1 : 4 CARTES KPI (24H)
   ========================================================================= */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  flex-shrink: 0;
}

.kpi-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 15px 18px;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  gap: 6px;
  position: relative;
  overflow: hidden;
}

.kpi-card::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
}
.kpi-temp::before { background: var(--temp); }
.kpi-hum::before { background: var(--hum); }
.kpi-online::before { background: var(--online); }
.kpi-total::before { background: var(--primary); }

.kpi-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}

.kpi-label {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-muted);
}

.kpi-badge {
  font-size: 0.68rem;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 999px;
  white-space: nowrap;
}
.kpi-badge.temp { background: var(--temp-soft); color: var(--temp); }
.kpi-badge.hum { background: var(--hum-soft); color: var(--hum); }
.kpi-badge.online { background: var(--online-soft); color: var(--online-dark); }
.kpi-badge.neutral { background: var(--primary-soft); color: var(--primary); }

.kpi-value {
  font-size: 1.88rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  line-height: 1.15;
}
.kpi-temp .kpi-value { color: var(--temp); }
.kpi-hum .kpi-value { color: var(--hum); }
.kpi-online .kpi-value { color: var(--online-dark); }

.kpi-sub {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.76rem;
  color: var(--text-muted);
  flex-wrap: wrap;
}
.kpi-sub strong {
  color: var(--text-secondary);
}
.kpi-sub .sep {
  color: #cbd5e1;
}

/* =========================================================================
   ÉCRAN 2 : CONTRÔLES DE PÉRIODE & GRILLE DES CAPTEURS
   ========================================================================= */
.controls-cluster {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.range-pills-scroll {
  display: flex;
  align-items: center;
  gap: 6px;
  max-width: 100%;
}

.range-pills {
  display: inline-flex;
  background: var(--surface-subtle);
  padding: 3px;
  border-radius: 9px;
  border: 1px solid var(--border);
  gap: 2px;
}

.pill {
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.76rem;
  font-weight: 700;
  padding: 5px 10px;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.15s ease;
  touch-action: manipulation;
}

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

.pill.active {
  background: var(--surface);
  color: var(--primary);
  box-shadow: var(--shadow-xs);
}

.custom-dates {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 3px 6px;
  border-radius: 9px;
}

.custom-dates input[type="datetime-local"] {
  border: none;
  font-size: 0.75rem;
  color: var(--text);
  background: transparent;
  outline: none;
  padding: 2px 4px;
}

.custom-dates .arrow {
  color: var(--text-muted);
  font-size: 0.78rem;
}

.sub-infobar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-size: 0.78rem;
  color: var(--text-muted);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 7px 14px;
  flex-shrink: 0;
}

.sub-infobar-right {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.btn-link-reset {
  border: none;
  background: transparent;
  color: var(--primary);
  font-size: 0.75rem;
  font-weight: 700;
  text-decoration: underline;
  cursor: pointer;
}

.selection-badge {
  font-size: 0.73rem;
  font-weight: 700;
  color: var(--primary);
  background: var(--primary-soft);
  padding: 3px 10px;
  border-radius: 999px;
  white-space: nowrap;
}

.sensor-grid-s2 {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  grid-auto-rows: minmax(0, 1fr);
  gap: 12px;
  padding: 2px;
}

.sensor-card {
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: 13px;
  padding: 13px 15px;
  cursor: pointer;
  transition: all 0.16s ease;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 8px;
  box-shadow: var(--shadow-xs);
  position: relative;
}

.sensor-card:hover {
  border-color: #93c5fd;
  box-shadow: var(--shadow-md);
}

.sensor-card.selected {
  border-color: var(--primary);
  background: #f8fbff;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.14);
}

.sensor-card.flash {
  animation: cardFlash 1.2s ease;
}

@keyframes cardFlash {
  0% { box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.45); border-color: var(--online); }
  100% { box-shadow: var(--shadow-xs); }
}

.sensor-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}

.sensor-title-wrap {
  min-width: 0;
}

.sensor-name {
  font-weight: 700;
  font-size: 0.92rem;
  display: flex;
  align-items: center;
  gap: 7px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sensor-color-tag {
  width: 10px;
  height: 10px;
  border-radius: 3px;
  flex-shrink: 0;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 0.68rem;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 999px;
}
.status-pill.online {
  background: var(--online-soft);
  color: var(--online-dark);
}
.status-pill.offline {
  background: var(--offline-soft);
  color: #64748b;
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--offline);
}
.status-dot.online {
  background: var(--online);
}

.sensor-submeta {
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sensor-top-right {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.edit-sensor-btn {
  background: var(--surface-subtle);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  cursor: pointer;
  width: 28px;
  height: 28px;
  border-radius: 7px;
  display: grid;
  place-items: center;
  font-size: 0.82rem;
  transition: all 0.15s;
}
.edit-sensor-btn:hover {
  background: var(--primary-soft);
  color: var(--primary);
  border-color: #bfdbfe;
}

.sensor-metrics-s2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.metric-box {
  border-radius: 10px;
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}
.metric-box.temp {
  background: var(--temp-soft);
  border: 1px solid var(--temp-border);
}
.metric-box.hum {
  background: var(--hum-soft);
  border: 1px solid var(--hum-border);
}

.metric-box-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  font-size: 0.68rem;
  font-weight: 700;
  color: var(--text-muted);
  flex-wrap: wrap;
}

.metric-live-tag {
  font-size: 0.64rem;
  font-weight: 700;
  color: var(--text-secondary);
  background: rgba(255, 255, 255, 0.8);
  padding: 1px 6px;
  border-radius: 999px;
  white-space: nowrap;
}

.metric-avg-val {
  font-size: 1.24rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1.15;
}
.metric-box.temp .metric-avg-val { color: var(--temp); }
.metric-box.hum .metric-avg-val { color: var(--hum); }

.metric-minmax {
  font-size: 0.68rem;
  color: var(--text-muted);
  display: flex;
  justify-content: space-between;
  gap: 4px;
}

.sensor-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.72rem;
  color: var(--text-muted);
  border-top: 1px solid #f1f5f9;
  padding-top: 7px;
}

.bat-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-weight: 600;
  color: var(--text-secondary);
}

/* =========================================================================
   ÉCRAN 3 : FILTRE RAPIDE & DOUBLE GRAPHIQUE PLEINE HAUTEUR
   ========================================================================= */
.quick-sensor-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  flex-shrink: 0;
}

.sensor-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 11px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
  flex-shrink: 0;
}

.sensor-chip:hover {
  border-color: var(--border-strong);
  background: var(--surface-hover);
}

.sensor-chip.active {
  background: #0f172a;
  color: #ffffff;
  border-color: #0f172a;
}

.chip-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.mobile-chart-tabs {
  display: none;
}

.dual-charts-grid {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.chart-panel {
  display: flex;
  flex-direction: column;
  padding: 14px 16px;
  min-height: 0;
  min-width: 0;
  overflow: hidden;
}

.stat-pill {
  font-size: 0.74rem;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 999px;
  white-space: nowrap;
}
.stat-pill.temp { background: var(--temp-soft); color: var(--temp); border: 1px solid var(--temp-border); }
.stat-pill.hum { background: var(--hum-soft); color: var(--hum); border: 1px solid var(--hum-border); }

/* =========================================================================
   ÉCRAN 4 : CARTOGRAPHIE INTERACTIVE DE L'ENTREPÔT (ZOOM + PAN + MOBILE SHEET)
   ========================================================================= */
.map-header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.map-hint {
  font-size: 0.77rem;
  color: var(--text-muted);
}

.btn-edit-active {
  background: #0f172a !important;
  color: #ffffff !important;
  border-color: #0f172a !important;
}

/* Barre d'accès rapide aux capteurs sur le plan */
.map-quick-strip {
  display: flex;
  align-items: center;
  gap: 6px;
  overflow-x: auto;
  scrollbar-width: none;
  padding-bottom: 2px;
  flex-shrink: 0;
}

.map-quick-strip::-webkit-scrollbar {
  display: none;
}

.map-jump-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 11px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  font-size: 0.74rem;
  font-weight: 700;
  color: var(--text-secondary);
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
  transition: all 0.15s ease;
}

.map-jump-chip:hover {
  border-color: var(--border-strong);
}

.map-jump-chip.active {
  background: #0f172a;
  color: #ffffff;
  border-color: #0f172a;
}

.map-jump-temp {
  color: var(--temp);
  font-weight: 800;
}

.map-jump-chip.active .map-jump-temp {
  color: #fdba74;
}

/* Barre d'édition */
.map-edit-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  background: #ffffff;
  border: 1.5px solid var(--primary);
  border-radius: 12px;
  padding: 8px 12px;
  box-shadow: 0 6px 18px rgba(37, 99, 235, 0.10);
  flex-shrink: 0;
}

.edit-tool-group {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 0.76rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.edit-tool-actions {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.coords-badge {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.72rem;
  background: var(--surface-subtle);
  border: 1px solid var(--border);
  padding: 3px 7px;
  border-radius: 6px;
  color: var(--text-secondary);
}

.color-swatches {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.color-swatch-btn {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 2px solid #ffffff;
  box-shadow: 0 0 0 1px #cbd5e1;
  cursor: pointer;
  transition: transform 0.14s ease;
}

.color-swatch-btn.active {
  box-shadow: 0 0 0 2px #0f172a;
  transform: scale(1.15);
}

#mapColorPicker {
  width: 26px;
  height: 24px;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 1px;
  background: var(--surface);
  cursor: pointer;
}

#mapRadiusSlider {
  width: 100px;
  accent-color: var(--primary);
  cursor: pointer;
}

/* Map Viewport & Interactive Pan/Zoom Stage */
.map-viewport {
  flex: 1;
  min-height: 0;
  position: relative;
  display: grid;
  place-items: center;
  padding: 10px;
  background: #e2e8f0;
  overflow: hidden;
  touch-action: none; /* Enables smooth custom 1-finger pan & 2-finger pinch-zoom */
}

.map-floating-controls {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 25;
  display: flex;
  align-items: center;
  gap: 4px;
  background: rgba(15, 23, 42, 0.86);
  backdrop-filter: blur(8px);
  padding: 4px;
  border-radius: 10px;
  box-shadow: var(--shadow-md);
}

.map-ctrl-btn {
  border: none;
  background: rgba(255, 255, 255, 0.12);
  color: #ffffff;
  min-width: 30px;
  height: 30px;
  padding: 0 8px;
  border-radius: 7px;
  font-size: 0.85rem;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease;
}

.map-ctrl-btn:hover,
.map-ctrl-btn:active {
  background: rgba(255, 255, 255, 0.25);
}

.map-ctrl-wide {
  font-size: 0.72rem;
  padding: 0 9px;
}

.map-zoom-badge {
  color: #cbd5e1;
  font-size: 0.71rem;
  font-weight: 700;
  padding: 0 5px;
  min-width: 40px;
  text-align: center;
}

.map-exit-immersive {
  position: absolute;
  top: calc(var(--safe-top) + 46px);
  right: 8px;
  z-index: 35;
  background: #0f172a;
  color: #ffffff;
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 0.74rem;
  font-weight: 700;
  box-shadow: var(--shadow-lg);
  cursor: pointer;
}

body.map-immersive .topbar,
body.map-immersive .mobile-bottom-nav,
body.map-immersive .side-dots,
body.map-immersive .s4-topbar {
  display: none !important;
}

body.map-immersive #screen-3 {
  padding: calc(var(--safe-top) + 6px) 8px calc(var(--safe-bottom) + 6px) 8px !important;
}

.map-panzoom-layer {
  transform-origin: center center;
  will-change: transform;
  transition: transform 0.22s cubic-bezier(0.22, 1, 0.36, 1);
}

.map-panzoom-layer.is-gesturing {
  transition: none !important;
}

.map-stage {
  position: relative;
  aspect-ratio: 1024 / 630;
  background: #ffffff;
  border-radius: 10px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-md);
  user-select: none;
  --inv-zoom: 1;
}

.map-stage img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  border-radius: 9px;
  pointer-events: none;
}

.map-overlay {
  position: absolute;
  inset: 0;
  overflow: visible;
  border-radius: 9px;
}

.map-node {
  position: absolute;
  transform: translate(-50%, -50%);
  z-index: 5;
}

.map-node.selected-edit,
.map-node.focused-node,
.map-node:hover {
  z-index: 18;
}

.map-halo {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  aspect-ratio: 1 / 1;
  border-radius: 50%;
  pointer-events: none;
  transition: width 0.08s linear, background-color 0.2s ease, border-color 0.2s ease;
}

.map-node.focused-node .map-halo {
  box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.22);
}

.edit-mode .map-node.selected-edit .map-halo {
  border-style: dashed !important;
  border-width: 2px !important;
}

.halo-resize-handle {
  position: absolute;
  right: -8px;
  top: 50%;
  transform: translateY(-50%) scale(var(--inv-zoom, 1));
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #ffffff;
  border: 3px solid var(--primary);
  box-shadow: var(--shadow-sm);
  cursor: ew-resize;
  pointer-events: auto;
  display: none;
}

.edit-mode .map-node.selected-edit .halo-resize-handle {
  display: block;
}

.map-bubble {
  position: relative;
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(6px);
  border: 2px solid var(--node-color, #2563eb);
  border-radius: 12px;
  padding: 5px 9px;
  box-shadow: 0 6px 16px rgba(15, 23, 42, 0.18);
  cursor: pointer;
  min-width: 96px;
  text-align: center;
  transform: scale(var(--inv-zoom, 1));
  transform-origin: center center;
  transition: box-shadow 0.15s ease;
}

.map-node.focused-node .map-bubble {
  background: #0f172a;
  color: #ffffff;
  box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.35), 0 10px 24px rgba(15, 23, 42, 0.3);
}

.map-node.focused-node .bubble-header {
  color: #ffffff;
}
.map-node.focused-node .bubble-temp {
  color: #fdba74;
}
.map-node.focused-node .bubble-hum {
  color: #7dd3fc;
}

.edit-mode .map-bubble {
  cursor: grab;
}

.edit-mode .map-node.selected-edit .map-bubble {
  box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.28), 0 10px 24px rgba(15, 23, 42, 0.24);
}

.bubble-header {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  font-size: 0.71rem;
  font-weight: 800;
  color: var(--text);
  white-space: nowrap;
}

.bubble-short-num {
  display: none;
}

.bubble-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--offline);
  flex-shrink: 0;
}
.bubble-dot.online {
  background: var(--online);
}

.bubble-metrics {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  margin-top: 2px;
  font-size: 0.73rem;
  font-weight: 800;
  white-space: nowrap;
}

.bubble-temp { color: var(--temp); }
.bubble-sep { color: #cbd5e1; font-weight: 400; }
.bubble-hum { color: var(--hum); }

/* Desktop Floating Map Popover */
.map-popover {
  position: absolute;
  z-index: 30;
  width: 268px;
  background: rgba(15, 23, 42, 0.96);
  backdrop-filter: blur(10px);
  color: #f8fafc;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 13px;
  padding: 12px 14px;
  box-shadow: var(--shadow-lg);
  font-size: 0.76rem;
}

.pop-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
  padding-bottom: 8px;
  margin-bottom: 8px;
}

.pop-title {
  font-size: 0.88rem;
  font-weight: 800;
  color: #ffffff;
}

.pop-eui {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.68rem;
  color: #94a3b8;
}

.pop-close {
  background: transparent;
  border: none;
  color: #94a3b8;
  font-size: 1.2rem;
  line-height: 1;
  cursor: pointer;
}
.pop-close:hover { color: #ffffff; }

.pop-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 7px;
  margin-bottom: 8px;
}

.pop-metric {
  background: rgba(255, 255, 255, 0.07);
  border-radius: 8px;
  padding: 6px 8px;
}

.pop-metric .lbl {
  font-size: 0.66rem;
  color: #94a3b8;
}

.pop-metric .val {
  font-size: 0.98rem;
  font-weight: 800;
}
.pop-metric.temp .val { color: #fb923c; }
.pop-metric.hum .val { color: #38bdf8; }

.pop-metric .mm {
  font-size: 0.65rem;
  color: #cbd5e1;
  margin-top: 2px;
}

.pop-meta-rows {
  display: flex;
  flex-direction: column;
  gap: 3px;
  font-size: 0.71rem;
  color: #cbd5e1;
}

.pop-meta-row {
  display: flex;
  justify-content: space-between;
}

.pop-actions {
  margin-top: 9px;
  padding-top: 8px;
  border-top: 1px solid rgba(255, 255, 255, 0.12);
  display: flex;
  justify-content: flex-end;
}

.pop-btn {
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: #ffffff;
  font-size: 0.72rem;
  font-weight: 600;
  padding: 5px 10px;
  border-radius: 6px;
  cursor: pointer;
}

/* Mobile & Tablet Map Bottom Sheet */
.map-mobile-sheet {
  position: absolute;
  left: 8px;
  right: 8px;
  bottom: 8px;
  z-index: 28;
  background: rgba(15, 23, 42, 0.96);
  backdrop-filter: blur(12px);
  color: #f8fafc;
  border-radius: 14px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  padding: 11px 13px;
  box-shadow: var(--shadow-lg);
  animation: sheetSlideUp 0.22s cubic-bezier(0.22, 1, 0.36, 1);
}

@keyframes sheetSlideUp {
  from { opacity: 0; transform: translateY(16px); }
  to { opacity: 1; transform: translateY(0); }
}

.msheet-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}

.msheet-title-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.msheet-color-badge {
  width: 12px;
  height: 12px;
  border-radius: 4px;
  flex-shrink: 0;
}

.msheet-name {
  font-size: 0.92rem;
  font-weight: 800;
  color: #ffffff;
}

.msheet-sub {
  font-size: 0.68rem;
  color: #94a3b8;
  display: block;
}

.msheet-nav-btns {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  flex-shrink: 0;
}

.msheet-icon-btn {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  background: rgba(255, 255, 255, 0.08);
  color: #ffffff;
  font-size: 0.85rem;
  font-weight: 700;
  cursor: pointer;
  display: grid;
  place-items: center;
}

.msheet-metrics {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 7px;
}

.msheet-box {
  background: rgba(255, 255, 255, 0.08);
  border-radius: 9px;
  padding: 7px 9px;
}

.msheet-box .lbl {
  font-size: 0.66rem;
  color: #cbd5e1;
}

.msheet-box .val {
  font-size: 1.12rem;
  font-weight: 800;
  line-height: 1.2;
}
.msheet-box.temp .val { color: #fb923c; }
.msheet-box.hum .val { color: #38bdf8; }

.msheet-box .mm {
  font-size: 0.65rem;
  color: #94a3b8;
}

.msheet-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 0.7rem;
  color: #cbd5e1;
}

/* =========================================================================
   ÉCRAN 5 : HISTORIQUE DES RELEVÉS
   ========================================================================= */
.s5-title-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.table-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.count-pill {
  font-size: 0.75rem;
  font-weight: 700;
  background: var(--primary-soft);
  color: var(--primary);
  padding: 4px 11px;
  border-radius: 999px;
  white-space: nowrap;
}

.filter-inline {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 0.76rem;
  font-weight: 600;
  color: var(--text-muted);
}

.select-compact {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 8px;
  padding: 5px 9px;
  font-size: 0.76rem;
  font-weight: 600;
  cursor: pointer;
  outline: none;
}

.pagination {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.page-info {
  font-size: 0.77rem;
  font-weight: 700;
  min-width: 72px;
  text-align: center;
}

.table-card {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.table-scroll-wrap {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: auto;
  overscroll-behavior: contain;
}

.data-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 0.82rem;
}

.data-table thead th {
  position: sticky;
  top: 0;
  z-index: 4;
  text-align: left;
  padding: 11px 14px;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  background: #f8fafc;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.data-table tbody td {
  padding: 9px 14px;
  border-bottom: 1px solid #f1f5f9;
  white-space: nowrap;
}

.data-table tbody tr:hover {
  background: #f8fbff;
}

.empty-cell {
  text-align: center;
  color: var(--text-muted);
  padding: 36px !important;
}

.tag {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 6px;
  font-weight: 700;
  font-size: 0.79rem;
}
.tag.temp { background: var(--temp-soft); color: var(--temp); border: 1px solid var(--temp-border); }
.tag.hum { background: var(--hum-soft); color: var(--hum); border: 1px solid var(--hum-border); }

.mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.77rem;
  color: var(--text-muted);
}

/* =========================================================================
   MODAL & TOASTS
   ========================================================================= */
.modal {
  position: fixed;
  inset: 0;
  z-index: 75;
  display: grid;
  place-items: center;
  padding: 14px;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  backdrop-filter: blur(3px);
}

.modal-card {
  position: relative;
  background: var(--surface);
  border-radius: var(--radius);
  width: min(430px, 94vw);
  max-height: 90dvh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
}

.modal-header {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.icon-btn {
  background: transparent;
  border: none;
  font-size: 1.4rem;
  line-height: 1;
  color: var(--text-muted);
  cursor: pointer;
}

.modal-body {
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 13px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.form-group label {
  font-size: 0.79rem;
  font-weight: 600;
  color: var(--text-muted);
}

.form-group input {
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.9rem;
}

.form-group input:disabled {
  background: var(--surface-subtle);
  color: var(--text-muted);
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 4px;
}

.toast-container {
  position: fixed;
  bottom: calc(var(--mobile-nav-h) + var(--safe-bottom) + 16px);
  left: 16px;
  right: 16px;
  z-index: 80;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 8px;
  pointer-events: none;
}

.toast {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 4px solid var(--online);
  border-radius: 10px;
  padding: 9px 13px;
  box-shadow: var(--shadow-md);
  font-size: 0.79rem;
  max-width: 340px;
  animation: toastSlideUp 0.24s ease;
}

@keyframes toastSlideUp {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

/* =========================================================================
   AUTHENTICATION GATE, ROLES & ADMIN USER MANAGEMENT
   ========================================================================= */
body.auth-pending .topbar,
body.auth-pending .snap-container,
body.auth-pending .side-dots,
body.auth-pending .mobile-bottom-nav,
body.auth-locked .topbar,
body.auth-locked .snap-container,
body.auth-locked .side-dots,
body.auth-locked .mobile-bottom-nav,
body.auth-locked .pwa-install-banner {
  display: none !important;
}

/* Masquage automatique des outils d'édition pour le rôle lecture seule (user) */
body[data-role="user"] .edit-sensor-btn,
body[data-role="user"] #btnToggleMapEdit,
body[data-role="user"] #btnPopRename,
body[data-role="user"] #btnSheetRename {
  display: none !important;
}

body:not([data-role="admin"]) .admin-only-el {
  display: none !important;
}

.auth-gate {
  position: fixed;
  inset: 0;
  z-index: 90;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 18px;
  background: radial-gradient(circle at 20% 15%, rgba(37, 99, 235, 0.10), transparent 50%),
              radial-gradient(circle at 80% 85%, rgba(234, 88, 12, 0.10), transparent 50%),
              #f1f5f9;
  overflow-y: auto;
}

.auth-card {
  width: min(410px, 100%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 26px 24px 22px;
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.auth-brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.auth-brand-icon {
  width: 44px;
  height: 44px;
  border-radius: 12px;
}

.auth-brand h1 {
  font-size: 1.2rem;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.auth-brand p {
  font-size: 0.77rem;
  color: var(--text-muted);
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 13px;
}

.pw-input-wrap {
  display: flex;
  align-items: center;
  gap: 6px;
  position: relative;
}

.pw-input-wrap input {
  flex: 1;
  min-width: 0;
}

.pw-eye-btn {
  border: 1px solid var(--border);
  background: var(--surface-subtle);
  border-radius: 8px;
  height: 38px;
  padding: 0 10px;
  cursor: pointer;
  font-size: 0.9rem;
}

.auth-remember {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 0.79rem;
  color: var(--text-secondary);
  cursor: pointer;
  user-select: none;
}

.auth-submit-btn {
  width: 100%;
  padding: 10px 14px;
  font-size: 0.88rem;
  margin-top: 2px;
}

.auth-alert {
  background: #fef2f2;
  border: 1px solid #fecaca;
  color: #991b1b;
  border-radius: 10px;
  padding: 9px 12px;
  font-size: 0.8rem;
  font-weight: 600;
}

.auth-footer-note {
  text-align: center;
  font-size: 0.71rem;
  color: var(--text-muted);
  border-top: 1px solid var(--border);
  padding-top: 12px;
}

/* User Menu in Topbar */
.user-menu-wrap {
  position: relative;
}

.user-pill-btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  border: 1px solid var(--border);
  background: var(--surface);
  padding: 4px 9px 4px 5px;
  border-radius: 999px;
  cursor: pointer;
  font-size: 0.77rem;
  font-weight: 700;
  color: var(--text);
  transition: border-color 0.15s ease;
}

.user-pill-btn:hover {
  border-color: var(--border-strong);
}

.user-avatar {
  width: 25px;
  height: 25px;
  border-radius: 50%;
  background: #0f172a;
  color: #ffffff;
  font-size: 0.71rem;
  font-weight: 800;
  display: grid;
  place-items: center;
  flex-shrink: 0;
}

.role-chip {
  font-size: 0.66rem;
  font-weight: 800;
  padding: 2px 7px;
  border-radius: 999px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.role-chip.admin { background: #f3e8ff; color: #7e22ce; border: 1px solid #d8b4fe; }
.role-chip.editor { background: #fff7ed; color: #c2410c; border: 1px solid #fed7aa; }
.role-chip.user { background: #f1f5f9; color: #475569; border: 1px solid #cbd5e1; }

.user-dropdown-menu {
  position: absolute;
  right: 0;
  top: calc(100% + 7px);
  min-width: 240px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow-lg);
  padding: 6px;
  z-index: 65;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.user-dropdown-head {
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 4px;
  display: flex;
  flex-direction: column;
}

.user-dropdown-head strong {
  font-size: 0.84rem;
}

.user-menu-item {
  border: none;
  background: transparent;
  text-align: left;
  padding: 9px 10px;
  border-radius: 8px;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
}

.user-menu-item:hover {
  background: var(--surface-subtle);
}

.user-menu-item.danger {
  color: #dc2626;
}
.user-menu-item.danger:hover {
  background: #fef2f2;
}

.menu-divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 3px 0;
}

/* Admin Modal & Users Table */
.admin-modal-card {
  width: min(760px, 95vw);
}

.admin-modal-body {
  gap: 14px;
}

.admin-user-form {
  background: var(--surface-subtle);
  border: 1.5px solid var(--primary);
  border-radius: 12px;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.admin-form-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.admin-form-head h4 {
  font-size: 0.92rem;
  font-weight: 800;
}

.admin-form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px 12px;
}

.select-full {
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.86rem;
  background: var(--surface);
  color: var(--text);
}

.admin-form-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.admin-users-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.admin-user-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 11px;
  padding: 10px 13px;
  flex-wrap: wrap;
}

.admin-user-row.inactive {
  opacity: 0.62;
  background: #f8fafc;
}

.adm-u-info {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.adm-u-meta {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.adm-u-title {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 0.88rem;
  font-weight: 700;
  flex-wrap: wrap;
}

.adm-u-sub {
  font-size: 0.73rem;
  color: var(--text-muted);
}

.adm-u-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

@media (max-width: 640px) {
  .admin-form-grid {
    grid-template-columns: 1fr;
  }
  .user-pill-btn {
    padding: 4px;
  }
  #userRoleBadge {
    display: none;
  }
}

.hidden {
  display: none !important;
}

/* =========================================================================
   RESPONSIVE TABLETTE & TÉLÉPHONE (<= 1024px : MODE APPLICATION NATIVE)
   ========================================================================= */
@media (max-width: 1420px) {
  #userDisplayShort { display: none !important; }
  .desktop-export-group { display: none !important; }
  .mobile-export-wrap { display: block; }
  .nav-pill { padding: 4px 8px; font-size: 0.74rem; }
  .topbar { padding-left: 14px; padding-right: 14px; }
}

@media (max-width: 1280px) {
  .brand-text .subtitle { display: none; }
  .hide-tablet { display: none !important; }
  .sensor-grid-s2 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    grid-auto-rows: auto;
  }
}

@media (max-width: 1024px) {
  :root {
    --header-h: 52px;
    --mobile-nav-h: 60px;
  }

  /* Masquer navigation desktop, activer Bottom Bar style App native */
  .topbar-nav,
  .side-dots {
    display: none !important;
  }

  .topbar {
    padding: var(--safe-top) 12px 0 12px;
  }

  .mobile-bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: calc(var(--mobile-nav-h) + var(--safe-bottom));
    padding-bottom: var(--safe-bottom);
    background: rgba(255, 255, 255, 0.97);
    backdrop-filter: blur(14px);
    border-top: 1px solid var(--border);
    z-index: 50;
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    box-shadow: 0 -2px 12px rgba(15, 23, 42, 0.05);
  }

  .m-nav-item {
    border: none;
    background: transparent;
    color: var(--text-muted);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    font-size: 0.67rem;
    font-weight: 700;
    cursor: pointer;
    position: relative;
    transition: color 0.16s ease;
  }

  .m-nav-item svg {
    width: 20px;
    height: 20px;
    transition: transform 0.16s ease;
  }

  .m-nav-item.active {
    color: var(--primary);
  }

  .m-nav-item.active svg {
    transform: translateY(-1px);
  }

  .m-nav-item.active::before {
    content: "";
    position: absolute;
    top: 0;
    left: 26%;
    right: 26%;
    height: 3px;
    border-radius: 0 0 4px 4px;
    background: var(--primary);
  }

  /* Mode onglet plein écran sans conflit de scroll tactile */
  .snap-container {
    overflow: hidden;
    scroll-snap-type: none;
  }

  .screen {
    display: none;
    height: 100dvh;
    padding: calc(var(--header-h) + var(--safe-top) + 10px) 14px calc(var(--mobile-nav-h) + var(--safe-bottom) + 10px) 14px;
  }

  .screen.is-active {
    display: flex;
  }

  .screen.is-active .screen-inner {
    animation: appTabFade 0.26s cubic-bezier(0.22, 1, 0.36, 1);
  }

  @keyframes appTabFade {
    from { opacity: 0.25; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
  }

  .kpi-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
  }

  .quick-sensor-bar {
    flex-wrap: nowrap;
    overflow-x: auto;
    scrollbar-width: none;
    padding-bottom: 2px;
  }
  .quick-sensor-bar::-webkit-scrollbar { display: none; }
}

/* =========================================================================
   RESPONSIVE TÉLÉPHONE (<= 820px)
   ========================================================================= */
@media (max-width: 820px) {
  .desktop-export-group {
    display: none !important;
  }

  .mobile-export-wrap {
    display: block;
  }

  .hide-mobile {
    display: none !important;
  }

  .show-mobile-inline {
    display: inline-flex;
  }

  .show-mobile-flex {
    display: inline-flex;
  }

  /* Plage de dates personnalisée repliable sur mobile */
  .collapsible-dates {
    display: none;
    width: 100%;
    flex-wrap: wrap;
    justify-content: space-between;
    padding: 6px 8px;
  }

  .collapsible-dates.open {
    display: flex;
  }

  .collapsible-dates input[type="datetime-local"] {
    flex: 1;
    min-width: 135px;
    font-size: 0.78rem;
  }

  /* Écran 3 : Onglets Température / Hygrométrie pleine hauteur sur mobile */
  .mobile-chart-tabs {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
    background: var(--surface-subtle);
    padding: 4px;
    border-radius: 10px;
    border: 1px solid var(--border);
    flex-shrink: 0;
  }

  .m-chart-tab {
    border: none;
    background: transparent;
    padding: 7px 10px;
    border-radius: 7px;
    font-size: 0.78rem;
    font-weight: 700;
    color: var(--text-muted);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    cursor: pointer;
  }

  .m-chart-tab.active {
    background: var(--surface);
    color: var(--text);
    box-shadow: var(--shadow-xs);
  }

  .dual-charts-grid {
    grid-template-columns: 1fr;
  }

  .dual-charts-grid[data-active-tab="temp"] .chart-panel-hum {
    display: none;
  }

  .dual-charts-grid[data-active-tab="hum"] .chart-panel-temp {
    display: none;
  }
}

/* =========================================================================
   OPTIMISATION SPÉCIALE PETITS ÉCRANS TÉLÉPHONE (<= 640px)
   ========================================================================= */
@media (max-width: 640px) {
  .screen {
    padding: calc(var(--header-h) + var(--safe-top) + 8px) 10px calc(var(--mobile-nav-h) + var(--safe-bottom) + 8px) 10px;
  }

  .screen-inner {
    gap: 8px;
  }

  .hide-xs {
    display: none !important;
  }

  .brand-icon {
    width: 32px;
    height: 32px;
  }

  .brand-text h1 {
    font-size: 0.9rem;
  }

  .live-badge {
    padding: 4px 8px;
    font-size: 0.69rem;
    gap: 5px;
  }

  .section-eyebrow {
    font-size: 0.62rem;
  }

  .section-title {
    font-size: 0.98rem;
  }

  /* Écran 1 : Défilement fluide + KPIs compacts 2x2 + grand graphique */
  .s1-scroll-mobile {
    overflow-y: auto;
    overscroll-behavior: contain;
  }

  .kpi-grid {
    gap: 8px;
  }

  .kpi-card {
    padding: 10px 11px;
    gap: 3px;
    border-radius: 11px;
  }

  .kpi-label {
    font-size: 0.7rem;
  }

  .kpi-badge {
    font-size: 0.62rem;
    padding: 1px 6px;
  }

  .kpi-value {
    font-size: 1.32rem;
  }

  .kpi-sub {
    font-size: 0.68rem;
    gap: 4px;
  }

  .s1-chart-card {
    min-height: 250px;
    padding: 10px 12px;
  }

  /* Écran 2 : Cartes pleine largeur ultra-lisibles */
  .range-pills-scroll {
    width: 100%;
    overflow-x: auto;
    scrollbar-width: none;
  }
  .range-pills-scroll::-webkit-scrollbar { display: none; }

  .pill {
    padding: 5px 9px;
    font-size: 0.74rem;
  }

  .sub-infobar {
    padding: 6px 10px;
    font-size: 0.72rem;
  }

  .sensor-grid-s2 {
    grid-template-columns: 1fr;
    gap: 9px;
  }

  .sensor-card {
    padding: 11px 12px;
  }

  .edit-sensor-btn {
    width: 32px;
    height: 32px;
  }

  /* Écran 4 : Pastilles capteurs compactes anti-chevauchement sur téléphone */
  .map-viewport {
    padding: 4px;
    border-radius: 12px;
  }

  .map-floating-controls {
    top: 6px;
    right: 6px;
    left: auto;
    max-width: calc(100% - 12px);
    overflow-x: auto;
  }

  .map-ctrl-btn {
    min-width: 28px;
    height: 28px;
    font-size: 0.8rem;
  }

  .map-ctrl-wide {
    font-size: 0.68rem;
    padding: 0 7px;
  }

  /* Pastilles compactes en vue globale sur mobile, détaillées dès qu'on zoome */
  .map-stage:not(.zoomed-detail) .map-bubble {
    min-width: 0;
    padding: 3px 6px;
    border-radius: 999px;
    display: inline-flex;
    align-items: center;
    gap: 4px;
  }

  .map-stage:not(.zoomed-detail) .bubble-full-name,
  .map-stage:not(.zoomed-detail) .bubble-sep,
  .map-stage:not(.zoomed-detail) .bubble-hum {
    display: none;
  }

  .map-stage:not(.zoomed-detail) .bubble-short-num {
    display: inline;
    font-size: 0.68rem;
    font-weight: 800;
  }

  .map-stage:not(.zoomed-detail) .bubble-metrics {
    margin-top: 0;
    font-size: 0.68rem;
  }

  .map-edit-toolbar {
    padding: 7px 9px;
    gap: 7px;
  }

  /* Écran 5 : Cartes de relevés responsives sans scroll horizontal sur téléphone */
  .s5-title-row {
    width: 100%;
    justify-content: space-between;
  }

  .table-toolbar {
    width: 100%;
    justify-content: space-between;
    gap: 6px;
  }

  .select-compact {
    padding: 5px 7px;
    font-size: 0.73rem;
    max-width: 145px;
  }

  .data-table thead {
    display: none;
  }

  .data-table,
  .data-table tbody {
    display: block;
    width: 100%;
  }

  .data-table tbody tr {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 5px 8px;
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
    align-items: center;
  }

  .data-table tbody td {
    padding: 0;
    border: none;
    white-space: normal;
  }

  .data-table tbody td.cell-sensor {
    grid-column: 1 / 2;
    grid-row: 1;
    font-size: 0.86rem;
  }

  .data-table tbody td.cell-date {
    grid-column: 2 / 3;
    grid-row: 1;
    font-size: 0.71rem;
    color: var(--text-muted);
    text-align: right;
  }

  .data-table tbody td.cell-metrics-mobile {
    display: none;
  }

  .data-table tbody td.cell-temp {
    grid-column: 1 / 2;
    grid-row: 2;
  }

  .data-table tbody td.cell-hum {
    grid-column: 2 / 3;
    grid-row: 2;
    text-align: right;
  }

  .data-table tbody td.cell-eui,
  .data-table tbody td.cell-sig {
    display: none;
  }

  .data-table tbody td.cell-bat {
    grid-column: 1 / 3;
    grid-row: 3;
    font-size: 0.69rem;
    color: var(--text-muted);
    display: flex;
    justify-content: space-between;
  }

  .data-table tbody tr td.empty-cell {
    grid-column: 1 / -1;
    padding: 28px 12px !important;
  }
}

@media (max-width: 390px) {
  #liveText {
    display: none;
  }
  .live-badge {
    padding: 6px;
  }
  .btn-install-label {
    display: none;
  }
}

/* Mode téléphone en paysage (faible hauteur) */
@media (max-height: 500px) and (max-width: 960px) {
  :root {
    --header-h: 44px;
    --mobile-nav-h: 46px;
  }
  .section-eyebrow { display: none; }
  .section-title { font-size: 0.92rem; }
  .screen-inner { gap: 6px; }
}
