:root {
  --bg: #eef3ec;
  --card: #ffffff;
  --green: #2e7d46;
  --green-soft: #e5f2e8;
  --water: #3f86d9;
  --water-soft: #e6f0fb;
  --ok: #4caf50;
  --warn: #f3a712;
  --bad: #e2574c;
  --grey: #b6c0ba;
  --text: #1d2a22;
  --muted: #71807a;
  --line: #e7ece8;
  --shadow: 0 6px 20px rgba(31, 60, 40, 0.10);
  --radius: 18px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: #cfd9d2;
  color: var(--text);
  display: flex;
  justify-content: center;
  align-items: stretch;
}

/* Cadre téléphone (visible sur desktop, plein écran sur mobile) */
#phone {
  width: 100%;
  max-width: 430px;
  background: var(--bg);
  position: relative;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  box-shadow: 0 0 40px rgba(0,0,0,0.25);
  overflow: hidden;
}
#app { flex: 1; display: flex; flex-direction: column; overflow-y: auto; padding-bottom: 92px; overscroll-behavior-y: contain; }

/* Indice discret sous la bannière d'accueil (le rafraîchissement se fait au geste). */
.pull-hint { text-align: center; color: var(--muted); font-size: 12.5px; padding: 2px 0 6px; }

/* Sélecteur de période (Mesures moyennes : 7 jours / 1 mois). */
.period-row { display: flex; gap: 8px; margin-bottom: 2px; }
.period-pill {
  flex: 1; border: 1.5px solid var(--line); background: #fff; color: var(--muted);
  padding: 7px 10px; border-radius: 999px; font-size: 13px; font-weight: 600; cursor: pointer;
}
.period-pill.on { background: var(--green-soft); border-color: var(--green); color: var(--green); }

/* Pile d'icônes (topbar accueil) qui se dépile vers la gauche au tap. */
.menu-backdrop { position: fixed; inset: 0; z-index: 40; }
.icon-stack { position: relative; width: 42px; height: 42px; z-index: 41; }
.icon-stack .stack-item { position: absolute; top: 0; right: 0; transition: transform .25s cubic-bezier(.2,.8,.3,1), opacity .2s; }
/* repliée : empilée (1re devant, les autres décalées/atténuées derrière), non cliquables → tap = ouvre */
.icon-stack:not(.open) .stack-item { transform: translate(calc(var(--i) * 3px), calc(var(--i) * 3px)); pointer-events: none; }
.icon-stack:not(.open) .stack-item:not(.stack-top) { opacity: .5; }
/* dépliée : s'étale vers la gauche (animation en cascade) */
.icon-stack.open .stack-item { animation: stackOut .25s cubic-bezier(.2,.8,.3,1) both; animation-delay: calc(var(--i) * .04s); }
@keyframes stackOut { from { transform: translateX(0) scale(.6); opacity: 0; } to { transform: translateX(calc(var(--i) * -48px)); opacity: 1; } }

/* Indicateur « tire pour mettre à jour » (overlay, suit le doigt). */
.ptr {
  position: absolute; top: 0; left: 0; right: 0; z-index: 6;
  display: flex; justify-content: center; pointer-events: none;
  opacity: 0; transform: translateY(0);
}
.ptr.show { opacity: 1; }
.ptr.snap { transition: transform .2s ease, opacity .2s ease; }
.ptr-txt {
  margin-top: calc(env(safe-area-inset-top, 0px) + 8px);
  background: var(--card); color: var(--muted); font-size: 13px; font-weight: 600;
  padding: 7px 14px; border-radius: 999px; box-shadow: var(--shadow); white-space: nowrap;
}

/* En-tête */
.topbar {
  position: sticky; top: 0; z-index: 5;
  background: var(--bg);
  padding: calc(env(safe-area-inset-top, 0px) + 18px) 20px 10px;
  display: flex; align-items: flex-start; justify-content: space-between;
}
/* Les vues sans .topbar (titre dans un simple bloc) doivent aussi descendre */
.safe-top { padding-top: calc(env(safe-area-inset-top, 0px) + 18px) !important; }
.topbar h1 { font-size: 26px; margin: 0; font-weight: 800; letter-spacing: -0.5px; }
.topbar .sub { color: var(--muted); font-size: 14px; margin-top: 2px; }
.icon-btn {
  border: none; background: var(--card); width: 42px; height: 42px;
  border-radius: 50%; font-size: 19px; box-shadow: var(--shadow); cursor: pointer;
}
.back {
  display: inline-flex; align-items: center; gap: 6px;
  background: none; border: none; color: var(--green);
  font-size: 16px; font-weight: 600; cursor: pointer; padding: 0;
}

