/* ============================================================
   CareWheel Hub — layout (en-tête, navigation, sidebar, contenu)
   ============================================================ */

/* ============================================================
   EN-TÊTE (header global)
   ============================================================ */
.site-header {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  padding: 0 1rem;
  height: var(--header-h);
  background: rgba(8, 15, 24, 0.82);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border-cyan);
  position: sticky;
  top: 0;
  z-index: 100;
}

/* Logo CareWheel — serpent + w (styles dans carewheel-logo.css) */
.wheel-logo {
  width: 42px;
  height: 42px;
  flex-shrink: 0;
  position: relative;
}

.wheel-logo .carewheel-logo,
.wheel-logo svg {
  display: block;
  width: 100%;
  height: 100%;
  overflow: visible;
}

.site-header-title {
  flex: 1;
  min-width: 0;
}

.site-header h1 {
  margin: 0;
  font-size: clamp(1.1rem, 2.5vw, 1.4rem);
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.2;
}

.site-header h1 span {
  color: var(--accent);
}

.subtitle {
  color: var(--muted);
  margin: 0.1rem 0 0;
  font-size: clamp(0.7rem, 1.5vw, 0.82rem);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

@media (max-width: 480px) {
  .subtitle {
    display: none;
  }
}

/* Contrôles en-tête droite */
.header-right {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  flex-shrink: 0;
}

/* Pill de statut connexion */
.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.75rem;
  color: var(--muted);
  background: var(--bg-elevated);
  border: 1px solid var(--card-border);
  border-radius: 999px;
  padding: 0.25rem 0.65rem;
  white-space: nowrap;
  flex-shrink: 0;
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--success);
  flex-shrink: 0;
  box-shadow: 0 0 6px var(--success);
  transition: background var(--transition), box-shadow var(--transition);
}

.status-dot.error {
  background: var(--danger);
  box-shadow: 0 0 6px var(--danger);
}

.status-dot.loading {
  background: var(--warn);
  box-shadow: 0 0 6px var(--warn);
  animation: pulse-dot 1s ease infinite;
}

.header-count {
  font-size: 0.72rem;
  color: var(--muted);
  white-space: nowrap;
  display: none;
}

@media (min-width: 768px) {
  .header-count {
    display: inline;
  }
}

@keyframes pulse-dot {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.4; }
}

/* Toggle auto-refresh */
.refresh-toggle {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  cursor: pointer;
  font-size: 0.75rem;
  color: var(--muted);
  user-select: none;
}

.refresh-toggle input[type="checkbox"] {
  display: none;
}

.toggle-track {
  width: 32px;
  height: 18px;
  border-radius: 999px;
  background: var(--bg-elevated);
  border: 1px solid var(--card-border);
  position: relative;
  transition: background var(--transition), border-color var(--transition);
  flex-shrink: 0;
}

.toggle-thumb {
  position: absolute;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--muted);
  top: 2px;
  left: 2px;
  transition: transform var(--transition), background var(--transition);
}

.refresh-toggle input:checked ~ .toggle-track {
  background: var(--accent-dim);
  border-color: var(--accent);
}

.refresh-toggle input:checked ~ .toggle-track .toggle-thumb {
  transform: translateX(14px);
  background: var(--accent);
}

/* Label auto-refresh caché sur petit mobile */
.refresh-label {
  display: none;
}

@media (min-width: 480px) {
  .refresh-label { display: inline; }
}

/* ============================================================
   NAVIGATION PAR ONGLETS
   ============================================================ */

/* Mobile : barre fixe en bas */
.nav-tabs {
  display: flex;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 200;
  background: rgba(9, 13, 20, 0.96);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-top: 1px solid var(--border-cyan);
  height: var(--nav-h);
}

.nav-tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  font-size: 0.58rem;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  border: none;
  background: transparent;
  padding: 0;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  transition: color var(--transition);
  -webkit-tap-highlight-color: transparent;
}

.nav-tab svg {
  width: 22px;
  height: 22px;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
  transition: stroke var(--transition);
}

.nav-tab svg.icon-solid {
  fill: currentColor;
  stroke: none;
  transition: fill var(--transition);
}

.nav-tab.active {
  color: var(--accent);
}

.nav-tab.active svg {
  filter: drop-shadow(0 0 4px var(--accent-glow));
}

/* Desktop : barre en haut, sous le header */
@media (min-width: 768px) {
  .nav-tabs {
    position: static;
    border-top: none;
    border-bottom: 1px solid var(--border-cyan);
    height: 48px;
    background: var(--bg-elevated);
    padding: 0 1.5rem;
    gap: 0.25rem;
  }

  .nav-tab {
    flex: none;
    flex-direction: row;
    gap: 0.45rem;
    font-size: 0.82rem;
    padding: 0 1.1rem;
    border-radius: 0;
    border-bottom: 2px solid transparent;
    text-transform: none;
    letter-spacing: 0;
  }

  .nav-tab svg {
    width: 17px;
    height: 17px;
  }

  .nav-tab.active {
    border-bottom-color: var(--accent);
    background: transparent;
  }
}

