:root {
  --bg: #0f1419;
  --panel: #161c24;
  --panel-2: #1d242e;
  --border: #2a3441;
  --text: #e6edf3;
  --muted: #8b98a5;
  --accent: #4c8bf5;
  --accent-dim: #2b5fae;
  --ok: #3fb950;
  --err: #f85149;
  --warn: #d29922;
  --radius: 10px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}

code { background: var(--panel-2); padding: 1px 5px; border-radius: 4px; font-size: 12px; }

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  flex-wrap: wrap; gap: 12px;
  padding: 14px 24px; border-bottom: 1px solid var(--border);
  background: var(--panel);
}

.brand { display: flex; align-items: center; gap: 12px; }
.logo {
  background: var(--accent); color: #fff; font-weight: 700; letter-spacing: .5px;
  padding: 6px 9px; border-radius: 8px; font-size: 13px;
}
.brand h1 { font-size: 17px; margin: 0; font-weight: 600; }
.brand small { color: var(--muted); font-weight: 400; font-size: 12px; }

.tabs { display: flex; gap: 6px; flex-wrap: wrap; }
.tab-btn {
  background: transparent; color: var(--muted); border: 1px solid transparent;
  padding: 8px 14px; border-radius: 8px; cursor: pointer; font-size: 13px;
}
.tab-btn:hover { color: var(--text); background: var(--panel-2); }
.tab-btn.active { color: var(--text); background: var(--panel-2); border-color: var(--border); }

main { max-width: 1100px; margin: 0 auto; padding: 24px; }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

.card {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 18px; margin-bottom: 18px;
}
.card h2 { margin: 0 0 12px; font-size: 15px; font-weight: 600; }

.row { display: flex; align-items: flex-end; gap: 12px; flex-wrap: wrap; }
.row.options { margin-top: 14px; align-items: center; }
.row .btn { margin-left: auto; }
.row.options .btn { margin-left: 0; }

.field { display: flex; flex-direction: column; gap: 5px; }
.field > span { font-size: 12px; color: var(--muted); }
.field.inline { max-width: 160px; }
.field.full { grid-column: 1 / -1; }

input, select, textarea {
  background: var(--panel-2); border: 1px solid var(--border); color: var(--text);
  padding: 8px 10px; border-radius: 8px; font-size: 13px; font-family: inherit;
}
input:focus, select:focus { outline: none; border-color: var(--accent); }
select { min-width: 200px; }

.btn {
  background: var(--accent); color: #fff; border: none; padding: 9px 14px;
  border-radius: 8px; cursor: pointer; font-size: 13px; font-weight: 500;
}
.btn:hover { background: #5b97f7; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.ghost { background: var(--panel-2); color: var(--text); border: 1px solid var(--border); }
.btn.ghost:hover { background: var(--border); }
.btn.small { padding: 5px 9px; font-size: 12px; }
.btn.danger { background: transparent; color: var(--err); border: 1px solid var(--err); }
.btn.danger:hover { background: rgba(248,81,73,.12); }

.check { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text); }
.check input { width: auto; }

.grid-form {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 14px; align-items: end;
}
.grid-form .actions { grid-column: 1 / -1; }
.inline-input { display: flex; gap: 8px; }
.inline-input input { flex: 1; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--border); font-size: 13px; }
th { color: var(--muted); font-weight: 500; font-size: 12px; text-transform: uppercase; letter-spacing: .3px; }
tbody tr:hover { background: var(--panel-2); }
tbody tr.conn-row { cursor: pointer; }
tbody tr.active-row { background: rgba(76, 139, 245, .10); }
tbody tr.active-row:hover { background: rgba(76, 139, 245, .16); }
td.name { font-weight: 500; }

.empty, .hint, .status { color: var(--muted); font-size: 12.5px; }
#usage-badge.over { color: #d33; font-weight: 600; }
.hint { margin: 12px 0 0; }
.empty { margin: 14px 0 0; }

.badge {
  background: var(--accent); color: #fff; border-radius: 20px;
  padding: 1px 7px; font-size: 11px; margin-left: 4px;
}
.hidden { display: none !important; }

