:root {
  --bg: #0e0f11;
  --panel: #16181b;
  --panel-2: #1c1f23;
  --line: #2a2e34;
  --line-soft: #22252a;
  --text: #e8e9eb;
  --muted: #9aa0a8;
  --faint: #6b7178;
  --accent: #e8a33d;
  --accent-ink: #1a1206;
  --ok: #4fb286;
  --warn: #e0b341;
  --bad: #e5625a;
  --run: #5aa2e5;
  --radius: 10px;
  --radius-sm: 6px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, monospace;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.5 var(--font); }
a { color: inherit; }
button, input, select, textarea { font: inherit; color: inherit; }
img, video { display: block; max-width: 100%; }

.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 24px;
  height: 52px; padding: 0 20px;
  background: rgba(14, 15, 17, .92); backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line-soft);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 600; text-decoration: none; letter-spacing: .2px; white-space: nowrap; }
.brand-mark { width: 18px; height: 18px; border-radius: 5px; background: var(--accent); position: relative; }
.brand-mark::after { content: ""; position: absolute; left: 7px; top: 5px; border-left: 6px solid var(--accent-ink); border-top: 4px solid transparent; border-bottom: 4px solid transparent; }
.nav { display: flex; gap: 4px; }
.nav a { padding: 6px 12px; border-radius: var(--radius-sm); text-decoration: none; color: var(--muted); }
.nav a:hover { color: var(--text); background: var(--panel); }
.nav a.active { color: var(--text); background: var(--panel-2); }
.topbar-jobs { margin-left: auto; display: flex; gap: 8px; }

.app { max-width: 1440px; margin: 0 auto; padding: 24px 20px 80px; }

