:root {
  --bg: #0f1420;
  --panel: #161c2b;
  --card: #1d2536;
  --card2: #232c40;
  --line: #2c374f;
  --text: #e6ebf5;
  --muted: #93a0bd;
  --accent: #4c8dff;
  --accent2: #2f6fe0;
  --danger: #e5484d;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
}

#app {
  display: flex;
  height: 100vh;
  height: 100dvh;
  width: 100vw;
}

/* ---------- Panel ---------- */
#panel {
  width: 340px;
  min-width: 340px;
  height: 100%;
  overflow-y: auto;
  background: var(--panel);
  border-right: 1px solid var(--line);
  padding: 14px;
}

.panel-head h1 {
  font-size: 18px;
  margin: 0 0 2px;
}
.panel-head .sub {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 12px;
}

/* ---------- Branding ---------- */
.brand {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 6px;
}
.brand-ia {
  font-size: 21px;
  font-weight: 800;
  letter-spacing: .5px;
  background: linear-gradient(90deg, #4c8dff, #9a6cff);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.brand-by { font-size: 11px; color: var(--muted); }
.brand-by a { color: var(--accent); text-decoration: none; }
.brand-by a:hover { text-decoration: underline; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px;
  margin-bottom: 12px;
}
.card h2 {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: .5px;
  color: var(--muted);
  margin: 0 0 10px;
}

label {
  display: flex;
  flex-direction: column;
  font-size: 12px;
  color: var(--muted);
  gap: 4px;
}
label.full { margin-bottom: 8px; }
label.check {
  flex-direction: row;
  align-items: center;
  gap: 6px;
  color: var(--text);
  margin-bottom: 8px;
}
label.check input { width: auto; }

.grid3 {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px;
  margin-bottom: 8px;
}

input, select {
  background: var(--card2);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 7px;
  padding: 7px 8px;
  font-size: 13px;
  width: 100%;
}
input[type="color"] {
  padding: 2px;
  height: 34px;
  cursor: pointer;
}
input:focus, select:focus {
  outline: none;
  border-color: var(--accent);
}

button {
  background: var(--card2);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 7px;
  padding: 8px 10px;
  font-size: 13px;
  cursor: pointer;
  transition: background .15s, border-color .15s;
}
button:hover { border-color: var(--accent); }
button:disabled { opacity: .4; cursor: default; }
button:disabled:hover { border-color: var(--line); }
button.primary { background: var(--accent2); border-color: var(--accent); width: 100%; }
button.primary:hover { background: var(--accent); }
button.danger { border-color: #5a2a2f; color: #ff9ea1; }
button.danger:hover { border-color: var(--danger); background: #331a1c; }
button.subtle { width: 100%; color: var(--muted); font-size: 12px; }

.client-add {
  display: grid;
  grid-template-columns: 1fr 44px 36px;
  gap: 6px;
  margin-bottom: 10px;
}
.client-list { list-style: none; margin: 0; padding: 0; }
.client-list li {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px;
  border-radius: 7px;
  background: var(--card2);
  margin-bottom: 6px;
}
.client-list .swatch {
  width: 16px; height: 16px; border-radius: 4px; flex: none;
  border: 1px solid rgba(255,255,255,.2);
}
.client-list .cname { flex: 1; font-size: 12.5px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.client-list .ccount { color: var(--muted); font-size: 11px; white-space: nowrap; }
.client-list button {
  padding: 2px 6px; font-size: 12px; line-height: 1;
}
.client-list .ord { color: var(--muted); font-size: 11px; width: 14px; text-align: center; }

.hint, .stats .warn {
  font-size: 11px;
  color: var(--muted);
  margin: 6px 0 0;
}

.radio-row, .toggle-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 10px;
}
.radio-row label, .toggle-row label {
  flex-direction: row;
  align-items: center;
  gap: 5px;
  color: var(--text);
  font-size: 12px;
}
.radio-row input, .toggle-row input { width: auto; }

.views, .actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.actions { margin-bottom: 6px; }
.views button { flex: 1; min-width: 56px; }
.actions button { flex: 1; }

.stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  font-size: 13px;
}
.stats .stat {
  background: var(--card2);
  border-radius: 7px;
  padding: 8px;
}
.stats .stat b { display: block; font-size: 15px; }
.stats .stat span { color: var(--muted); font-size: 10.5px; }
.stats .warn {
  grid-column: 1 / -1;
  color: #ffb454;
}

/* ---------- CTA ---------- */
.cta-card {
  border-color: var(--accent2);
  background: linear-gradient(180deg, #1c2742, #1d2536);
}
.cta-card p { font-size: 12px; color: var(--muted); margin: 0 0 10px; line-height: 1.5; }
.btn-cta {
  display: block;
  text-align: center;
  background: var(--accent2);
  color: #fff;
  text-decoration: none;
  border-radius: 7px;
  padding: 9px 10px;
  font-size: 13px;
  transition: background .15s;
}
.btn-cta:hover { background: var(--accent); }

.panel-foot {
  font-size: 11px;
  color: var(--muted);
  padding: 4px 2px 10px;
  line-height: 1.5;
}

/* ---------- Viewport ---------- */
#viewport {
  position: relative;
  flex: 1;
  height: 100%;
  min-width: 0;
}
#scene { display: block; width: 100%; height: 100%; touch-action: none; }

.legend {
  position: absolute;
  top: 12px;
  left: 12px;
  background: rgba(15,20,32,.82);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 12px;
  max-width: 240px;
  backdrop-filter: blur(4px);
}
.legend h3 { margin: 0 0 8px; font-size: 12px; color: var(--muted); text-transform: uppercase; }
.legend .row { display: flex; align-items: center; gap: 8px; margin-bottom: 5px; }
.legend .sw { width: 14px; height: 14px; border-radius: 3px; border: 1px solid rgba(255,255,255,.2); flex: none; }
.legend .sw.round { border-radius: 50%; }

.demo-badge {
  position: absolute;
  top: 12px;
  right: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(15,20,32,.82);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 6px 10px;
  font-size: 12px;
  backdrop-filter: blur(4px);
}
.demo-badge a { color: var(--text); text-decoration: none; }
.demo-badge a:hover { color: var(--accent); }
.demo-badge b { color: var(--accent); }
.demo-badge button { padding: 1px 8px; font-size: 12px; border-radius: 50%; }

.sel-info {
  position: absolute;
  bottom: 12px;
  left: 12px;
  background: rgba(15,20,32,.9);
  border: 1px solid var(--accent);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 12px;
  max-width: 260px;
}
.sel-info b { color: var(--accent); }
.hidden { display: none; }

/* ---------- Indicateur de chargement ---------- */
.loading {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-size: 13px;
  z-index: 5;
}
.spin {
  width: 34px;
  height: 34px;
  border: 3px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Ecran d'accueil ---------- */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(8,11,18,.72);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 16px;
  backdrop-filter: blur(3px);
}
.overlay.hidden { display: none; }
.modal {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  max-width: 470px;
  max-height: 90dvh;
  overflow-y: auto;
  padding: 22px 24px;
  box-shadow: 0 18px 60px rgba(0,0,0,.5);
}
.modal h2 { font-size: 17px; margin: 4px 0 10px; }
.modal p { font-size: 13px; line-height: 1.55; margin: 0 0 8px; }
.modal p.small { font-size: 11.5px; color: var(--muted); }
.modal ul {
  font-size: 12.5px;
  color: var(--muted);
  padding-left: 18px;
  line-height: 1.7;
  margin: 8px 0 10px;
}
.modal-actions { display: flex; gap: 8px; margin-top: 14px; }
.modal-actions .primary { flex: 1.2; }
.modal-actions .btn-cta { flex: 1; display: flex; align-items: center; justify-content: center; }

/* ---------- Mobile ---------- */
@media (max-width: 860px) {
  #app { flex-direction: column-reverse; }
  #viewport { flex: none; height: 46dvh; }
  #panel {
    width: 100%;
    min-width: 0;
    flex: 1;
    height: auto;
    border-right: none;
    border-top: 1px solid var(--line);
  }
  .legend { max-width: 170px; font-size: 11px; padding: 8px 10px; }
  .demo-badge { font-size: 11px; padding: 5px 8px; }
  .sel-info { max-width: 200px; font-size: 11px; }
}
