:root {
  --bg: #f6f5f8;
  --panel: #ffffff;
  --ink: #1f1d2b;
  --muted: #6b6880;
  --line: #e4e1ec;
  --accent: #c2185b;
  --accent-soft: #fce4ef;
  --accent-ink: #8e0f42;
  --ok: #1e8e5a;
  --ok-soft: #e3f5ec;
  --warn: #b26a00;
  --warn-soft: #fff3dc;
  --info: #2b5fd9;
  --info-soft: #e6eeff;
  --bad: #c62828;
  --bad-soft: #fdeaea;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(20, 16, 40, 0.06), 0 4px 16px rgba(20, 16, 40, 0.05);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: 'Segoe UI', 'Be Vietnam Pro', Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 14px;
  line-height: 1.5;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
h1, h2, h3, h4 { margin: 0; line-height: 1.25; }
h2 { font-size: 20px; }
h3 { font-size: 16px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.hidden { display: none !important; }

/* ---------- thanh trên ---------- */
.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: 16px;
  padding: 10px 24px; background: #1f1d2b; color: #fff;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 16px; cursor: pointer; white-space: nowrap; }
.brand .logo { width: 30px; height: 30px; border-radius: 8px; background: linear-gradient(135deg, #e91e63, #7b1fa2); display: grid; place-items: center; font-size: 15px; }
.topbar .project-name { font-weight: 600; opacity: 0.95; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar .spacer { flex: 1; }
.save-state { font-size: 12px; opacity: 0.8; white-space: nowrap; }
.api-badges { display: flex; gap: 6px; }
.api-badge { font-size: 11px; padding: 3px 8px; border-radius: 999px; background: rgba(255,255,255,0.1); white-space: nowrap; }
.api-badge.on { background: rgba(46, 204, 113, 0.25); }
.api-badge .dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; margin-right: 5px; background: #999; }
.api-badge.on .dot { background: #2ecc71; }
.topbar .btn { background: rgba(255,255,255,0.12); color: #fff; border-color: transparent; }
.topbar .btn:hover { background: rgba(255,255,255,0.2); }

/* ---------- nút ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px; justify-content: center;
  padding: 7px 14px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--panel); cursor: pointer; white-space: nowrap; font-weight: 500;
  transition: background 0.15s, border-color 0.15s;
}
.btn:hover { border-color: #c9c4d6; background: #faf9fc; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-ink); }
.btn.success { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn.danger { color: var(--bad); }
.btn.danger:hover { background: var(--bad-soft); border-color: var(--bad); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: rgba(0,0,0,0.05); }
.btn.sm { padding: 4px 9px; font-size: 12px; border-radius: 6px; }
.btn.icon { padding: 4px 7px; min-width: 28px; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* ---------- bố cục ---------- */
.container { max-width: 1440px; margin: 0 auto; padding: 20px 24px 60px; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.panel-pad { padding: 18px 20px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.row { display: flex; gap: 12px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.between { justify-content: space-between; }
.stack > * + * { margin-top: 12px; }
.section-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 16px; flex-wrap: wrap; }
.section-head p { margin: 4px 0 0; color: var(--muted); }

/* ---------- form ---------- */
label.field { display: block; }
label.field > span { display: block; font-size: 12px; font-weight: 600; color: var(--muted); margin-bottom: 4px; }
input[type=text], input[type=number], select, textarea {
  width: 100%; padding: 7px 10px; border: 1px solid var(--line); border-radius: 7px; background: #fff; outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
textarea { resize: vertical; min-height: 60px; }
textarea.script { min-height: 520px; font-family: 'JetBrains Mono', Consolas, monospace; font-size: 13.5px; line-height: 1.65; }
textarea.prompt { font-family: 'JetBrains Mono', Consolas, monospace; font-size: 12px; min-height: 170px; background: #fbfafd; }
textarea[readonly], input[readonly] { background: #f7f6fa; color: #444; }

/* ---------- stepper ---------- */
.stepper { display: flex; gap: 0; margin-bottom: 20px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; box-shadow: var(--shadow); }
.step {
  flex: 1; display: flex; align-items: center; gap: 10px; padding: 12px 16px; cursor: pointer; position: relative;
  border-right: 1px solid var(--line); background: var(--panel); min-width: 0;
}
.step:last-child { border-right: 0; }
.step:hover { background: #faf9fc; }
.step .num { width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; font-size: 13px; background: #eeecf3; color: var(--muted); flex: none; }
.step .label { font-weight: 600; white-space: nowrap; }
.step .sub { font-size: 11.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.step.done .num { background: var(--ok); color: #fff; }
.step.active { background: var(--accent-soft); }
.step.active .num { background: var(--accent); color: #fff; }
.step.active::after { content: ''; position: absolute; left: 0; right: 0; bottom: 0; height: 3px; background: var(--accent); }
.step.locked { cursor: not-allowed; opacity: 0.55; }
.step .arrow { margin-left: auto; color: #c9c4d6; }

/* ---------- banner ---------- */
.banner { display: flex; gap: 12px; align-items: center; padding: 10px 14px; border-radius: 8px; margin-bottom: 14px; border: 1px solid; }
.banner.ok { background: var(--ok-soft); border-color: #b9e3cd; color: #155c3b; }
.banner.warn { background: var(--warn-soft); border-color: #f2d7a6; color: #7a4a00; }
.banner.info { background: var(--info-soft); border-color: #c5d5fb; color: #1e3f8f; }
.banner .grow { flex: 1; }

/* ---------- trạng thái ---------- */
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px; border-radius: 999px; font-size: 11.5px; font-weight: 600; white-space: nowrap; }
.badge::before { content: ''; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.st-chua_tao { background: #eeecf3; color: #6b6880; }
.st-dang_xu_ly { background: var(--info-soft); color: var(--info); }
.st-hoan_thanh { background: var(--ok-soft); color: var(--ok); }
.st-can_lam_lai { background: var(--warn-soft); color: var(--warn); }
.st-dang_xu_ly::before { animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { opacity: 0.3; } }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px; border: 1px solid var(--line); background: #fff; cursor: pointer; font-size: 12.5px; user-select: none; }
.chip.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.chip img { width: 18px; height: 18px; border-radius: 50%; object-fit: cover; }
.tag { display: inline-block; font-size: 11px; padding: 1px 7px; border-radius: 5px; background: #eeecf3; color: var(--muted); }

/* ---------- trang chủ ---------- */
.home { display: grid; grid-template-columns: 1fr 380px; gap: 20px; align-items: start; }
.project-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; }
.project-card { cursor: pointer; overflow: hidden; display: flex; flex-direction: column; transition: transform 0.15s; }
.project-card:hover { transform: translateY(-2px); }
.project-card .cover { height: 140px; background: linear-gradient(135deg, #3d2c5c, #c2185b); display: flex; align-items: center; justify-content: center; overflow: hidden; }
.project-card .cover img { height: 100%; }
.project-card .body { padding: 12px 14px; }
.progress { height: 6px; background: #eeecf3; border-radius: 99px; overflow: hidden; }
.progress > div { height: 100%; background: var(--ok); }

/* ---------- nhân vật ---------- */
.char-layout { display: grid; grid-template-columns: 250px 1fr; gap: 16px; align-items: start; }
.char-list .item { display: flex; gap: 10px; align-items: center; padding: 10px 12px; cursor: pointer; border-bottom: 1px solid var(--line); }
.char-list .item:last-child { border-bottom: 0; }
.char-list .item.active { background: var(--accent-soft); }
.char-list .item img, .avatar { width: 40px; height: 40px; border-radius: 50%; object-fit: cover; background: #eeecf3; flex: none; }
.gallery { display: flex; gap: 10px; flex-wrap: wrap; }
.thumb { position: relative; width: 110px; height: 146px; border-radius: 8px; overflow: hidden; border: 1px solid var(--line); background: #f0eef5; }
.thumb img, .thumb video { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb .x { position: absolute; top: 4px; right: 4px; background: rgba(0,0,0,0.6); color: #fff; border: 0; border-radius: 5px; cursor: pointer; font-size: 12px; padding: 1px 6px; }
.thumb .star { position: absolute; left: 4px; bottom: 4px; font-size: 10.5px; background: var(--accent); color: #fff; padding: 1px 6px; border-radius: 4px; }
.upload-tile { width: 110px; height: 146px; border: 2px dashed #cfcadb; border-radius: 8px; display: grid; place-items: center; text-align: center; color: var(--muted); cursor: pointer; font-size: 12px; padding: 8px; background: #fbfafd; }
.upload-tile:hover { border-color: var(--accent); color: var(--accent); }
.outfit { border: 1px solid var(--line); border-radius: 8px; padding: 12px; }
.outfit.default { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
.identity-block { font-family: Consolas, monospace; font-size: 12px; background: #1f1d2b; color: #e8e6f0; padding: 12px; border-radius: 8px; white-space: pre-wrap; }

/* ---------- storyboard ---------- */
.scene { margin-bottom: 18px; }
.scene-head { display: grid; grid-template-columns: 36px 1.2fr 1.6fr 0.8fr auto; gap: 8px; align-items: center; padding: 10px 12px; border-bottom: 1px solid var(--line); background: #faf9fc; border-radius: var(--radius) var(--radius) 0 0; }
.scene-num { font-weight: 700; color: var(--accent); }
.shots { padding: 10px; display: flex; flex-direction: column; gap: 10px; min-height: 40px; }
.shot { border: 1px solid var(--line); border-radius: 9px; background: #fff; display: grid; grid-template-columns: 120px 1fr; gap: 12px; padding: 10px; }
.shot.dragging { opacity: 0.4; }
.shot.drop-before { box-shadow: 0 -3px 0 var(--accent); }
.shots.drop-end { box-shadow: inset 0 -3px 0 var(--accent); }
.shot-side { display: flex; flex-direction: column; gap: 6px; align-items: stretch; }
.shot-code { font-weight: 700; font-size: 13px; display: flex; align-items: center; gap: 6px; }
.drag-handle { cursor: grab; color: #aaa; user-select: none; }
.shot-ref { width: 100%; aspect-ratio: 9/16; border-radius: 6px; border: 1px dashed #cfcadb; background: #fbfafd; display: grid; place-items: center; overflow: hidden; cursor: pointer; color: var(--muted); font-size: 11px; text-align: center; position: relative; }
.shot-ref img, .shot-ref video { width: 100%; height: 100%; object-fit: cover; }
.shot-fields { display: grid; grid-template-columns: repeat(6, 1fr); gap: 8px 10px; }
.shot-fields .c2 { grid-column: span 2; }
.shot-fields .c3 { grid-column: span 3; }
.shot-fields .c4 { grid-column: span 4; }
.shot-fields .c6 { grid-column: span 6; }
.shot-fields textarea { min-height: 54px; }
.char-picker { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.char-picker select { width: auto; padding: 2px 6px; font-size: 12px; }
.readonly-mask input, .readonly-mask select, .readonly-mask textarea { pointer-events: none; background: #f7f6fa; }
.readonly-mask .chip { pointer-events: none; }
.summary-bar { display: flex; gap: 18px; align-items: center; padding: 10px 14px; flex-wrap: wrap; }
.summary-bar .stat b { font-size: 17px; }

/* ---------- video ---------- */
.video-row { display: grid; grid-template-columns: 150px 1fr 230px; gap: 14px; padding: 14px; border-bottom: 1px solid var(--line); }
.video-row:last-child { border-bottom: 0; }
.video-row .media { width: 150px; aspect-ratio: 9/16; background: #111; border-radius: 8px; overflow: hidden; display: grid; place-items: center; color: #888; font-size: 11px; text-align: center; }
.video-row .media video, .video-row .media img { width: 100%; height: 100%; object-fit: cover; }
.video-actions { display: flex; flex-direction: column; gap: 6px; }
.video-actions .btn { width: 100%; }
.mini-refs { display: flex; gap: 4px; flex-wrap: wrap; }
.mini-refs img { width: 34px; height: 45px; border-radius: 4px; object-fit: cover; border: 1px solid var(--line); }
.filters { display: flex; gap: 6px; flex-wrap: wrap; }
.job-error { color: var(--bad); font-size: 12px; }

/* ---------- dựng phim ---------- */
.edit-layout { display: grid; grid-template-columns: 1fr 380px; gap: 18px; align-items: start; }
.timeline-item { display: grid; grid-template-columns: 24px 64px 1fr auto; gap: 10px; align-items: center; padding: 8px 12px; border-bottom: 1px solid var(--line); }
.timeline-item.excluded { opacity: 0.45; }
.timeline-item.playing { background: var(--accent-soft); }
.timeline-item .tl-thumb { width: 64px; height: 86px; border-radius: 6px; overflow: hidden; background: #111; display: grid; place-items: center; color: #777; font-size: 10px; text-align: center; }
.timeline-item .tl-thumb video { width: 100%; height: 100%; object-fit: cover; }
.player { position: sticky; top: 70px; }
.player-frame { background: #000; border-radius: 12px; overflow: hidden; position: relative; margin: 0 auto; }
.player-frame video { width: 100%; height: 100%; display: block; object-fit: contain; background: #000; }
.player-frame .sub { position: absolute; left: 8%; right: 8%; bottom: 12%; text-align: center; color: #fff; font-weight: 600; text-shadow: 0 1px 4px #000, 0 0 2px #000; font-size: 15px; }
.player-frame .code { position: absolute; top: 10px; left: 10px; background: rgba(0,0,0,0.55); color: #fff; font-size: 11px; padding: 2px 8px; border-radius: 5px; }
.player-frame .empty { color: #aaa; display: grid; place-items: center; height: 100%; text-align: center; padding: 20px; }
.timebar { height: 8px; display: flex; gap: 2px; margin-top: 10px; }
.timebar > div { background: #d6d2e0; border-radius: 2px; cursor: pointer; }
.timebar > div.on { background: var(--accent); }

/* ---------- modal & toast ---------- */
.modal-back { position: fixed; inset: 0; background: rgba(20, 16, 40, 0.5); display: grid; place-items: center; z-index: 50; }
.modal { width: min(640px, 92vw); max-height: 90vh; overflow: auto; }
.toasts { position: fixed; right: 20px; bottom: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 60; }
.toast { background: #1f1d2b; color: #fff; padding: 10px 14px; border-radius: 8px; box-shadow: var(--shadow); max-width: 420px; animation: slide 0.2s; }
.toast.error { background: var(--bad); }
.toast.ok { background: var(--ok); }
@keyframes slide { from { transform: translateY(10px); opacity: 0; } }
.spinner { width: 14px; height: 14px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; display: inline-block; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.empty-state { text-align: center; padding: 40px 20px; color: var(--muted); }
kbd { background: #eeecf3; border-radius: 4px; padding: 0 5px; font-size: 12px; }

/* ===================== v2 ===================== */
input[type=email], input[type=password] { width: 100%; padding: 7px 10px; border: 1px solid var(--line); border-radius: 7px; background: #fff; outline: none; }
.mt { margin-top: 16px; } .mt-s { margin-top: 8px; }
.end { justify-content: flex-end; }
.block { width: 100%; }
.narrow { max-width: 760px; margin: 0 auto; }
.grid-2.top, .grid-3.top { align-items: start; }
.lbl, .field .lbl { display: block; font-size: 12px; font-weight: 600; color: var(--muted); margin-bottom: 4px; }
label.check { display: inline-flex; gap: 6px; align-items: center; margin-right: 12px; cursor: pointer; }
.pre { white-space: pre-wrap; word-break: break-word; }
.mono { font-family: Consolas, monospace; word-break: break-all; }
.warn-text { color: var(--warn); } .ok-text { color: var(--ok); }
.tag.bad { background: var(--bad-soft); color: var(--bad); font-weight: 600; }
input.missing { border-color: #f2b45a; background: #fffaf0; }
.btn.loading { position: relative; color: transparent !important; }
.btn.loading::after { content: ''; position: absolute; width: 14px; height: 14px; border: 2px solid var(--muted); border-right-color: transparent; border-radius: 50%; animation: spin 0.8s linear infinite; }
.brand.dark { color: var(--ink); margin-bottom: 6px; }
a.brand { color: #fff; text-decoration: none; }
.api-badge.mid .dot { background: #f1c40f; } .api-badge.bad .dot { background: #e74c3c; } .api-badge.on { background: rgba(46, 204, 113, 0.25); } .api-badge.on .dot { background: #2ecc71; }
.topbar a.btn { text-decoration: none; }

/* đăng nhập */
.auth-wrap { min-height: 70vh; display: grid; place-items: center; }
.auth-box { width: min(420px, 94vw); }
.auth-box form { margin-top: 12px; }

/* bảng, danh sách */
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { text-align: left; padding: 7px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
.table th { font-size: 12px; color: var(--muted); font-weight: 600; }
.table td.btn-row { display: table-cell; }
.table td.btn-row .btn { margin: 2px; }
.table.beats textarea, .table.beats input { min-height: 0; font-size: 12.5px; }
.table.beats tr.dialogue td:first-child { color: var(--accent); font-weight: 700; }
.list { display: flex; flex-direction: column; }
.list-item { display: flex; justify-content: space-between; gap: 8px; align-items: center; padding: 8px 4px; border-bottom: 1px solid var(--line); text-decoration: none; color: inherit; }
.list-item:hover { background: #faf9fc; }
.item-row { display: flex; gap: 10px; align-items: flex-start; padding: 8px 0; border-bottom: 1px solid var(--line); }
.grow { flex: 1; min-width: 0; }
.avatar.lg { width: 56px; height: 72px; border-radius: 8px; }
a.project-card { text-decoration: none; color: inherit; }

/* tab */
.tabs { display: flex; gap: 4px; flex-wrap: wrap; border-bottom: 1px solid var(--line); }
.tab { padding: 8px 14px; border: 0; background: none; cursor: pointer; border-bottom: 2px solid transparent; color: var(--muted); font-weight: 600; text-decoration: none; }
.tab.on { color: var(--accent); border-bottom-color: var(--accent); }

/* bước */
.stepper .step { text-decoration: none; color: inherit; }
.outline-scene { display: grid; grid-template-columns: 70px 1fr 1fr; gap: 6px; margin-bottom: 8px; align-items: start; }
.outline-scene textarea { grid-column: 2 / 4; min-height: 44px; }
.scene-box { border: 1px solid var(--line); border-radius: 8px; padding: 10px; margin-top: 10px; }
.diff { font-family: Consolas, monospace; font-size: 12.5px; background: #fbfafd; border: 1px solid var(--line); border-radius: 8px; padding: 8px; max-height: 50vh; overflow: auto; white-space: pre-wrap; }
.d-add { background: #e3f5ec; color: #155c3b; } .d-del { background: #fdeaea; color: #8e1c1c; text-decoration: line-through; }
.modal.wide { width: min(980px, 95vw); }
textarea.script.short { min-height: 220px; }

/* nhân vật */
.ref { margin: 0; width: 170px; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: #fff; }
.ref.approved { border-color: var(--ok); box-shadow: 0 0 0 2px var(--ok-soft); }
.ref img { width: 100%; aspect-ratio: 3/4; object-fit: cover; display: block; background: #f0eef5; }
.ref figcaption { padding: 6px 8px; font-size: 12px; }
.char-list .item .avatar { display: inline-block; }

/* storyboard */
.scene-label { font-weight: 700; color: var(--accent); margin: 14px 0 6px; }
.shot-card { display: grid; grid-template-columns: 130px 1fr; gap: 12px; border: 1px solid var(--line); border-radius: 10px; padding: 10px; margin-bottom: 10px; background: #fff; }
.shot-card.approved { border-left: 4px solid var(--ok); }
.shot-card.dragging { opacity: 0.4; } .shot-card.drop-before { box-shadow: 0 -3px 0 var(--accent); }
.shot-grid { display: grid; grid-template-columns: 1.2fr 2fr 1fr 0.7fr; gap: 8px; margin: 6px 0; }
.dialogue-line { background: var(--accent-soft); border-radius: 6px; padding: 6px 10px; }
.flags { background: var(--warn-soft); color: #7a4a00; border-radius: 6px; padding: 6px 10px; font-size: 12px; margin: 6px 0; }
.summary-bar .stat b { font-size: 16px; }

/* render */
.st-chua_render { background: #eeecf3; color: #6b6880; }
.st-da_co_clip { background: var(--info-soft); color: var(--info); }
.st-da_duyet { background: var(--ok-soft); color: var(--ok); }
.st-loi_tu_choi { background: var(--bad-soft); color: var(--bad); }
.qc { display: flex; flex-wrap: wrap; gap: 2px 10px; }
.qc textarea { width: 100%; min-height: 40px; }
.mini-video { width: 54px; height: 96px; object-fit: cover; background: #111; border-radius: 4px; }
.video-row .media { height: auto; }
.player-frame { max-height: 70vh; max-width: 100%; }
.player-frame video { width: 100%; height: 100%; }
@media (max-width: 1000px) { .home, .edit-layout, .char-layout, .grid-2, .grid-3 { grid-template-columns: 1fr; } .shot-grid { grid-template-columns: 1fr 1fr; } .video-row { grid-template-columns: 110px 1fr; } .video-row .video-actions { grid-column: span 2; flex-direction: row; flex-wrap: wrap; } }
a.btn { text-decoration: none; color: inherit; }
a.btn.primary { color: #fff; }
textarea.prompt { font-family: inherit; font-size: 13px; line-height: 1.55; }
.row select, .item-row select, .btn-row select { width: auto; max-width: 360px; }