h1 { font-size: 22px; font-weight: 600; margin: 0; letter-spacing: -.2px; }
h2 { font-size: 16px; font-weight: 600; margin: 0 0 12px; }
h3 { font-size: 13px; font-weight: 600; margin: 0 0 8px; color: var(--muted); text-transform: uppercase; letter-spacing: .6px; }
p { margin: 0 0 8px; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.mono { font-family: var(--mono); font-size: 12.5px; }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.spread { justify-content: space-between; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.grow { flex: 1; min-width: 0; }

.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head .sub { color: var(--muted); margin-top: 4px; }

.panel { background: var(--panel); border: 1px solid var(--line-soft); border-radius: var(--radius); padding: 16px; }
.panel + .panel { margin-top: 16px; }
.section { margin-top: 28px; }

.btn {
  display: inline-flex; align-items: center; gap: 8px;
  height: 34px; padding: 0 14px; border-radius: var(--radius-sm);
  border: 1px solid var(--line); background: var(--panel-2); color: var(--text);
  cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn:hover:not(:disabled) { border-color: #3a3f46; background: #23272c; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn.primary:hover:not(:disabled) { background: #f0b252; }
.btn.danger { color: var(--bad); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.ghost:hover:not(:disabled) { color: var(--text); background: var(--panel-2); }
.btn.small { height: 28px; padding: 0 10px; font-size: 13px; }

.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 12px; color: var(--muted); }
.field .hint { font-size: 12px; color: var(--faint); }
input[type=text], input[type=number], input[type=password], select, textarea {
  width: 100%; padding: 8px 10px; border-radius: var(--radius-sm);
  background: var(--bg); border: 1px solid var(--line); outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
textarea { resize: vertical; min-height: 72px; line-height: 1.45; }
textarea.code { font-family: var(--mono); font-size: 12.5px; min-height: 420px; }

.login-page { min-height: 100vh; background: radial-gradient(circle at 50% -10%, #24201a 0, var(--bg) 42%); }
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-card { width: min(100%, 410px); padding: 32px; background: rgba(22, 24, 27, .96); border: 1px solid var(--line); border-radius: 16px; box-shadow: 0 24px 80px rgba(0, 0, 0, .35); }
.login-brand { display: flex; align-items: center; gap: 10px; margin-bottom: 32px; font-weight: 600; letter-spacing: .2px; }
.login-card h1 { margin-bottom: 8px; }
.login-form { display: flex; flex-direction: column; gap: 8px; margin-top: 24px; }
.login-form label { color: var(--muted); font-size: 12px; }
.login-form input[type=password] { height: 42px; font-size: 16px; }
.login-form .btn { justify-content: center; height: 42px; margin-top: 8px; }
.login-error { padding: 10px 12px; margin-top: 16px; border: 1px solid rgba(229, 98, 90, .45); border-radius: var(--radius-sm); color: #ffaaa5; background: rgba(229, 98, 90, .1); }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.form-grid .wide { grid-column: 1 / -1; }

.voice-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 14px; align-items: end; padding: 12px 0; border-top: 1px solid var(--line-soft); }
.voice-row:first-of-type { border-top: 0; padding-top: 0; }
.voice-main { min-width: 0; }
.voice-actions { display: flex; flex-direction: column; gap: 8px; align-items: stretch; min-width: 190px; }
.voice-preview { width: 190px; max-width: 100%; height: 30px; }
.voice-candidates { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 12px; }
.voice-card { display: flex; flex-direction: column; gap: 8px; padding: 12px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--panel-2); }
.voice-card audio { width: 100%; height: 30px; }

.chip { display: inline-flex; align-items: center; gap: 6px; height: 22px; padding: 0 8px; border-radius: 999px; font-size: 12px; background: var(--panel-2); color: var(--muted); border: 1px solid var(--line-soft); white-space: nowrap; }
.chip::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--faint); }
.chip.done::before { background: var(--ok); }
.chip.review::before, .chip.attention::before { background: var(--warn); }
.chip.ready::before { background: var(--accent); }
.chip.running::before, .chip.queued::before { background: var(--run); animation: pulse 1.2s infinite; }
.chip.error::before, .chip.interrupted::before { background: var(--bad); }
.chip.plain::before { display: none; }
@keyframes pulse { 50% { opacity: .35; } }

.grid { display: grid; gap: 16px; }
.projects { grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }
.project-card { display: flex; flex-direction: column; text-decoration: none; overflow: hidden; padding: 0; transition: border-color .15s; }
.project-card:hover { border-color: var(--line); }
.cover { aspect-ratio: 16 / 9; background: var(--panel-2) center / cover no-repeat; border-bottom: 1px solid var(--line-soft); display: grid; place-items: center; color: var(--faint); }
.project-card .body { padding: 14px; display: flex; flex-direction: column; gap: 8px; }
.project-card .title { font-weight: 600; font-size: 15px; }
.project-card .logline { color: var(--muted); font-size: 13px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; min-height: 38px; }
.stagebar { display: grid; grid-template-columns: repeat(9, 1fr); gap: 3px; }
.stagebar span { height: 4px; border-radius: 2px; background: var(--line); }
.stagebar .done { background: var(--ok); }
.stagebar .review, .stagebar .attention { background: var(--warn); }
.stagebar .ready { background: var(--accent); }
.stagebar .running, .stagebar .queued { background: var(--run); }
.stagebar .error { background: var(--bad); }
.meta { display: flex; gap: 14px; color: var(--faint); font-size: 12.5px; flex-wrap: wrap; }

.new-card { display: grid; place-items: center; min-height: 260px; border-style: dashed; color: var(--muted); cursor: pointer; }
.new-card:hover { color: var(--text); border-color: var(--line); }

.thumbs { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 10px; }
.thumb { position: relative; border-radius: var(--radius-sm); overflow: hidden; background: var(--panel-2); aspect-ratio: 9 / 16; border: 1px solid var(--line-soft); cursor: pointer; }
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.thumb .cap { position: absolute; left: 0; right: 0; bottom: 0; padding: 18px 8px 6px; font-size: 11.5px; background: linear-gradient(transparent, rgba(0,0,0,.8)); }

.split { display: grid; grid-template-columns: 2fr 1fr; gap: 16px; }
.money { font-size: 26px; font-weight: 600; letter-spacing: -.5px; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 16px; font-size: 13px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: var(--radius-sm); overflow: hidden; }
.seg button { border: 0; background: transparent; padding: 4px 10px; color: var(--muted); cursor: pointer; }
.seg button.on { background: var(--panel-2); color: var(--text); }

/* Workspace */
.workspace { display: grid; grid-template-columns: 236px minmax(0, 1fr); gap: 20px; align-items: start; }
.stages { position: sticky; top: 72px; display: flex; flex-direction: column; gap: 2px; }
.stage-link { display: grid; grid-template-columns: 22px 1fr; gap: 2px 8px; padding: 9px 10px; border-radius: var(--radius-sm); text-decoration: none; color: var(--muted); }
.stage-link:hover { background: var(--panel); color: var(--text); }
.stage-link.active { background: var(--panel-2); color: var(--text); }
.stage-link .num { grid-row: span 2; width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; font-size: 11px; border: 1px solid var(--line); color: var(--faint); }
.stage-link .num.done { background: var(--ok); border-color: var(--ok); color: #08130e; }
.stage-link .num.review, .stage-link .num.attention { border-color: var(--warn); color: var(--warn); }
.stage-link .num.ready { border-color: var(--accent); color: var(--accent); }
.stage-link .num.running { border-color: var(--run); color: var(--run); }
.stage-link .num.error { border-color: var(--bad); color: var(--bad); }
.stage-link .name { font-weight: 500; }
.stage-link .note { font-size: 11.5px; color: var(--faint); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.ws-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
.ws-head .facts { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.notice { padding: 10px 12px; border-radius: var(--radius-sm); background: var(--panel-2); border: 1px solid var(--line-soft); color: var(--muted); font-size: 13px; }
.notice.warn { border-color: rgba(224,179,65,.35); color: #e8cf8a; }
.notice.bad { border-color: rgba(229,98,90,.4); color: #f0a49f; }
.notice.good { border-color: rgba(79,178,134,.35); color: #9fd8bd; }
.notice ul { margin: 6px 0 0; padding-left: 18px; }

.scenes { grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); }
.scene-card { padding: 0; overflow: hidden; display: flex; flex-direction: column; cursor: pointer; }
.scene-card:hover { border-color: var(--line); }
.scene-card .shot { aspect-ratio: 9 / 16; max-height: 260px; background: var(--panel-2) center / cover no-repeat; display: grid; place-items: center; color: var(--faint); font-size: 12px; }
.scene-card.wide .shot { aspect-ratio: 16 / 9; }
.scene-card .body { padding: 10px 12px 12px; display: flex; flex-direction: column; gap: 6px; }
.scene-card .text { font-size: 12.5px; color: var(--muted); display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }

.list { display: flex; flex-direction: column; }
.list-row { display: grid; grid-template-columns: 64px minmax(0, 1fr) auto; gap: 14px; align-items: center; padding: 12px 0; border-top: 1px solid var(--line-soft); }
.list-row:first-child { border-top: 0; }
.mini { width: 64px; aspect-ratio: 9 / 16; border-radius: 5px; background: var(--panel-2) center / cover no-repeat; border: 1px solid var(--line-soft); }
.takes { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.take { width: 54px; aspect-ratio: 9 / 16; border-radius: 5px; border: 1px solid var(--line); background: var(--panel-2); font-size: 11px; color: var(--faint); display: grid; place-items: center; cursor: pointer; position: relative; overflow: hidden; }
.take.active { border-color: var(--accent); color: var(--accent); }
.take.bad { color: var(--bad); }
audio { width: 100%; height: 34px; }

.lines-editor .line { display: grid; grid-template-columns: 1.2fr 3fr 70px 90px 32px; gap: 8px; align-items: start; }

.drawer-back { position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 40; }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(560px, 100%); background: var(--panel); border-left: 1px solid var(--line); z-index: 41; display: flex; flex-direction: column; }
.drawer-head { padding: 16px 20px; border-bottom: 1px solid var(--line-soft); display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.drawer-body { padding: 18px 20px; overflow: auto; flex: 1; display: flex; flex-direction: column; gap: 14px; }
.drawer-foot { padding: 14px 20px; border-top: 1px solid var(--line-soft); display: flex; gap: 10px; justify-content: flex-end; }

.modal-back { position: fixed; inset: 0; background: rgba(0,0,0,.6); z-index: 50; display: grid; place-items: center; padding: 16px; }
.modal { width: min(520px, 100%); background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; display: flex; flex-direction: column; gap: 14px; max-height: 90vh; overflow: auto; }
.modal video { max-height: 70vh; margin: 0 auto; border-radius: var(--radius-sm); }
.modal.video { width: auto; max-width: min(900px, 100%); }
.price { font-size: 28px; font-weight: 600; }

.job { display: flex; flex-direction: column; gap: 6px; }
.job .log { font-family: var(--mono); font-size: 12px; color: var(--muted); background: var(--bg); border: 1px solid var(--line-soft); border-radius: var(--radius-sm); padding: 8px 10px; max-height: 180px; overflow: auto; white-space: pre-wrap; }

.sheet { overflow-x: auto; border-radius: var(--radius-sm); border: 1px solid var(--line-soft); }
.sheet img { max-width: none; height: 160px; }

.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%) translateY(20px); background: var(--panel-2); border: 1px solid var(--line); padding: 10px 16px; border-radius: var(--radius-sm); opacity: 0; transition: .2s; pointer-events: none; z-index: 60; max-width: calc(100% - 32px); }
.toast.show { opacity: 1; transform: translateX(-50%); pointer-events: auto; }
.toast { display: flex; align-items: center; gap: 12px; }
.toast-close { border: 0; background: transparent; color: var(--muted); font-size: 18px; line-height: 1; cursor: pointer; padding: 0 2px; }
.toast-close:hover { color: var(--text); }
.toast.bad { border-color: var(--bad); }

.empty { padding: 32px; text-align: center; color: var(--muted); }
.loading { padding: 48px; text-align: center; color: var(--faint); }

@media (max-width: 1000px) {
  .split { grid-template-columns: 1fr; }
  .workspace { grid-template-columns: 1fr; }
  .stages { position: static; flex-direction: row; overflow-x: auto; gap: 6px; padding-bottom: 4px; }
  .stage-link { grid-template-columns: 22px auto; min-width: 150px; }
}
@media (max-width: 640px) {
  .app { padding: 16px 16px 64px; }
  .topbar { height: auto; min-height: 52px; flex-wrap: wrap; gap: 8px 12px; padding: 10px 16px; }
  .nav { order: 3; flex: 0 0 100%; width: 100%; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 4px; }
  .nav a { padding: 7px 8px; text-align: center; }
  .topbar-jobs { display: none; }
  .form-grid { grid-template-columns: 1fr; }
  .voice-row { grid-template-columns: 1fr; }
  .voice-actions { min-width: 0; }
  .voice-preview { width: 100%; }
  .lines-editor .line { grid-template-columns: 1fr 1fr; }
  .lines-editor .line textarea { grid-column: 1 / -1; }
  .list-row { grid-template-columns: 52px minmax(0, 1fr); }
  .list-row > :last-child { grid-column: 1 / -1; }
  .scenes { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
