/* =============================================================================
   H3 — interface mobile (thème sombre)
   ========================================================================== */

/* Rappel : un attribut HTML `hidden` est neutralisé par toute règle d'auteur qui
   définit `display` — d'où ce `!important` en tête de feuille. */
[hidden] { display: none !important; }

:root {
  --bg: #0d1117;
  --bg-soft: #161b22;
  --bg-card: #171d26;
  --border: #263040;
  --border-soft: #1f2733;
  --text: #e6edf3;
  --muted: #8b98a9;
  --accent: #3b82f6;
  --accent-2: #a855f7;
  --ok: #34d399;
  --warn: #fbbf24;
  --error: #f87171;
  --radius: 14px;
  --radius-sm: 10px;
  --bar-h: 64px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --shadow: 0 10px 30px rgba(0, 0, 0, .45);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body { margin: 0; padding: 0; }

body {
  background: radial-gradient(1200px 600px at 50% -10%, #16202f 0%, var(--bg) 60%);
  color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  min-height: 100dvh;
  padding-bottom: calc(var(--bar-h) + var(--safe-bottom) + 12px);
  overscroll-behavior-y: contain;
}

h1, h2, h3 { margin: 0; font-weight: 650; letter-spacing: -0.01em; }
h1 { font-size: 1.05rem; }
h2 { font-size: 1.05rem; }
p { margin: 0; }
code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: .86em;
  background: rgba(255, 255, 255, .06);
  padding: 1px 5px;
  border-radius: 6px;
}
a { color: var(--accent); }

.muted { color: var(--muted); }
.small { font-size: .82rem; }
.error { color: var(--error); }
.hidden { display: none !important; }

/* --- Sélecteur de workflow ------------------------------------------------- */

.workflow-bar { padding: 10px 14px 0; }
.workflow-picker {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 10px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg-soft);
}
.workflow-picker .workflow-icon { font-size: 1.1rem; }
.workflow-picker select {
  flex: 1;
  border: 0;
  background: transparent;
  padding: 8px 24px 8px 0;
  font-size: .9rem;
  font-weight: 600;
  color: var(--text);
}

/* --- Références ------------------------------------------------------------ */

.refs { display: flex; flex-direction: column; gap: 10px; }
.refs-list { display: flex; flex-direction: column; gap: 8px; }
.refs-empty { color: var(--muted); font-size: .82rem; }
.ref-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: #10151c;
}
.ref-thumb {
  width: 46px; height: 46px;
  flex: 0 0 auto;
  border-radius: 10px;
  background: #0b0f14 center/cover no-repeat;
  display: grid; place-items: center;
  font-size: 1.2rem;
  overflow: hidden;
}
.ref-thumb img { width: 100%; height: 100%; object-fit: cover; }
.ref-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.ref-title { font-size: .84rem; font-weight: 620; }
.ref-name { font-size: .74rem; color: var(--muted); word-break: break-all; }
.ref-tools { display: flex; align-items: center; gap: 4px; }
.ref-tools .btn { padding: 6px 8px; font-size: .8rem; line-height: 1; }
.ref-sound { display: flex; align-items: center; gap: 6px; font-size: .74rem; color: var(--muted); }
.refs-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.refs-actions .btn[disabled] { opacity: .4; }

/* --- Sorties texte --------------------------------------------------------- */

.text-output { border: 1px solid var(--border); border-radius: var(--radius-sm); background: #10151c; overflow: hidden; }
.text-output-head {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 8px 10px; border-bottom: 1px solid var(--border-soft);
  font-size: .8rem; color: var(--muted);
}
.text-output pre {
  margin: 0; padding: 10px; white-space: pre-wrap; word-break: break-word;
  font-size: .84rem; line-height: 1.45; max-height: 40vh; overflow: auto;
}

/* --- Barre supérieure ----------------------------------------------------- */

.app-bar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: calc(var(--safe-top) + 10px) 14px 10px;
  background: rgba(13, 17, 23, .82);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border-soft);
}

.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-icon { font-size: 1.5rem; line-height: 1; }
.brand-text { min-width: 0; }
.brand-text h1 { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand-text .muted { font-size: .76rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 52vw; }

.app-bar-actions { display: flex; align-items: center; gap: 8px; }

.pod-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg-soft);
  color: var(--muted);
  font-size: .72rem;
  cursor: pointer;
}
.pod-chip .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.pod-chip.is-ok .dot { background: var(--ok); box-shadow: 0 0 8px var(--ok); }
.pod-chip.is-ko .dot { background: var(--error); box-shadow: 0 0 8px var(--error); }

