/* ---- adaptation mobile des templates : tuiles qui s'adaptent a leur largeur (container queries), cibles tactiles, popups en feuille basse ---- */
.pgc { container-type:size; }
.tile svg { flex:none; }
.tile .tstate { padding-right:34px; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
.tile.thermo .tstate { padding-right:0; }
@container (max-width: 170px) {
  .tile { padding:11px 10px 10px; border-radius:16px; }
  .tile svg.bulb { width:40px; height:40px; }
  .tile .tname { font-size:1rem; }
  .tile .tstate { font-size:.74rem; }
  .tile.thermo svg.thermo { width:24px; height:24px; }
  .tile.thermo .tval { font-size:1.55rem; }
  .tile.thermo .tval small { font-size:.75rem; }
  .chip, .tinfo { font-size:.68rem; padding:2px 6px; }
}
@container (min-width: 300px) { .tile .tname { font-size:1.1rem; } .tile.thermo .tval { font-size:2.4rem; } }
@media (pointer:coarse) {
  .tile .tmore { width:40px; height:40px; right:4px; top:4px; }
  .tile .tmore svg { width:20px; height:20px; }
  .tile.thermo .trow, .tile.wind .wrow { padding-right:44px; }
  .pill, .sw, select, input, button { min-height:40px; }
  .tile { -webkit-tap-highlight-color:transparent; user-select:none; -webkit-user-select:none; }
}
@media (max-width:700px) {
  body { padding:12px 12px calc(12px + env(safe-area-inset-bottom)); }
  h1 { font-size:1.3rem; }
  #tabs, #pgBar { flex-wrap:nowrap; overflow-x:auto; scrollbar-width:none; padding-bottom:2px; }
  #tabs .pill, #pgBar .pill { white-space:nowrap; flex:none; }
  #pgBar #pgToggleEdit { margin-left:0 !important; }
  dialog { width:100vw; max-width:none; margin:auto 0 0; border-radius:20px 20px 0 0; max-height:92vh; padding:16px 16px calc(16px + env(safe-area-inset-bottom)); }
  dialog select, dialog input[type=text], dialog input[type=number], .pgtools input, .pgtools select { font-size:16px; }
}
.mv { display:flex; gap:6px; flex-wrap:wrap; align-items:center; }
.mv button { min-width:44px; }
.modal { position: fixed; inset: 0; z-index: 50; background: rgba(8, 10, 14, .55); display: flex; align-items: center; justify-content: center; padding: 12px; }
.modal[hidden] { display: none; }
.sheet { width: min(900px, 100%); max-height: 100%; overflow-y: auto; background: var(--panel); border: 1px solid var(--line); border-radius: 22px; padding: 16px 18px 18px; box-shadow: 0 24px 60px -20px rgba(0, 0, 0, .6); }
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.sheet-head h2 { margin: 0; font-size: 1.25rem; letter-spacing: -.01em; }
.periods { display: inline-flex; flex-wrap: wrap; background: var(--bg); border: 1px solid var(--line); border-radius: 999px; padding: 3px; gap: 2px; }
.periods button { border: 0; background: none; color: var(--muted); font: inherit; font-size: .85rem; font-weight: 600; padding: 6px 14px; border-radius: 999px; cursor: pointer; }
.periods button.act { background: var(--on-soft); color: var(--on); }
.xbtn { border: 1px solid var(--line); background: var(--bg); color: var(--text); width: 34px; height: 34px; border-radius: 50%; font-size: 1.1rem; line-height: 1; cursor: pointer; flex: none; }
.chartbox { position: relative; margin-bottom: 18px; }
.chartbox h3 { margin: 0 0 2px; font-size: .95rem; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }
.stats { display: flex; flex-wrap: wrap; gap: 4px 18px; font-size: .85rem; color: var(--muted); margin-bottom: 4px; }
.stats b { color: var(--text); font-weight: 700; }
.chart { position: relative; width: 100%; touch-action: pan-y; cursor: crosshair; user-select: none; -webkit-user-select: none; }
.chart .mm { stroke-width: .8; stroke-dasharray: 2 4; opacity: .8; }
.chart .mm-t { font-size: 10.5px; font-weight: 600; opacity: .95; }
.chart .selrect { fill: var(--on); fill-opacity: .16; stroke: var(--on); stroke-width: 1; }
.zoombar { display: flex; align-items: center; gap: 4px 12px; flex-wrap: wrap; margin: -4px 0 10px; font-size: .78rem; color: var(--muted); }
.zoombar .zrange { color: var(--on); font-weight: 600; }
.zoombar .zctl { display: inline-flex; gap: 4px; margin-left: auto; }
.zoombar button { border: 1px solid var(--line); background: var(--bg); color: var(--text); border-radius: 8px; min-width: 30px; height: 28px; padding: 0 9px; font: inherit; font-size: .85rem; cursor: pointer; }
.zoombar button[hidden] { display: none; }
.zoombar button:active { transform: scale(.95); }
html.compact .zoombar .hint { display: none; }
.chart svg { display: block; width: 100%; overflow: visible; }
.chart .grid-l { stroke: var(--line); stroke-width: 1; }
.chart .axis-t { fill: var(--muted); font-size: 11px; }
.chart .cross { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 3 3; }
.tip { position: absolute; pointer-events: none; background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 6px 9px; font-size: .8rem; white-space: nowrap; box-shadow: 0 6px 20px -8px rgba(0, 0, 0, .5); transform: translate(-50%, -100%); z-index: 2; }
.tip b { display: block; font-size: .95rem; }
.tip span { color: var(--muted); }
.nodata { color: var(--muted); text-align: center; padding: 30px 0; }
.zoombar { display: flex; align-items: center; gap: 4px 12px; flex-wrap: wrap; margin: -4px 0 10px; font-size: .78rem; color: var(--muted); }
.zoombar .zrange { color: var(--on); font-weight: 600; }
.zoombar .zctl { display: inline-flex; gap: 4px; margin-left: auto; }
.zoombar button { border: 1px solid var(--line); background: var(--bg); color: var(--text); border-radius: 8px; min-width: 30px; height: 28px; padding: 0 9px; font: inherit; font-size: .85rem; cursor: pointer; }
.zoombar button[hidden] { display: none; }
.zoombar button:active { transform: scale(.95); }
html.compact .zoombar .hint { display: none; }
.chart svg { display: block; width: 100%; overflow: visible; }
/* titres de la fenetre de courbes : pas le style des titres de section */
.sheet-head h2 { text-transform:none; color:var(--text); }
.chartbox h3 { margin:0 0 2px; }
/* tuile thermometre : courbe en fond, contenu au-dessus */
.tile.thermo > :not(.spark):not(.tbadge):not(.tmore) { position:relative; z-index:1; }
.tile .tmore { z-index:2; }
.tile .tbadge { z-index:2; }
.tile .spark { position:absolute; left:0; right:0; bottom:0; width:100%; height:58%; margin:0; opacity:.55; z-index:0; pointer-events:none; }
.tile .tname { display:-webkit-box; -webkit-line-clamp:2; -webkit-box-orient:vertical; overflow:hidden; }
/* thermometre (1 case) : valeur + grandeur secondaire sur la meme ligne, nom, heure, tendances compactes ; la courbe des 24 h occupe le fond (elle passe sous le titre) */
.tile.thermo { display:flex; flex-direction:column; justify-content:flex-start; gap:0; padding:11px 11px 9px; }
.tile.thermo .trow { flex-wrap:nowrap; gap:6px; align-items:baseline; }
.tile.thermo svg.thermo { align-self:center; }
.tile .tpills { margin-top:auto; display:flex; align-items:center; gap:3px; min-width:0; }
.tile .tpills .tpill { margin-top:0; max-width:none; min-width:0; flex:0 1 auto; font-size:.66rem; padding:1px 4px; letter-spacing:-.01em; }
.tile .tpills .tpill.ter { margin-left:auto; }
.tile.thermo .trow, .tile.wind .wrow { padding-right:28px; }                    /* place du bouton « i » en haut a droite */
.tile.thermo .tbadge, .tile.wind .tbadge { display:none !important; }              /* tuiles de mesure : « Hors ligne » est deja ecrit, pas de pastille a cote du bouton */
.tile .tpill { margin-top:auto; align-self:flex-start; max-width:100%; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; border:1px solid var(--line); border-radius:999px; padding:1px 9px; font-size:.7rem; color:var(--muted); background:color-mix(in srgb, var(--panel) 75%, transparent); }
.tile.thermo .tsec { flex:none; font-size:1.1rem; font-weight:600; color:var(--text); opacity:.75; white-space:nowrap; }
/* structure commune des tuiles : en-tete (picto / valeur), titre centre dans l'espace libre, pastille en bas */
.tile .tnamebox { flex:1 1 auto; min-height:0; display:flex; flex-direction:column; justify-content:center; gap:2px; padding:2px 0; }
.tile .tname { font-size:1.08rem; line-height:1.15; -webkit-line-clamp:2; }
.tile .tstate { white-space:normal; padding-right:0; min-height:0; }
.tile .tpill { max-width:calc(100% - 32px); padding:1px 7px; font-size:.68rem; }
.tile .thead { display:flex; align-items:flex-start; }
.tile.thermo .tage { margin-left:auto; flex:none; max-width:55%; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; font-size:.68rem; color:var(--muted); align-self:baseline; }
.tile.thermo .chips { flex-wrap:nowrap; gap:10px; margin:3px 0 0; }
.tile.thermo .chip { font-size:.66rem; padding:0; border:0; background:none; white-space:nowrap; }
@container (max-width:199px) { .tile.thermo svg.thermo { width:20px; height:20px; } .tile.thermo .tval { font-size:1.7rem; } }
/* tuile vent : meme structure que le thermometre (valeur, tendances 1 h / 24 h, nom, pastille de la rafale en bas, courbe 24 h en fond) avec un compas a la place du picto */
.tile.wind > :not(.spark):not(.tbadge):not(.tmore) { position:relative; z-index:1; }
.tile.wind { display:flex; flex-direction:column; justify-content:flex-start; gap:0; padding:11px 11px 9px; }
.tile.wind .wrow { display:flex; align-items:center; gap:8px; min-height:0; }
.tile.wind svg.compass { flex:none; width:58px; height:58px; }
.tile.wind svg.compass circle { fill:none; stroke:var(--line); stroke-width:2; }
.tile.wind svg.compass line { stroke:var(--muted); stroke-width:1.6; stroke-linecap:round; }
.tile.wind svg.compass .north { fill:var(--bad); }
.tile.wind svg.compass text { fill:var(--muted); font-size:11px; font-weight:600; text-anchor:middle; dominant-baseline:middle; }
.tile.wind svg.compass text.cn { fill:var(--bad); }
.tile.wind svg.compass .needle { transform-origin:50px 50px; transform-box:view-box; transition:transform .8s ease; }
.tile.wind svg.compass .needle path { fill:var(--text); }
.tile.wind svg.compass .hub { fill:var(--panel); stroke:var(--text); stroke-width:1.5; }
.tile.wind .wtxt { min-width:0; display:flex; flex-direction:column; gap:0; }
.tile.wind .tval { font-size:clamp(1.6rem,4.2vw,2rem); white-space:nowrap; font-weight:700; line-height:1; letter-spacing:-.02em; color:var(--tc,var(--text)); }
.tile.wind .tval small { font-size:.85rem; font-weight:600; margin-left:3px; color:var(--muted); }
.tile.wind .wdir { font-size:.8rem; font-weight:600; margin-top:3px; white-space:nowrap; }
.tile.wind .tage { margin-left:auto; flex:none; max-width:40%; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; font-size:.68rem; color:var(--muted); align-self:flex-start; }
.tile.wind .chips { flex-wrap:nowrap; gap:10px; margin:3px 0 0; }
.tile.wind .chip { font-size:.66rem; padding:0; border:0; background:none; white-space:nowrap; }
.tile.wind.offline svg.compass .needle path { fill:var(--muted); }
@container (max-width:199px) {                                  /* case standard (~170 px) : tout est conserve, en plus compact */
  .tile.wind { padding:8px 8px 7px; }
  .tile.wind svg.compass { width:44px; height:44px; }
  .tile.wind svg.compass text { display:none; }
  .tile.wind .tval { font-size:1.75rem; }
  .tile.wind .tval small { font-size:.7rem; margin-left:2px; }
  .tile.wind .wdir { font-size:.74rem; margin-top:2px; }
  .tile.wind .tage { display:none; }
}
@container (min-width: 300px) { .tile.wind .tval { font-size:2.4rem; } .tile.wind svg.compass { width:80px; height:80px; } }
.tile .spark { height:78%; opacity:.5; }
@container (max-height:160px) { .tile svg.bulb { width:36px; height:36px; } }

/* ---- emplacements fixes : le titre est toujours au meme endroit, quels que soient les elements affiches ----
   Chaque tuile se decoupe en trois emplacements : l'en-tete (valeur + tendances, ou pictogramme de la lampe), le titre, et le pied (pastilles / energie).
   Les emplacements gardent leur hauteur meme quand la tendance ou les pastilles sont masquees ou absentes : le titre ne bouge donc plus. */
.tile, .tile.thermo, .tile.wind { --head:70px; --foot:22px; justify-content:flex-start; gap:0; padding:11px 11px 9px; }
.tile .tmain, .tile .thead { height:var(--head); flex:none; min-height:0; overflow:hidden; }
.tile .tmain { display:flex; flex-direction:column; }
.tile .tfoot { height:var(--foot); flex:none; display:flex; align-items:flex-end; min-width:0; }
.tile .tfoot .tpills { width:100%; margin-top:0; }
.tile .tfoot > .tpill { margin-top:0; }
.tile.wind svg.compass { width:52px; height:52px; }
@container (max-width:199px) {
  .tile, .tile.thermo, .tile.wind { --head:62px; --foot:20px; padding:8px 8px 7px; }
  .tile.wind svg.compass { width:44px; height:44px; }
}
@container (min-width: 300px) { .tile, .tile.thermo, .tile.wind { --head:104px; --foot:26px; } }
@container (max-height:112px) { .tile, .tile.thermo, .tile.wind { --head:46px; --foot:0px; } .tile .tfoot, .tile .chips { display:none; } }

/* ---- tuile Caméra : image plein cadre, nom en bandeau, clic = direct */
.tile.camera { padding:0; overflow:hidden; position:relative; cursor:pointer; background:#10131a; color:#fff; }
.tile.camera img { position:absolute; inset:0; width:100%; height:100%; object-fit:cover; }
.tile.camera.nopic img, .tile.camera.offline img:not([src]) { display:none; }
.tile.camera .camph { position:absolute; inset:0; display:none; place-items:center; align-content:center; gap:4px; text-align:center; font-size:.75rem; color:#aab; }
.tile.camera.nopic .camph, .tile.camera.offline .camph { display:grid; }
.tile.camera.offline { cursor:default; opacity:.75; }
.tile.camera .camname { position:absolute; left:0; right:0; bottom:0; display:flex; align-items:center; gap:6px; padding:16px 8px 6px; font-size:.78rem; font-weight:600; background:linear-gradient(transparent, rgba(0,0,0,.65)); }
.tile.camera .camname span { flex:1; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.tile.camera .camplay { font-style:normal; font-size:.7rem; opacity:.85; }
.tile.camera .tmore { background:rgba(0,0,0,.45); color:#fff; border-radius:50%; }
.camdlg { position:fixed; inset:0; z-index:300; display:grid; place-items:center; background:rgba(0,0,0,.72); padding:12px; }
.camdbox { width:min(96vw, 1100px); background:var(--card, #fff); border-radius:12px; padding:10px; display:grid; gap:8px; }
.camdhead { display:flex; align-items:center; gap:10px; } .camdhead .camdmsg { flex:1; color:var(--muted); font-size:.85rem; }
.camdbox video { width:100%; max-height:78vh; background:#000; border-radius:8px; }
.camhist { display:flex; flex-wrap:wrap; gap:8px; } .camhist a { display:grid; gap:2px; font-size:.7rem; text-align:center; color:var(--muted); text-decoration:none; } .camhist img { width:150px; border-radius:6px; }
