/* ============================================================
   creazalainLASER — Thème sombre moderne
   ============================================================ */

:root {
  --bg: #0e1116;
  --bg2: #151a22;
  --bg3: #1c232e;
  --line: #2a3342;
  --txt: #e8edf4;
  --txt2: #97a3b4;
  --accent: #ff6b35;
  --accent2: #ffa24f;
  --ok: #41d99d;
  --warn: #ffcf5c;
  --danger: #ff5c6c;
  --radius: 10px;
  font-size: 15px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }

body {
  background: var(--bg);
  color: var(--txt);
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

/* ---------- En-tête ---------- */
header {
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 10px 18px;
  background: var(--bg2);
  border-bottom: 1px solid var(--line);
  flex: 0 0 auto;
}
.logo { font-size: 1.35rem; font-weight: 700; letter-spacing: .5px; white-space: nowrap; }
.logo .accent { color: var(--accent); }
.logo-mark { filter: drop-shadow(0 0 6px var(--accent)); }
.logo-img { height: 32px; vertical-align: -8px; margin-right: 4px; }
.tag {
  font-size: .65rem; vertical-align: super; color: var(--accent2);
  border: 1px solid var(--accent2); border-radius: 6px; padding: 1px 5px; margin-left: 4px;
}
.tagline { color: var(--txt2); font-size: .85rem; flex: 1 1 auto; min-width: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lang-switch { display: flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.lang-switch button {
  background: transparent; color: var(--txt2); border: none; padding: 5px 12px;
  cursor: pointer; font-weight: 600;
}
.lang-switch button.active { background: var(--accent); color: #fff; }

/* ---------- Mise en page ---------- */
main { display: flex; flex: 1 1 auto; min-height: 0; }

#sidebar {
  width: 340px; flex: 0 0 auto; overflow-y: auto;
  background: var(--bg2); border-right: 1px solid var(--line);
  padding: 10px; scrollbar-width: thin;
}
#sidebar::-webkit-scrollbar { width: 8px; }
#sidebar::-webkit-scrollbar-thumb { background: var(--line); border-radius: 4px; }

details {
  background: var(--bg3); border: 1px solid var(--line);
  border-radius: var(--radius); margin-bottom: 10px; overflow: hidden;
}
summary {
  cursor: pointer; padding: 10px 14px; font-weight: 600; user-select: none;
  list-style: none; position: relative; color: var(--accent2);
}
summary::after { content: "▾"; position: absolute; right: 14px; transition: transform .2s; color: var(--txt2); }
details:not([open]) summary::after { transform: rotate(-90deg); }
summary::-webkit-details-marker { display: none; }
.sec-body { padding: 4px 14px 14px; }

/* ---------- Contrôles ---------- */
.lbl {
  display: flex; justify-content: space-between; align-items: baseline;
  font-size: .8rem; color: var(--txt2); margin: 10px 0 4px; font-weight: 600;
}
.lbl output { color: var(--accent2); font-variant-numeric: tabular-nums; }

input[type="number"], input[type="text"], select {
  width: 100%; background: var(--bg); color: var(--txt);
  border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px;
  font-size: .9rem; outline: none;
}
input:focus, select:focus { border-color: var(--accent); }

input[type="range"] { width: 100%; accent-color: var(--accent); height: 22px; }

.check { display: flex; align-items: center; gap: 8px; margin-top: 12px; cursor: pointer; font-size: .9rem; }
.check input { accent-color: var(--accent); width: 16px; height: 16px; }

.row { display: flex; gap: 8px; margin-top: 8px; align-items: flex-end; }
.grow { flex: 1 1 0; min-width: 0; }

.kv {
  display: flex; justify-content: space-between; font-size: .85rem;
  color: var(--txt2); margin-top: 10px;
}
.kv b { color: var(--txt); font-variant-numeric: tabular-nums; }

.hint { font-size: .75rem; color: var(--txt2); margin-top: 8px; line-height: 1.45; }
.hint.warn { color: var(--warn); }

hr { border: none; border-top: 1px solid var(--line); margin: 14px 0 6px; }

/* ---------- Boutons ---------- */
.btn {
  background: var(--bg); color: var(--txt); border: 1px solid var(--line);
  border-radius: 8px; padding: 8px 12px; cursor: pointer; font-size: .85rem;
  font-weight: 600; transition: all .15s; width: 100%; margin-top: 8px;
}
.btn:hover:not(:disabled) { border-color: var(--accent); color: var(--accent2); }
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover:not(:disabled) { background: var(--accent2); color: #1a1a1a; }
.btn.small { padding: 6px 10px; font-size: .78rem; width: auto; }
.btn.toggle.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.row .btn { width: auto; flex: 1 1 0; margin-top: 0; }

/* ---------- Grille matériaux ---------- */
.mat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 8px; }
.mat-btn {
  background: var(--bg); border: 1px solid var(--line); border-radius: 8px;
  padding: 9px 8px; cursor: pointer; color: var(--txt); font-size: .78rem;
  display: flex; align-items: center; gap: 7px; transition: all .15s; text-align: left;
}
.mat-btn:hover { border-color: var(--accent); }
.mat-btn.active { border-color: var(--accent); background: rgba(255, 107, 53, .12); }
.mat-btn .ic { font-size: 1.1rem; }

/* ---------- Tableau de référence ---------- */
table.ref { width: 100%; border-collapse: collapse; font-size: .72rem; margin-top: 8px; }
table.ref th, table.ref td { border: 1px solid var(--line); padding: 5px 6px; text-align: left; }
table.ref th { color: var(--accent2); background: var(--bg); }
table.ref td { color: var(--txt2); }
table.ref td:first-child { color: var(--txt); }

/* ---------- Zone d'aperçu ---------- */
#stage {
  flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; padding: 18px; position: relative;
  background:
    radial-gradient(ellipse at 30% 20%, rgba(255, 107, 53, .05), transparent 60%),
    var(--bg);
}

#dropzone {
  width: 100%; height: 100%; display: flex; align-items: center; justify-content: center;
  border: 2px dashed var(--line); border-radius: 16px; transition: all .2s; cursor: pointer;
}
#dropzone.over { border-color: var(--accent); background: rgba(255, 107, 53, .06); }
.drop-inner { text-align: center; max-width: 420px; padding: 30px; }
.drop-icon { font-size: 3.4rem; margin-bottom: 12px; }
.drop-inner h2 { margin-bottom: 8px; font-size: 1.25rem; }
.drop-inner p { color: var(--txt2); margin-bottom: 18px; font-size: .9rem; }
.drop-inner .btn { width: auto; }

#previewWrap { width: 100%; height: 100%; display: flex; flex-direction: column; gap: 10px; min-height: 0; }

#warnBanner {
  background: rgba(255, 92, 108, .15); border: 1px solid var(--danger);
  color: var(--danger); border-radius: 8px; padding: 8px 12px; font-size: .85rem; font-weight: 600;
}

