/* ══════════════════════════════════════════════════════
   dashboard.mobile.css — chargé uniquement ≤ 1000px
   ══════════════════════════════════════════════════════ */

@media (max-width: 1000px) {

  /* ── Layout général ── */
  body {
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
  }

  /* ──────────────────────────────────────────
     HEADER
     ────────────────────────────────────────── */
  .header {
    flex-shrink: 0;
    padding: 0;
  }

  .header-row-nav {
    padding: 6px 10px;
    gap: 8px;
    flex-wrap: nowrap;
  }

  .header-title {
    font-size: 13px;
    white-space: nowrap;
    flex-shrink: 0;
  }

  .header-tabs {
    display: flex;
    gap: 4px;
    flex: 1;
    overflow-x: auto;
    scrollbar-width: none;
  }
  .header-tabs::-webkit-scrollbar { display: none; }

  .tab-btn {
    white-space: nowrap;
    font-size: clamp(10px, 2.5vw, 13px);
    padding: 5px 10px;
  }

  .header-row-status {
    padding: 4px 10px;
    gap: 6px;
    flex-wrap: nowrap;
  }

  .header-stats {
    display: flex;
    gap: 5px;
    flex-wrap: nowrap;
    overflow-x: auto;
    scrollbar-width: none;
    flex: 1;
  }
  .header-stats::-webkit-scrollbar { display: none; }

  .stat-badge {
    font-size: 10px;
    white-space: nowrap;
    padding: 2px 6px;
  }

  .header-events-btn {
    flex-shrink: 0;
    font-size: 11px;
    padding: 4px 8px;
  }

  /* ──────────────────────────────────────────
     APP WRAPPER
     ────────────────────────────────────────── */
  .app {
    flex: 1 1 0;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }

  /* ──────────────────────────────────────────
     DASHBOARD VIEW : colonne sur mobile
     ────────────────────────────────────────── */
  .view-dashboard-wrap {
    flex-direction: column !important;
    overflow: hidden;
    flex: 1 1 0;
    min-height: 0;
  }

  /* ── Liste caméras : barre horizontale scrollable ── */
  .cam-list-panel {
    flex-shrink: 0;
    width: 100% !important;
    height: auto !important;
    border-right: none !important;
    border-bottom: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    max-height: 140px;
  }

  .panel-top {
    padding: 6px 10px;
    font-size: 11px;
    flex-shrink: 0;
  }

  .cam-list-body {
    display: flex;
    flex-direction: column;
    overflow-x: auto;
    overflow-y: hidden;
    gap: 6px;
    padding: 6px 10px;
    flex: 1;
    scrollbar-width: thin;
    scrollbar-color: var(--border) transparent;
    -webkit-overflow-scrolling: touch;
  }

  /* Carte caméra horizontale */
  .cam-card {
    flex-shrink: 0;
    width: 140px;
    min-height: unset;
    padding: 8px 10px;
    font-size: 11px;
  }

  .no-cam {
    font-size: 11px;
    white-space: nowrap;
    padding: 10px 0;
    align-self: center;
  }

  /* ── Detail panel : prend le reste ── */
  .detail-panel {
    flex: 1 1 0;
    min-height: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* ── Detail header ── */
  .detail-header {
    padding: 8px 10px;
    gap: 6px;
    flex-wrap: wrap;
  }

  .detail-devname { font-size: 13px; }
  .detail-link    { font-size: 11px; }

  .detail-bdg {
    font-size: 9px;
    padding: 2px 5px;
  }

  /* ── Tab nav ── */
  .tab-nav {
    padding: 0 8px;
    gap: 4px;
    overflow-x: auto;
    scrollbar-width: none;
    flex-wrap: nowrap;
  }
  .tab-nav::-webkit-scrollbar { display: none; }

  .tab-nav .tab-btn {
    font-size: clamp(10px, 2.5vw, 12px);
    padding: 6px 10px;
    white-space: nowrap;
    flex-shrink: 0;
  }

  /* ── Stream area ── */
  .stream-area {
    width: 100%;
    flex: 1 1 0; /* Prend tout l'espace restant */
    min-height: 0; /* Crucial pour le flexbox en colonne */
    background: #000;
  }

  .stream-area img {
    width: 100%;
    height: 100%;
    object-fit: contain;
  }

  .stream-controls {
    padding: 6px 10px;
    gap: 6px;
    flex-wrap: wrap;
  }

  .cbtn {
    font-size: 12px;
    padding: 6px 10px;
  }

  /* ──────────────────────────────────────────
     SETTINGS : sliders optimisés mobile
     ────────────────────────────────────────── */
  .settings-view {
    padding: 10px;
  }

  .sett-section {
    margin-bottom: 20px;
    padding: 12px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 10px;
  }

  .sett-title {
    font-size: 11px;
    margin-bottom: 14px;
  }

  /* ── Slider row : s'adapte au contenu ── */
  .slider-row {
    height: auto !important;
    min-height: 0 !important;
    max-height: none !important;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 6px;
    margin-bottom: 18px;
    width: 100%;
    flex-shrink: 0;
    flex-grow: 0;
    flex-basis: auto;
    padding: 0;
    box-sizing: border-box;
    overflow: visible;
  }

  .slider-row-bottom {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 10px;
    height: auto;
    flex-shrink: 0;
    width: 100%;
  }

  .slider-row input[type="range"] {
    display: block;
    height: 4px;
    flex: 1 1 auto;
    min-width: 0;
    margin: 0;
    padding: 8px 0;
    box-sizing: content-box;
    align-self: center;
  }

  .slider-row .slider-val {
    height: auto;
    line-height: 1;
    flex-shrink: 0;
    min-width: 52px;
    text-align: right;
    font-size: 13px;
    font-weight: 700;
    color: var(--accent-blue);
    white-space: nowrap;
  }

  .slider-val {
    font-size: 13px;
    font-weight: 700;
    color: var(--accent-blue);
    white-space: nowrap;
    min-width: 52px;
    text-align: right;
    flex-shrink: 0;
  }

  /* Toggle rows : plus grands sur mobile */
  .toggle-row {
    padding: 10px 0;
    border-top: 1px solid var(--border);
  }

  .toggle-lbl {
    font-size: 13px;
    line-height: 1.3;
    flex: 1;
    padding-right: 12px;
  }

  .tgl {
    width: 44px;
    height: 24px;
    flex-shrink: 0;
  }

  .tgl-track::after {
    width: 18px;
    height: 18px;
  }

  .tgl input:checked + .tgl-track::after {
    transform: translateX(20px);
  }

  /* Bouton Appliquer pleine largeur */
  .btn-apply {
    width: 100%;
    padding: 12px;
    font-size: 14px;
    border-radius: 8px;
    margin-top: 8px;
    touch-action: manipulation;
  }

  /* Select pleine largeur */
  .slider-row select,
  .settings-view select {
    width: 100%;
    padding: 10px 12px;
    font-size: 13px;
    border-radius: 8px;
    background: var(--bg-primary);
    border: 1px solid var(--border);
    color: var(--text-primary);
  }

  /* ──────────────────────────────────────────
     LIBRARY dans le panel detail
     ────────────────────────────────────────── */
  .lib-view { padding: 10px; }

  .lib-section-hdr {
    flex-direction: column;
    align-items: stretch;
    gap: 6px;
  }

  .lib-section-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
    width: 100%;
  }

  .btn-sm {
    font-size: 11px;
    padding: 6px 10px;
    flex: 1 1 auto;
    justify-content: center;
    text-align: center;
    touch-action: manipulation;
  }

  .lib-grid {
    grid-template-columns: 1fr !important;
    gap: 8px !important;
  }

  /* Table : scroll horizontal */
  .lib-table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .rec-table { font-size: 11px; }
  .rec-table thead th,
  .rec-table tbody td { padding: 8px 10px; }

  /* ──────────────────────────────────────────
     EVENTS SLIDE PANEL — override mobile : depuis le bas
     ────────────────────────────────────────── */
  .slide-panel {
    position: fixed;
    right: 0;
    left: 0;
    top: auto;
    bottom: 0;
    width: 100vw;
    max-width: 100%;
    height: 70dvh;
    border-left: none;
    border-top: 1px solid var(--border);
    /* Réinitialise la translation desktop (translateX) et passe en translateY */
    transform: translateY(100%);
    transition: transform .25s ease;
    z-index: 200;
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }

  .slide-panel.open { transform: translateY(0); }

  .panel-header {
    padding: 12px 14px;
  }

  .panel-header h2 { font-size: 14px; }
  .panel-body      { padding: 10px; }

  /* ──────────────────────────────────────────
     VIDEO MODAL
     ────────────────────────────────────────── */
  .vid-modal {
    width: calc(100vw - 16px);
    max-height: 85dvh;
  }

  /* ──────────────────────────────────────────
     GLOBAL LIBRARY VIEW
     ────────────────────────────────────────── */
  #viewLibrary {
    padding: 12px !important;
  }

  #viewLibrary > div:first-child {
    font-size: 14px !important;
    margin-bottom: 12px !important;
    flex-wrap: wrap;
    gap: 8px;
  }

  /* ──────────────────────────────────────────
     SAFE AREAS iOS
     ────────────────────────────────────────── */
  body {
    padding-top:    env(safe-area-inset-top,    0px);
    padding-bottom: env(safe-area-inset-bottom, 0px);
    padding-left:   env(safe-area-inset-left,   0px);
    padding-right:  env(safe-area-inset-right,  0px);
    box-sizing: border-box;
  }
}

