:root {
  --bg: #0b0e14; --panel: #11151c; --panel2: #171c25; --line: #232a36; --line2: #2f3846;
  --text: #e6e9ef; --muted: #8b95a7; --accent: #38bdf8; --accent2: #0ea5e9; --ok: #34d399; --warn: #fbbf24; --bad: #f87171;
  --radius: 10px; --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; --mono: ui-monospace, Consolas, monospace;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.45 var(--font); }
a { color: var(--accent); text-decoration: none; }
button, select, input, textarea { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0 0 .5rem; font-weight: 650; letter-spacing: -.01em; }
h1 { font-size: 1.5rem; } h2 { font-size: 1.15rem; } h3 { font-size: 1rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.mono { font-family: var(--mono); font-size: .82rem; }
code { font-family: var(--mono); font-size: .85em; background: var(--panel2); padding: .05em .35em; border-radius: 4px; }
pre { font-family: var(--mono); font-size: .8rem; background: var(--panel2); border: 1px solid var(--line); border-radius: 8px; padding: .75rem; overflow: auto; white-space: pre-wrap; word-break: break-word; margin: .5rem 0; }

/* ----- En-tête ----- */
.top { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 1.25rem; padding: .6rem 1.25rem; background: rgba(11,14,20,.92); backdrop-filter: blur(10px); border-bottom: 1px solid var(--line); }
.brand { font-weight: 800; font-size: 1.1rem; color: var(--text); letter-spacing: -.02em; }
.brand span { color: var(--accent); }
.tabs { display: flex; gap: .25rem; }
.tabs a { padding: .4rem .8rem; border-radius: 8px; color: var(--muted); font-weight: 500; }
.tabs a:hover { color: var(--text); background: var(--panel2); }
.tabs a.active { color: var(--text); background: var(--panel2); box-shadow: inset 0 -2px 0 var(--accent); }
.top-right { margin-left: auto; display: flex; align-items: center; gap: .75rem; }
.balances { display: flex; gap: .5rem; }
.balance { display: flex; flex-direction: column; align-items: flex-end; padding: .2rem .55rem; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); min-width: 84px; }
.balance b { font-size: .8rem; }
.balance .small { font-size: .7rem; text-transform: uppercase; letter-spacing: .04em; }
.balance.off { opacity: .45; }
.balance.err b { color: var(--bad); }
.icon-link { font-size: 1.25rem; color: var(--muted); padding: .2rem .4rem; border-radius: 8px; }
.icon-link.active, .icon-link:hover { color: var(--text); background: var(--panel2); }

