:root {
  --bg: #0e1116;
  --panel: #171c24;
  --panel2: #1f2630;
  --line: #2a313c;
  --txt: #e7ecf2;
  --dim: #93a0b0;
  --accent: #ffb01f;
  --accent2: #3aa0ff;
  --danger: #e2503a;
  --ok: #34c759;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; } /* prime sur les .btn / .topbar qui définissent display */
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--txt);
  font: 14px/1.45 -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  min-height: 100vh;
}

/* ---------- Top bar ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 20px;
  background: linear-gradient(#161b22, #11151b);
  border-bottom: 1px solid var(--line);
}
.brand { font-size: 18px; font-weight: 700; }
.brand span { color: var(--dim); font-weight: 500; }
.top-actions { display: flex; align-items: center; gap: 10px; }

.conn { display: inline-flex; align-items: center; gap: 7px; color: var(--dim); font-size: 13px; }
.conn i { width: 9px; height: 9px; border-radius: 50%; background: var(--danger); box-shadow: 0 0 8px var(--danger); }
.conn.on i { background: var(--ok); box-shadow: 0 0 8px var(--ok); }

/* ---------- Boutons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--panel2);
  color: var(--txt);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  transition: background 140ms, border-color 140ms, transform 60ms;
}
.btn:hover { background: #28313d; border-color: #3a4453; }
.btn:active { transform: translateY(1px); }
.btn.sm { padding: 5px 9px; font-size: 12px; }
.btn.ghost { background: transparent; }
.btn.danger { color: #ffd2c9; border-color: #5a2b22; background: #2a1713; }
.btn.danger:hover { background: #3a1d16; }
.btn.primary { background: var(--accent); color: #1a1305; border-color: #d8920f; }
.btn.primary:hover { background: #ffbf45; }
.btn[disabled] { opacity: 0.45; cursor: not-allowed; }

/* ---------- Grid ---------- */
.grid {
  display: grid;
  grid-template-columns: 340px 1fr;
  gap: 16px;
  padding: 16px 20px 60px;
  align-items: start;
}
.col { display: flex; flex-direction: column; gap: 16px; }

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px;
}
.panel-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.panel-head.sub { margin-top: 18px; border-top: 1px solid var(--line); padding-top: 14px; }
.panel-head h2 { font-size: 15px; margin: 0; }
.panel-head h3 { font-size: 14px; margin: 0; color: var(--dim); text-transform: uppercase; letter-spacing: 0.5px; }
.editor-head-actions { display: flex; gap: 8px; }

