:root {
  --bg: #0f172a;
  --bg2: #1e293b;
  --card: #1e293b;
  --txt: #e2e8f0;
  --muted: #94a3b8;
  --accent: #38bdf8;
  --accent2: #0ea5e9;
  --ok: #22c55e;
  --border: #334155;
  --radius: 14px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: linear-gradient(180deg, var(--bg), #0b1220);
  color: var(--txt);
  min-height: 100vh;
  -webkit-text-size-adjust: 100%;
}

.topbar {
  text-align: center;
  padding: 1.4rem 1rem 0.6rem;
}
.topbar h1 { margin: 0; font-size: 1.6rem; }
.subtitle { margin: 0.3rem 0 0; color: var(--muted); font-size: 0.95rem; }

.container {
  max-width: 820px;
  margin: 0 auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.1rem 1.2rem;
}
.card h2 { margin: 0 0 0.9rem; font-size: 1.1rem; }

/* Dropzone */
.dropzone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 1.5rem 1rem;
  text-align: center;
  cursor: pointer;
  transition: border-color .15s, background .15s;
}
.dropzone.drag { border-color: var(--accent); background: rgba(56,189,248,.08); }
.drop-hint { margin: 0; color: var(--txt); }
.muted { color: var(--muted); font-size: 0.85rem; }

.thumbs {
  display: flex; flex-wrap: wrap; gap: 8px; margin-top: 1rem;
  justify-content: center;
}
.thumb { position: relative; width: 72px; height: 72px; }
.thumbs img {
  width: 72px; height: 72px; object-fit: cover;
  border-radius: 8px; border: 1px solid var(--border); display: block;
}
.thumb-rm {
  position: absolute; top: -6px; right: -6px;
  width: 20px; height: 20px; padding: 0; border: none; border-radius: 50%;
  background: #ef4444; color: #fff; font-size: 15px; line-height: 1;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
}
.thumb-more {
  width: 72px; height: 72px; border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg2); border: 1px solid var(--border); color: var(--muted);
  font-size: .8rem; cursor: pointer;
}

/* Form rows */
.row { margin: 0.9rem 0; display: flex; flex-direction: column; gap: 0.4rem; }
.row.toggle-row { flex-direction: row; align-items: center; gap: 0.7rem; }
label { font-size: 0.92rem; color: var(--txt); }
select { width: 100%; }
select {
  background: var(--bg2); color: var(--txt); border: 1px solid var(--border);
  border-radius: 10px; padding: 0.6rem; font-size: 0.95rem;
}

/* Slider cross-browser (track + thumb explicites, glissable au doigt) */
input[type="range"] {
  -webkit-appearance: none; appearance: none;
  width: 100%; height: 8px; margin: 12px 0;
  background: var(--border); border-radius: 6px;
  outline: none; touch-action: none; cursor: pointer;
}
input[type="range"].slim { width: 200px; max-width: 70%; }
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 28px; height: 28px; border-radius: 50%;
  background: var(--accent2); border: 2px solid #fff; cursor: pointer;
}
input[type="range"]::-moz-range-thumb {
  width: 28px; height: 28px; border-radius: 50%;
  background: var(--accent2); border: 2px solid #fff; cursor: pointer;
}
input[type="range"]::-moz-range-track {
  height: 8px; background: var(--border); border-radius: 6px;
}