/* Cartes plantes (accueil) */
.list { padding: 6px 16px 16px; display: flex; flex-direction: column; gap: 12px; }
/* En-tête de pièce (regroupement) — bouton pliable, discret, avec traits latéraux. */
.room-title {
  display: flex; align-items: center; gap: 10px; width: 100%;
  margin: 8px 0 0; padding: 2px; font-size: 12px; font-weight: 700; letter-spacing: .06em;
  text-transform: uppercase; color: var(--muted);
  background: none; border: 0; cursor: pointer; font-family: inherit; text-align: left;
}
.room-title > span:first-child { display: inline-flex; align-items: center; gap: 6px; }
.room-title::before { content: ''; order: 3; flex: 1; height: 1px; background: var(--green-soft); }
.room-count {
  display: inline-flex; align-items: center; justify-content: center; min-width: 18px; height: 18px;
  padding: 0 5px; border-radius: 9px; background: var(--green-soft); color: var(--green);
  font-size: 11px; font-weight: 700; letter-spacing: 0;
}
.room-chevron { order: 4; transition: transform .18s ease; font-size: 15px; line-height: 1; }
.room-title.collapsed .room-chevron { transform: rotate(-90deg); }
.plant-card {
  background: var(--card); border-radius: var(--radius); padding: 16px;
  box-shadow: var(--shadow); display: flex; align-items: center; gap: 14px;
  cursor: pointer; border: 1px solid var(--line); transition: transform .12s;
}
.plant-card:active { transform: scale(0.98); }
.plant-emoji { font-size: 34px; width: 52px; height: 52px; border-radius: 14px;
  background: var(--green-soft); display: grid; place-items: center; flex: none; }
.plant-main { flex: 1; min-width: 0; }
.plant-name { font-weight: 700; font-size: 17px; display: flex; align-items: center; gap: 8px; }
.plant-meta { color: var(--muted); font-size: 13.5px; margin-top: 3px; }
.plant-action { font-size: 13.5px; margin-top: 5px; font-weight: 600; }

.dot { width: 11px; height: 11px; border-radius: 50%; flex: none; display: inline-block; }
.dot.ok { background: var(--ok); }
.dot.warn { background: var(--warn); }
.dot.bad { background: var(--bad); }
.dot.none { background: var(--grey); }

.tag { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .4px;
  padding: 2px 8px; border-radius: 20px; }
