/* Maison, disposition téléphone (≤ 760 px). Chargé en dernier : il remplace les anciens réglages mobiles page par page.
   Principes : barre du haut fine, barre d'onglets en bas, listes tactiles au lieu de grandes cartes, fiches en « bottom sheet ». */

.chip-row{display:contents}
#ptr{display:none}

@media (max-width:760px){
  #ptr{position:fixed;left:50%;top:calc(var(--appbar) + var(--safe-top) + 10px);z-index:25;display:block;padding:8px 16px;border:1px solid var(--m-line);border-radius:999px;background:var(--m-surface-2);color:var(--muted);font-size:13px;font-weight:600;white-space:nowrap;opacity:0;transform:translate(-50%,-24px);pointer-events:none;transition:opacity .15s}
  #ptr.on{opacity:1}
  #ptr.ready{color:var(--accent)}
  :root{--tabbar:64px;--appbar:54px;--gutter:16px;--m-surface:#141a1d;--m-surface-2:#1b2327;--m-line:rgba(255,255,255,.08);--m-radius:18px;
    --safe-bottom:env(safe-area-inset-bottom,0px);--safe-top:env(safe-area-inset-top,0px);--body-font:'Manrope',Roboto,'Segoe UI',system-ui,sans-serif}

  /* ---- Base : fond uni, pas de flou (coûteux sur téléphone), pas de sélection de texte ---- */
  html{-webkit-text-size-adjust:100%;overscroll-behavior:none}
  body{background:#0d1113;background-attachment:scroll;font-size:15px;line-height:1.45;overscroll-behavior:none;touch-action:manipulation;-webkit-user-select:none;user-select:none}
  input,textarea,select{-webkit-user-select:text;user-select:text}
  *,*::before,*::after{-webkit-tap-highlight-color:transparent;-webkit-backdrop-filter:none!important;backdrop-filter:none!important;scrollbar-width:none}
  ::-webkit-scrollbar{display:none}
  h1,h2,h3{font-family:var(--body-font);letter-spacing:0}
  button,a,.tab,.room-chip{touch-action:manipulation}
  footer{display:none}

  /* ---- Coque : barre du haut + onglets du bas ---- */
  .app-shell{margin-left:0;padding-bottom:calc(var(--tabbar) + var(--safe-bottom) + 18px)}
  body .topbar{position:sticky;top:0;z-index:15;height:var(--appbar);margin:0;padding:0 8px 0 var(--gutter);border:0;border-bottom:1px solid var(--m-line);border-radius:0;background:#0d1113;box-shadow:none}
  .breadcrumb{font-size:0}
  .breadcrumb span{display:none}
  .breadcrumb strong{font-size:19px;font-weight:700;letter-spacing:-.01em;color:var(--text)}
  .local-pill{display:none}
  .top-actions{gap:4px}
  body .topbar .icon-button{width:44px;height:44px;border:0!important;background:transparent!important;box-shadow:none!important;color:var(--muted)}
  .topbar .icon-button svg{width:22px;height:22px}
  .topbar .icon-button:active{background:rgba(255,255,255,.08)}

  body .sidebar{position:fixed;inset:auto 0 0 0;display:block;width:auto;height:calc(var(--tabbar) + var(--safe-bottom));margin:0;padding:0 6px var(--safe-bottom);border:0;border-top:1px solid var(--m-line);border-radius:0;background:#10161a;box-shadow:0 -10px 28px rgba(0,0,0,.4);z-index:30}
  .sidebar .brand,.sidebar .home-label,.sidebar .nav-caption,.sidebar .sidebar-bottom{display:none}
  .sidebar nav{display:grid;grid-template-columns:repeat(5,minmax(0,1fr));height:100%}
  .sidebar .nav-item{position:relative;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:4px;height:100%;min-width:0;margin:0;padding:6px 2px 4px;border:0;border-radius:14px;background:none;box-shadow:none;transform:none;color:var(--muted);font-size:0}
  .sidebar .nav-item::after{content:attr(data-short);font-size:11px;font-weight:600;line-height:1;letter-spacing:.01em}
  .sidebar .nav-item svg{width:24px;height:24px}
  .sidebar .nav-item:hover{background:none;transform:none}
  .sidebar .nav-item:active{background:rgba(255,255,255,.07)}
  .sidebar .nav-item.active{color:var(--accent);background:none;box-shadow:none}
  .sidebar .nav-item.active::before{content:"";position:absolute;top:0;left:50%;width:30px;height:3px;margin:0;border-radius:0 0 4px 4px;background:var(--accent);box-shadow:0 0 12px var(--soft-accent);transform:translateX(-50%)}
  .sidebar .nav-badge,.sidebar .nav-item-overflow{display:none}
  .sidebar .nav-item-more{display:flex}

  #toast{left:50%;bottom:calc(var(--tabbar) + var(--safe-bottom) + 14px);width:max-content;max-width:calc(100vw - 32px);border-radius:14px;font-size:14px}

  /* ---- Contenu ---- */
  main{max-width:none;padding:14px var(--gutter) 8px}
  .page-title{display:flex;flex-direction:column;align-items:stretch;gap:12px;margin-bottom:16px}
  .eyebrow{margin:0 0 4px;font-size:11px;letter-spacing:.14em}
  h1{font-size:28px;line-height:1.15;font-weight:800;letter-spacing:-.02em}
  .subtitle{display:none}
  .header-actions{display:flex;flex-direction:column;flex-wrap:nowrap;align-items:stretch;justify-content:flex-start;gap:12px}
  .chip-row{display:flex;gap:8px;overflow-x:auto;margin:0 calc(var(--gutter)*-1);padding:0 var(--gutter);scroll-snap-type:x proximity}
  body .weather-chip{flex:none;padding:10px 14px;border-radius:14px;background:var(--m-surface);border:1px solid var(--m-line);font-size:15px;white-space:nowrap;scroll-snap-align:start}
  .weather-chip span{font-size:12px}
  .page-actions{display:flex;justify-content:stretch;gap:8px;width:100%}
  .page-actions .button{flex:1}
  body .button{min-height:46px;padding:0 18px;border-radius:14px;font-size:14px}
  .button:active{filter:brightness(.92)}
  .text-button{min-height:44px}

  body .overview-stats{display:grid;grid-template-columns:repeat(4,minmax(0,1fr));gap:8px;margin:0 0 16px;border:0;background:none;overflow:visible}
  body .overview-stats>div,body .overview-stats>button{display:flex;flex-direction:column;align-items:flex-start;gap:3px;min-width:0;padding:12px 10px;border:1px solid var(--m-line);border-radius:16px;background:var(--m-surface);text-align:left}
  .overview-stats>div>span,.overview-stats>button>span{display:none}
  body .overview-stats strong{font-size:22px;line-height:1}
  body .overview-stats small{display:block;font-size:11px;line-height:1.25}
  .overview-stats small svg{display:none}
  .overview-stats .stat-alert strong{color:#eab27f}

  body .room-navigation{gap:8px;margin:0 calc(var(--gutter)*-1) 10px;padding:2px var(--gutter);scroll-snap-type:x proximity}
  body .room-chip{flex:none;min-height:40px;gap:8px;padding:0 14px;border-radius:999px;background:var(--m-surface);font-size:14px;font-weight:600;scroll-snap-align:start}
  .room-chip>svg{display:none}
  body .room-chip b{padding:1px 7px;border-radius:999px;font-size:11px}
  body .room-chip.active{background:var(--accent);border-color:var(--accent);color:var(--accent-ink)}

  body .device-toolbar{display:flex;flex-direction:column;flex-wrap:nowrap;align-items:stretch;gap:10px;margin:0 0 12px;padding:0;border:0}
  body .category-tabs{flex-wrap:nowrap;gap:6px;overflow-x:auto;margin:0 calc(var(--gutter)*-1);padding:0 var(--gutter)}
  body .category-tabs .tab{flex:none;min-height:36px;padding:0 14px;border-radius:999px;font-size:13px;font-weight:600}
  body .search-actions{display:flex;align-items:center;gap:8px}
  body .search{order:-1;flex:1;min-width:0;max-width:none;min-height:46px;border-radius:14px;border:1px solid var(--m-line);background:var(--m-surface)}
  .search input{font-size:16px}
  body .favorite-filter{flex:none;min-height:46px;padding:0 12px;border:1px solid var(--m-line);border-radius:14px;background:var(--m-surface);font-size:13px}

  /* ---- Appareils : une ligne par appareil (icône, nom, état, interrupteur) ---- */
  body .device-group{margin-bottom:18px}
  body .group-heading{margin:0 0 8px;padding:0 2px}
  body .group-heading h2{gap:8px;font-size:12px;font-weight:700;letter-spacing:.09em;text-transform:uppercase;color:var(--muted)}
  .group-heading h2>svg{display:none}
  .group-heading .text-button{font-size:12px}
  body .room-device-grid{display:flex;flex-direction:column;gap:8px}
  body .compact-device{display:grid;grid-template-columns:46px minmax(0,1fr) auto;grid-template-areas:"icon name control" "icon state control" "range range range" "swatches swatches swatches" "actions actions actions";column-gap:14px;row-gap:0;align-items:center;min-height:70px;padding:12px 14px;border:1px solid var(--m-line);border-radius:var(--m-radius);background:var(--m-surface);transition:background .15s,border-color .15s,transform .1s}
  body .compact-device.on{border-color:rgba(81,184,212,.4);background:rgba(81,184,212,.08)}
  body .compact-device:active{transform:scale(.99)}
  body .compact-device .device-top{display:contents}
  body .compact-device .device-symbol{grid-area:icon;width:46px;height:46px;border-radius:14px}
  body .compact-device .device-symbol svg{width:24px;height:24px}
  body .compact-device h3{grid-area:name;align-self:end;margin:0;font-size:16px;font-weight:650;line-height:1.25}
  body .compact-device .device-room{display:none}
  body .compact-device .device-bottom{display:contents}
  body .compact-device .device-state{grid-area:state;align-self:start;margin-top:2px;font-size:13px}
  .compact-device .device-state::after{content:"";display:inline-block;width:6px;height:6px;margin:-3px 0 0 8px;border:solid currentColor;border-width:0 2px 2px 0;opacity:.55;transform:rotate(45deg);transition:transform .15s}
  .compact-device.open .device-state::after{margin-top:2px;transform:rotate(-135deg)}
  body .compact-device .toggle{grid-area:control;justify-self:end;width:54px;height:32px;padding:3px;border-radius:999px}
  body .compact-device .toggle span{width:26px;height:26px}
  body .compact-device .toggle[aria-checked="true"] span{transform:translateX(22px)}
  body .compact-device .button,body .compact-device .read-only,body .compact-device .text-button{grid-area:control;justify-self:end}
  body .compact-device .button{min-height:40px;padding:0 14px;font-size:13px}
  body .compact-device .read-only{font-size:12px}
  body .compact-device .device-range,body .compact-device .color-swatches,body .compact-device .device-meta-actions{display:none}
  body .compact-device.open .device-range{display:flex;grid-area:range;margin:14px 0 4px;font-size:13px}
  body .compact-device.open .device-range input{height:36px}
  body .compact-device.open .device-range span{min-width:38px;font-size:13px}
  body .compact-device.open .color-swatches{display:flex;grid-area:swatches;flex-wrap:nowrap;gap:12px;margin:8px -14px 4px;padding:4px 14px;overflow-x:auto}
  body .compact-device.open .color-swatches .swatch{flex:none;width:36px;height:36px}
  body .compact-device.open .device-meta-actions{display:flex;grid-area:actions;justify-content:flex-end;gap:4px;margin-top:8px;padding-top:6px;border-top:1px solid var(--m-line)}
  body .compact-device.open .favorite{min-width:46px;min-height:46px;font-size:22px}

  /* ---- Pièces ---- */
  body .rooms-grid{display:flex;flex-direction:column;gap:8px}
  body .room-card{position:relative;display:grid;grid-template-columns:46px minmax(0,1fr) auto;grid-template-areas:"icon name edit" "icon count edit";column-gap:14px;align-items:center;min-height:70px;padding:12px 14px;border:1px solid var(--m-line);border-radius:var(--m-radius);background:var(--m-surface);box-shadow:none}
  body .room-card>.stat-icon{grid-area:icon;width:46px;height:46px;margin:0;border-radius:14px}
  body .room-card h3{grid-area:name;align-self:end;margin:0;font-size:16px}
  body .room-card p{grid-area:count;align-self:start;margin:0;font-size:13px}
  body .room-card .room-preview{display:none}
  body .room-card .room-edit{position:static;grid-area:edit;z-index:2;width:44px;height:44px;border:0;background:transparent}
  body .room-card>.text-button{position:absolute;inset:0;z-index:1;padding:0;border-radius:var(--m-radius);font-size:0}
  .room-card>.text-button svg{display:none}

  /* ---- Cartes et panneaux ---- */
  body .panel,body .account-card,body .connection-card,body .scene-full{padding:16px;border:1px solid var(--m-line);border-radius:20px;background:var(--m-surface);box-shadow:none}
  .panel{margin-top:14px}
  .panel h2{font-size:17px}
  body .panel p,body .account-card>p{font-size:14px;line-height:1.6}
  body .account-grid{display:flex;flex-direction:column;gap:12px}
  body .account-card>p{margin:14px 0}
  .account-top{flex-wrap:nowrap;gap:12px}
  body .account-actions{gap:8px}
  .account-actions .danger{margin-left:0}
  body .dashboard-notice{align-items:flex-start;padding:14px;border-radius:16px;font-size:13px}
  body .empty{padding:32px 18px;border-radius:20px}
  .settings-layout{max-width:none}
  .setting-row{flex-wrap:wrap}
  body .field input,body .field select{min-height:48px;font-size:16px}
  .field{margin:14px 0}

  .schedule-row{align-items:center;padding:14px}
  .schedule-actions{gap:8px}
  body .history-row{grid-template-columns:1fr auto;gap:2px 12px;padding:12px 14px;font-size:13px}
  .history-row span:first-child{grid-column:1/-1;font-size:14px}
  body .history-row span:not(:first-child){font-size:12px;text-align:left}
  body .energy-history{max-height:none!important;border:0;border-radius:0}

  /* ---- Caméras ---- */
  body .camera-list{display:flex;flex-direction:column;gap:14px}
  body .camera-panel{overflow:hidden;border:1px solid var(--m-line);border-radius:20px;background:var(--m-surface)}
  body .camera-panel-heading{flex-wrap:wrap;gap:8px;padding:14px 16px}
  .camera-panel-heading h2{font-size:17px}
  body .camera-stage{min-height:0;aspect-ratio:16/9}
  .camera-stage img{width:100%;height:100%;object-fit:cover}
  body .camera-panel-footer{flex-direction:column;align-items:stretch;gap:8px;padding:12px 16px}
  .camera-panel-footer>div{display:flex;flex-wrap:wrap;gap:8px}
  .rec-chips{gap:6px}
  body .rec-chip{min-height:38px;padding:0 12px}

  /* ---- Fiches en « bottom sheet » ---- */
  body dialog{position:fixed;inset:auto 0 0 0;width:100%;max-width:none;max-height:90vh;max-height:90dvh;margin:0;padding:6px 18px calc(18px + var(--safe-bottom));border:0;border-top:1px solid var(--m-line);border-radius:24px 24px 0 0;background:#151b1f;box-shadow:0 -20px 60px rgba(0,0,0,.6);overflow:auto;animation:sheet-up .22s ease-out}
  dialog::before{content:"";display:block;width:40px;height:4px;margin:6px auto 12px;border-radius:2px;background:rgba(255,255,255,.25)}
  dialog::backdrop{background:rgba(0,0,0,.55)}
  body dialog.wide-dialog{max-height:94vh;max-height:94dvh}
  .dialog-heading h2{font-size:19px}
  .dialog-copy{font-size:14px}
  .dialog-actions{gap:10px;margin-top:18px}
  .dialog-actions .button{flex:1}
  .more-menu{gap:0}
  .more-menu .nav-item{display:flex;align-items:center;gap:16px;width:100%;margin:0;padding:16px 8px;border-radius:14px;font-size:16px;font-weight:600;color:var(--text)}
  .more-menu .nav-item svg{width:24px;height:24px;color:var(--accent)}
  .more-menu .nav-item:active{background:rgba(255,255,255,.07)}
  @keyframes sheet-up{from{transform:translateY(40px);opacity:.4}to{transform:none;opacity:1}}

  /* ---- Finitions ---- */
  body .room-navigation,body .category-tabs,body .chip-row,body .color-swatches{scrollbar-width:none}
  body::before,body::after{display:none}
  body .pin-card{max-width:340px;padding:16px 8px;border:0;background:transparent;box-shadow:none}
  .pin-keypad{gap:16px}
  body .pin-key{border-color:var(--m-line);background:var(--m-surface-2);font-size:26px}
  /* La barre du haut porte déjà le titre : l'en-tête de page ne reste que sur l'accueil. */
  body:not([data-page="home"]) .page-title>div:first-child:not(:only-child){display:none}
  body:not([data-page="home"]) .page-title:not(:has(.page-actions,.header-actions,.button)){display:none}
  body:not([data-page="home"]) main{padding-top:16px}
  dialog::backdrop{background:rgba(0,0,0,.6);-webkit-backdrop-filter:none!important;backdrop-filter:none!important}
  dialog button:focus,dialog button:focus-visible{outline:none;box-shadow:none}
  body .camera-stage{min-height:190px;aspect-ratio:auto}
  body .camera-stage:has(img:not([hidden])){min-height:0;aspect-ratio:16/9}
  .camera-placeholder{padding:22px 16px}
  .camera-placeholder h3{font-size:17px}
  .section-heading{flex-wrap:wrap;gap:10px}
  .section-heading .button{flex:1 1 100%}
  body .panel:has(.energy-history){padding:4px 0;overflow:hidden}
  body .history-row{padding:12px 16px}
}
