:root {
  --bg: #0a0e17;
  --panel: #0f1523;
  --panel-2: #131b2c;
  --panel-3: #182238;
  --elevated: #1c2740;
  --line: rgba(255, 255, 255, .07);
  --line-strong: rgba(255, 255, 255, .13);
  --fg: #eef2fb;
  --muted: #93a0bd;
  --faint: #66738f;
  --accent: #38bdf8;
  --accent-2: #a78bfa;
  --plot: #f5b942;
  --road: #38f5c8;
  --danger: #f4547b;
  --ok: #4ade80;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 12px 40px -12px rgba(0, 0, 0, .7);
  --ease: cubic-bezier(.16, 1, .3, 1);
  --topbar-h: 50px;
  --timeline-h: clamp(150px, 30vh, 260px);
  --tool-w: clamp(150px, 13vw, 196px);
  --insp-w: clamp(230px, 20vw, 320px);
  color-scheme: dark;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--fg); font: 13px/1.4 "Be Vietnam Pro", system-ui, sans-serif; overflow: hidden; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
kbd { font: 10px/1 ui-monospace, monospace; padding: 2px 5px; border-radius: 4px; background: var(--panel-3); border: 1px solid var(--line-strong); color: var(--muted); }
code { font-family: ui-monospace, monospace; background: var(--panel-3); padding: 1px 5px; border-radius: 4px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }

#app { display: grid; grid-template-rows: var(--topbar-h) minmax(0, 1fr) var(--timeline-h); height: 100vh; }