/* ---------- Liste des vues ---------- */
.views { display: flex; flex-direction: column; gap: 8px; }
.view-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--panel2);
  cursor: pointer;
}
.view-item.editing { border-color: var(--accent2); box-shadow: 0 0 0 1px var(--accent2) inset; }
.view-item .vname { flex: 1; font-weight: 600; }
.view-item .count { color: var(--dim); font-size: 12px; }
.view-item .live {
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.6px;
  color: #1a1305;
  background: var(--accent);
  border-radius: 5px;
  padding: 2px 6px;
  visibility: hidden;
}
.view-item.live .live { visibility: visible; }
.view-item .air {
  border: 1px solid var(--line);
  background: #11151b;
  color: var(--dim);
  border-radius: 6px;
  padding: 4px 8px;
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
}
.view-item.live .air { color: #1a1305; background: var(--accent); border-color: var(--accent); }

/* ---------- Propriétés de la vue ---------- */
.view-props { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.field { display: flex; flex-direction: column; gap: 5px; }
.field.full { grid-column: 1 / -1; }
.field label { font-size: 12px; color: var(--dim); font-weight: 600; }
.field input[type="text"],
.field select {
  background: var(--panel2);
  border: 1px solid var(--line);
  color: var(--txt);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 14px;
  width: 100%;
}
.field input[type="text"]:focus,
.field select:focus { outline: none; border-color: var(--accent2); }

.row-inline { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

/* Interrupteur */
.switch { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; user-select: none; font-size: 13px; }
.switch input { display: none; }
.switch .track { width: 40px; height: 22px; border-radius: 22px; background: #39424f; position: relative; transition: background 160ms; }
.switch .track::after { content: ""; position: absolute; top: 2px; left: 2px; width: 18px; height: 18px; border-radius: 50%; background: #fff; transition: left 160ms; }
.switch input:checked + .track { background: var(--ok); }
.switch input:checked + .track::after { left: 20px; }

/* Curseur niveau en cours */
.current-controls { display: flex; align-items: center; gap: 8px; }

/* Logo picker */
.logo-picker { display: flex; align-items: center; gap: 8px; }
.logo-picker img { width: 34px; height: 34px; object-fit: contain; background: #0c1f33; border: 1px solid var(--line); border-radius: 6px; padding: 3px; }
.logo-picker select { flex: 1; }

/* ---------- Éditeur de cases ---------- */
.boxes-editor { display: flex; flex-direction: column; gap: 8px; }
.box-row {
  display: grid;
  grid-template-columns: 20px 1fr auto auto auto auto auto auto auto;
  align-items: center;
  gap: 8px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--panel2);
}
.box-row.current { box-shadow: 0 0 0 2px var(--accent) inset; }
.box-row .drag { cursor: grab; color: var(--dim); text-align: center; user-select: none; }
.box-row.dragging { opacity: 0.4; }
.box-row .btext {
  background: #11151b;
  border: 1px solid var(--line);
  color: var(--txt);
  border-radius: 7px;
  padding: 7px 9px;
  font-size: 14px;
  font-weight: 700;
  width: 100%;
}
.box-row .btext:focus { outline: none; border-color: var(--accent2); }
.swatch { display: inline-flex; flex-direction: column; align-items: center; gap: 2px; }
.swatch small { font-size: 9px; color: var(--dim); }
.swatch input[type="color"] {
  width: 34px; height: 30px; border: 1px solid var(--line); border-radius: 6px; background: none; cursor: pointer; padding: 0;
}
.icon-btn {
  width: 32px; height: 32px; display: inline-flex; align-items: center; justify-content: center;
  border: 1px solid var(--line); border-radius: 7px; background: #11151b; color: var(--dim); cursor: pointer; font-size: 15px;
}
.icon-btn:hover { color: var(--txt); border-color: #3a4453; }
.icon-btn.on { color: var(--accent); border-color: var(--accent); }
.icon-btn.act-on { color: var(--ok); }
.icon-btn.danger:hover { color: #ff8b73; border-color: #5a2b22; }

.palette { display: flex; gap: 4px; }
.palette .chip { width: 18px; height: 18px; border-radius: 4px; border: 1px solid rgba(255,255,255,0.2); cursor: pointer; }

/* ---------- Caméra ---------- */
.camera { display: flex; flex-direction: column; gap: 10px; }
.cam-preview {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: repeating-conic-gradient(#1b212a 0 25%, #161b22 0 50%) 50% / 22px 22px;
  overflow: hidden;
}
.cam-preview .frame { position: absolute; inset: 0; background: linear-gradient(135deg, #2a3340, #1a2029); opacity: 0.65; }
.cam-preview .hole {
  position: absolute;
  background: #0b0e13;
  box-shadow: 0 0 0 2px var(--accent2);
  outline: 2px dashed rgba(58,160,255,0.6);
}
.cam-preview .hole span { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; color: var(--accent2); font-size: 11px; }
.slider-row { display: grid; grid-template-columns: 70px 1fr 44px; align-items: center; gap: 8px; font-size: 12px; }
.slider-row label { color: var(--dim); }
.slider-row input[type="range"] { width: 100%; }
.slider-row .val { text-align: right; color: var(--dim); font-variant-numeric: tabular-nums; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: #11151b; border: 1px solid var(--line); color: var(--txt);
  padding: 10px 16px; border-radius: 10px; opacity: 0; pointer-events: none;
  transition: opacity 180ms, transform 180ms; z-index: 50; font-size: 13px;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.err { border-color: var(--danger); }

.empty { color: var(--dim); font-size: 13px; padding: 8px 2px; }

/* ---------- Login ---------- */
.login {
  position: fixed; inset: 0; z-index: 100;
  display: flex; align-items: center; justify-content: center;
  background: radial-gradient(1200px 600px at 50% -10%, #1b2330, #0e1116);
}
.login[hidden] { display: none; }
.login-card {
  width: 320px; background: var(--panel); border: 1px solid var(--line);
  border-radius: 14px; padding: 26px; display: flex; flex-direction: column; gap: 12px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
}
.login-brand { font-size: 20px; font-weight: 800; text-align: center; }
.login-sub { margin: 0 0 6px; text-align: center; color: var(--dim); font-size: 13px; }
.login-card input {
  background: var(--panel2); border: 1px solid var(--line); color: var(--txt);
  border-radius: 9px; padding: 11px 12px; font-size: 15px;
}
.login-card input:focus { outline: none; border-color: var(--accent2); }
.btn.block { justify-content: center; width: 100%; padding: 11px; }
.login-err { color: #ff8b73; font-size: 13px; min-height: 16px; text-align: center; }

/* ---------- Topbar additions ---------- */
.editing-name { color: var(--accent); font-weight: 700; margin-left: 6px; }

/* ---------- Navigation principale ---------- */
.mainnav {
  display: flex;
  gap: 2px;
  padding: 0 20px;
  background: #11151b;
  border-bottom: 1px solid var(--line);
}
.mainnav[hidden] { display: none; }
.navtab {
  background: none;
  border: none;
  border-bottom: 3px solid transparent;
  color: var(--dim);
  padding: 10px 18px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: color 140ms, border-color 140ms;
}
.navtab:hover { color: var(--txt); }
.navtab.active { color: var(--txt); border-bottom-color: var(--accent); }

/* ---------- Dashboard ---------- */
.wrap { max-width: 1100px; margin: 0 auto; padding: 16px 20px 60px; display: flex; flex-direction: column; gap: 16px; }
.wrap[hidden], .grid[hidden] { display: none; }

.create-row { display: flex; align-items: flex-end; gap: 12px; flex-wrap: wrap; }
.create-row .field { min-width: 180px; }
.create-row .field.grow { flex: 1; }
.create-row select, .create-row input {
  background: var(--panel2); border: 1px solid var(--line); color: var(--txt);
  border-radius: 8px; padding: 8px 10px; font-size: 14px; width: 100%;
}
.tpl-desc { color: var(--dim); font-size: 13px; margin: 10px 2px 0; }

.overlay-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 14px; }
.ov-card {
  border: 1px solid var(--line); border-radius: 12px; background: var(--panel2); padding: 14px;
  display: flex; flex-direction: column; gap: 10px;
}
.ov-card h3 { margin: 0; font-size: 16px; display: flex; align-items: center; gap: 8px; }
.ov-badge { font-size: 10px; font-weight: 800; letter-spacing: 0.5px; color: #0c1320; background: var(--accent2); border-radius: 5px; padding: 2px 6px; }
.ov-url {
  display: flex; gap: 6px; align-items: center; background: #11151b; border: 1px solid var(--line);
  border-radius: 8px; padding: 6px 8px; font-size: 12px; color: var(--dim);
}
.ov-url code { color: var(--txt); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
.ov-meta { color: var(--dim); font-size: 12px; }
.ov-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 2px; }
.ov-dup { display: flex; align-items: center; gap: 4px; }
.ov-dup input { width: 46px; background: #11151b; border: 1px solid var(--line); color: var(--txt); border-radius: 6px; padding: 5px 6px; font-size: 13px; }

/* ---------- Zone échelle / Endpoint panels ---------- */
.ladder-panel { display: flex; flex-direction: column; gap: 8px; }
.endpoint { display: flex; flex-direction: column; gap: 10px; font-size: 13px; }
.endpoint .kv { display: flex; flex-direction: column; gap: 4px; }
.endpoint .kv label { color: var(--dim); font-size: 12px; }
.endpoint code {
  display: block; background: #11151b; border: 1px solid var(--line); border-radius: 7px;
  padding: 7px 9px; font-size: 12px; color: var(--txt); overflow-x: auto; white-space: nowrap;
}
.endpoint .copyable { cursor: pointer; }
.endpoint .copyable:hover { border-color: var(--accent2); }
.endpoint .hint { color: var(--dim); font-size: 12px; }

/* ---------- Bibliothèque de sons ---------- */
.hint-inline { color: var(--dim); font-size: 11px; }
.sound-panel { display: flex; flex-direction: column; gap: 10px; }
.sound-panel-full { display: grid; grid-template-columns: 320px 1fr; gap: 20px; align-items: start; }
.sound-panel-full .sound-list { max-height: 500px; }

.upload-drop {
  display: flex; align-items: center; justify-content: center;
  border: 2px dashed var(--line); border-radius: 9px; padding: 14px 10px;
  cursor: pointer; font-size: 13px; color: var(--dim); transition: border-color 140ms;
  text-align: center;
}
.upload-drop:hover { border-color: var(--accent2); color: var(--txt); }

.progress-wrap { display: flex; align-items: center; gap: 8px; }
.progress-track {
  flex: 1; height: 8px; background: var(--panel2); border: 1px solid var(--line);
  border-radius: 99px; overflow: hidden;
}
.progress-fill { height: 100%; width: 0%; background: var(--accent2); border-radius: 99px; transition: width 80ms linear; }
.progress-label { font-size: 12px; color: var(--dim); min-width: 34px; text-align: right; }

.sound-list { display: flex; flex-direction: column; gap: 5px; max-height: 240px; overflow-y: auto; }
.sound-item {
  display: flex; align-items: center; gap: 6px;
  background: var(--panel2); border: 1px solid var(--line); border-radius: 7px; padding: 5px 8px;
}
.sound-name { flex: 1; font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--txt); }

/* ---------- Sons par case ---------- */
.box-wrap { display: flex; flex-direction: column; }
.box-sounds {
  background: #0d1117; border: 1px solid var(--line); border-top: none;
  border-radius: 0 0 9px 9px; padding: 8px 10px; display: flex; flex-direction: column; gap: 6px;
}
.bsound-row { display: flex; align-items: center; gap: 8px; }
.bsound-label { font-size: 11px; color: var(--dim); min-width: 80px; }
.bsound-row select {
  flex: 1; background: var(--panel2); border: 1px solid var(--line); color: var(--txt);
  border-radius: 6px; padding: 4px 6px; font-size: 12px;
}
.bsound-row select:focus { outline: none; border-color: var(--accent2); }
/* Arrondi du bas de la box-row quand sounds ouverts */
.box-wrap .box-sounds:not([hidden]) ~ * { display: none; }
.box-wrap:has(.box-sounds:not([hidden])) .box-row { border-radius: 9px 9px 0 0; }

@media (max-width: 860px) {
  .grid { grid-template-columns: 1fr; }
}