.icon-btn {
  width: 38px; height: 38px;
  display: inline-grid; place-items: center;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--bg-soft);
  color: var(--text);
  font-size: 1rem;
  cursor: pointer;
}
.icon-btn:active { transform: scale(.95); }

/* --- Onglets -------------------------------------------------------------- */

.tabs { display: flex; gap: 6px; padding: 10px 14px 0; }
.tab {
  flex: 1;
  padding: 10px 12px;
  border: 1px solid var(--border);
  background: var(--bg-soft);
  color: var(--muted);
  border-radius: 12px 12px 0 0;
  font-size: .9rem;
  font-weight: 600;
  cursor: pointer;
}
.tab.is-active { background: var(--bg-card); color: var(--text); border-bottom-color: var(--bg-card); }
.badge {
  display: inline-block;
  min-width: 18px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-size: .68rem;
}

main { padding: 0 12px; }
.tab-panel { padding-top: 12px; }

/* --- Sections du formulaire ---------------------------------------------- */

.section {
  background: var(--bg-card);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  margin-bottom: 12px;
  overflow: hidden;
}
.section > summary {
  list-style: none;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px;
  cursor: pointer;
  font-weight: 620;
}
.section > summary::-webkit-details-marker { display: none; }
.section > summary .chevron { margin-left: auto; color: var(--muted); transition: transform .18s ease; }
.section[open] > summary .chevron { transform: rotate(90deg); }
.section-head-title { display: flex; align-items: center; gap: 8px; }
.section-help { padding: 0 14px 6px; color: var(--muted); font-size: .8rem; }
.section-body { padding: 0 14px 14px; display: flex; flex-direction: column; gap: 14px; }

.field { display: flex; flex-direction: column; gap: 6px; }
.field-head { display: flex; align-items: baseline; gap: 8px; }
.field-label { font-size: .9rem; font-weight: 570; }
.field-unit { color: var(--muted); font-size: .78rem; }
.field-req { color: var(--muted); font-size: .68rem; border: 1px solid var(--border); border-radius: 6px; padding: 0 5px; }
.field-help { color: var(--muted); font-size: .78rem; }
.field-row { display: flex; align-items: center; gap: 10px; }

input[type="text"], input[type="number"], input[type="password"], textarea, select {
  width: 100%;
  padding: 11px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: #10151c;
  color: var(--text);
  font-size: 1rem;
  font-family: inherit;
  appearance: none;
}
textarea { resize: vertical; min-height: 84px; line-height: 1.4; }
select { background-image: linear-gradient(45deg, transparent 49%, var(--muted) 50%), linear-gradient(-45deg, transparent 49%, var(--muted) 50%); background-position: right 16px center, right 11px center; background-size: 5px 5px, 5px 5px; background-repeat: no-repeat; padding-right: 34px; }
input:focus, textarea:focus, select:focus { outline: 2px solid rgba(59, 130, 246, .55); outline-offset: 1px; }
input[type="range"] { width: 100%; accent-color: var(--accent); }

.slider-row { display: grid; grid-template-columns: 1fr 88px; gap: 10px; align-items: center; }