/* ============================================================
   CORPS APP (sidebar + colonne principale)
   ============================================================ */
.app-body {
  display: flex;
  flex: 1;
  flex-direction: column;
  min-height: 0;
}

.main-column {
  flex: 1;
  min-width: 0;
}

/* ============================================================
   SIDEBAR (desktop terrariums, ≥ 1090px)
   ============================================================ */
.sidebar {
  display: none;
  flex-direction: column;
  width: 220px;
  flex-shrink: 0;
  background: var(--sidebar-gradient);
  border-right: 1px solid var(--border-cyan);
  padding: 1rem 0.75rem;
  justify-content: space-between;
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.sidebar-item {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  width: 100%;
  padding: 0.55rem 0.65rem;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  text-align: left;
  transition: color var(--transition), background var(--transition), border-color var(--transition);
}

.sidebar-item svg {
  width: 18px;
  height: 18px;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex-shrink: 0;
}

.sidebar-item:hover:not(.disabled) {
  color: var(--text-soft);
  background: rgba(255, 255, 255, 0.03);
  border-color: rgba(140, 190, 220, 0.12);
}

.sidebar-item.active {
  color: var(--accent);
  background: linear-gradient(135deg, rgba(88, 200, 184, 0.14), rgba(70, 160, 200, 0.08));
  border-color: rgba(110, 220, 210, 0.28);
  box-shadow: 0 0 16px var(--glow-cyan);
}

.sidebar-item.disabled {
  opacity: 0.45;
  cursor: not-allowed;
  pointer-events: none;
}

.sidebar-badge {
  margin-left: auto;
  min-width: 1.25rem;
  height: 1.25rem;
  padding: 0 0.35rem;
  border-radius: 999px;
  background: var(--danger);
  color: #fff;
  font-size: 0.65rem;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.sidebar-soon {
  margin-left: auto;
  font-size: 0.62rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  opacity: 0.7;
}

.sidebar-footer {
  margin-top: 1.5rem;
  padding-top: 1rem;
  border-top: 1px solid rgba(120, 190, 220, 0.08);
}

.sidebar-system-card {
  display: flex;
  align-items: flex-start;
  gap: 0.55rem;
  padding: 0.65rem;
  background: var(--card-gradient);
  border-radius: var(--radius-sm);
  border: 1px solid var(--card-border);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.035);
  margin-bottom: 0.65rem;
}

.sidebar-system-card strong {
  display: block;
  font-size: 0.78rem;
  color: var(--text);
}

.sidebar-system-card p {
  margin: 0.15rem 0 0;
  font-size: 0.68rem;
  color: var(--muted);
  line-height: 1.35;
}

.sidebar-wifi {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin: 0;
  font-size: 0.68rem;
  color: var(--muted);
}

.sidebar-wifi svg {
  width: 14px;
  height: 14px;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.8;
  flex-shrink: 0;
}

/* ============================================================
   CONTENU PRINCIPAL
   ============================================================ */
.main-content {
  flex: 1;
  padding: 1rem 1rem calc(var(--nav-h) + 1rem);
}

@media (min-width: 768px) {
  .main-content {
    padding: 1.25rem 1.5rem 2rem;
  }
}

.tab-section {
  display: none;
}

.tab-section.active {
  display: block;
}

/* En-tête de page terrariums */
.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.page-header-simple {
  margin-bottom: 1.25rem;
}

.page-title {
  margin: 0;
  font-size: clamp(1.25rem, 3vw, 1.55rem);
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text);
}

.page-subtitle {
  margin: 0.25rem 0 0;
  font-size: 0.82rem;
  color: var(--muted);
  line-height: 1.45;
}

.btn-outline {
  background: transparent;
  color: var(--accent);
  border: 1px solid rgba(92, 184, 168, 0.45);
  padding: 0.5rem 0.9rem;
  font-size: 0.8rem;
  flex-shrink: 0;
}

.btn-outline:hover {
  background: var(--accent-dim);
  box-shadow: none;
}

.btn-add-icon {
  display: none;
}

@media (max-width: 599px) {
  .btn-add-label {
    display: none;
  }

  .btn-add-icon {
    display: inline;
    font-size: 1.25rem;
    line-height: 1;
  }

  .btn-add-enclosure {
    width: 2.5rem;
    height: 2.5rem;
    padding: 0;
  }
}

/* Filtres chips (mobile uniquement) */
.filter-chips {
  display: flex;
  gap: 0.45rem;
  overflow-x: auto;
  padding-bottom: 0.35rem;
  margin-bottom: 1rem;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}

.filter-chips::-webkit-scrollbar {
  display: none;
}

/* Layout desktop : sidebar + colonne principale côte à côte (≥ 1090px). */
@media (min-width: 1090px) {
  .app-body {
    flex-direction: row;
    align-items: stretch;
  }

  .sidebar {
    display: flex;
  }

  .filter-chips {
    display: none;
  }
}