/* ══════════════════════════════════════════════════════
   Très petits écrans ≤ 480px
   ══════════════════════════════════════════════════════ */
@media (max-width: 480px) {

  .header-title { font-size: 12px; }

  .tab-btn {
    font-size: clamp(9px, 2.2vw, 11px);
    padding: 4px 8px;
  }

  .cam-list-panel { max-height: 120px; }
  .cam-card       { width: 120px; font-size: 10px; }

  .slider-row input[type="range"]::-webkit-slider-thumb {
    width: 26px;
    height: 26px;
  }

  .slider-row input[type="range"]::-moz-range-thumb {
    width: 26px;
    height: 26px;
  }

  .slider-row { margin-bottom: 20px; }
  .slider-lbl {
    max-height: 30px;
    display: block;
    line-height: 1.4;
    font-size: 13px;
    color: var(--text-muted);
    flex-shrink: 0;
  }

  .slider-val { font-size: 14px; min-width: 56px; }

  .btn-apply { padding: 13px; font-size: 15px; }

  .slide-panel { height: 75dvh; }
}

/* ══════════════════════════════════════════════════════
   Slider zone de tap sur écrans < 900px
   ══════════════════════════════════════════════════════ */
@media (max-width: 900px) {
  .slider-row {
    gap: 8px;
    margin-bottom: 20px;
  }

  .slider-row input[type="range"] {
    padding: 12px 0;
  }
}