/* Switch */
.switch { position: relative; display: inline-block; width: 48px; height: 26px; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider-sw {
  position: absolute; inset: 0; cursor: pointer;
  background: var(--border); border-radius: 26px; transition: .2s;
}
.slider-sw:before {
  content: ""; position: absolute; height: 20px; width: 20px; left: 3px; top: 3px;
  background: #fff; border-radius: 50%; transition: .2s;
}
.switch input:checked + .slider-sw { background: var(--accent2); }
.switch input:checked + .slider-sw:before { transform: translateX(22px); }

/* Buttons */
.btn {
  display: inline-block; width: 100%; text-align: center;
  padding: 0.85rem 1rem; border: none; border-radius: 12px;
  font-size: 1rem; font-weight: 600; cursor: pointer; margin-top: 0.5rem;
  text-decoration: none;
}
.btn.primary { background: var(--accent2); color: #04212f; }
.btn.primary:disabled { background: var(--border); color: var(--muted); cursor: not-allowed; }
.btn.secondary { background: var(--bg2); color: var(--accent); border: 1px solid var(--accent2); }
.btn.ghost { background: var(--bg2); color: var(--txt); border: 1px solid var(--border); }
.btn.ghost:disabled { opacity: .6; cursor: not-allowed; }

.btn-grid { display: flex; gap: 8px; margin-top: 0.8rem; }
.btn-grid .btn { margin-top: 0; }
.center { text-align: center; }

/* Aperçu débruitage */
.preview { display: flex; gap: 12px; margin-top: 0.8rem; flex-wrap: wrap; }
.preview figure { margin: 0; text-align: center; }
.preview img { width: 150px; max-width: 42vw; border-radius: 10px; border: 1px solid var(--border); image-rendering: auto; }
.preview figcaption { color: var(--muted); font-size: 0.8rem; margin-top: 4px; }

/* Barre de progression */
.progress { margin-bottom: 1rem; }
.progress-head { display: flex; justify-content: space-between; font-size: 0.92rem; margin-bottom: 6px; }
.bar { height: 12px; background: var(--bg2); border-radius: 8px; overflow: hidden; border: 1px solid var(--border); }
.bar-fill { height: 100%; width: 0; background: linear-gradient(90deg, var(--accent2), var(--accent)); transition: width .4s ease; }
.live-prev { width: 110px; border-radius: 8px; border: 1px solid var(--border); margin-top: 0.7rem; }

/* Modale caméra */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.8); display: flex; align-items: center; justify-content: center; z-index: 50; padding: 1rem; }
.modal-box { background: var(--card); border-radius: var(--radius); padding: 1rem; max-width: 95vw; }
.modal-box video { width: 100%; max-width: 480px; border-radius: 10px; background: #000; }

/* Results */
.status { color: var(--muted); margin-bottom: 0.6rem; min-height: 1.2em; }
.spinner {
  display: inline-block; width: 16px; height: 16px; border: 2px solid var(--border);
  border-top-color: var(--accent); border-radius: 50%; animation: spin .7s linear infinite;
  vertical-align: -3px; margin-right: 8px;
}
@keyframes spin { to { transform: rotate(360deg); } }

.result-single { display: flex; gap: 1rem; flex-wrap: wrap; align-items: flex-start; }
.result-single img { width: 200px; max-width: 45%; border-radius: 10px; border: 1px solid var(--border); }
.badge {
  display: inline-block; background: var(--accent2); color: #04212f;
  padding: 0.25rem 0.7rem; border-radius: 999px; font-weight: 700; font-size: 0.9rem;
}
.caption-box {
  margin-top: 0.7rem; font-size: 1.05rem; line-height: 1.4;
  background: var(--bg2); padding: 0.8rem; border-radius: 10px; border-left: 3px solid var(--accent);
}
.meta { color: var(--muted); font-size: 0.82rem; margin-top: 0.5rem; }

table { width: 100%; border-collapse: collapse; margin-top: 0.6rem; font-size: 0.9rem; }
th, td { text-align: left; padding: 0.5rem 0.4rem; border-bottom: 1px solid var(--border); vertical-align: top; }
th { color: var(--muted); font-weight: 600; }
td.cls .badge { font-size: 0.78rem; }

.loadbanner {
  background: #1e3a5f; color: var(--txt); text-align: center;
  padding: 0.6rem 1rem; font-size: 0.88rem; border-bottom: 1px solid var(--accent2);
}

#dl { margin-bottom: 1rem; }

/* Répartition par classe (mode dossier) */
.summary { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 0.9rem; }
.sum-chip { padding: 0.32rem 0.72rem; border-radius: 999px; font-weight: 700; font-size: 0.85rem; }

/* Couleurs par classe (pastilles + chips de répartition) */
.cls-Painting   { background: #a855f7; color: #fff; }
.cls-Photo      { background: #22c55e; color: #04212f; }
.cls-Schematics { background: #f59e0b; color: #04212f; }
.cls-Sketch     { background: #ec4899; color: #fff; }
.cls-Text       { background: #38bdf8; color: #04212f; }

.hidden { display: none !important; }
.foot { text-align: center; padding: 1.2rem; font-size: 0.8rem; }

@media (max-width: 520px) {
  .topbar h1 { font-size: 1.35rem; }
  .result-single img { max-width: 100%; width: 100%; }
}