.pill { padding: 2px 9px; border-radius: 20px; font-size: 11.5px; font-weight: 600; }
.pill.queued { background: rgba(210,153,34,.18); color: var(--warn); }
.pill.running { background: rgba(76,139,245,.18); color: var(--accent); }
.pill.cancelling { background: rgba(210,153,34,.18); color: var(--warn); }
.pill.done { background: rgba(63,185,80,.18); color: var(--ok); }
.pill.error { background: rgba(248,81,73,.18); color: var(--err); }
.pill.cancelled { background: rgba(139,152,165,.18); color: var(--muted); }

.log {
  background: #0b0f13; border: 1px solid var(--border); border-radius: 8px;
  padding: 12px; max-height: 380px; overflow: auto; font-size: 12px;
  white-space: pre-wrap; word-break: break-word; color: #c9d1d9;
}

.toast {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%);
  background: var(--panel-2); border: 1px solid var(--border); color: var(--text);
  padding: 11px 18px; border-radius: 8px; font-size: 13px; box-shadow: 0 8px 24px rgba(0,0,0,.4);
  max-width: 80vw;
}
.toast.error { border-color: var(--err); color: #ffb4b0; }
.toast.ok { border-color: var(--ok); }

.file-links { display: flex; gap: 6px; flex-wrap: wrap; }
.file-links a {
  color: var(--accent); text-decoration: none; font-size: 12px;
  border: 1px solid var(--border); padding: 3px 8px; border-radius: 6px;
}
.file-links a:hover { background: var(--panel-2); }

/* Explorateur d'artefacts : une ligne par artefact, aperçu à droite */
.artifacts-layout { display: flex; flex-direction: column; gap: 16px; }
.artifacts-cols {
  display: grid;
  grid-template-columns: minmax(280px, 380px) 1fr;
  gap: 18px;
  align-items: start;
}
@media (max-width: 900px) {
  .artifacts-cols { grid-template-columns: 1fr; }
}
.artifacts-head {
  display: flex; align-items: center; gap: 10px; margin-bottom: 0;
  background: var(--panel-2); border-left: 3px solid var(--accent);
}
.artifacts-head b { color: var(--accent); }
.artifacts-head-actions { margin-left: auto; display: flex; gap: 8px; }
.fmt-switch { display: inline-flex; gap: 6px; margin-left: auto; flex-wrap: wrap; }
.artifacts-list { margin-bottom: 0; }
.artifact-viewer { margin-bottom: 0; }
.artifact-viewer .row { align-items: baseline; }
#artifacts-table tbody tr.artifact-row { cursor: pointer; }
#artifacts-table tbody tr.artifact-row.absent { cursor: default; color: var(--muted); }
#artifacts-table tbody tr.active-row { background: rgba(76, 139, 245, .14); }

/* Boutons-icônes par format, sur une seule ligne par catégorie */
.icon-btn {
  display: inline-flex; align-items: center; gap: 5px;
  background: var(--panel-2); border: 1px solid var(--border); color: var(--text);
  padding: 5px 9px; border-radius: 8px; cursor: pointer; font-size: 12px; line-height: 1;
}
.icon-btn:hover { border-color: var(--accent); background: var(--border); }
.icon-btn.active { border-color: var(--accent); background: rgba(76,139,245,.16); }
.icon-btn.disabled { opacity: .4; cursor: not-allowed; }
.icon-btn .ico { font-size: 14px; }
.icon-btn .fmt { font-weight: 600; letter-spacing: .3px; }
.artifact-media { margin-top: 6px; }
.artifact-video { width: 100%; max-width: 100%; border-radius: 8px; background: #000; }
.artifact-audio { width: 100%; }
.artifact-text { max-height: 460px; }
.viewer-actions { margin-top: 12px; }

@media (max-width: 720px) {
  .row .btn { margin-left: 0; }
  select { min-width: 0; width: 100%; }
}

/* Modale d'assistant de workflow */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.55);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 5vh 16px; z-index: 50; overflow: auto;
}
.modal {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  width: min(760px, 100%); box-shadow: 0 20px 60px rgba(0,0,0,.5);
}
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.modal-head h2 { margin: 0; font-size: 16px; }
.modal-body { padding: 18px 20px 20px; }
.wf-top { justify-content: space-between; margin-bottom: 14px; }

