/* OpenAvatar — régie broadcast : rail sombre, plan de travail clair, un seul accent « tally » (rouge d'enregistrement). */

:root {
  --bay: #063d2e;            /* rail */
  --bay-line: #0d5641;
  --bay-text: #a8cfc0;
  --paper: #eef0eb;          /* plan de travail */
  --card: #ffffff;
  --ink: #141a21;
  --muted: #5a6670;
  --line: #d6dbd3;
  --tally: #e23a1f;          /* action principale, enregistrement */
  --tally-deep: #b92c14;
  --signal: #1b8f6a;         /* prêt, publié */
  --amber: #b7791f;          /* en attente */
  --alert: #b42318;          /* échec */
  --radius: 10px;
  --font: "Archivo", "Segoe UI", system-ui, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, "Cascadia Mono", monospace;
  --rail: 15.5rem;
}

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

body {
  margin: 0;
  min-height: 100vh;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font);
  font-size: 0.97rem;
  line-height: 1.5;
}

a { color: var(--tally-deep); }
h1, h2, h3 { font-family: var(--font); font-stretch: 112%; letter-spacing: -0.02em; line-height: 1.15; }
code { font-family: var(--font-mono); font-size: 0.85em; background: rgba(20, 26, 33, 0.07); padding: 0.1em 0.35em; border-radius: 4px; }
:focus-visible { outline: 2px solid var(--tally); outline-offset: 2px; }