.filter-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.4rem 0.75rem;
  border-radius: 999px;
  border: 1px solid var(--card-border);
  background: var(--bg-elevated);
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
  transition: border-color var(--transition), color var(--transition), background var(--transition);
}

.filter-chip svg {
  width: 14px;
  height: 14px;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.8;
}

.filter-chip.active {
  border-color: rgba(110, 220, 210, 0.28);
  color: var(--accent);
  background: linear-gradient(135deg, rgba(88, 200, 184, 0.14), rgba(70, 160, 200, 0.08));
  box-shadow: 0 0 12px var(--glow-cyan);
}

.filter-badge {
  min-width: 1.1rem;
  height: 1.1rem;
  padding: 0 0.3rem;
  border-radius: 999px;
  background: var(--danger);
  color: #fff;
  font-size: 0.6rem;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

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

.filter-dot.ok {
  background: var(--success);
  box-shadow: 0 0 4px var(--success);
}

.filter-dot.offline {
  background: var(--muted);
}

.filter-count {
  font-size: 0.65rem;
  opacity: 0.75;
}

/* Toast */
.toast {
  position: fixed;
  bottom: calc(var(--nav-h) + 1rem);
  left: 50%;
  transform: translateX(-50%);
  z-index: 600;
  padding: 0.55rem 1rem;
  border-radius: 999px;
  background: var(--card);
  border: 1px solid var(--card-border);
  color: var(--text-soft);
  font-size: 0.82rem;
  box-shadow: var(--shadow);
  pointer-events: none;
}

@media (min-width: 768px) {
  .toast {
    bottom: 1.5rem;
  }
}

/* Bannière annulation maintenance (eau, …) */
.maintenance-undo-toast {
  position: fixed;
  bottom: calc(var(--nav-h) + 1rem);
  left: 50%;
  transform: translateX(-50%);
  z-index: 610;
  display: flex;
  align-items: center;
  gap: 0.65rem;
  max-width: min(92vw, 28rem);
  padding: 0.5rem 0.5rem 0.5rem 1rem;
  border-radius: 999px;
  background: var(--card);
  border: 1px solid var(--card-border);
  color: var(--text-soft);
  font-size: 0.82rem;
  box-shadow: var(--shadow);
}

.maintenance-undo-toast[hidden] {
  display: none !important;
}

.maintenance-undo-toast-message {
  flex: 1 1 auto;
  min-width: 0;
  line-height: 1.35;
}

.maintenance-undo-toast-btn {
  flex: 0 0 auto;
  padding: 0.35rem 0.85rem;
  border-radius: 999px;
  border: 1px solid rgba(90, 175, 255, 0.55);
  background: rgba(90, 175, 255, 0.14);
  color: #8ec8ff;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}

.maintenance-undo-toast-btn:hover,
.maintenance-undo-toast-btn:focus-visible {
  background: rgba(90, 175, 255, 0.24);
  outline: none;
}

.maintenance-undo-toast-btn:disabled {
  opacity: 0.55;
  cursor: default;
}

.maintenance-undo-toast--feedback {
  padding: 0.55rem 1rem;
}

.maintenance-undo-toast--feedback .maintenance-undo-toast-btn {
  display: none;
}

.maintenance-undo-toast--error {
  border-color: rgba(255, 70, 100, 0.45);
  color: #ff9aaa;
}

@media (min-width: 768px) {
  .maintenance-undo-toast {
    bottom: 1.5rem;
  }
}

/* --- Shell authentification cloud (login + sélection Hub) --- */
.cloud-auth-shell {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 60vh;
  padding: 1.5rem 1rem 3rem;
}

.cloud-auth-card {
  width: min(100%, 22rem);
  padding: 1.5rem;
  border-radius: 12px;
  background: rgba(8, 16, 24, 0.92);
  border: 1px solid rgba(110, 168, 255, 0.22);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.35);
}

.cloud-auth-card h2 {
  margin: 0 0 0.35rem;
  font-size: 1.25rem;
}

.cloud-auth-lead,
.cloud-auth-status {
  margin: 0 0 1rem;
  color: var(--text-muted, #9eb0c4);
  font-size: 0.92rem;
}

.cloud-auth-field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin-bottom: 0.85rem;
}

.cloud-auth-field input {
  width: 100%;
}

.cloud-auth-error {
  margin: 0.5rem 0 0;
  color: #ff9aaa;
  font-size: 0.88rem;
}

.cloud-hub-list {
  list-style: none;
  margin: 0 0 1rem;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.cloud-hub-item {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  text-align: left;
}

.cloud-hub-id {
  font-family: ui-monospace, monospace;
  font-size: 0.9rem;
}

.cloud-hub-status.is-online {
  color: #5fd49a;
}

.cloud-hub-status.is-offline {
  color: var(--text-muted, #9eb0c4);
}

.header-cloud-btn {
  font-size: 0.78rem;
  padding: 0.25rem 0.55rem;
}
