:root {
  --bg: #0d0a14;
  --card: #16111f;
  --card-2: #1d1729;
  --border: #2b2339;
  --text: #ece8f5;
  --muted: #9a91ab;
  --accent: #6b35e0;
  --accent-hover: #7c49ee;
  --accent-soft: rgba(107, 53, 224, 0.16);
  --ok: #3ecf8e;
  --warn: #f2b94b;
  --error: #ff6b6b;
  --radius: 14px;
  color-scheme: dark;
}

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", Roboto, sans-serif;
}

a { color: #b79cff; }
.muted { color: var(--muted); }
.error { color: var(--error); margin: 12px 0 0; white-space: pre-wrap; }

/* En-tête */
.top {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 14px 18px;
  max-width: 1180px;
  margin: 0 auto;
  padding: 24px 20px 8px;
}
.top .logo { width: 88px; height: auto; }
.top-title { flex: 1; min-width: 200px; }
.top h1 { margin: 0; font-size: 21px; letter-spacing: -0.01em; }
.top p { margin: 2px 0 0; }
.tabs { display: flex; gap: 4px; padding: 4px; background: var(--card); border: 1px solid var(--border); border-radius: 12px; }
.tabs button {
  border: 0;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-weight: 600;
  padding: 7px 14px;
  border-radius: 9px;
  cursor: pointer;
}
.tabs button[aria-selected="true"] { background: var(--accent); color: #fff; }

main {
  max-width: 1180px;
  margin: 0 auto;
  padding: 14px 20px 60px;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 18px;
}
.tab-panel { display: grid; grid-template-columns: minmax(0, 1fr); gap: 18px; }

.banner {
  max-width: 1140px;
  margin: 12px auto 0;
  padding: 12px 16px;
  border: 1px solid rgba(242, 185, 75, 0.4);
  background: rgba(242, 185, 75, 0.08);
  color: var(--warn);
  border-radius: var(--radius);
}
.banner ul { margin: 4px 0 0; padding-left: 18px; }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}
.card h2, .card h3 { margin: 0 0 10px; font-size: 15px; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 10px; }
.card-head h2, .card-head h3 { margin: 0; }

/* Formulaires */
label { display: block; font-weight: 600; margin: 0 0 6px; }
input:not([type]), input[type="password"], textarea, select {
  width: 100%;
  background: var(--card-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 11px 13px;
  font: inherit;
}
textarea { resize: vertical; }
input:focus, textarea:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
#query { font-size: 17px; padding: 13px 14px; }
.hint { color: var(--muted); font-size: 13px; margin: 6px 0 14px; }

.form-row { display: flex; flex-wrap: wrap; gap: 16px 24px; align-items: flex-end; margin-bottom: 16px; }
.form-row > div { min-width: 200px; }
.form-foot { display: flex; flex-wrap: wrap; gap: 14px; align-items: center; justify-content: space-between; margin-top: 14px; }

.check { display: inline-flex; align-items: center; gap: 8px; font-weight: 500; margin: 0; cursor: pointer; }
.check input { width: 17px; height: 17px; accent-color: var(--accent); }

.segmented { border: 0; padding: 0; margin: 0; display: flex; flex-wrap: wrap; gap: 6px; }
.segmented legend { font-weight: 600; margin-bottom: 6px; padding: 0; }
.segmented label { margin: 0; font-weight: 500; }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented span {
  display: inline-block;
  padding: 8px 13px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--card-2);
  color: var(--muted);
  cursor: pointer;
}
.segmented small { opacity: 0.75; margin-left: 4px; }
.segmented input:checked + span { border-color: var(--accent); background: var(--accent-soft); color: var(--text); }
.segmented input:focus-visible + span { outline: 2px solid var(--accent); }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 11px 18px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--card-2);
  color: var(--text);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-hover); }