.switch { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; }
.switch input { display: none; }
.switch .track { width: 46px; height: 28px; border-radius: 999px; background: #2a3442; position: relative; transition: background .16s ease; }
.switch .track::after { content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #8b98a9; transition: transform .16s ease, background .16s ease; }
.switch input:checked + .track { background: rgba(59, 130, 246, .45); }
.switch input:checked + .track::after { transform: translateX(18px); background: var(--accent); }

/* Champ image */
.image-field { display: flex; gap: 12px; align-items: center; }
.image-thumb {
  width: 78px; height: 78px; flex: 0 0 auto;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: #0b0f14 center/cover no-repeat;
  display: grid; place-items: center;
  color: var(--muted);
  font-size: 1.4rem;
  overflow: hidden;
}
.image-thumb img { width: 100%; height: 100%; object-fit: cover; }
.image-meta { min-width: 0; display: flex; flex-direction: column; gap: 8px; }
.image-name { font-size: .82rem; color: var(--muted); word-break: break-all; }
.image-buttons { display: flex; gap: 8px; flex-wrap: wrap; }

/* --- Boutons -------------------------------------------------------------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 16px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--bg-soft);
  color: var(--text);
  font-size: .95rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
}
.btn:active { transform: scale(.98); }
.btn.primary { background: linear-gradient(135deg, var(--accent), var(--accent-2)); border-color: transparent; color: #fff; }
.btn.ghost { background: transparent; color: var(--muted); }
.btn.danger { border-color: rgba(248, 113, 113, .5); color: var(--error); background: rgba(248, 113, 113, .08); }
.btn.small-btn { padding: 8px 12px; font-size: .84rem; }
.btn[disabled] { opacity: .55; cursor: not-allowed; }

/* --- Valeurs calculées et avertissements --------------------------------- */

.derived-bar { display: flex; flex-wrap: wrap; gap: 8px; margin: 4px 0 12px; }
.chip {
  display: inline-flex;
  flex-direction: column;
  padding: 8px 12px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--bg-soft);
  font-size: .82rem;
}
.chip .chip-label { color: var(--muted); font-size: .7rem; text-transform: uppercase; letter-spacing: .04em; }
.chip .chip-value { font-weight: 650; }
.chip .chip-sub { color: var(--muted); font-size: .72rem; }

.warnings { display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; }
.warning {
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid rgba(251, 191, 36, .4);
  background: rgba(251, 191, 36, .1);
  color: #fde68a;
  font-size: .82rem;
}

/* --- Carte de job --------------------------------------------------------- */

.job-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 12px;
  box-shadow: var(--shadow);
}
.job-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 10px; }
.status-chip {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 5px 11px; border-radius: 999px;
  background: rgba(59, 130, 246, .14); color: #bfdbfe;
  font-size: .78rem; font-weight: 620;
}
.status-chip.is-done { background: rgba(52, 211, 153, .15); color: #a7f3d0; }
.status-chip.is-error { background: rgba(248, 113, 113, .15); color: #fecaca; }
.status-chip.is-running .spinner { display: inline-block; }
.spinner {
  width: 12px; height: 12px; border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, .35);
  border-top-color: #fff;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.progress { height: 8px; border-radius: 999px; background: #1b2330; overflow: hidden; margin-bottom: 8px; }
.progress-bar { height: 100%; width: 0; background: linear-gradient(90deg, var(--accent), var(--accent-2)); transition: width .4s ease; }
.progress.is-indeterminate .progress-bar { width: 35% !important; animation: slide 1.4s ease-in-out infinite; }
@keyframes slide { 0% { margin-left: -35%; } 100% { margin-left: 100%; } }

.job-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.job-media { margin-top: 12px; display: flex; flex-direction: column; gap: 10px; }
.job-media video, .job-media img { width: 100%; border-radius: 12px; background: #000; display: block; }
.media-meta { display: flex; justify-content: space-between; align-items: center; gap: 10px; font-size: .78rem; color: var(--muted); }
.telegram-note { font-size: .78rem; color: var(--muted); }

/* --- Galerie -------------------------------------------------------------- */

.gallery-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; }
.gallery-toolbar .small { flex: 1; }

.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.gallery-card {
  position: relative;
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  background: var(--bg-card);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.gallery-thumb {
  position: relative;
  aspect-ratio: 9 / 16;
  background: #0b0f14 center/cover no-repeat;
  display: grid;
  place-items: center;
  border: 0;
  padding: 0;
  cursor: pointer;
}
.gallery-thumb video { width: 100%; height: 100%; object-fit: cover; display: block; }
.gallery-thumb .placeholder { color: var(--muted); font-size: 1.6rem; }
.gallery-thumb .play-badge {
  position: absolute; inset: auto 8px 8px auto;
  background: rgba(0, 0, 0, .55);
  border-radius: 999px; padding: 4px 9px; font-size: .72rem;
}
.gallery-body { padding: 9px 10px 10px; display: flex; flex-direction: column; gap: 5px; }
.gallery-body .title { font-size: .8rem; font-weight: 600; }
.gallery-body .meta { font-size: .72rem; color: var(--muted); }
.gallery-body .actions { display: flex; gap: 6px; margin-top: 4px; }
.gallery-body .actions .btn { padding: 6px 9px; font-size: .74rem; }
.gallery-card .status-chip { font-size: .68rem; padding: 3px 8px; }
.empty { color: var(--muted); text-align: center; padding: 32px 12px; font-size: .9rem; }

/* --- Barre d'action ------------------------------------------------------- */

.action-bar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 35;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px calc(10px + var(--safe-bottom));
  background: rgba(13, 17, 23, .92);
  backdrop-filter: blur(14px);
  border-top: 1px solid var(--border-soft);
}
.action-info { flex: 1; min-width: 0; }
.action-info .small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#generateBtn { flex: 0 0 auto; padding: 13px 20px; }

/* --- Modales -------------------------------------------------------------- */

.modal-overlay {
  position: fixed; inset: 0; z-index: 60;
  display: flex; align-items: center; justify-content: center;
  padding: 16px;
  background: rgba(3, 6, 10, .72);
  backdrop-filter: blur(3px);
}
.modal {
  width: 100%;
  max-width: 560px;
  max-height: 86dvh;
  display: flex;
  flex-direction: column;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 18px;
  box-shadow: var(--shadow);
  overflow: hidden;
}
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 14px; border-bottom: 1px solid var(--border-soft); }
.modal-body { padding: 14px; overflow-y: auto; display: flex; flex-direction: column; gap: 12px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 14px; border-top: 1px solid var(--border-soft); }

.kv { display: flex; justify-content: space-between; gap: 12px; font-size: .84rem; padding: 7px 0; border-bottom: 1px dashed var(--border-soft); }
.kv:last-child { border-bottom: 0; }
.kv .k { color: var(--muted); }
.kv .v { text-align: right; word-break: break-word; }

.image-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: 8px; }
.image-grid button {
  padding: 0; border: 1px solid var(--border); border-radius: 10px; overflow: hidden;
  background: #0b0f14; aspect-ratio: 1; cursor: pointer;
}
.image-grid img { width: 100%; height: 100%; object-fit: cover; display: block; }