#compare {
  position: relative; flex: 1 1 auto; min-height: 0;
  display: flex; align-items: center; justify-content: center;
  border-radius: 12px; overflow: hidden; user-select: none; touch-action: none;
  background:
    repeating-conic-gradient(#181d26 0% 25%, #11151c 0% 50%) 0 0 / 22px 22px;
  border: 1px solid var(--line);
}
#compare canvas {
  max-width: 100%; max-height: 100%; display: block;
  image-rendering: pixelated;
}
#cvAfter { position: relative; z-index: 1; }
#beforeClip {
  position: absolute; z-index: 2; top: 0; left: 0; height: 100%;
  overflow: hidden; pointer-events: none;
}
#beforeClip canvas { position: absolute; top: 0; left: 0; max-width: none !important; max-height: none !important; }
#cmpHandle {
  position: absolute; z-index: 3; top: 0; bottom: 0; width: 3px;
  background: var(--accent); cursor: ew-resize;
  display: flex; align-items: center;
}
#cmpHandle .grip {
  position: absolute; left: 50%; transform: translateX(-50%);
  background: var(--accent); color: #fff; border-radius: 50%;
  width: 34px; height: 34px; display: flex; align-items: center; justify-content: center;
  font-size: 1rem; box-shadow: 0 2px 10px rgba(0, 0, 0, .5);
}

#infoBar {
  flex: 0 0 auto; text-align: center; color: var(--txt2); font-size: .85rem;
  font-variant-numeric: tabular-nums;
}

/* ---------- Pied de page ---------- */
footer {
  flex: 0 0 auto; padding: 8px 18px; font-size: .75rem; line-height: 1.5;
  color: var(--txt2); background: var(--bg2); border-top: 1px solid var(--line);
}
footer b { color: var(--warn); }

/* ---------- Toast ---------- */
#toast {
  position: fixed; bottom: 60px; left: 50%; transform: translateX(-50%);
  background: var(--bg3); border: 1px solid var(--accent); color: var(--txt);
  padding: 10px 22px; border-radius: 10px; font-size: .9rem; z-index: 100;
  box-shadow: 0 6px 24px rgba(0, 0, 0, .5); animation: toastIn .25s ease;
}
@keyframes toastIn { from { opacity: 0; transform: translate(-50%, 10px); } }