.btn.ghost { background: transparent; }
.btn.small { padding: 6px 12px; font-size: 13px; }
.btn.block { display: flex; width: 100%; margin-top: 14px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* Choix des vidéos */
.candidate-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 14px; }
.candidate {
  position: relative;
  margin: 0;
  font-weight: 400;
  background: var(--card-2);
  border: 2px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  cursor: pointer;
  display: flex;
  flex-direction: column;
}
.candidate:has(input:checked) { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.candidate > input { position: absolute; top: 10px; left: 10px; z-index: 2; width: 20px; height: 20px; accent-color: var(--accent); }
.candidate-media { position: relative; aspect-ratio: 16 / 10; background: #000; }
.candidate-media img, .candidate-media video { width: 100%; height: 100%; object-fit: cover; display: block; }
.candidate-media .duration { position: absolute; right: 8px; bottom: 8px; background: rgba(0, 0, 0, 0.75); color: #fff; font-size: 12px; padding: 1px 6px; border-radius: 6px; }
.candidate-media .play {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  width: 44px; height: 44px; border-radius: 50%; border: 0;
  background: rgba(0, 0, 0, 0.6); color: #fff; font-size: 16px; cursor: pointer;
}
.candidate-media .play:hover { background: var(--accent); }
.candidate-body { padding: 10px 12px 12px; display: grid; gap: 6px; }
.candidate-author { font-size: 13px; color: var(--muted); }
.candidate-author strong { color: var(--text); }
.candidate-text { margin: 0; font-size: 13.5px; display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden; }
.candidate-meta { font-size: 12px; }
.candidates-foot {
  position: sticky; bottom: 0;
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  margin: 16px -20px -20px; padding: 14px 20px;
  background: var(--card); border-top: 1px solid var(--border); border-radius: 0 0 var(--radius) var(--radius);
}

/* Générations */
.jobs-head { display: flex; justify-content: space-between; align-items: center; }
.jobs-head h2 { margin: 0; font-size: 17px; }
.jobs { display: grid; gap: 18px; }
.job-head { display: grid; grid-template-columns: 64px minmax(0, 1fr) auto; gap: 14px; align-items: center; }
.job-thumb { width: 64px; height: 64px; object-fit: cover; border-radius: 10px; background: var(--card-2); }
.job-info { display: grid; gap: 2px; min-width: 0; }
.job-title { overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.job-sub { font-size: 13px; }
.badge { font-size: 12px; font-weight: 600; padding: 3px 10px; border-radius: 999px; background: var(--card-2); color: var(--muted); white-space: nowrap; }
.badge.running { background: var(--accent-soft); color: #c6adff; }
.badge.done { background: rgba(62, 207, 142, 0.14); color: var(--ok); }
.badge.error { background: rgba(255, 107, 107, 0.14); color: var(--error); }
.job-progress { margin-top: 16px; }
.progress-head { display: flex; justify-content: space-between; margin-bottom: 8px; font-size: 14px; }
.bar { height: 8px; background: var(--card-2); border-radius: 999px; overflow: hidden; }
.bar-fill { height: 100%; width: 0; background: linear-gradient(90deg, #5a2bc4, #8b5cf6); border-radius: 999px; transition: width 0.3s ease; }
.steps { list-style: none; margin: 14px 0 0; padding: 0; display: grid; gap: 8px; }
.steps li { display: grid; grid-template-columns: 22px 1fr auto; gap: 10px; align-items: center; color: var(--muted); font-size: 14px; }
.steps li.active, .steps li.done { color: var(--text); }
.steps .icon { width: 18px; height: 18px; border-radius: 50%; border: 2px solid var(--border); display: grid; place-items: center; font-size: 11px; line-height: 1; }
.steps li.done .icon { background: var(--accent); border-color: var(--accent); color: #fff; }
.steps li.error { color: var(--error); }
.steps li.error .icon { background: var(--error); border-color: var(--error); color: #fff; }
.steps li.active .icon { border-color: var(--accent); border-top-color: transparent; animation: spin 0.9s linear infinite; }
.steps .detail { font-size: 12.5px; color: var(--muted); text-align: right; }
@keyframes spin { to { transform: rotate(360deg); } }

.job-result { display: grid; grid-template-columns: minmax(260px, 400px) minmax(0, 1fr); gap: 18px; align-items: start; margin-top: 18px; }
.job.vertical .job-result { grid-template-columns: minmax(220px, 320px) minmax(0, 1fr); }
.preview video { display: block; width: 100%; aspect-ratio: 4 / 5; background: #000; border-radius: 10px; }
.job.vertical .preview video { aspect-ratio: 9 / 16; }
.side { display: grid; gap: 14px; min-width: 0; }
.sub-card { background: var(--card-2); border: 1px solid var(--border); border-radius: 12px; padding: 14px; }
.sub-card h3 { margin: 0 0 8px; font-size: 14px; }
.sub-card textarea { background: var(--bg); }
.caption { min-height: 320px; line-height: 1.55; }
.caption-count { margin-bottom: 0; }
.caption-count.over { color: var(--error); }
.sources ul { margin: 0; padding-left: 18px; }
.sources li + li { margin-top: 4px; }
.sources a { word-break: break-word; }
.adjust summary { cursor: pointer; font-weight: 600; }
.adjust[open] summary { margin-bottom: 10px; }
.adjust-row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-top: 10px; }
.adjust-row select { width: auto; flex: 1; min-width: 180px; }
.origin blockquote { margin: 8px 0; padding: 10px 12px; border-left: 3px solid var(--accent); background: var(--bg); border-radius: 0 8px 8px 0; white-space: pre-wrap; }
.origin-author { margin: 0; font-weight: 600; }
.origin-author a { color: var(--text); }
.origin-meta { margin: 0; font-size: 13px; }

/* Historique */
.history-list { display: grid; gap: 10px; }
.history-item { display: grid; grid-template-columns: 56px minmax(0, 1fr) auto auto; gap: 14px; align-items: center; padding: 10px; background: var(--card-2); border: 1px solid var(--border); border-radius: 12px; }
.history-item img { width: 56px; height: 56px; object-fit: cover; border-radius: 8px; background: var(--bg); }
.history-info { display: grid; gap: 2px; min-width: 0; }
.history-info strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.history-info .muted { font-size: 13px; }
.history-error { font-size: 12.5px; color: var(--error); }
.history-actions { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }
.history-confirm {
  grid-column: 1 / -1;
  display: flex; flex-wrap: wrap; gap: 10px 16px; align-items: center; justify-content: space-between;
  padding: 12px; border-radius: 10px;
  background: rgba(255, 107, 107, 0.07); border: 1px solid rgba(255, 107, 107, 0.35);
}
.history-confirm .error { flex-basis: 100%; margin: 0; }
.history-deleted { margin: 0; padding: 10px 14px; font-size: 13px; }
.btn.danger { color: var(--error); border-color: rgba(255, 107, 107, 0.4); }
.btn.danger:hover { border-color: var(--error); }

/* Connexion */
.login-page { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: 100%; max-width: 380px; display: grid; gap: 6px; }
.login-card .logo { width: 120px; justify-self: center; }
.login-card h1 { text-align: center; font-size: 20px; margin: 4px 0 14px; }

@media (max-width: 860px) {
  .job-result, .job.vertical .job-result { grid-template-columns: minmax(0, 1fr); }
  .preview { max-width: 420px; width: 100%; justify-self: center; }
}
@media (max-width: 520px) {
  main, .top { padding-left: 16px; padding-right: 16px; }
  .form-foot .btn.primary { width: 100%; }
  .history-item { grid-template-columns: 48px minmax(0, 1fr); }
  .history-item .badge, .history-item > .history-actions { grid-column: 2; justify-self: start; }
  .job-head { grid-template-columns: 48px minmax(0, 1fr); }
  .job-head .badge { grid-column: 2; justify-self: start; }
  .job-thumb { width: 48px; height: 48px; }
}