.wf-tabs { display: flex; gap: 4px; flex-wrap: wrap; border-bottom: 1px solid var(--border); margin-bottom: 14px; }
.wf-tab {
  background: transparent; border: none; border-bottom: 2px solid transparent;
  color: var(--muted); padding: 9px 12px; cursor: pointer; font-size: 13px;
}
.wf-tab:hover { color: var(--text); }
.wf-tab.active { color: var(--text); border-bottom-color: var(--accent); }
.wf-tab.done { color: var(--ok); }

.wf-pane { display: none; }
.wf-pane.active { display: block; }
.wf-pane .field { margin-bottom: 14px; }
.wf-pane textarea { width: 100%; }
.wf-pane-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.wf-note { color: var(--muted); font-size: 13px; }

/* Aperçu structuré (diarisation, attribution) */
.log.structured { white-space: normal; }
.art-table { width: 100%; border-collapse: collapse; margin-top: 8px; }
.art-table th, .art-table td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--border); font-size: 12.5px; }
.art-table th { color: var(--muted); font-weight: 500; }

.wf-warn { background: rgba(210,153,34,.14); border: 1px solid var(--warn); color: var(--warn); padding: 10px 12px; border-radius: 8px; font-size: 12.5px; }
.log { max-height: 520px; }

/* Temps par étape — encarts contrastés par rapport au fond */
.timings-cell { display: flex; flex-wrap: wrap; gap: 4px; max-width: 360px; }
.timing-chip {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--panel-2); border: 1px solid var(--border);
  border-radius: 6px; padding: 2px 7px; font-size: 11.5px; white-space: nowrap;
}
.timing-chip .t-label { color: var(--muted); }
.timing-chip .t-time { color: var(--accent); font-weight: 700; font-variant-numeric: tabular-nums; }
.timing-chip.err { border-color: var(--err); }
.timing-chip.err .t-time { color: var(--err); }

.timings { margin-bottom: 12px; }
.timings:empty { display: none; }
.timings-row { display: flex; flex-wrap: wrap; gap: 8px; }
.timing-box {
  display: flex; flex-direction: column; gap: 2px; min-width: 140px;
  background: var(--panel-2); border: 1px solid var(--border);
  border-left: 3px solid var(--accent); border-radius: 8px; padding: 8px 12px;
}
.timing-box .t-label { color: var(--muted); font-size: 11.5px; }
.timing-box .t-time { color: var(--accent); font-weight: 700; font-size: 15px; font-variant-numeric: tabular-nums; }
.timing-box.err { border-left-color: var(--err); }
.timing-box.err .t-time { color: var(--err); }

.wf-estimate {
  margin-top: 10px; padding: 9px 12px; border-radius: 8px;
  background: var(--panel-2); border: 1px dashed var(--warn);
  color: var(--warn); font-size: 12.5px;
}

/* Modale « Extraire » : choix médias seuls / workflows à enchaîner */
.pick-options { display: flex; flex-direction: column; gap: 10px; margin: 14px 0; }
.pick-opt {
  display: flex; align-items: flex-start; gap: 10px; cursor: pointer;
  background: var(--panel-2); border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px;
}
.pick-opt:hover { border-color: var(--accent); }
.pick-opt input { margin-top: 3px; }
.pick-opt small { color: var(--muted); }
.pick-actions { justify-content: flex-end; gap: 8px; }

.pick-config { margin: -2px 0 4px 30px; }

/* Coût par étape */
.timing-chip .t-cost { color: var(--ok); font-variant-numeric: tabular-nums; }
.timing-box .t-cost { color: var(--ok); font-size: 12.5px; font-variant-numeric: tabular-nums; }
.timings-total { margin-top: 8px; color: var(--muted); font-size: 12.5px; }
.timings-total b { color: var(--ok); }

.cost-cell { color: var(--ok); font-variant-numeric: tabular-nums; white-space: nowrap; }

.row-cost { color: var(--ok); font-size: 12px; font-variant-numeric: tabular-nums; }

.prompt-lib-actions { margin: -4px 0 8px; }

/* Étape préexistante (produite par une étape antérieure, non rejouée ici) */
#artifacts-table tr.inherited .name { color: var(--muted); }
.badge-inherited {
  background: var(--panel-2); border: 1px dashed var(--border); color: var(--muted);
  border-radius: 6px; padding: 1px 6px; font-size: 10.5px; margin-left: 4px;
}

.auth-box { display: flex; align-items: center; gap: 8px; }
.auth-modal { max-width: 420px; }
