:root {
  --bg: #fdf6ee; --bg2: #eaf4ff; --ink: #2f2a3b; --muted: #7b7489; --line: #ece4da;
  --card: #ffffff; --card2: #faf6f1; --accent: #ff7aa2; --accent-ink: #ffffff;
  --ok: #3fae7a; --warn: #f0a23a; --bad: #e25c6a; --shadow: 0 10px 30px rgba(60, 40, 80, .12);
  --r: 18px;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #1d1b26; --bg2: #262338; --ink: #f3eef8; --muted: #a79fb8; --line: #3a3549; --card: #292536; --card2: #221f2d; --shadow: 0 10px 30px rgba(0,0,0,.35); }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink); font-family: 'Nunito', system-ui, sans-serif; -webkit-font-smoothing: antialiased; }
h1, h2, h3, .brand { font-family: 'Fredoka', 'Nunito', sans-serif; letter-spacing: .2px; }
button { font: inherit; color: inherit; cursor: pointer; }
input, textarea, select { font: inherit; color: var(--ink); background: var(--card); border: 1.5px solid var(--line); border-radius: 12px; padding: 10px 12px; width: 100%; }
textarea { min-height: 110px; resize: vertical; }
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--accent); }
[hidden] { display: none !important; }

.btn { border: none; border-radius: 12px; padding: 10px 16px; font-weight: 800; background: var(--card2); border: 1.5px solid var(--line); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn.ok { background: var(--ok); color: #fff; border-color: transparent; }
.btn.ghost { background: transparent; }
.btn.small { padding: 6px 10px; font-size: 13px; border-radius: 10px; }
.btn:disabled { opacity: .5; cursor: wait; }
.linkish { background: none; border: none; color: var(--accent); font-weight: 800; text-decoration: underline; padding: 0; }
.icon-btn { position: relative; width: 42px; height: 42px; border-radius: 14px; border: 1.5px solid var(--line); background: var(--card); display: grid; place-items: center; font-size: 18px; box-shadow: var(--shadow); }
.icon-btn .count { position: absolute; top: -6px; right: -6px; min-width: 20px; height: 20px; padding: 0 5px; border-radius: 10px; background: var(--accent); color: #fff; font-size: 12px; font-weight: 800; display: grid; place-items: center; }

/* Connexion */
.login { position: fixed; inset: 0; display: grid; place-items: center; background: radial-gradient(circle at 30% 20%, #ffe1ec, transparent 50%), radial-gradient(circle at 80% 80%, #d9f0e2, transparent 50%), var(--bg); padding: 16px; }
.login-card { width: min(360px, 100%); background: var(--card); border-radius: 24px; padding: 32px 24px; box-shadow: var(--shadow); text-align: center; display: grid; gap: 12px; }
.login-card h1 { margin: 0; font-size: 30px; }
.login-card p { margin: 0 0 8px; color: var(--muted); }
.login-logo { font-size: 48px; }
.login-error { color: var(--bad); font-weight: 700; }

/* Scène */
.scene { position: fixed; inset: 0; background: linear-gradient(180deg, var(--bg2) 0%, var(--bg) 70%); transition: background 2s; }
.scene[data-night="1"] { background: linear-gradient(180deg, #2a2d52 0%, #4a3d62 100%); }
.scene canvas { display: block; touch-action: none; }
.labels { position: absolute; inset: 0; pointer-events: none; }
.label { position: absolute; left: 0; top: 0; pointer-events: auto; display: flex; align-items: center; gap: 6px; padding: 6px 12px; border-radius: 999px; border: none;
  background: var(--card); color: var(--ink); font-weight: 800; font-size: 13px; white-space: nowrap; box-shadow: 0 6px 16px rgba(60,40,80,.18); border-bottom: 3px solid var(--c); transition: opacity .2s; }
.label .badge { background: var(--accent); color: #fff; border-radius: 999px; min-width: 20px; height: 20px; padding: 0 6px; display: grid; place-items: center; font-size: 12px; }
.label.alert::after { content: '!'; background: var(--bad); color: #fff; border-radius: 50%; width: 18px; height: 18px; display: grid; place-items: center; font-size: 12px; }

/* Barre du haut */
.topbar { position: fixed; top: 0; left: 0; right: 0; display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: calc(env(safe-area-inset-top) + 12px) 16px 12px; pointer-events: none; }
.topbar > * { pointer-events: auto; }
.brand { display: flex; align-items: center; gap: 8px; font-size: 20px; font-weight: 700; background: var(--card); padding: 8px 14px; border-radius: 14px; box-shadow: var(--shadow); }
.top-pills { display: flex; gap: 8px; flex: 1; justify-content: center; flex-wrap: wrap; }
.pill { background: var(--card); border-radius: 999px; padding: 7px 12px; font-size: 13px; font-weight: 700; box-shadow: var(--shadow); display: flex; gap: 8px; align-items: center; }
.pill .bar { width: 60px; height: 6px; border-radius: 3px; background: var(--line); overflow: hidden; }
.pill .bar i { display: block; height: 100%; background: var(--ok); }
.prov { display: inline-flex; align-items: center; gap: 4px; }
.prov::before { content: ''; width: 8px; height: 8px; border-radius: 50%; background: var(--line); }
.prov.on::before { background: var(--ok); }
.top-actions { display: flex; gap: 8px; }
.banner { position: fixed; top: calc(env(safe-area-inset-top) + 70px); left: 50%; transform: translateX(-50%); width: min(560px, calc(100% - 32px)); background: #fff4d6; color: #5c4515; padding: 10px 14px; border-radius: 14px; font-size: 14px; box-shadow: var(--shadow); text-align: center; }

/* Barre de commande */
.command { position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom) + 16px); transform: translateX(-50%); width: min(640px, calc(100% - 32px)); display: flex; gap: 8px; background: var(--card); padding: 8px; border-radius: 18px; box-shadow: var(--shadow); }
.command input { border: none; background: transparent; }
.command-reply { position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom) + 84px); transform: translateX(-50%); width: min(640px, calc(100% - 32px)); max-height: 45vh; overflow: auto; background: var(--card); border-radius: 18px; padding: 16px; box-shadow: var(--shadow); }

/* Panneau latéral / feuille mobile */
.panel { position: fixed; top: 80px; right: 16px; bottom: 90px; width: min(460px, calc(100% - 32px)); background: var(--card); border-radius: 24px; box-shadow: var(--shadow); display: flex; flex-direction: column; overflow: hidden; animation: slidein .25s ease; }
@keyframes slidein { from { transform: translateX(30px); opacity: 0; } }
.panel-grip { display: none; }
.panel-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 16px 8px; }
.panel-head .icon-btn { box-shadow: none; }
.panel-title { display: flex; align-items: center; gap: 10px; }
.panel-title h2 { margin: 0; font-size: 22px; }
.dot { width: 14px; height: 14px; border-radius: 5px; }
.tabs { display: flex; gap: 6px; padding: 0 16px 10px; overflow-x: auto; }
.tabs button { border: none; background: var(--card2); border-radius: 999px; padding: 7px 13px; font-weight: 800; font-size: 13px; white-space: nowrap; color: var(--muted); }
.tabs button.on { background: var(--ink); color: var(--card); }
.panel-body { flex: 1; overflow: auto; padding: 4px 16px 20px; }
@media (max-width: 760px) {
  .panel { top: auto; left: 0; right: 0; bottom: 0; width: 100%; height: 78vh; border-radius: 24px 24px 0 0; animation: slideup .25s ease; padding-bottom: env(safe-area-inset-bottom); }
  @keyframes slideup { from { transform: translateY(40px); opacity: 0; } }
  .panel-grip { display: block; width: 44px; height: 5px; border-radius: 3px; background: var(--line); margin: 8px auto 0; }
  .brand span:last-child { display: none; }
  .top-pills { justify-content: flex-start; }
  .pill.providers { display: none; }
  .hide-m { display: none; }
  .label { font-size: 12px; padding: 5px 10px; }
  .banner { font-size: 13px; top: calc(env(safe-area-inset-top) + 64px); }
}
@media (min-width: 761px) { .show-m { display: none; } }

/* Cartes */
.card { background: var(--card2); border-radius: var(--r); padding: 14px; margin-bottom: 10px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.row { display: flex; align-items: center; gap: 8px; }
.row.between { justify-content: space-between; }
.wrap { flex-wrap: wrap; }
.agent-head { display: flex; gap: 10px; align-items: center; }
.avatar { width: 42px; height: 42px; border-radius: 14px; display: grid; place-items: center; font-size: 22px; background: var(--card); flex: none; }
.agent-name { font-weight: 800; }
.tag { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; font-weight: 800; padding: 3px 8px; border-radius: 999px; background: var(--card); color: var(--muted); }
.tag.claude { color: #c2693e; } .tag.openai { color: #2e9a74; } .tag.gemini { color: #4f7de0; } .tag.auto { color: var(--muted); }
.task { display: grid; gap: 4px; padding: 10px 0; border-top: 1px dashed var(--line); }
.task:first-of-type { border-top: none; }
.task-title { font-weight: 700; }
.status { font-size: 12px; font-weight: 800; padding: 3px 9px; border-radius: 999px; background: var(--card); }
.status.pending_approval { background: #ffe6ee; color: #c23d6a; }
.status.executed, .status.approved, .status.done { background: #dff5e9; color: #22794f; }
.status.failed { background: #fde2e4; color: #b3303e; }
.status.rejected { background: var(--line); color: var(--muted); }
.status.running { background: #e5eeff; color: #3b62c4; }
.run { cursor: pointer; }
.run:hover { outline: 2px solid var(--line); }
.kpis { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 10px; }
.kpi { background: var(--card2); border-radius: var(--r); padding: 14px; }
.kpi b { display: block; font-family: 'Fredoka', 'Nunito', system-ui, sans-serif; font-size: 24px; }
.kpi span { color: var(--muted); font-size: 13px; font-weight: 700; }
.kpi em { font-style: normal; font-size: 12px; font-weight: 800; }
.goal { height: 10px; background: var(--card); border-radius: 5px; overflow: hidden; margin-top: 6px; }
.goal i { display: block; height: 100%; border-radius: 5px; }
.chart { width: 100%; height: 140px; }
.md { line-height: 1.55; font-size: 15px; overflow-wrap: anywhere; }
.md h1, .md h2, .md h3 { font-size: 17px; margin: 14px 0 6px; }
.md pre { background: var(--card2); padding: 10px; border-radius: 10px; overflow: auto; font-size: 12px; }
.md table { border-collapse: collapse; font-size: 13px; } .md td, .md th { border: 1px solid var(--line); padding: 4px 6px; }
.chat { display: grid; gap: 8px; max-height: 45vh; overflow: auto; margin: 8px 0; }
.bubble { padding: 10px 12px; border-radius: 14px; max-width: 90%; }
.bubble.user { background: var(--accent); color: #fff; justify-self: end; }
.bubble.assistant { background: var(--card); }
.empty { text-align: center; color: var(--muted); padding: 30px 10px; }
.field { display: grid; gap: 6px; margin-bottom: 12px; }
.field label { font-weight: 800; font-size: 13px; }
.switch { position: relative; width: 44px; height: 26px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch span { position: absolute; inset: 0; background: var(--line); border-radius: 13px; transition: .2s; }
.switch span::after { content: ''; position: absolute; left: 3px; top: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; transition: .2s; }
.switch input:checked + span { background: var(--ok); }
.switch input:checked + span::after { transform: translateX(18px); }

/* Fenêtre */
.modal { position: fixed; inset: 0; background: rgba(30, 20, 40, .35); display: grid; place-items: center; padding: 16px; z-index: 20; }
.modal-card { background: var(--card); border-radius: 24px; width: min(720px, 100%); max-height: 88vh; display: flex; flex-direction: column; box-shadow: var(--shadow); }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 16px 18px 8px; }
.modal-head h3 { margin: 0; font-size: 20px; }
.modal-head .icon-btn { box-shadow: none; }
.modal-body { overflow: auto; padding: 4px 18px 18px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 14px; position: sticky; bottom: -18px; background: var(--card); padding: 12px 0; }
.toast { position: fixed; top: calc(env(safe-area-inset-top) + 76px); left: 50%; transform: translateX(-50%); background: var(--ink); color: var(--card); padding: 10px 16px; border-radius: 12px; font-weight: 700; z-index: 30; max-width: calc(100% - 32px); }

/* Agence de clips */
.clip-filters { margin: 4px 0 12px; }
.clip-card { display: grid; grid-template-columns: 84px 1fr; gap: 12px; cursor: pointer; align-items: start; }
.clip-card:hover { outline: 2px solid var(--line); }
.clip-thumb { position: relative; aspect-ratio: 9 / 16; border-radius: 12px; overflow: hidden; background: #2f2a3b; display: grid; place-items: center; }
.clip-thumb img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.clip-thumb.big { width: 100%; max-height: 62vh; }
.clip-play, .clip-busy { position: relative; color: #fff; font-size: 22px; text-shadow: 0 2px 8px rgba(0,0,0,.5); }
.clip-info { display: grid; gap: 6px; min-width: 0; }
.clip-hook { font-weight: 800; font-family: 'Fredoka', 'Nunito', sans-serif; font-size: 15px; line-height: 1.25; }
.status.clip-pending { background: #ffe6ee; color: #c23d6a; }
.status.clip-published { background: #dff5e9; color: #22794f; }
.status.clip-processing, .status.clip-rerendering { background: #e5eeff; color: #3b62c4; }
.status.clip-kept { background: #fff1d6; color: #9a6512; }
.status.clip-rejected { background: var(--line); color: var(--muted); }
.status.clip-failed { background: #fde2e4; color: #b3303e; }
.live-dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; background: var(--line); margin-right: 6px; vertical-align: 1px; }
.live-dot.on { background: #ff3b5c; box-shadow: 0 0 0 3px rgba(255, 59, 92, .2); animation: pulse 1.6s infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 6px rgba(255, 59, 92, 0); } }
.robot.off { border: 1.5px dashed var(--bad); }
.robot code { font-size: 12px; }
.clip-modal { display: grid; grid-template-columns: minmax(200px, 280px) 1fr; gap: 18px; align-items: start; }
.clip-player { display: grid; gap: 8px; justify-items: start; position: sticky; top: 0; }
.clip-player video { width: 100%; aspect-ratio: 9 / 16; max-height: 62vh; border-radius: 14px; background: #000; object-fit: contain; }
.clip-edit .field { margin-bottom: 10px; }
.clip-edit details { margin: 4px 0 8px; }
@media (max-width: 760px) {
  .clip-modal { grid-template-columns: 1fr; }
  .clip-player { position: static; justify-items: center; }
  .clip-player video { max-height: 55vh; width: auto; max-width: 100%; }
}
.clip-info .row.between { flex-wrap: wrap; gap: 4px 8px; }
.clip-info .row.between b { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tag input[type=checkbox] { width: auto; margin: 0; }
a.btn { text-decoration: none; display: inline-block; }