.tag.sensor { background: var(--green-soft); color: var(--green); }
.tag.estim { background: #eef1ef; color: var(--muted); }

.text-ok { color: var(--ok); }
.text-warn { color: #c9810a; }
.text-bad { color: var(--bad); }

/* Bouton flottant + ajouter */
.fab-row { padding: 4px 16px 18px; }
.btn {
  width: 100%; border: none; border-radius: 14px; padding: 15px;
  font-size: 16px; font-weight: 700; cursor: pointer;
}
.btn.primary { background: var(--green); color: #fff; }
.btn.ghost { background: var(--card); color: var(--green); border: 1.5px solid var(--green-soft); }
.btn.subtle { background: #eef1ef; color: var(--text); }
.btn + .btn { margin-top: 10px; }
.btn:active { filter: brightness(0.96); }

/* Détail */
.hero-photo { margin: 4px 16px 0; height: 170px; border-radius: var(--radius);
  background: #eef1ef; box-shadow: var(--shadow); overflow: hidden; flex-shrink: 0; }
.status-banner { margin: 14px 16px 0; background: var(--card); border-radius: var(--radius);
  padding: 16px; box-shadow: var(--shadow); }
.status-banner .head { display: flex; align-items: center; gap: 9px; font-weight: 800; font-size: 17px; }
.status-banner p { margin: 8px 0 0; color: #46524b; font-size: 15px; line-height: 1.45; }

.section { margin: 16px 16px 0; }
.section-label { font-size: 12px; font-weight: 800; text-transform: uppercase;
  letter-spacing: .6px; color: var(--muted); margin: 0 4px 8px; }
.section-label.measured { color: var(--green); }
.help-btn { display: inline-flex; align-items: center; justify-content: center; width: 17px; height: 17px;
  margin-left: 6px; padding: 0; border: none; border-radius: 50%; background: var(--green); color: #fff;
  font-size: 11px; font-weight: 800; line-height: 1; cursor: pointer; vertical-align: middle; }
.modal-overlay { position: fixed; inset: 0; z-index: 100; display: flex; align-items: flex-end; justify-content: center; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.45); }
.modal-card { position: relative; z-index: 1; width: 100%; max-width: 480px; background: var(--card);
  border-radius: 18px 18px 0 0; padding: 16px 20px 28px; box-shadow: 0 -4px 24px rgba(0,0,0,.2);
  max-height: 80vh; overflow-y: auto; animation: sheetUp .2s ease; }
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; font-size: 16px; }
.modal-body p { margin: 9px 0; line-height: 1.5; font-size: 14.5px; color: var(--text); }
.modal-body b { color: var(--text); }
@keyframes sheetUp { from { transform: translateY(100%); } to { transform: translateY(0); } }
.card-block { background: var(--card); border-radius: var(--radius); padding: 6px 16px;
  box-shadow: var(--shadow); }
.metric { display: flex; align-items: center; gap: 12px; padding: 13px 0; border-bottom: 1px solid var(--line); }
.metric:last-child { border-bottom: none; }
.metric .m-ico { font-size: 20px; width: 26px; text-align: center; }
.metric .m-name { flex: 1; font-size: 15px; }
.metric .m-val { font-weight: 700; font-size: 15px; }
.bar { height: 7px; border-radius: 6px; background: #edf1ee; margin-top: 7px; overflow: hidden; }
.bar > span { display: block; height: 100%; border-radius: 6px; }
.bar.water > span { background: var(--water); }
.bar.light > span { background: #f1c40f; }
.soil-range { -webkit-appearance: none; appearance: none; width: 100%; height: 7px; border-radius: 6px; margin-top: 9px; background: linear-gradient(90deg, #cfe6f5, var(--water)); outline: none; }
.soil-range::-webkit-slider-thumb { -webkit-appearance: none; appearance: none; width: 22px; height: 22px; border-radius: 50%; background: #fff; border: 2px solid var(--water); box-shadow: 0 1px 4px rgba(0,0,0,.25); cursor: pointer; }
.soil-range::-moz-range-thumb { width: 20px; height: 20px; border-radius: 50%; background: #fff; border: 2px solid var(--water); box-shadow: 0 1px 4px rgba(0,0,0,.25); cursor: pointer; }
.m-name .hint { color: var(--muted); font-weight: 400; font-size: 11.5px; }
.metric-note { color: var(--muted); font-size: 12px; line-height: 1.35; padding: 2px 0 6px 30px; }
.measured-time { text-align: center; color: var(--muted); font-size: 12.5px; padding: 10px 0 4px; }
.m-val { text-align: right; }
.qual { display: block; font-size: 11px; font-weight: 700; margin-top: 1px; }
.q-ok { color: var(--ok); }
.q-warn { color: #c9810a; }
.q-bad { color: var(--bad); }

.advice li { margin: 9px 0; font-size: 15px; line-height: 1.4; }
.advice ul { margin: 8px 0; padding-left: 20px; }

/* Scan / diagnostic */
.viewfinder { margin: 8px 16px 0; height: 280px; border-radius: var(--radius);
  background: #1d2a22; display: grid; place-items: center; position: relative; overflow: hidden; }
.viewfinder .frame { width: 78%; height: 78%; border: 2px dashed rgba(255,255,255,.55); border-radius: 16px;
  display: grid; place-items: center; font-size: 70px; }
.viewfinder .hint { position: absolute; bottom: 12px; color: rgba(255,255,255,.8); font-size: 13px; }
.shutter { margin: 18px auto; width: 74px; height: 74px; border-radius: 50%; background: #fff;
  border: 5px solid var(--green); cursor: pointer; }
.result { margin: 4px 16px; }
.result .row { display: flex; justify-content: space-between; padding: 10px 0; border-bottom: 1px solid var(--line); font-size: 15px; }
.result .row.top { font-weight: 700; }
.pill { display:inline-block; background: var(--green-soft); color: var(--green); font-weight:700;
  padding: 3px 10px; border-radius: 20px; font-size: 13px; }

/* Vacances */
.chips { display: flex; gap: 8px; padding: 4px 16px; }
.chip { flex:1; text-align:center; padding: 12px; border-radius: 12px; background: var(--card);
  border: 1.5px solid var(--line); font-weight: 700; cursor: pointer; font-size: 14px; }
.chip.active { background: var(--green); color:#fff; border-color: var(--green); }
.range { text-align:center; color: var(--muted); font-size: 14px; padding: 6px 0 2px; }
.vac-plant { background: var(--card); border-radius: 14px; padding: 14px 16px; box-shadow: var(--shadow); }
.vac-plant .vh { display:flex; align-items:center; gap:9px; font-weight:700; }
.vac-plant .vd { color:#46524b; font-size: 14px; margin-top: 6px; line-height: 1.45; }

/* Config */
.opt { display:flex; gap: 12px; padding: 15px 16px; background: var(--card); cursor: pointer; align-items: flex-start; }
.opt + .opt { border-top: 1px solid var(--line); }
.radio { width: 22px; height: 22px; border-radius: 50%; border: 2px solid var(--grey); flex: none; margin-top: 2px; display:grid; place-items:center; }
.opt.sel .radio { border-color: var(--green); }
.opt.sel .radio::after { content:''; width:11px;height:11px;border-radius:50%;background:var(--green); }
.opt .ot { font-weight: 700; font-size: 15.5px; }
.opt .od { color: var(--muted); font-size: 13.5px; margin-top: 2px; }
.sensor-row { display:flex; align-items:center; gap:10px; padding: 13px 16px; border-bottom:1px solid var(--line); font-size: 14.5px; }
.sensor-row:last-child { border-bottom:none; }
.upsell { margin: 14px 16px; background: var(--green-soft); border-radius: 14px; padding: 14px 16px;
  font-size: 14px; color: #2c4a37; }
.kv { display:flex; justify-content:space-between; padding: 14px 16px; border-bottom:1px solid var(--line); font-size:15px; }

/* Stabilisation capteur */
.progress { height: 9px; border-radius: 6px; background:#edf1ee; overflow:hidden; margin-top:10px; }
.progress > span { display:block; height:100%; width:0; background: var(--green); transition: width .25s linear; }
.warn-box { margin: 4px 16px; background:#fff7e8; border:1px solid #f6e2b8; border-radius:14px; padding:14px 16px; font-size:14px; color:#7a5a12; }

/* Barre de navigation */
.tabbar {
  position: absolute; bottom: 0; left: 0; right: 0; height: 76px;
  background: rgba(255,255,255,0.94); backdrop-filter: blur(10px);
  border-top: 1px solid var(--line); display: flex; padding-bottom: env(safe-area-inset-bottom);
}
.tabbar button { flex:1; border:none; background:none; cursor:pointer; color: var(--muted);
  font-size: 11px; font-weight: 600; display:flex; flex-direction:column; align-items:center; gap:3px; padding-top: 12px; }
.tabbar button .ti { font-size: 22px; }
.tabbar button.active { color: var(--green); }
/* Gros bouton « appareil photo » flottant, centré, qui déborde du footer */
.fab-cam {
  position: absolute; left: 50%; bottom: 24px; transform: translateX(-50%);
  width: 66px; height: 66px; border-radius: 50%; z-index: 60;
  background: var(--green); color: #fff; border: 4px solid var(--bg);
  font-size: 30px; line-height: 1; cursor: pointer; padding: 0;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 8px 20px rgba(46, 125, 70, 0.45);
}
.fab-cam:active { filter: brightness(0.95); }

/* Sélecteur compact (association capteur ↔ plante) */
.mini-select {
  border: 1px solid var(--line); border-radius: 8px; padding: 5px 7px;
  font-size: 13px; background: var(--card); color: var(--text); max-width: 58%; font-family: inherit;
}

.spacer { height: 8px; }

/* Formulaires (ajout / édition) */
.field { margin: 14px 16px; }
.field label { display:block; font-size: 13px; font-weight: 700; color: var(--muted); margin: 0 2px 6px; }
.field input[type=text], .field input[type=number], .field select {
  width: 100%; border: 1.5px solid var(--line); border-radius: 12px; padding: 13px 14px;
  font-size: 16px; background: var(--card); color: var(--text); font-family: inherit;
}
.field input:focus, .field select:focus, .field textarea:focus { outline: none; border-color: var(--green); }
.field textarea {
  width: 100%; border: 1.5px solid var(--line); border-radius: 12px; padding: 13px 14px;
  font-size: 16px; background: var(--card); color: var(--text); font-family: inherit; resize: vertical;
}
.stars { display: flex; gap: 6px; font-size: 30px; line-height: 1; }
.stars .star { color: var(--line); cursor: pointer; transition: color .1s; }
.stars .star.on { color: #f5b301; }
/* Assistant de démarrage (onboarding) */
.onboard { min-height: 100vh; display: flex; flex-direction: column; padding: 22px 20px calc(env(safe-area-inset-bottom) + 24px); position: relative; }
.ob-progress { display: flex; gap: 8px; justify-content: center; padding: 6px 0 4px; }
.ob-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--line); transition: background .2s, width .2s; }
.ob-dot.done { background: var(--green); }
.ob-dot.on { width: 22px; border-radius: 5px; background: var(--green); }
.ob-skip { position: absolute; top: 16px; right: 16px; background: none; border: none; color: var(--muted); font-size: 14px; padding: 6px 8px; cursor: pointer; }
.ob-body { flex: 1; display: flex; flex-direction: column; justify-content: center; text-align: center; max-width: 440px; width: 100%; margin: 0 auto; }
.ob-hero { font-size: 64px; line-height: 1; margin-bottom: 14px; }
.ob-title { font-size: 28px; margin: 0 0 8px; }
.ob-sub { color: var(--muted); font-size: 15.5px; line-height: 1.5; margin: 0 0 22px; }
.ob-actions { display: flex; flex-direction: column; gap: 10px; margin-top: 18px; }
.ob-actions .btn { width: 100%; }
.catalog { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin: 0 16px; }
.cat-item { background: var(--card); border: 1.5px solid var(--line); border-radius: 14px;
  padding: 10px 4px; text-align: center; cursor: pointer; font-size: 12px; }
.cat-item .ce { font-size: 26px; display:block; }
.cat-item.sel { border-color: var(--green); background: var(--green-soft); }
.cap-btn { display:flex; align-items:center; justify-content:center; gap:8px;
  margin: 14px 16px; padding: 16px; border: 2px dashed var(--green-soft); border-radius: 14px;
  color: var(--green); font-weight: 700; cursor: pointer; background: var(--card); }
.photo-preview { margin: 8px 16px 0; height: 180px; border-radius: var(--radius); overflow: hidden;
  background: #eef1ef; flex-shrink: 0; }
.photo-preview img { width:100%; height:100%; object-fit: cover; display:block; }
.toggle-row { display:flex; align-items:center; justify-content:space-between; margin:14px 16px;
  background: var(--card); border:1px solid var(--line); border-radius:14px; padding:14px 16px; }
.switch { width:50px; height:30px; border-radius:30px; background:#d4dcd6; position:relative; cursor:pointer; transition: background .15s; flex:none; }
.switch.on { background: var(--green); }
.switch::after { content:''; position:absolute; top:3px; left:3px; width:24px; height:24px; border-radius:50%; background:#fff; transition: left .15s; }
.switch.on::after { left:23px; }
.danger { color: var(--bad); }
.btn.danger-btn { background:#fdecea; color: var(--bad); }
.empty { text-align:center; color: var(--muted); padding: 40px 24px; font-size: 15px; }
.note { margin: 10px 16px; font-size: 12.5px; color: var(--muted); font-style: italic; }
.badge { position:absolute; top:6px; right:6px; background: var(--bad); color:#fff;
  font-size:11px; font-weight:700; min-width:18px; height:18px; border-radius:10px; display:grid; place-items:center; padding:0 4px; }
.icon-btn { position: relative; }
.rem-item { background:var(--card); border-radius:14px; padding:14px 16px; box-shadow:var(--shadow); display:flex; align-items:center; gap:12px; }
.hero-photo img { width:100%; height:100%; object-fit:cover; border-radius: var(--radius); }
.plant-emoji img { width:100%; height:100%; object-fit:cover; border-radius:14px; display:block; }
