/* Plan lumière — pensé d'abord pour le téléphone, sur un set */
:root {
  --bg: #f4f3ef;
  --card: #ffffff;
  --ink: #17181b;
  --mute: #6f7279;
  --line: #dedcd6;
  --soft: #ebe9e3;
  --accent: #17181b;
  --on-accent: #ffffff;
  --flash: #2b76dd;
  --cont: #dd4545;
  --grid: #e3e1db;
  --wall: #2a2b2f;
  --plan: #fbfaf8;
  --danger: #c0392b;
  --r: 14px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15171b;
    --card: #1f2227;
    --ink: #f1f1ee;
    --mute: #9a9da5;
    --line: #33363d;
    --soft: #2a2d33;
    --accent: #f1f1ee;
    --on-accent: #15171b;
    --flash: #5a9cf0;
    --cont: #f06a6a;
    --grid: #2b2e34;
    --wall: #e6e6e2;
    --plan: #1a1c20;
    --danger: #f08070;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
h1, h2, h3, p { margin: 0; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--flash); outline-offset: 2px; }

#app { height: 100dvh; display: flex; flex-direction: column; max-width: 760px; margin: 0 auto; }

/* ---------- Pages (sets, studios, favoris, matrice) ---------- */
.page { flex: 1; overflow-y: auto; padding: 18px 16px 24px; -webkit-overflow-scrolling: touch; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin: 6px 0 16px; }
.page-head h1 { font-size: 28px; letter-spacing: -0.02em; line-height: 1.1; }
.page-head p { color: var(--mute); font-size: 14px; margin-top: 4px; }
.empty { color: var(--mute); padding: 28px 8px; text-align: center; }
.foot { color: var(--mute); font-size: 12.5px; text-align: center; margin-top: 22px; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--r);
  padding: 14px;
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 12px;
}
.card-main { flex: 1; min-width: 0; text-align: left; background: none; border: 0; padding: 0; }
.card-main b { display: block; font-size: 17px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card-main span { display: block; color: var(--mute); font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card-main span + span { margin-top: 1px; }

.btn {
  min-height: 46px;
  padding: 0 18px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--card);
  font-weight: 600;
  white-space: nowrap;
}
.btn.primary { background: var(--accent); color: var(--on-accent); border-color: var(--accent); }
.btn.ghost { background: none; }
.btn.danger { color: var(--danger); }
.btn.small { min-height: 38px; padding: 0 12px; font-size: 14px; border-radius: 10px; }
.btn.wide { width: 100%; }
.icon-btn {
  width: 42px; height: 42px; flex: none;
  border-radius: 12px; border: 1px solid var(--line); background: var(--card);
  display: grid; place-items: center; font-size: 20px; line-height: 1;
}
.icon-btn.plain { border-color: transparent; background: none; }

.dot { width: 12px; height: 12px; border-radius: 50%; flex: none; background: var(--mute); }
.dot.flash { background: var(--flash); }
.dot.continu { background: var(--cont); }
.dot.poly { border-radius: 2px; height: 5px; width: 16px; background: var(--wall); }
.dot.frame { border-radius: 2px; height: 5px; width: 16px; background: var(--mute); opacity: 0.6; }
.dot.floor { border-radius: 3px; background: none; border: 1.5px dashed var(--mute); }
.dot.subject { background: none; border: 2px solid var(--mute); }
.dot.camera { border-radius: 3px; }
.badge {
  width: 30px; height: 30px; flex: none; border-radius: 50%;
  display: grid; place-items: center; font-weight: 700; font-size: 15px;
  border: 1.5px solid var(--flash); color: var(--flash);
  background: color-mix(in srgb, var(--flash) 12%, var(--card));
}
.badge.continu { border-color: var(--cont); color: var(--cont); background: color-mix(in srgb, var(--cont) 12%, var(--card)); }

/* ---------- Barre du bas ---------- */
.tabs {
  display: flex;
  border-top: 1px solid var(--line);
  background: var(--card);
  padding-bottom: var(--safe-b);
}
.tabs button {
  flex: 1; min-height: 56px; border: 0; background: none;
  color: var(--mute); font-size: 13.5px; font-weight: 600;
}
.tabs button.on { color: var(--ink); box-shadow: inset 0 2px 0 var(--ink); }

/* ---------- Éditeur d'un set ---------- */
.ed { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.ed-head { display: flex; align-items: center; gap: 8px; padding: 10px 12px 8px; }
.ed-title { flex: 1; min-width: 0; background: none; border: 0; text-align: left; padding: 4px 0; }
.ed-title b { display: block; font-size: 17px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ed-title span { display: block; font-size: 12.5px; color: var(--mute); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ed-main { flex: 1; min-height: 0; position: relative; margin: 0 12px; }
.plan-wrap {
  position: absolute; inset: 0;
  background: var(--plan);
  border: 1px solid var(--line);
  border-radius: var(--r);
  overflow: hidden;
}
#plan { width: 100%; height: 100%; display: block; touch-action: none; -webkit-user-select: none; user-select: none; }
.fiche { position: absolute; inset: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.fiche .card { align-items: flex-start; }
.fiche .card-main span { white-space: normal; }
.placing-tip {
  position: absolute; left: 12px; right: 12px; top: 12px;
  background: var(--accent); color: var(--on-accent);
  border-radius: 12px; padding: 10px 14px; font-weight: 600; font-size: 15px;
  text-align: center; pointer-events: none;
}

/* hauteur fixe : le plan ne bouge pas quand on sélectionne un élément */
.panel { padding: 10px 12px calc(12px + var(--safe-b)); height: calc(262px + var(--safe-b)); display: flex; flex-direction: column; justify-content: flex-end; }
.panel.auto { height: auto; }
.chips { flex: 1; min-height: 0; display: flex; flex-wrap: wrap; align-content: flex-start; gap: 8px; overflow-y: auto; margin-bottom: 10px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; display: flex; align-items: center; gap: 8px;
  min-height: 38px; padding: 0 12px; border-radius: 20px;
  border: 1px solid var(--line); background: var(--card); font-size: 14.5px; font-weight: 600;
  max-width: 220px;
}
.chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip i { font-style: normal; color: var(--flash); font-weight: 700; }
.chip i.continu { color: var(--cont); }

.sel { background: var(--card); border: 1px solid var(--line); border-radius: var(--r); padding: 12px; }
.sel-head { display: flex; align-items: center; gap: 10px; }
.sel-head div { flex: 1; min-width: 0; }
.sel-head b { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sel-head span { display: block; color: var(--mute); font-size: 13.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sel-row { display: flex; align-items: center; gap: 8px; margin-top: 10px; }
.sel-row > label { color: var(--mute); font-size: 13.5px; width: 76px; flex: none; }
.sel-row select { flex: 1; min-width: 0; }
.stepper { display: flex; align-items: center; gap: 6px; flex: 1; }
.stepper button { width: 46px; height: 42px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); font-size: 22px; line-height: 1; }
.stepper output { flex: 1; text-align: center; font-weight: 700; font-size: 18px; font-variant-numeric: tabular-nums; }
.sel-actions { display: flex; gap: 8px; margin-top: 12px; }
.sel-actions .btn { flex: 1; padding: 0 8px; }
.sel-actions .btn.narrow { flex: none; width: 46px; padding: 0; }

.seg { display: flex; background: var(--soft); border-radius: 11px; padding: 3px; gap: 3px; }
.seg label { flex: 1; position: relative; }
.seg input { position: absolute; opacity: 0; inset: 0; }
.seg span {
  display: grid; place-items: center; min-height: 38px; padding: 0 10px;
  border-radius: 9px; font-size: 14.5px; font-weight: 600; color: var(--mute); text-align: center;
}
.seg input:checked + span { background: var(--card); color: var(--ink); box-shadow: 0 1px 2px rgba(0, 0, 0, 0.12); }
.seg input:focus-visible + span { outline: 2px solid var(--flash); }
.seg.head { width: 132px; flex: none; }
.seg.head span { min-height: 34px; font-size: 13.5px; }

/* ---------- Feuilles (formulaires) ---------- */
.sheet-back {
  position: fixed; inset: 0; z-index: 20;
  background: rgba(0, 0, 0, 0.42);
  display: flex; align-items: flex-end; justify-content: center;
  animation: fade 0.18s ease;
}
.sheet {
  width: 100%; max-width: 760px; max-height: 92dvh;
  background: var(--bg);
  border-radius: 20px 20px 0 0;
  display: flex; flex-direction: column;
  animation: up 0.24s cubic-bezier(0.2, 0.8, 0.2, 1);
}
@keyframes fade { from { opacity: 0; } }
@keyframes up { from { transform: translateY(40px); opacity: 0; } }
.sheet-head { display: flex; align-items: center; gap: 10px; padding: 14px 14px 8px 18px; }
.sheet-head h2 { flex: 1; font-size: 19px; letter-spacing: -0.01em; }
.sheet-body { overflow-y: auto; padding: 4px 16px 16px; -webkit-overflow-scrolling: touch; }
.sheet-foot { display: flex; gap: 8px; padding: 10px 16px calc(14px + var(--safe-b)); border-top: 1px solid var(--line); }
.sheet-foot .btn { flex: 1; }

.blk { background: var(--card); border: 1px solid var(--line); border-radius: var(--r); padding: 12px 14px 14px; margin-bottom: 10px; }
.blk > h3 { font-size: 12.5px; text-transform: uppercase; letter-spacing: 0.07em; color: var(--mute); margin-bottom: 10px; }
.f { display: block; margin-bottom: 10px; }
.f:last-child { margin-bottom: 0; }
.f > span { display: block; font-size: 13.5px; color: var(--mute); margin-bottom: 5px; }
input[type="text"], input:not([type]), select, textarea {
  width: 100%; min-height: 46px; padding: 10px 12px;
  border: 1px solid var(--line); border-radius: 11px; background: var(--bg);
  font-size: 16px; -webkit-appearance: none; appearance: none;
}
select {
  padding-right: 34px;
  background-image: linear-gradient(45deg, transparent 50%, var(--mute) 50%), linear-gradient(135deg, var(--mute) 50%, transparent 50%);
  background-position: calc(100% - 18px) 50%, calc(100% - 13px) 50%;
  background-size: 5px 5px; background-repeat: no-repeat;
}
textarea { min-height: 76px; resize: vertical; }
.unit { position: relative; }
.unit input { padding-right: 40px; font-variant-numeric: tabular-nums; }
.unit i { position: absolute; right: 13px; top: 50%; transform: translateY(-50%); font-style: normal; color: var(--mute); }
.row { display: flex; gap: 10px; align-items: flex-end; }
.row > * { flex: 1; min-width: 0; margin-bottom: 10px; }
.hint { color: var(--mute); font-size: 13px; margin-top: 6px; }
.check { display: flex; align-items: center; gap: 10px; min-height: 44px; }
.check input { width: 22px; height: 22px; accent-color: var(--ink); }

.pick { display: flex; align-items: center; gap: 12px; background: var(--card); border: 1px solid var(--line); border-radius: var(--r); padding: 10px 10px 10px 14px; margin-bottom: 8px; }
.pick-main { flex: 1; min-width: 0; }
.pick-main b { display: block; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pick-main span { display: block; color: var(--mute); font-size: 13.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sub-h { font-size: 12.5px; text-transform: uppercase; letter-spacing: 0.07em; color: var(--mute); margin: 14px 2px 8px; }
.radio-card { display: flex; align-items: center; gap: 12px; background: var(--card); border: 1px solid var(--line); border-radius: var(--r); padding: 12px 14px; margin-bottom: 8px; }
.radio-card input { width: 20px; height: 20px; accent-color: var(--ink); flex: none; }

/* ---------- Matrice ---------- */
.mx { width: 100%; border-collapse: collapse; font-size: 14.5px; }
.mx th, .mx td { text-align: left; vertical-align: top; padding: 8px 0; border-top: 1px solid var(--line); }
.mx tr:first-child th, .mx tr:first-child td { border-top: 0; }
.mx th { width: 96px; font-weight: 600; padding-right: 10px; }
.mx td { color: var(--mute); }
.blk.txt p { margin-bottom: 8px; }
.blk.txt p:last-child { margin-bottom: 0; }
.blk.txt ol { margin: 0; padding-left: 20px; }
.blk.txt li { margin-bottom: 6px; }
.mx-title { display: flex; align-items: center; gap: 10px; font-size: 16px; font-weight: 600; margin-bottom: 6px; }

/* ---------- Le plan (SVG) ---------- */
.pg { stroke: var(--grid); stroke-width: 1.5; }
.pt { fill: var(--mute); font-family: inherit; }
.pt.strong { fill: var(--ink); font-weight: 600; }
.pw { stroke: var(--wall); fill: none; stroke-linecap: round; }
.pw.thin { opacity: 0.28; }
.beam.flash { fill: var(--flash); opacity: 0.13; }
.beam.continu { fill: var(--cont); opacity: 0.13; }
.ray { fill: none; stroke-linecap: round; }
.ray.flash { stroke: var(--flash); }
.ray.continu { stroke: var(--cont); }
.ray.bounce { stroke: var(--mute); stroke-dasharray: 9 9; }
.lbody { fill: var(--plan); }
.lbody.flash { stroke: var(--flash); }
.lbody.continu { stroke: var(--cont); }
.lfront.flash { stroke: var(--flash); }
.lfront.continu { stroke: var(--cont); }
.lbadge.flash { fill: color-mix(in srgb, var(--flash) 14%, var(--plan)); stroke: var(--flash); }
.lbadge.continu { fill: color-mix(in srgb, var(--cont) 14%, var(--plan)); stroke: var(--cont); }
.lletter { font-family: inherit; font-weight: 700; }
.lletter.flash { fill: var(--flash); }
.lletter.continu { fill: var(--cont); }
.poly { stroke: var(--wall); stroke-linecap: round; }
.poly-face { stroke: var(--plan); stroke-linecap: round; }
.frame { stroke: var(--mute); opacity: 0.55; stroke-linecap: round; }
.floor { fill: color-mix(in srgb, var(--mute) 10%, transparent); stroke: var(--mute); stroke-dasharray: 8 7; }
.subj { fill: var(--plan); stroke: var(--mute); }
.cam { fill: var(--plan); stroke: var(--mute); }
.hit { fill: transparent; cursor: grab; }
.selring { fill: none; stroke: var(--ink); stroke-dasharray: 7 6; }
.handle { fill: var(--ink); stroke: var(--plan); cursor: grab; }
.handle-line { stroke: var(--ink); stroke-dasharray: 4 6; }
.snap { fill: none; stroke: var(--ink); }

@media (min-width: 761px) {
  #app { border-left: 1px solid var(--line); border-right: 1px solid var(--line); }
  .sheet { border-radius: 20px; margin-bottom: 4vh; }
  .sheet-back { align-items: center; }
}
@media (prefers-reduced-motion: reduce) {
  .sheet, .sheet-back { animation: none; }
}