/* ------------------------------------------------------------------ rail de navigation */
.sidenav {
  position: fixed; inset: 0 auto 0 0; width: var(--rail);
  display: flex; flex-direction: column; gap: 0.15rem;
  padding: 1.25rem 0.75rem; background: var(--bay); color: var(--bay-text); overflow-y: auto; z-index: 5;
}
.brand-mark { display: flex; align-items: center; gap: 0.6rem; padding: 0 0.6rem 1.25rem; color: #fff; }
.brand-orb { width: 0.7rem; height: 0.7rem; border-radius: 50%; background: var(--tally); box-shadow: 0 0 0 4px rgba(226, 58, 31, 0.25); }
.brand-name { font-stretch: 125%; font-weight: 800; font-size: 1.05rem; letter-spacing: -0.02em; }
.nav-group { margin: 1rem 0 0.3rem; padding: 0 0.6rem; font-size: 0.68rem; font-weight: 600; letter-spacing: 0.14em; text-transform: uppercase; color: #6fa592; }
.sidenav a {
  display: grid; gap: 0.05rem; padding: 0.55rem 0.6rem; border-radius: 8px; border-left: 3px solid transparent;
  color: var(--bay-text); text-decoration: none; font-weight: 600; transition: background 0.15s, color 0.15s;
}
.sidenav a small { font-weight: 400; font-size: 0.76rem; color: #84b3a1; }
.sidenav a:hover, .sidenav a:focus-visible { background: var(--bay-line); color: #fff; }
.sidenav a[aria-current="page"] { background: var(--bay-line); color: #fff; border-left-color: var(--tally); }
.sidenav a[aria-current="page"] small { color: var(--bay-text); }
.nav-spacer { flex: 1; }

.stage { margin-left: var(--rail); padding: 2rem clamp(1rem, 3vw, 2.5rem) 3rem; max-width: 1320px; }
.footer { margin-left: var(--rail); padding: 1.5rem; color: var(--muted); font-size: 0.8rem; }

/* ------------------------------------------------------------------ blocs et formulaires */
.panel { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.5rem; }
.panel + .panel { margin-top: 1.25rem; }
.panel h2 { margin: 0; font-size: 1.55rem; font-weight: 800; }
.panel h3 { font-weight: 700; }
.panel-copy { margin: 0.4rem 0 1.25rem; color: var(--muted); max-width: 46rem; }
.hint { margin: 0.4rem 0 0; color: var(--muted); font-size: 0.85rem; }
.status { min-height: 1.3rem; margin: 0.8rem 0 0; font-size: 0.9rem; color: var(--ink); }

label, .field > span { display: block; margin: 1rem 0 0.35rem; font-size: 0.85rem; font-weight: 600; }
.field { display: grid; gap: 0.1rem; margin-bottom: 0.4rem; }
.field > span { margin: 0.4rem 0 0.2rem; }
.field-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(10rem, 1fr)); gap: 0.8rem; }
.check-field, label.inline { display: flex; align-items: center; gap: 0.6rem; margin: 0.5rem 0; font-weight: 500; }
input[type="checkbox"] { width: 1.05rem; height: 1.05rem; accent-color: var(--tally); }

input[type="text"], input[type="url"], input[type="password"], input[type="search"], input[type="datetime-local"],
input[type="number"], input:not([type]), select, textarea {
  width: 100%; border: 1px solid var(--line); border-radius: 8px; background: #fff; color: var(--ink);
  font: inherit; padding: 0.65rem 0.8rem; transition: border-color 0.15s, box-shadow 0.15s;
}
input[type="file"] { width: 100%; font: inherit; padding: 0.55rem; border: 1px dashed #b8c0b6; border-radius: 8px; background: #fafbf9; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--tally); box-shadow: 0 0 0 3px rgba(226, 58, 31, 0.15); }
textarea { resize: vertical; min-height: 5rem; }
select[size] { padding: 0.3rem; }
details { margin-top: 1.1rem; border-top: 1px solid var(--line); padding-top: 0.7rem; }
summary { cursor: pointer; font-weight: 600; color: var(--muted); }
summary:hover { color: var(--ink); }

.button {
  appearance: none; display: inline-flex; align-items: center; justify-content: center; gap: 0.5rem;
  border: 1px solid var(--ink); border-radius: 8px; padding: 0.65rem 1.1rem; background: var(--card); color: var(--ink);
  font: inherit; font-weight: 600; text-decoration: none; cursor: pointer; transition: background 0.15s, color 0.15s, transform 0.15s;
}
.button:hover { background: var(--ink); color: #fff; }
.button.primary { background: var(--tally); border-color: var(--tally); color: #fff; }
.button.primary:hover { background: var(--tally-deep); border-color: var(--tally-deep); }
.button.ghost { border-color: var(--line); background: transparent; }
.button.ghost:hover { border-color: var(--ink); background: var(--ink); }
.button.danger { border-color: var(--alert); color: var(--alert); background: transparent; }
.button.danger:hover { background: var(--alert); color: #fff; }
.button.wide { width: 100%; margin-top: 1rem; }
.button:disabled { opacity: 0.5; cursor: wait; }
.cta-row, .publish-actions { display: flex; flex-wrap: wrap; gap: 0.6rem; margin-top: 1rem; }

/* ------------------------------------------------------------------ Série : l'URL d'abord */
.series > .panel-copy, .series form { max-width: 46rem; }
.url-row { display: grid; grid-template-columns: 1fr auto; gap: 0.6rem; }
.url-row input { font-size: 1.1rem; padding: 0.9rem 1rem; }
.url-row .button { padding: 0 1.5rem; font-size: 1rem; }
.url-row .button::before { content: ""; width: 0.6rem; height: 0.6rem; border-radius: 50%; background: #fff; }
.series video { display: block; width: min(100%, 22rem); margin-top: 1.25rem; border-radius: var(--radius); background: #000; }
.series-progress { margin-top: 1.5rem; max-width: 46rem; }

/* ------------------------------------------------------------------ progression (Série, Studio) */
.progress-block, .series-progress { padding: 1rem 1.1rem; border: 1px solid var(--line); border-radius: var(--radius); background: #fafbf9; }
.progress-meta { display: flex; justify-content: space-between; gap: 0.75rem; font-size: 0.88rem; margin-bottom: 0.55rem; }
#progress-timer, #progress-percent { font-family: var(--font-mono); font-size: 0.82rem; }
.progress-track { height: 0.4rem; border-radius: 99px; background: #dfe4dc; overflow: hidden; }
.progress-fill { height: 100%; width: 0; border-radius: inherit; background: var(--tally); transition: width 0.35s ease; }
.progress-steps, .stages { list-style: none; display: flex; flex-wrap: wrap; gap: 0.4rem; margin: 0.8rem 0 0; padding: 0; }
.progress-steps li, .stages li {
  padding: 0.2rem 0.6rem; border: 1px solid var(--line); border-radius: 99px; background: #fff;
  font-size: 0.72rem; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase; color: var(--muted);
}
.progress-steps li.active, .stages li.active { border-color: var(--tally); color: var(--tally-deep); background: #fff3f0; }
.progress-steps li.done, .stages li.done { border-color: var(--signal); color: var(--signal); }

/* ------------------------------------------------------------------ Studio */
.workspace { display: grid; grid-template-columns: minmax(0, 1fr); gap: 1.25rem; align-items: start; }
.workspace > .studio { display: contents; }
@media (min-width: 1000px) { .workspace { grid-template-columns: minmax(0, 1fr) minmax(0, 0.9fr); } }
.preview-frame {
  position: relative; aspect-ratio: 1; border-radius: var(--radius); overflow: hidden; display: grid; place-items: center;
  background: var(--bay);
}
.preview-frame img { width: 100%; height: 100%; object-fit: cover; display: block; }
.placeholder { padding: 1rem; text-align: center; color: var(--bay-text); }
.mouth {
  position: absolute; left: 50%; bottom: 27%; width: 18%; height: 4%; border-radius: 50%; background: rgba(20, 10, 10, 0.72);
  transform: translateX(-50%) scaleY(0.35); transform-origin: center; pointer-events: none; transition: transform 40ms linear;
}
#result-audio, #result-video { width: 100%; margin-top: 0.9rem; border-radius: var(--radius); }
.result-meta { margin-top: 0.9rem; font-size: 0.88rem; color: var(--muted); }
.result-meta p { margin: 0.2rem 0; }
.result-meta strong { color: var(--ink); }

/* ------------------------------------------------------------------ Automivy */
.automivy-row { display: flex; flex-wrap: wrap; gap: 0.6rem; }
.automivy-row input { flex: 1 1 22rem; width: auto; }

/* ------------------------------------------------------------------ Mes vidéos */
.library-head { display: flex; align-items: center; gap: 0.8rem; flex-wrap: wrap; }
.library-head h2 { margin: 0 auto 0 0; }
.library-count, .library-spend { font-family: var(--font-mono); font-size: 0.8rem; color: var(--muted); font-weight: 400; }
.library-head input[type="search"] { width: min(18rem, 100%); }
.library-list { list-style: none; margin: 1rem 0 0; padding: 0; display: grid; gap: 0.5rem; }
.library-row { display: flex; align-items: center; gap: 0.9rem; padding: 0.55rem 0.7rem; border: 1px solid var(--line); border-radius: 8px; background: #fafbf9; }
.library-row img { width: 45px; height: 80px; object-fit: cover; border-radius: 6px; background: #000; flex: none; }
.library-row img.no-thumb { visibility: hidden; }
.library-row-text { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.library-row-text strong { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.library-row-text span { font-family: var(--font-mono); font-size: 0.74rem; color: var(--muted); }
.library-actions { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-top: 0.5rem; }
.library-actions .button, .library-row .button { padding: 0.35rem 0.7rem; font-size: 0.8rem; }
.library-actions a.button { color: inherit; }
.library-dialog { width: min(26rem, 94vw); max-height: 94vh; overflow-y: auto; border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; background: var(--card); color: var(--ink); }
.library-dialog::backdrop { background: rgba(6, 61, 46, 0.6); }
.library-dialog-head { display: flex; justify-content: space-between; align-items: center; gap: 0.6rem; }
.library-dialog-head h3 { margin: 0; font-size: 1rem; }
.library-dialog video { width: 100%; max-height: 60vh; margin-top: 0.6rem; border-radius: 8px; background: #000; }
.library-info { margin: 0.4rem 0; font-size: 0.8rem; color: var(--muted); }
.library-caption { width: 100%; font-size: 0.82rem; margin-top: 0.5rem; }
#library-more { margin-top: 0.8rem; }

/* ------------------------------------------------------------------ Publication */
.publish { display: grid; gap: 1.25rem; grid-template-columns: minmax(0, 1fr); align-items: start; }
.publish > .panel { margin-top: 0; }
@media (min-width: 1200px) { .publish { grid-template-columns: minmax(0, 1fr) minmax(0, 1.2fr); } .publish > :last-child { grid-column: 1 / -1; } }
.publish-targets { border: 1px solid var(--line); border-radius: 8px; margin: 1rem 0; padding: 0.6rem 0.9rem; display: flex; flex-wrap: wrap; gap: 0.3rem 1.2rem; }
.publish-targets legend { padding: 0 0.4rem; font-size: 0.8rem; font-weight: 600; color: var(--muted); }
.publish-targets label { display: flex; align-items: center; gap: 0.4rem; margin: 0.2rem 0; font-weight: 500; }
.publish-calendar { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.7rem; max-height: 70vh; overflow: auto; }
.pub-post { border: 1px solid var(--line); border-radius: 8px; padding: 0.9rem; background: #fafbf9; }
.pub-post h3 { margin: 0 0 0.2rem; font-size: 1rem; }
.pub-date { font-family: var(--font-mono); font-size: 0.74rem; color: var(--muted); }
.pub-target { display: flex; flex-wrap: wrap; align-items: center; gap: 0.4rem 0.7rem; padding: 0.5rem 0; border-top: 1px dashed var(--line); font-size: 0.85rem; }
.pub-badge { padding: 0.1rem 0.6rem; border-radius: 99px; font-size: 0.72rem; font-weight: 700; background: #f4e6c8; color: var(--amber); }
.pub-badge[data-status="published"] { background: #d3eee3; color: var(--signal); }
.pub-badge[data-status="failed"] { background: #f7d9d4; color: var(--alert); }
.pub-target label { display: flex; align-items: center; gap: 0.25rem; margin: 0; font-size: 0.78rem; }
.pub-target input[type="number"] { width: 4.6rem; padding: 0.25rem 0.4rem; }
.pub-target .button { padding: 0.25rem 0.7rem; font-size: 0.78rem; }
.pub-error { flex-basis: 100%; color: var(--alert); font-size: 0.8rem; }
.publish-accounts { display: grid; gap: 0.8rem; grid-template-columns: repeat(auto-fit, minmax(15rem, 1fr)); }
.pub-account { border: 1px solid var(--line); border-radius: 8px; padding: 0.9rem; display: grid; gap: 0.4rem; background: #fafbf9; }
.pub-account h3 { margin: 0; font-size: 1rem; }
.pub-account .hint { font-size: 0.78rem; margin: 0; }
.publish-ideas { display: grid; gap: 0.75rem; margin-top: 1rem; }
.publish-idea { display: grid; gap: 0.35rem; padding: 1rem; border: 1px solid var(--line); border-left: 3px solid var(--tally); border-radius: 8px; }
.publish-idea p { margin: 0; white-space: pre-wrap; }
.publish-idea small { color: var(--muted); }

/* ------------------------------------------------------------------ Réglages */
.settings #llm-model { min-height: 12rem; }
.settings input[type="password"], .settings input[type="search"] { max-width: 34rem; }
.llm-tabs { display: flex; flex-wrap: wrap; gap: 0.4rem; margin: 0.9rem 0; }
.llm-tabs button[aria-pressed="true"] { background: var(--ink); color: #fff; border-color: var(--ink); }
.llm-table-wrap { overflow-x: auto; margin-top: 0.75rem; }
.llm-table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
.llm-table th, .llm-table td { padding: 0.5rem 0.6rem; text-align: left; border-bottom: 1px solid var(--line); white-space: nowrap; font-family: var(--font-mono); font-size: 0.8rem; }
.llm-table td:first-child { white-space: normal; min-width: 14rem; font-family: var(--font); font-size: 0.88rem; }
.llm-table th { font-family: var(--font); font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); }
.usage-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(16rem, 1fr)); gap: 1rem; margin: 1rem 0 1.25rem; }
.usage-card { border: 1px solid var(--line); border-radius: 8px; padding: 1rem; background: #fafbf9; }
.usage-card h3 { margin: 0 0 0.5rem; font-size: 0.95rem; }
.usage-card p { margin: 0; font-size: 0.88rem; }
.usage-cost { font-family: var(--font-mono); font-size: 0.82rem; font-weight: 600; margin: 0.4rem 0 !important; }
.usage-sub { font-size: 0.8rem; color: var(--muted); }
.usage-bars { margin-top: 0.75rem; display: grid; gap: 0.45rem; }
.usage-bar-row { display: grid; grid-template-columns: 7rem 1fr 4.5rem; gap: 0.5rem; align-items: center; font-size: 0.78rem; }
.usage-bar-track { height: 0.4rem; border-radius: 99px; background: #dfe4dc; overflow: hidden; }
.usage-bar-fill { height: 100%; border-radius: inherit; background: var(--tally); }
.usage-recent { margin: 0.7rem 0 0; padding-left: 1.1rem; font-size: 0.8rem; color: var(--muted); }
.stack-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(20rem, 1fr)); gap: 1rem; }
.stack-card { border: 1px solid var(--line); border-radius: 8px; padding: 1rem; background: #fafbf9; }
.stack-card h3 { margin: 0 0 0.6rem; font-size: 1.05rem; }
.stack-card ul { margin: 0; padding-left: 1.1rem; color: var(--muted); }

/* ------------------------------------------------------------------ une vue à la fois */
body[data-view] [data-view] { display: none; }
body[data-view="automivy"] [data-view="automivy"],
body[data-view="series"] [data-view="series"],
body[data-view="videos"] [data-view="videos"],
body[data-view="settings"] [data-view="settings"] { display: block; }
body[data-view="studio"] [data-view="studio"] { display: block; }
body[data-view="studio"] .workspace[data-view="studio"] { display: grid; }
body[data-view="publish"] [data-view="publish"] { display: block; }
body[data-view="publish"] .publish[data-view="publish"] { display: grid; }

.nav-logout {
  margin-top: 0.75rem;
  width: 100%;
  border: 1px solid var(--bay-line);
  background: transparent;
  color: var(--bay-text);
  border-radius: 8px;
  padding: 0.55rem 0.7rem;
  font: inherit;
  cursor: pointer;
  text-align: left;
}
.nav-logout:hover { background: rgba(255, 255, 255, 0.06); color: #fff; }

body.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  background:
    radial-gradient(circle at top left, rgba(226, 58, 31, 0.12), transparent 40%),
    linear-gradient(160deg, #063d2e 0%, #0a2a22 45%, #eef0eb 45%);
}
.login-card {
  width: min(26rem, calc(100vw - 2rem));
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 1.5rem;
  box-shadow: 0 18px 50px rgba(6, 61, 46, 0.18);
}
.login-card h1 { margin: 1rem 0 0.4rem; font-size: 1.6rem; }
.login-card .hint { margin: 0 0 1.1rem; color: var(--muted); font-size: 0.9rem; }
.login-form { display: grid; gap: 0.85rem; }
.login-form label { display: grid; gap: 0.35rem; font-size: 0.88rem; color: var(--muted); }
.login-form input {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.7rem 0.8rem;
  font: inherit;
  color: var(--ink);
  background: #fff;
}
.login-error { margin: 0; color: var(--alert); font-size: 0.88rem; }
.login-form .button { width: 100%; }

/* ------------------------------------------------------------------ mobile : le rail devient une barre en haut */
@media (max-width: 899px) {
  .sidenav { position: sticky; top: 0; inset: auto; width: auto; flex-direction: row; align-items: center; gap: 0.2rem; padding: 0.5rem 0.75rem; overflow-x: auto; }
  .brand-mark { padding: 0 0.6rem 0 0; }
  .nav-group, .nav-spacer, .sidenav a small { display: none; }
  .nav-logout { width: auto; margin-top: 0; white-space: nowrap; }
  .sidenav a { border-left: 0; border-bottom: 3px solid transparent; white-space: nowrap; border-radius: 6px; }
  .sidenav a[aria-current="page"] { border-bottom-color: var(--tally); }
  .stage, .footer { margin-left: 0; }
  .url-row { grid-template-columns: 1fr; }
  .url-row .button { padding: 0.8rem; }
}

@media (prefers-reduced-motion: reduce) { * { transition: none !important; scroll-behavior: auto !important; } }