/* ---------- Mode Simple / Avancé ---------- */
body.simple .adv { display: none !important; }
.ui-switch { margin-right: 10px; }
.ui-switch button.active { background: var(--ok); color: #0a2018; }

/* ---------- Recadrage interactif ---------- */
#cropOverlay { position: absolute; z-index: 5; touch-action: none; }
#cropRect {
  position: absolute; border: 2px solid var(--accent); cursor: move;
  box-shadow: 0 0 0 4000px rgba(0, 0, 0, .55);
}
.crop-h {
  position: absolute; width: 16px; height: 16px; background: var(--accent);
  border-radius: 50%; border: 2px solid #fff;
}
.crop-h.nw { left: -9px; top: -9px; cursor: nwse-resize; }
.crop-h.ne { right: -9px; top: -9px; cursor: nesw-resize; }
.crop-h.sw { left: -9px; bottom: -9px; cursor: nesw-resize; }
.crop-h.se { right: -9px; bottom: -9px; cursor: nwse-resize; }
#cropBar {
  position: absolute; z-index: 6; bottom: 12px; left: 50%; transform: translateX(-50%);
  display: flex; gap: 8px; background: var(--bg3); border: 1px solid var(--line);
  border-radius: 10px; padding: 8px; box-shadow: 0 4px 18px rgba(0, 0, 0, .5);
}
#cropBar .btn { margin-top: 0; width: auto; }

/* ---------- Éditeur de courbe ---------- */
#curveCanvas {
  width: 100%; height: 160px; background: var(--bg); border: 1px solid var(--line);
  border-radius: 8px; margin-top: 8px; cursor: crosshair; display: block; touch-action: none;
}

/* ---------- Pipette ---------- */
body.picking #compare { cursor: crosshair; }
#btnBgPick.on { background: var(--accent); border-color: var(--accent); color: #fff; }

/* ---------- Aide (notice + recherche) ---------- */
.btn-help {
  background: transparent; color: var(--txt2); border: 1px solid var(--line);
  border-radius: 8px; padding: 5px 12px; cursor: pointer; font-weight: 600;
  white-space: nowrap; margin-right: 10px;
}
.btn-help:hover { border-color: var(--accent); color: var(--accent2); }

#helpModal {
  position: fixed; inset: 0; z-index: 50; display: flex;
  align-items: center; justify-content: center;
  background: rgba(0, 0, 0, .6); backdrop-filter: blur(3px);
}
#helpModal[hidden] { display: none; }
.help-box {
  width: min(680px, 92vw); max-height: 86vh; display: flex; flex-direction: column;
  background: var(--bg2); border: 1px solid var(--line); border-radius: 14px;
  box-shadow: 0 18px 60px rgba(0, 0, 0, .6); overflow: hidden;
}
.help-head {
  display: flex; align-items: center; gap: 12px; padding: 14px 18px;
  border-bottom: 1px solid var(--line);
}
.help-head h2 { font-size: 1.1rem; flex: 1; color: var(--accent2); }
.help-head .btn { width: auto; margin: 0; }
.help-search-wrap { padding: 12px 18px 4px; }
#helpSearch {
  width: 100%; background: var(--bg); color: var(--txt);
  border: 1px solid var(--line); border-radius: 10px; padding: 11px 14px;
  font-size: .95rem; outline: none;
}
#helpSearch:focus { border-color: var(--accent); }
.help-body { overflow-y: auto; padding: 8px 18px 18px; scrollbar-width: thin; }
.help-sub { font-size: .78rem; font-weight: 700; color: var(--txt2); text-transform: uppercase;
  letter-spacing: .6px; margin: 12px 0 6px; }
.help-item {
  background: var(--bg3); border: 1px solid var(--line); border-radius: 10px;
  margin-bottom: 8px; overflow: hidden;
}
.help-item summary { color: var(--txt); font-size: .9rem; padding: 10px 14px; }
.help-item.best summary { color: var(--accent2); }
.help-item .help-a { padding: 0 14px 12px; font-size: .85rem; color: var(--txt2); line-height: 1.55; }
.help-empty { color: var(--txt2); font-size: .85rem; padding: 10px 2px; }
mark { background: rgba(255, 107, 53, .3); color: inherit; border-radius: 3px; padding: 0 2px; }

/* ---------- Responsive ---------- */
@media (max-width: 860px) {
  body { overflow: auto; height: auto; }
  main { flex-direction: column-reverse; }
  #sidebar { width: 100%; border-right: none; border-top: 1px solid var(--line); }
  #stage { min-height: 55vh; }
  .tagline { display: none; }
}