/* --- Visionneuse ---------------------------------------------------------- */

.viewer {
  position: fixed; inset: 0; z-index: 70;
  display: flex; flex-direction: column;
  background: rgba(3, 6, 10, .96);
  padding-top: var(--safe-top);
  padding-bottom: var(--safe-bottom);
}
.viewer-bar { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 14px; }
.viewer-title { font-size: .86rem; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.viewer-actions { display: flex; align-items: center; gap: 8px; }
.viewer-stage { flex: 1; display: grid; place-items: center; padding: 0 10px; min-height: 0; }
.viewer-stage video, .viewer-stage img { max-width: 100%; max-height: 100%; border-radius: 12px; background: #000; }
.viewer-details { padding: 10px 14px 14px; color: var(--muted); font-size: .78rem; }

/* --- Dépôt de fichier ----------------------------------------------------- */

.drop-overlay {
  position: fixed; inset: 0; z-index: 80;
  display: grid; place-items: center;
  background: rgba(13, 17, 23, .75);
  border: 2px dashed var(--accent);
  pointer-events: none;
  opacity: 0;
  transition: opacity .15s ease;
}
body.dragging-files .drop-overlay { opacity: 1; }
.drop-card { padding: 18px 26px; border-radius: 16px; background: var(--bg-card); font-weight: 650; }

/* --- Notifications -------------------------------------------------------- */

.toasts {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(var(--bar-h) + var(--safe-bottom) + 16px);
  z-index: 90;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: min(92vw, 460px);
  pointer-events: none;
}
.toast {
  padding: 11px 14px;
  border-radius: 12px;
  background: #1f2733;
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  font-size: .86rem;
  animation: toast-in .18s ease;
}
.toast.is-error { background: rgba(248, 113, 113, .16); border-color: rgba(248, 113, 113, .45); color: #fee2e2; }
.toast.is-ok { background: rgba(52, 211, 153, .16); border-color: rgba(52, 211, 153, .4); color: #d1fae5; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

@media (min-width: 720px) {
  main { max-width: 760px; margin: 0 auto; }
  .tabs { max-width: 760px; margin: 0 auto; }
  .app-bar { padding-left: 24px; padding-right: 24px; }
  .gallery { grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); }
}
