:root {
  --bg: #111317; --panel: #1a1d23; --panel2: #22262e; --line: #2f343d; --text: #e7e9ee; --muted: #9aa1ad;
  --accent: #f2b33d; --accent2: #4fa3ff; --ok: #3fbf6f; --bad: #e25555; --warn: #e2a355;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font-size: 14px; }
h2, h3 { font-weight: 600; margin: 18px 0 10px; }
h3 { font-size: 15px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.hidden { display: none !important; }
button, .btn { background: var(--panel2); color: var(--text); border: 1px solid var(--line); border-radius: 6px;
  padding: 7px 12px; cursor: pointer; font-size: 13px; display: inline-flex; align-items: center; gap: 6px; }
button:hover, .btn:hover { border-color: var(--accent); }
button.primary { background: var(--accent); color: #111; border-color: var(--accent); font-weight: 600; }
button.primary:disabled { opacity: .5; cursor: default; }
button.ghost { background: transparent; }
button.big { width: 100%; padding: 12px; font-size: 15px; margin: 10px 0 6px; }
button.small { padding: 3px 8px; font-size: 12px; }
input, select, textarea { background: var(--panel2); color: var(--text); border: 1px solid var(--line); border-radius: 6px;
  padding: 6px 8px; font: inherit; }
textarea { width: 100%; min-height: 70px; resize: vertical; }
input[type=number] { width: 70px; }
label { color: var(--muted); display: inline-flex; gap: 6px; align-items: center; }
label.check { gap: 4px; }

.topbar { display: flex; align-items: center; gap: 18px; padding: 10px 18px; border-bottom: 1px solid var(--line); background: #0c0d10; }
.brand { font-weight: 700; font-size: 18px; letter-spacing: .02em; }
.brand small { color: var(--muted); font-weight: 400; font-size: 12px; margin-left: 4px; }
.logo { color: var(--accent); }
.project-picker { display: flex; gap: 8px; flex: 1; }
.project-picker select { min-width: 220px; }
.health { display: flex; gap: 12px; color: var(--muted); font-size: 12px; }
.dot::before { content: "●"; margin-right: 4px; color: var(--muted); }
.dot.ok::before { color: var(--ok); } .dot.bad::before { color: var(--bad); }

.tabs { display: flex; gap: 2px; padding: 0 18px; border-bottom: 1px solid var(--line); background: #0f1114; }
.tabs button { border: none; border-bottom: 2px solid transparent; border-radius: 0; background: transparent; padding: 11px 14px; color: var(--muted); }
.tabs button.active { color: var(--text); border-bottom-color: var(--accent); }
.spacer { flex: 1; }
.badge { background: var(--accent2); color: #fff; border-radius: 9px; padding: 0 6px; font-size: 11px; }

main { padding: 16px 18px 60px; }
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 14px; }
.hint { color: var(--muted); font-size: 12px; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 16px; }

.scene-list { display: grid; gap: 14px; }
.scene { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.scene-head { display: flex; align-items: center; gap: 10px; padding: 10px 14px; background: var(--panel2); }
.scene-head b { font-family: "Courier New", monospace; font-size: 14px; }
.tag { font-size: 11px; padding: 2px 7px; border-radius: 10px; background: #2b3039; color: var(--muted); }
.tag.ok { background: #1f3d2a; color: #8be0a8; } .tag.warn { background: #3d331f; color: #e8c37d; }
.scene-body { display: grid; grid-template-columns: 1.2fr 1fr; gap: 0; }
.script { font-family: "Courier New", monospace; font-size: 12.5px; padding: 12px 16px; max-height: 420px; overflow: auto; border-right: 1px solid var(--line); }
.script .blk { margin: 0 0 8px; }
.script .bid { color: #5d6573; margin-right: 6px; font-size: 11px; }
.script .dlg { margin-left: 70px; }
.script .cue { margin-left: 140px; display: block; }
.enh { padding: 12px 16px; font-size: 13px; }
.enh dt { color: var(--muted); font-size: 11px; text-transform: uppercase; margin-top: 8px; }
.enh dd { margin: 2px 0 0; }

.shot-scene { margin-bottom: 26px; }
.shot-row { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 12px; }
.shot { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; overflow: hidden; display: flex; flex-direction: column; }
.shot .thumb { aspect-ratio: 16/9; background: #0b0c0f; position: relative; display: flex; align-items: center; justify-content: center; color: #555; font-size: 12px; }
.shot .thumb img { width: 100%; height: 100%; object-fit: cover; }
.shot .thumb .lbl { position: absolute; left: 6px; top: 6px; background: rgba(0,0,0,.65); padding: 1px 6px; border-radius: 4px; font-size: 11px; color: #ddd; }
.thumb-switch { display: flex; gap: 4px; padding: 6px 8px 0; flex-wrap: wrap; }
.thumb-switch button { padding: 2px 6px; font-size: 11px; }
.thumb-switch button.on { border-color: var(--accent); color: var(--accent); }
.shot .meta { padding: 8px 10px; font-size: 12.5px; flex: 1; }
.shot .meta .t { font-weight: 600; color: var(--accent); }
.shot .meta .d { color: var(--text); margin: 4px 0; }
.shot .meta .q { color: var(--muted); font-style: italic; }
.shot .actions { display: flex; gap: 6px; padding: 8px 10px; border-top: 1px solid var(--line); flex-wrap: wrap; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 10px; font-size: 12.5px; }
.card .imgs { display: flex; gap: 6px; margin-bottom: 8px; }
.card .imgs img, .card .imgs .ph { width: 50%; aspect-ratio: 3/4; object-fit: cover; border-radius: 6px; background: #0b0c0f; display: flex; align-items: center; justify-content: center; color: #555; font-size: 11px; }
.card .imgs.wide img, .card .imgs.wide .ph { width: 100%; aspect-ratio: 16/9; }
.card b { font-size: 14px; }
.card p { margin: 4px 0; color: var(--muted); }

.set { display: grid; grid-template-columns: 1.4fr 1fr; gap: 14px; margin-bottom: 20px; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 12px; }
.set img { width: 100%; border-radius: 8px; background: #0b0c0f; }
.set ul { margin: 6px 0; padding-left: 18px; font-size: 12px; color: var(--muted); max-height: 300px; overflow: auto; }
.topdown { width: 100%; background: #0b0c0f; border-radius: 8px; }

.sb-layout { display: grid; grid-template-columns: 320px 1fr; gap: 16px; align-items: start; }
.sb-controls label { display: flex; justify-content: space-between; margin: 8px 0; }
.sb-controls select[multiple] { width: 170px; }
.checklist { list-style: none; padding: 0; margin: 0; }
.checklist li { padding: 7px 0; border-bottom: 1px solid var(--line); display: flex; gap: 8px; align-items: flex-start; }
.checklist .st { width: 18px; }
.checklist small { color: var(--muted); display: block; }
.frames { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 14px; }
.frame { background: #fff; color: #111; border-radius: 6px; padding: 8px; font-size: 12px; }
.frame img { width: 100%; border: 2px solid #111; display: block; }
.frame .cap { padding-top: 6px; }
.frame .cap b { display: block; }
.scene-title { grid-column: 1 / -1; color: var(--accent); font-family: "Courier New", monospace; margin-top: 10px; }

.job { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 10px 14px; margin-bottom: 10px; }
.job .row { display: flex; gap: 10px; align-items: center; }
.job .kind { font-weight: 600; }
.job .status { font-size: 11px; padding: 2px 8px; border-radius: 10px; background: #2b3039; }
.job .status.running { background: #1f3550; color: #9cc8ff; } .job .status.done { background: #1f3d2a; color: #8be0a8; }
.job .status.failed { background: #4a2020; color: #ffb0b0; }
.bar { height: 6px; background: #2b3039; border-radius: 3px; margin: 8px 0; overflow: hidden; }
.bar > div { height: 100%; background: var(--accent2); transition: width .4s; }
.job pre { background: #0b0c0f; padding: 8px; border-radius: 6px; max-height: 220px; overflow: auto; font-size: 11.5px; white-space: pre-wrap; }

.model { color: var(--muted); font-size: 11px; margin: 3px 0; cursor: help; }
.frame .model { color: #666; }
.direction { color: var(--accent2); font-size: 12px; margin: 3px 0; }
table.usage { width: 100%; border-collapse: collapse; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; font-size: 13px; }
table.usage th, table.usage td { padding: 7px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
table.usage th { color: var(--muted); font-weight: 600; font-size: 12px; }
table.usage td.n { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
table.usage td.models { font-size: 11.5px; color: var(--muted); }
table.usage tr.total td { font-weight: 700; border-top: 2px solid var(--line); }
dialog:has(table.usage) { width: min(1100px, 96vw); }

dialog { background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 12px; width: min(720px, 94vw); padding: 18px; }
dialog::backdrop { background: rgba(0,0,0,.6); }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }
.form-grid { display: grid; grid-template-columns: 140px 1fr; gap: 8px 10px; align-items: center; }
.form-grid label { justify-content: flex-end; }
.form-grid textarea, .form-grid input, .form-grid select { width: 100%; }
.toast { position: fixed; right: 20px; bottom: 20px; background: var(--panel2); border: 1px solid var(--accent); padding: 10px 14px; border-radius: 8px; max-width: 420px; z-index: 10; }

@media (max-width: 900px) {
  .scene-body, .set, .sb-layout { grid-template-columns: 1fr; }
  .script { border-right: none; border-bottom: 1px solid var(--line); }
  .topbar { flex-wrap: wrap; }
}

/* grid-storyboard flow */
.shot .meta .visual { color: var(--text); opacity: .85; margin: 6px 0; font-size: 12.5px; line-height: 1.45; white-space: pre-wrap; }
.shot-row { grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); }
.card .imgs .slot { width: 50%; display: flex; flex-direction: column; gap: 4px; }
.card .imgs.wide .slot { width: 100%; }
.card .imgs .slot img, .card .imgs .slot .ph { width: 100%; aspect-ratio: 3/4; object-fit: cover; border-radius: 6px; background: #0b0c0f;
  display: flex; align-items: center; justify-content: center; color: #555; font-size: 11px; border: 1px dashed var(--line); }
.card .imgs.wide .slot img, .card .imgs.wide .slot .ph { aspect-ratio: 16/9; }
.slot-actions { display: flex; gap: 4px; }
.sheet { margin-bottom: 28px; }
.sheet-head { margin-bottom: 6px; }
.frame .ph16 { aspect-ratio: 16/9; background: #ddd; display: flex; align-items: center; justify-content: center; color: #777; }
.frame details { margin-top: 4px; color: #333; }
.frame details summary { cursor: pointer; color: #666; font-size: 11.5px; }
.frame .direction { color: #2a6db5; }
.frame button.ghost { color: #333; border-color: #ccc; margin-top: 4px; }
.models-form { max-width: 760px; }
.models-form h3.span { grid-column: 1 / -1; margin: 14px 0 2px; }
.health .dot { white-space: nowrap; }