/* ----- Mise en page ----- */
main { padding: 1.25rem; max-width: 1400px; margin: 0 auto; }
.page-head { display: flex; align-items: baseline; gap: 1rem; margin-bottom: 1rem; flex-wrap: wrap; }
.page-head .spacer { flex: 1; }
.grid { display: grid; gap: .9rem; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: .9rem; }
.card.clickable { cursor: pointer; transition: border-color .15s, transform .15s; }
.card.clickable:hover { border-color: var(--line2); transform: translateY(-1px); }
.card h3 { display: flex; align-items: center; gap: .5rem; }
.chips { display: flex; flex-wrap: wrap; gap: .3rem; margin-top: .5rem; }
.chip { font-size: .72rem; padding: .12rem .45rem; border-radius: 999px; background: var(--panel2); border: 1px solid var(--line); color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.chip.kie { color: #f0abfc; } .chip.fal { color: #a5b4fc; } .chip.wavespeed { color: #6ee7b7; }
.chip.sync { color: var(--warn); } .chip.manual { color: var(--ok); }
.empty { padding: 2.5rem; text-align: center; color: var(--muted); border: 1px dashed var(--line); border-radius: var(--radius); }

/* ----- Boutons et champs ----- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: .45rem; padding: .5rem .9rem; border-radius: 8px; border: 1px solid var(--line2); background: var(--panel2); color: var(--text); cursor: pointer; font-weight: 500; }
.btn:hover { border-color: var(--accent); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #04121c; font-weight: 700; }
.btn.primary:hover { background: #7dd3fc; }
.btn.danger { color: var(--bad); }
.btn.sm { padding: .3rem .6rem; font-size: .82rem; }
.btn .price { font-weight: 600; opacity: .85; font-family: var(--mono); font-size: .85em; }
.field { display: flex; flex-direction: column; gap: .25rem; margin-bottom: .7rem; }
.field label { font-size: .78rem; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; display: flex; justify-content: space-between; }
.field label b { color: var(--text); text-transform: none; letter-spacing: 0; font-family: var(--mono); font-weight: 500; }
select, input[type=text], input[type=number], input[type=password], textarea { width: 100%; background: var(--panel2); border: 1px solid var(--line); border-radius: 8px; padding: .45rem .6rem; color: var(--text); outline: none; }
select:focus, input:focus, textarea:focus { border-color: var(--accent); }
textarea { min-height: 96px; resize: vertical; }
input[type=range] { width: 100%; accent-color: var(--accent); }
.row { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; }
.row > .field { flex: 1; min-width: 120px; margin-bottom: 0; }
.check { display: flex; align-items: center; gap: .5rem; font-size: .9rem; }
.check input { accent-color: var(--accent); }

/* ----- Écran de génération ----- */
.gen { display: grid; grid-template-columns: 360px 1fr; gap: 1.25rem; align-items: start; }
@media (max-width: 900px) { .gen { grid-template-columns: 1fr; } }
.settings { position: sticky; top: 64px; }
.decision { margin-top: .75rem; font-size: .82rem; color: var(--muted); white-space: pre-wrap; border-left: 2px solid var(--line2); padding-left: .6rem; }
.decision.err { color: var(--bad); border-color: var(--bad); }
.history { display: flex; flex-direction: column; gap: .75rem; }
.job { display: grid; grid-template-columns: 220px 1fr; gap: .9rem; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: .75rem; }
@media (max-width: 700px) { .job { grid-template-columns: 1fr; } }
.job .media { background: #05070a; border-radius: 8px; overflow: hidden; display: flex; align-items: center; justify-content: center; min-height: 140px; position: relative; }
.job .media img, .job .media video { width: 100%; height: auto; display: block; max-height: 320px; object-fit: contain; }
.job .media audio { width: 100%; }
.job .media .state { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: .4rem; color: var(--muted); font-size: .85rem; }
.spinner { width: 22px; height: 22px; border: 2px solid var(--line2); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.job .info { display: flex; flex-direction: column; gap: .35rem; min-width: 0; }
.job .prompt { font-size: .92rem; white-space: pre-wrap; word-break: break-word; }
.job .meta { display: flex; flex-wrap: wrap; gap: .35rem .8rem; font-size: .78rem; color: var(--muted); }
.job .meta b { color: var(--text); font-weight: 500; }
.job .actions { display: flex; gap: .4rem; flex-wrap: wrap; margin-top: .25rem; }
.job.failed { border-color: rgba(248,113,113,.4); }
.badge { display: inline-block; font-size: .72rem; padding: .1rem .45rem; border-radius: 999px; border: 1px solid var(--line2); }
.badge.done { color: var(--ok); } .badge.failed { color: var(--bad); } .badge.running, .badge.queued { color: var(--warn); }
.progress { height: 3px; background: var(--line); border-radius: 2px; overflow: hidden; }
.progress > div { height: 100%; background: var(--accent); transition: width .5s; }

/* ----- Références (dépôt) ----- */
.dropzone { border: 1px dashed var(--line2); border-radius: 8px; padding: .7rem; text-align: center; color: var(--muted); font-size: .85rem; cursor: pointer; transition: border-color .15s, background .15s; }
.dropzone.over { border-color: var(--accent); background: rgba(56,189,248,.06); color: var(--text); }
.refs { display: flex; flex-wrap: wrap; gap: .4rem; margin-top: .5rem; }
.ref { position: relative; width: 64px; height: 64px; border-radius: 6px; overflow: hidden; border: 2px solid var(--line); background: #05070a; cursor: pointer; }
.ref.selected { border-color: var(--accent); }
.ref img, .ref video { width: 100%; height: 100%; object-fit: cover; }
.ref .kind { position: absolute; bottom: 0; left: 0; right: 0; background: rgba(0,0,0,.6); font-size: .6rem; text-align: center; padding: 1px; }
.ref .x { position: absolute; top: 0; right: 0; background: rgba(0,0,0,.7); color: #fff; font-size: .7rem; width: 16px; height: 16px; line-height: 16px; text-align: center; border-radius: 0 0 0 6px; }
.ref-slot { display: flex; align-items: center; gap: .5rem; padding: .35rem .5rem; border: 1px solid var(--line); border-radius: 8px; background: var(--panel2); font-size: .82rem; margin-bottom: .4rem; }
.ref-slot .thumb { width: 36px; height: 36px; border-radius: 4px; object-fit: cover; background: #05070a; }
.ref-slot .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ----- Accueil ----- */
.gallery { display: grid; gap: .9rem; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.tile { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; display: flex; flex-direction: column; }
.tile .media { background: #05070a; aspect-ratio: 16/10; display: flex; align-items: center; justify-content: center; }
.tile .media img, .tile .media video { width: 100%; height: 100%; object-fit: cover; }
.tile .media audio { width: 92%; }
.tile .body { padding: .6rem .75rem; display: flex; flex-direction: column; gap: .25rem; }
.tile .prompt { font-size: .85rem; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }

/* ----- Réglages ----- */
.settings-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 1rem; align-items: start; }
table { width: 100%; border-collapse: collapse; font-size: .85rem; }
th, td { text-align: left; padding: .4rem .5rem; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 500; font-size: .75rem; text-transform: uppercase; letter-spacing: .05em; }
td.num { text-align: right; font-family: var(--mono); }
.issue { padding: .3rem .5rem; border-left: 2px solid var(--warn); margin: .25rem 0; font-size: .82rem; }
.issue.error { border-color: var(--bad); }
.note { background: rgba(56,189,248,.07); border: 1px solid rgba(56,189,248,.25); border-radius: 8px; padding: .6rem .8rem; font-size: .85rem; margin: .5rem 0; }
.note.warn { background: rgba(251,191,36,.07); border-color: rgba(251,191,36,.3); }

/* ----- Notifications ----- */
#toasts { position: fixed; bottom: 1rem; right: 1rem; display: flex; flex-direction: column; gap: .5rem; z-index: 50; max-width: 420px; }
.toast { background: var(--panel2); border: 1px solid var(--line2); border-left: 3px solid var(--accent); border-radius: 8px; padding: .6rem .8rem; font-size: .85rem; box-shadow: 0 8px 30px rgba(0,0,0,.4); white-space: pre-wrap; }
.toast.err { border-left-color: var(--bad); }
.toast.ok { border-left-color: var(--ok); }
details summary { cursor: pointer; color: var(--muted); font-size: .85rem; }