/* ===== Buttons ===== */
.btn { display: inline-flex; align-items: center; gap: 6px; height: 34px; padding: 0 14px; border-radius: var(--radius-sm); border: 1px solid var(--line-strong); background: var(--panel-2); font-weight: 600; white-space: nowrap; transition: background .15s, border-color .15s, transform .1s; }
.btn:hover { background: var(--panel-3); border-color: rgba(255,255,255,.2); }
.btn:active { transform: translateY(1px); }
.btn.ghost { background: transparent; }
.btn.ghost:hover { background: var(--panel-3); }
.btn.primary { background: linear-gradient(135deg, #3b82f6, #22d3ee); border-color: transparent; color: #04111f; box-shadow: 0 6px 20px -6px rgba(56,189,248,.6); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.accent { border-color: rgba(56,189,248,.45); color: var(--accent); background: rgba(56,189,248,.08); }
.btn.danger:hover { color: var(--danger); border-color: rgba(244,84,123,.5); }
.btn.sm { height: 28px; padding: 0 10px; font-size: 12px; }
.btn.icon-only { padding: 0; width: 34px; justify-content: center; }
.btn.sm.icon-only { width: 28px; }
.btn:disabled { opacity: .4; pointer-events: none; }

.seg { display: inline-flex; padding: 3px; gap: 2px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; }
.seg-btn { display: inline-flex; align-items: center; gap: 6px; border: 0; background: transparent; padding: 5px 12px; border-radius: 7px; color: var(--muted); font-weight: 600; font-size: 12px; }
.seg-btn:hover { color: var(--fg); }
.seg-btn.is-active { background: var(--elevated); color: var(--fg); box-shadow: inset 0 0 0 1px var(--line-strong); }
.ar { display: inline-block; border: 1.5px solid currentColor; border-radius: 2px; }
.ar-l { width: 14px; height: 9px; } .ar-p { width: 8px; height: 13px; } .ar-s { width: 11px; height: 11px; }

/* ===== Topbar ===== */
.topbar { display: flex; align-items: center; gap: 10px; padding: 0 12px; min-width: 0; overflow: hidden; white-space: nowrap; background: var(--panel); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 9px; }
.brand-name { font-family: Montserrat, sans-serif; font-weight: 800; font-size: 16px; letter-spacing: -.2px; }
.brand-name b { font-weight: 600; color: var(--accent); margin-left: 2px; }
.project-name input { width: 100%; background: transparent; border: 1px solid transparent; border-radius: 6px; padding: 5px 8px; color: var(--muted); font-weight: 500; }
.project-name input:hover { border-color: var(--line); }
.project-name input:focus { outline: none; border-color: var(--accent); color: var(--fg); background: var(--panel-2); }
.topbar-right { margin-left: auto; display: flex; gap: 6px; align-items: center; flex: none; }
.topbar .seg-btn { padding: 5px 10px; white-space: nowrap; }
.project-name { min-width: 0; flex: 0 1 220px; }

/* ===== Workspace ===== */
.workspace { display: grid; grid-template-columns: var(--tool-w) minmax(0, 1fr) var(--insp-w); min-height: 0; }

.toolbar { display: grid; grid-template-columns: 1fr 1fr; grid-auto-rows: max-content; align-content: start; gap: 4px; padding: 8px 6px; background: var(--panel); border-right: 1px solid var(--line); overflow-y: auto; }
.tool-sep { grid-column: 1 / -1; height: 1px; background: var(--line); margin: 4px 2px; }
.tool { position: relative; display: flex; flex-direction: column; align-items: center; justify-content: flex-start; gap: 4px; min-height: 56px; padding: 6px 3px 5px; border: 1px solid transparent; border-radius: var(--radius-sm); background: var(--panel-2); color: var(--muted); text-align: center; font-size: 11px; font-weight: 600; line-height: 1.2; }
.tool:hover { background: var(--panel-3); color: var(--fg); }
.tool.is-active { background: rgba(56,189,248,.12); border-color: rgba(56,189,248,.45); color: var(--fg); }
.tool .ti { width: 24px; height: 24px; flex: none; display: grid; place-items: center; border-radius: 8px; background: var(--panel-3); font-size: 15px; }
.tool.is-active .ti { background: var(--accent); color: #04111f; }
.tool span:last-child { display: flex; flex-direction: column; }
.tool small { font-size: 9px; color: var(--faint); font-weight: 500; }
.tool-pro { background: linear-gradient(160deg, rgba(167,139,250,.12), var(--panel-2) 60%); }
.tool.soon { opacity: .55; }
.tool.soon::after { content: "SẮP CÓ"; position: absolute; top: 3px; right: 3px; font-size: 7.5px; font-weight: 800; letter-spacing: .04em; padding: 1px 4px; border-radius: 4px; background: var(--panel-3); color: var(--faint); }
.badge-new { position: absolute; top: 3px; right: 3px; font-size: 7.5px; font-weight: 800; padding: 1px 4px; border-radius: 4px; background: #f43f5e; color: #fff; }

/* ===== Stage ===== */
.stage { position: relative; display: flex; flex-direction: column; min-width: 0; min-height: 0; background: radial-gradient(ellipse at 50% 40%, #121a2b 0%, var(--bg) 70%); }
.map-controls { position: relative; z-index: 20; display: flex; align-items: center; flex-wrap: nowrap; gap: 8px; padding: 6px 10px; border-bottom: 1px solid var(--line); background: rgba(15,21,35,.7); }
.mc-group { display: flex; align-items: center; gap: 8px; }
.mc-label { font-size: 11px; color: var(--faint); font-weight: 600; }
.mc-check { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 12px; cursor: pointer; }
.mc-check input { accent-color: var(--accent); }
.mc-search { position: relative; margin-left: auto; flex: 0 1 240px; min-width: 110px; }
.mc-seg .seg-btn { padding: 4px 9px; }
.mc-more { position: relative; }
.mc-pop { position: absolute; right: 0; top: 36px; z-index: 60; width: 270px; display: flex; flex-direction: column; gap: 10px; padding: 12px; background: var(--elevated); border: 1px solid var(--line-strong); border-radius: 12px; box-shadow: var(--shadow); }
.mc-row { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); }
.mc-row > span { width: 72px; flex: none; }
.mc-row select, .mc-row input[type=range] { flex: 1; min-width: 0; }
.mc-hint { margin: 0; font-size: 11px; color: var(--faint); }
.mc-select { height: 28px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 7px; padding: 0 6px; font-size: 12px; }
.mc-slider { display: flex; align-items: center; gap: 4px; color: var(--muted); font-size: 12px; }
.mc-slider input { accent-color: var(--accent); }
.mc-slider output { width: 32px; font: 10px ui-monospace, monospace; color: var(--faint); }
.btn.is-on { border-color: rgba(56,189,248,.5); background: rgba(56,189,248,.12); }
.bg-pick { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 12px; font-weight: 600; cursor: pointer; }
.bg-pick input { width: 26px; height: 26px; padding: 0; border: 1px solid var(--line-strong); border-radius: 6px; background: none; }
.safe-guides { position: absolute; inset: 0; pointer-events: none; }
.safe-guides i { position: absolute; border: 0 dashed rgba(255,255,255,.55); }
.safe-guides .g-v { left: 50%; top: 0; bottom: 0; border-left-width: 1px; }
.safe-guides .g-h { top: 50%; left: 0; right: 0; border-top-width: 1px; }
.safe-guides .g-safe { inset: 5% 5%; border-width: 1px; border-color: rgba(250,204,21,.6); }
.canvas-frame:fullscreen { border-radius: 0; background: #000; }
.mc-search input { width: 100%; height: 30px; padding: 0 10px 0 30px; background: var(--panel-2) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%2393a0bd' stroke-width='2.4'%3E%3Ccircle cx='11' cy='11' r='7'/%3E%3Cpath d='m20 20-4-4'/%3E%3C/svg%3E") no-repeat 10px center; border: 1px solid var(--line); border-radius: 8px; }
.mc-search input:focus { outline: none; border-color: var(--accent); }
.loc-suggest { position: absolute; right: 0; top: 34px; width: 320px; max-height: 300px; overflow-y: auto; z-index: 50; background: var(--elevated); border: 1px solid var(--line-strong); border-radius: 10px; box-shadow: var(--shadow); padding: 4px; }
.loc-suggest button { display: block; width: 100%; text-align: left; border: 0; background: transparent; padding: 7px 9px; border-radius: 6px; font-size: 12px; }
.loc-suggest button:hover { background: var(--panel-3); }
.loc-suggest small { display: block; color: var(--faint); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.stage-area { position: relative; flex: 1; min-height: 0; display: grid; place-items: center; padding: 10px; overflow: hidden; }
.canvas-frame { position: relative; overflow: hidden; border-radius: 6px; background: #000; box-shadow: 0 0 0 1px var(--line-strong), 0 24px 60px -20px rgba(0,0,0,.9); }
#map { position: absolute; inset: 0; }
.overlay-canvas { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.frame-badge { position: absolute; top: 8px; left: 8px; padding: 3px 8px; border-radius: 6px; background: rgba(0,0,0,.55); font: 600 10px/1.4 ui-monospace, monospace; color: #cbd5e1; pointer-events: none; backdrop-filter: blur(4px); }
.draw-hint { position: absolute; left: 50%; bottom: 12px; transform: translateX(-50%); padding: 7px 12px; border-radius: 8px; background: rgba(10,14,23,.85); border: 1px solid var(--line-strong); font-size: 12px; color: var(--fg); pointer-events: none; white-space: nowrap; }
.canvas-frame.drawing .maplibregl-canvas { cursor: crosshair; }
.maplibregl-ctrl-attrib { font-size: 9px; opacity: .7; }
.maplibregl-ctrl-bottom-right { pointer-events: none; }

.transport { display: flex; align-items: center; gap: 6px; padding: 5px 12px; border-top: 1px solid var(--line); background: var(--panel); }
.tbtn { width: 28px; height: 28px; border-radius: 50%; border: 1px solid var(--line-strong); background: var(--panel-2); display: grid; place-items: center; font-size: 12px; }
.tbtn:hover { background: var(--panel-3); }
.tbtn.play { width: 34px; height: 34px; font-size: 14px; background: var(--fg); color: #04111f; border: 0; }
.time { margin-left: 8px; font: 500 13px ui-monospace, monospace; color: var(--muted); }
.time b { color: var(--fg); }
.stage-hint { margin-left: auto; font-size: 11px; color: var(--faint); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ===== Inspector ===== */
.inspector { background: var(--panel); border-left: 1px solid var(--line); overflow-y: auto; }
.inspector-empty { height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; padding: 24px; color: var(--muted); }
.inspector-empty p { margin: 10px 0 4px; font-weight: 600; color: var(--fg); }
.inspector-empty small { color: var(--faint); }
.ie-icon { width: 54px; height: 54px; border-radius: 14px; display: grid; place-items: center; background: var(--panel-2); border: 1px dashed var(--line-strong); font-size: 22px; color: var(--faint); }
.insp-head { display: flex; align-items: center; gap: 8px; padding: 12px 14px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--panel); z-index: 2; }
.insp-head .badge { font-size: 10px; font-weight: 700; padding: 3px 7px; border-radius: 5px; text-transform: uppercase; letter-spacing: .05em; }
.insp-head input { flex: 1; min-width: 0; background: transparent; border: 1px solid transparent; border-radius: 6px; padding: 4px 6px; font-weight: 600; }
.insp-head input:focus { outline: none; border-color: var(--accent); background: var(--panel-2); }
.insp-sec { padding: 12px 14px; border-bottom: 1px solid var(--line); }
.insp-sec h4 { margin: 0 0 10px; font-size: 10px; letter-spacing: .08em; text-transform: uppercase; color: var(--faint); }
.prop { display: grid; grid-template-columns: 96px 1fr; align-items: center; gap: 8px; margin-bottom: 8px; }
.prop > * { min-width: 0; }
.prop > span { color: var(--muted); font-size: 12px; }
.prop.full { grid-template-columns: 1fr; }
.prop input[type=text], .prop input[type=number], .prop select, .prop textarea, .field input, .field select { width: 100%; background: var(--panel-2); border: 1px solid var(--line); border-radius: 7px; padding: 6px 8px; }
.prop textarea { resize: vertical; min-height: 54px; }
.prop input:focus, .prop select:focus, .prop textarea:focus, .field input:focus, .field select:focus { outline: none; border-color: var(--accent); }
.prop .range { display: flex; align-items: center; gap: 8px; }
.prop .range input[type=range] { flex: 1; accent-color: var(--accent); }
.prop .range output { width: 38px; text-align: right; font: 11px ui-monospace, monospace; color: var(--muted); }
.prop input[type=color] { width: 100%; height: 30px; padding: 2px; border: 1px solid var(--line); border-radius: 7px; background: var(--panel-2); }
.swatches { display: flex; gap: 5px; flex-wrap: wrap; margin-top: 6px; }
.swatches button { width: 18px; height: 18px; border-radius: 5px; border: 1px solid rgba(255,255,255,.2); padding: 0; }
.prop .toggle { justify-self: start; }
.toggle { position: relative; width: 34px; height: 20px; appearance: none; background: var(--panel-3); border-radius: 20px; border: 1px solid var(--line-strong); cursor: pointer; transition: background .15s; }
.toggle::after { content: ""; position: absolute; top: 2px; left: 2px; width: 14px; height: 14px; border-radius: 50%; background: var(--muted); transition: transform .2s var(--ease), background .15s; }
.toggle:checked { background: var(--accent); }
.toggle:checked::after { transform: translateX(14px); background: #fff; }
.insp-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.kf-list { display: flex; flex-direction: column; gap: 4px; }
.kf-row { display: flex; align-items: center; gap: 8px; padding: 6px 8px; border-radius: 7px; background: var(--panel-2); font-size: 12px; }
.kf-row b { color: #fbbf24; font-family: ui-monospace, monospace; }
.kf-row span { flex: 1; color: var(--muted); font-size: 11px; }

/* ===== Timeline ===== */
.timeline { position: relative; display: flex; flex-direction: column; min-height: 0; background: var(--panel); border-top: 1px solid var(--line); }
.tl-resize { position: absolute; top: -4px; left: 0; right: 0; height: 8px; cursor: ns-resize; z-index: 5; }
.tl-resize:hover { background: rgba(56,189,248,.35); }
.tl-ruler .mk { position: absolute; top: 0; bottom: 0; width: 0; cursor: pointer; z-index: 2; }
.tl-ruler .mk::before { content: ""; position: absolute; left: -1px; top: 0; bottom: 0; width: 2px; background: #22d3ee; }
.tl-ruler .mk span { position: absolute; left: 2px; top: 1px; font-size: 9px; font-weight: 700; padding: 0 4px; border-radius: 3px; background: #22d3ee; color: #04111f; white-space: nowrap; }
.tl-mkline { position: absolute; top: 26px; bottom: 0; width: 0; border-left: 1px dashed rgba(34,211,238,.4); pointer-events: none; z-index: 1; }
.tl-bar { display: flex; align-items: center; gap: 5px; padding: 5px 10px; border-bottom: 1px solid var(--line); overflow-x: auto; overflow-y: hidden; white-space: nowrap; scrollbar-width: thin; }
.tl-bar > * { flex: none; }
.tl-title { font-weight: 700; margin-right: 6px; }
.tl-sep { width: 1px; height: 18px; background: var(--line-strong); margin: 0 4px; }
.tl-spacer { flex: 1; }
.tl-dur { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 12px; }
.tl-dur input { width: 60px; height: 28px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 6px; padding: 0 6px; }
#zoomRange { width: 110px; accent-color: var(--accent); }
.tl-body { flex: 1; display: grid; grid-template-columns: clamp(130px, 12vw, 180px) 1fr; min-height: 0; }
.tl-labels { overflow: hidden; border-right: 1px solid var(--line); padding-top: 26px; background: var(--panel); }
.tl-label { height: 28px; display: flex; align-items: center; gap: 7px; padding: 0 8px 0 10px; border-bottom: 1px solid var(--line); font-size: 12px; color: var(--muted); cursor: pointer; }
.tl-label:hover { background: var(--panel-2); }
.tl-label.is-selected { background: rgba(56,189,248,.1); color: var(--fg); }
.tl-label .dot { width: 8px; height: 8px; border-radius: 2px; flex: none; }
.tl-label .nm { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tl-label button { border: 0; background: transparent; color: var(--faint); padding: 2px; font-size: 12px; opacity: 0; }
.tl-label:hover button, .tl-label button.off { opacity: 1; }
.tl-label button.off { color: var(--danger); }
.tl-scroll { position: relative; overflow: auto; }
.tl-inner { position: relative; min-height: 100%; }
.tl-ruler { position: sticky; top: 0; height: 26px; z-index: 3; background: var(--panel-2); border-bottom: 1px solid var(--line); cursor: ew-resize; }
.tl-ruler .tick { position: absolute; bottom: 0; width: 1px; background: var(--line-strong); height: 6px; }
.tl-ruler .tick.major { height: 11px; background: rgba(255,255,255,.3); }
.tl-ruler .tick span { position: absolute; left: 4px; bottom: 9px; font: 10px ui-monospace, monospace; color: var(--faint); white-space: nowrap; }
.tl-ruler .end { position: absolute; top: 0; bottom: 0; background: repeating-linear-gradient(45deg, transparent 0 4px, rgba(255,255,255,.04) 4px 8px); }
.tl-lane { position: relative; height: 28px; border-bottom: 1px solid var(--line); }
.tl-lane.is-selected { background: rgba(56,189,248,.04); }
.tl-lane.cam { background: rgba(251,191,36,.03); }
.tl-clip { position: absolute; top: 3px; height: 21px; border-radius: 6px; cursor: grab; display: flex; align-items: center; padding: 0 9px; font-size: 11px; font-weight: 600; color: #04111f; overflow: hidden; white-space: nowrap; box-shadow: inset 0 0 0 1px rgba(255,255,255,.25); }
.tl-clip.is-selected { box-shadow: 0 0 0 2px #fff, 0 4px 14px -4px rgba(0,0,0,.6); }
.tl-clip.hidden-layer { opacity: .35; }
.tl-clip .h { position: absolute; top: 0; bottom: 0; width: 7px; cursor: ew-resize; }
.tl-clip .h.l { left: 0; } .tl-clip .h.r { right: 0; }
.tl-clip .h::after { content: ""; position: absolute; top: 6px; bottom: 6px; left: 2px; width: 2px; border-radius: 1px; background: rgba(0,0,0,.35); }
.tl-clip .wave { position: absolute; inset: 0; opacity: .35; pointer-events: none; }
.kf { position: absolute; top: 6px; width: 15px; height: 15px; margin-left: -7.5px; transform: rotate(45deg); background: #fbbf24; border: 2px solid #78350f; border-radius: 3px; cursor: grab; }
.kf.is-selected { background: #fff; border-color: #fbbf24; box-shadow: 0 0 0 3px rgba(251,191,36,.35); }
.kf-seg { position: absolute; top: 13px; height: 2px; background: rgba(251,191,36,.35); pointer-events: none; }
.tl-playhead { position: absolute; top: 0; bottom: 0; width: 0; z-index: 4; pointer-events: none; }
.tl-playhead::before { content: ""; position: absolute; top: 0; bottom: 0; left: -1px; width: 2px; background: var(--danger); }
.tl-playhead i { position: absolute; top: 0; left: -7px; width: 14px; height: 16px; background: var(--danger); clip-path: polygon(0 0, 100% 0, 100% 60%, 50% 100%, 0 60%); }

/* ===== Modals ===== */
.modal { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; background: rgba(3,6,12,.7); backdrop-filter: blur(4px); animation: fadeIn .2s; }
.modal-card { width: min(560px, calc(100vw - 32px)); max-height: calc(100vh - 40px); display: flex; flex-direction: column; background: var(--panel); border: 1px solid var(--line-strong); border-radius: 16px; box-shadow: var(--shadow); animation: popIn .25s var(--ease); }
.modal-card.sm { width: min(420px, calc(100vw - 32px)); }
.modal-card header { display: flex; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.modal-card h3 { margin: 0; font-size: 15px; }
.modal-card .x { margin-left: auto; border: 0; background: transparent; font-size: 22px; color: var(--muted); line-height: 1; }
.modal-body { padding: 16px 18px; overflow-y: auto; }
.modal-card footer { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 18px; border-top: 1px solid var(--line); }
.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 12px; }
.field > span { font-size: 12px; color: var(--muted); font-weight: 500; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.progress { height: 8px; border-radius: 8px; background: var(--panel-3); overflow: hidden; margin: 10px 0; }
.progress i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, #3b82f6, #22d3ee); transition: width .2s; }
.pick-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.pick { border: 1px solid var(--line-strong); border-radius: 10px; background: var(--panel-2); padding: 0; overflow: hidden; text-align: left; transition: border-color .15s, transform .15s; }
.pick:hover { border-color: var(--accent); transform: translateY(-2px); }
.pick canvas { display: block; width: 100%; aspect-ratio: 16/9; background: #1e293b; }
.pick span { display: block; padding: 7px 9px; font-size: 12px; font-weight: 600; }
table.hk { width: 100%; border-collapse: collapse; }
table.hk td { padding: 7px 4px; border-bottom: 1px solid var(--line); }
table.hk td:first-child { white-space: nowrap; width: 45%; }

.busy { position: fixed; inset: 0; z-index: 200; display: grid; place-items: center; background: rgba(3,6,12,.55); }
.busy-card { width: min(460px, 90vw); padding: 20px; border-radius: 14px; background: var(--panel); border: 1px solid var(--line-strong); text-align: center; box-shadow: var(--shadow); }
.busy-card b { font-size: 12px; letter-spacing: .03em; color: var(--plot); }
.busy-card span { display: block; margin-bottom: 10px; font: 12px ui-monospace, monospace; color: var(--muted); }

.toast-host { position: fixed; right: 16px; bottom: 16px; z-index: 300; display: flex; flex-direction: column; gap: 8px; }
.toast { padding: 10px 14px; border-radius: 10px; background: var(--elevated); border: 1px solid var(--line-strong); box-shadow: var(--shadow); font-size: 12.5px; animation: popIn .25s var(--ease); max-width: 360px; }
.toast.err { border-color: rgba(244,84,123,.5); }
.toast.ok { border-color: rgba(74,222,128,.45); }

@keyframes fadeIn { from { opacity: 0; } }
@keyframes popIn { from { opacity: 0; transform: translateY(8px) scale(.98); } }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--panel-3); border-radius: 10px; border: 2px solid var(--panel); }
::-webkit-scrollbar-track { background: transparent; }

@media (max-width: 1500px) {
  .brand-name, .project-name { display: none; }
  .topbar .btn { padding: 0 10px; }
}
@media (max-height: 760px) {
  :root { --topbar-h: 44px; --timeline-h: clamp(140px, 28vh, 220px); }
  .btn { height: 30px; }
  .tool { min-height: 48px; font-size: 10.5px; }
  .tool small { display: none; }
}
@media (max-width: 1100px) {
  .toolbar { grid-template-columns: 1fr; }
  :root { --tool-w: 58px; --insp-w: 260px; }
  .tool > span:last-child, .badge-new, .tool.soon::after { display: none; }
  .tool { justify-content: center; }
  .stage-hint, .project-name { display: none; }
}

/* ===== Bảng chọn ===== */
.modal-card.wide { width: min(860px, calc(100vw - 32px)); }
.pick-note { margin: 0 0 12px; font-size: 12px; color: var(--muted); line-height: 1.55; }
.pick-note b { color: var(--fg); }
.pick-row, .pick-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 10px; }
.pick-input { flex: 1; min-width: 0; width: 100%; height: 36px; padding: 0 12px; margin-bottom: 10px; background: var(--panel-2); border: 1px solid var(--line-strong); border-radius: 9px; }
.pick-row .pick-input { margin-bottom: 0; }
.pick-input:focus { outline: none; border-color: var(--accent); }
.pick-seg { margin-bottom: 12px; flex-wrap: wrap; }
.pick-h { margin: 14px 0 8px; font-size: 11px; letter-spacing: .06em; text-transform: uppercase; color: var(--faint); }
.pick-list { display: flex; flex-direction: column; gap: 4px; max-height: 50vh; overflow-y: auto; }
.pick-item { display: block; width: 100%; text-align: left; border: 1px solid var(--line); background: var(--panel-2); padding: 9px 11px; border-radius: 8px; }
.pick-item:hover { border-color: var(--accent); }
.pick-item b { display: block; font-size: 13px; }
.pick-item small { display: block; color: var(--faint); font-size: 11px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pick-empty { padding: 16px; text-align: center; color: var(--faint); }
.pick-grid.sm { grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); }
.pick.tile { display: flex; flex-direction: column; align-items: center; gap: 7px; padding: 12px 6px 4px; }
.pick.tile i { width: 44px; height: 44px; display: grid; place-items: center; border-radius: 50%; font-style: normal; font-size: 22px; box-shadow: inset 0 0 0 2px rgba(255,255,255,.7); }
.pick.tile span { padding: 0 0 6px; text-align: center; }
.pick-grid.flags { grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); max-height: 46vh; overflow-y: auto; }
.pick.flag img { display: block; width: 100%; aspect-ratio: 4/3; object-fit: cover; background: var(--panel-3); }
.pick.flag span { font-size: 11px; }
.chip-grid { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { height: 30px; padding: 0 12px; border-radius: 15px; border: 1px solid var(--line-strong); background: var(--panel-2); font-size: 12px; font-weight: 600; color: var(--muted); }
.chip:hover { color: var(--fg); }
.chip.is-active { background: var(--accent); border-color: var(--accent); color: #04111f; }
.check-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 4px 0 6px; }
.kml-row { display: flex; align-items: center; gap: 8px; padding: 6px 8px; border-radius: 6px; background: var(--panel-2); cursor: pointer; font-size: 12.5px; }
.kml-row i { font-style: normal; width: 18px; text-align: center; }
.sfx-row { display: flex; align-items: center; gap: 10px; padding: 6px 8px; border-radius: 8px; background: var(--panel-2); }
.sfx-row span { flex: 1; font-weight: 600; }
.sfx-row small { color: var(--faint); }

/* ===== Kho mẫu 3D ===== */
.modal-card.lib3d { width: min(1100px, calc(100vw - 32px)); height: min(860px, calc(100vh - 40px)); }
.lib3d header { gap: 10px; flex-wrap: wrap; }
.lib3d header h3 { font-size: 20px; margin-right: 6px; }
.lib3d .modal-body { flex: 1; padding-top: 0; }
.lib-search { position: sticky; top: 0; z-index: 2; height: 42px; margin: 0 0 14px; border-radius: 12px; box-shadow: 0 10px 20px -10px var(--bg); }
.lib-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 14px; }
.lib-card { position: relative; display: flex; flex-direction: column; padding: 0; overflow: hidden; text-align: left; border: 1px solid var(--line-strong); border-radius: 14px; background: var(--panel-2); transition: border-color .15s, transform .15s; }
.lib-card:hover { border-color: rgba(56,189,248,.6); transform: translateY(-2px); }
.lib-card.is-selected { border: 2px solid var(--accent); box-shadow: 0 0 0 3px rgba(56,189,248,.18); }
.lib-thumb { aspect-ratio: 4 / 3; display: grid; place-items: center; background: radial-gradient(ellipse at 50% 60%, #1e293b, #0b1220 75%); }
.lib-thumb img { width: 92%; height: 92%; object-fit: contain; }
.lib-meta { padding: 10px 14px 12px; }
.lib-meta b { display: block; font-size: 15px; }
.lib-meta small { color: var(--faint); font-size: 11.5px; }
.lib-badge { position: absolute; top: 10px; left: 10px; font-style: normal; font-size: 10.5px; font-weight: 700; padding: 3px 8px; border-radius: 6px; background: rgba(245,185,66,.15); border: 1px solid rgba(245,185,66,.5); color: #f5c84b; }
.lib-foot { align-items: center; gap: 12px; }
.lib-info { flex: 1; min-width: 0; font-size: 13px; }
.lib-title b { font-size: 15px; }
.lib-title span { color: var(--muted); }
.lib-info p { margin: 4px 0 2px; color: var(--muted); }
.lib-info small { color: var(--faint); }
.lib-up-preview { display: flex; flex-direction: column; align-items: center; gap: 4px; margin-bottom: 12px; padding: 10px; border-radius: 10px; background: radial-gradient(ellipse at 50% 60%, #1e293b, #0b1220 75%); color: var(--muted); font-size: 12px; }
.lib-up-preview img { max-width: 100%; height: 200px; object-fit: contain; }
.field textarea { font: inherit; color: inherit; }
.sub-item { margin: 8px 0; padding: 6px 8px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel-2); }
.sub-item summary { display: flex; align-items: center; justify-content: space-between; gap: 6px; cursor: pointer; font-weight: 600; font-size: 12.5px; padding: 2px 0 6px; }
.sub-item[open] summary { border-bottom: 1px solid var(--line); margin-bottom: 8px; }
.lib-viewer { width: 220px; height: 130px; flex: none; border-radius: 10px; background: radial-gradient(ellipse at 50% 60%, #1e293b, #0b1220 75%); cursor: grab; }
