/* Koh Render — ngôn ngữ thiết kế Koh: nền mềm (neumorphism), sáng mặc định, tối tuỳ chọn */
:root{
  --bg:#e0e5ec;--panel:#e0e5ec;--text:#4a5568;--muted:#7b8794;--accent:#0fb891;--accent-2:#2563eb;
  --up:#059669;--down:#dc2626;--warn:#d97706;--line:rgba(0,0,0,.08);
  --sh-out:6px 6px 14px #b8bec7,-6px -6px 14px #ffffff;
  --sh-in:inset 4px 4px 9px #b8bec7,inset -4px -4px 9px #ffffff;
  --sh-pill:4px 4px 9px #b8bec7,-4px -4px 9px #ffffff;
  --card:#e6ebf2;--row-hover:rgba(0,0,0,.035);--overlay:rgba(120,130,150,.55);--on-accent:#ffffff;
}
[data-theme="dark"]{
  --bg:#252b2e;--panel:#2a3033;--text:#b8afa2;--muted:#8a8f92;--accent:#10b894;--accent-2:#3b82f6;
  --up:#34e0b0;--down:#ef4444;--warn:#f59e0b;--line:rgba(255,255,255,.06);
  --sh-out:0 0 18px rgba(140,150,185,.30),4px 6px 14px rgba(0,0,0,.45);
  --sh-in:inset 3px 4px 8px rgba(0,0,0,.55),inset -2px -2px 6px rgba(140,150,185,.14);
  --sh-pill:0 0 10px rgba(140,150,185,.26),3px 4px 9px rgba(0,0,0,.45);
  --card:#2d3437;--row-hover:rgba(255,255,255,.035);--overlay:rgba(20,24,26,.72);--on-accent:#06251d;
}
*{box-sizing:border-box;margin:0;padding:0;-webkit-tap-highlight-color:transparent}
html,body{height:100%}
body{background:var(--bg);color:var(--text);font:400 14px/1.4 Inter,system-ui,-apple-system,"Segoe UI",sans-serif;-webkit-font-smoothing:antialiased;overflow:hidden}
button,input,select,textarea{font:inherit;color:inherit;background:none;border:0;outline:0}
button{cursor:pointer;touch-action:manipulation}
button:focus-visible,input:focus-visible,select:focus-visible,textarea:focus-visible{outline:2px solid var(--accent);outline-offset:2px}
.ms{display:inline-flex;align-items:center;justify-content:center;font-size:20px;line-height:1;width:1em;height:1em;flex:none;user-select:none}
.ms svg{display:block;width:1em;height:1em}
.mono{font-family:'JetBrains Mono',ui-monospace,monospace}

#app{height:100%;height:100dvh;display:flex;flex-direction:column;padding:max(10px,env(safe-area-inset-top)) max(12px,env(safe-area-inset-right)) max(10px,env(safe-area-inset-bottom)) max(12px,env(safe-area-inset-left));gap:12px}

/* ----- Đầu trang ----- */
.top{display:flex;align-items:center;gap:14px;flex:none}
.brand{display:flex;align-items:center;gap:11px;text-decoration:none;color:inherit;min-width:0}
.brand .logo{border-radius:12px;box-shadow:var(--sh-pill);flex:none}
.brand h1{font-size:18px;font-weight:800;color:var(--text);letter-spacing:-.2px;line-height:1.1}
.brand p{font-size:11.5px;color:var(--muted);white-space:nowrap}
.top-actions{margin-left:auto;display:flex;align-items:center;gap:8px}
.iconbtn{width:42px;height:42px;border-radius:50%;display:inline-grid;place-items:center;box-shadow:var(--sh-pill);color:var(--text);flex:none;transition:box-shadow .15s,color .15s}
.iconbtn:active,.iconbtn.on{box-shadow:var(--sh-in);color:var(--accent)}
.iconbtn:disabled{opacity:.4;pointer-events:none}
.iconbtn.sm{width:36px;height:36px}
.btn{display:inline-flex;align-items:center;justify-content:center;gap:7px;height:42px;padding:0 18px;border-radius:21px;font-weight:700;color:var(--text);box-shadow:var(--sh-pill);white-space:nowrap}
.btn:active{box-shadow:var(--sh-in)}
.btn.sm{height:36px;padding:0 13px;border-radius:18px;font-size:13px}
.btn.primary{background:var(--accent);color:var(--on-accent);box-shadow:var(--sh-pill)}
.btn.primary:active{filter:brightness(.92);box-shadow:var(--sh-in)}
.btn.danger{color:var(--down)}
.btn.ghost{box-shadow:none;background:transparent}
.btn:disabled{opacity:.45;pointer-events:none}
.seg{display:flex;gap:6px;padding:5px;border-radius:24px;box-shadow:var(--sh-in)}
.seg button{display:flex;align-items:center;gap:6px;height:34px;padding:0 13px;border-radius:17px;color:var(--muted);font-size:13px}
.seg button b{font-weight:600}
.seg button.on{box-shadow:var(--sh-pill);color:var(--accent)}

/* ----- Bố cục chính ----- */
.work{flex:1;min-height:0;display:grid;grid-template-columns:86px minmax(0,1fr) 340px;gap:14px}
.tools{display:flex;flex-direction:column;gap:10px;overflow:auto;padding:6px 4px}
.tools button{display:flex;flex-direction:column;align-items:center;justify-content:center;gap:4px;min-height:68px;border-radius:18px;box-shadow:var(--sh-out);color:var(--muted);font-size:11px;text-align:center;padding:6px 2px}
.tools button b{font-weight:600;line-height:1.15}
.tools button .ms{font-size:24px}
.tools button.on{box-shadow:var(--sh-in);color:var(--accent)}
.stage-col{display:flex;flex-direction:column;gap:10px;min-width:0;min-height:0}
.sticky{display:flex;flex-direction:column;gap:10px;min-height:0;flex:1}
.stage{flex:1;min-height:0;display:grid;place-items:center;border-radius:22px;box-shadow:var(--sh-in);padding:12px;overflow:hidden;container-type:size}
.frame{position:relative;border-radius:14px;overflow:hidden;background:#0b1a20;box-shadow:0 10px 30px rgba(0,0,0,.35);
  aspect-ratio:var(--ar,16/9);width:min(100cqw,calc(100cqh * var(--arv,1.7778)));max-height:100cqh;touch-action:none}
.frame[data-aspect="9:16"]{--ar:9/16;--arv:.5625}
.frame[data-aspect="1:1"]{--ar:1/1;--arv:1}
.frame[data-aspect="16:9"]{--ar:16/9;--arv:1.7778}
#map,#ov{position:absolute;inset:0;width:100%;height:100%}
#ov{pointer-events:none}
.maplibregl-canvas{outline:none}
.frame.tool .maplibregl-canvas{cursor:crosshair}
.hint{position:absolute;left:10px;right:10px;top:10px;padding:8px 12px;border-radius:12px;background:rgba(12,16,18,.78);color:#fff;font-size:12.5px;display:none;pointer-events:none;backdrop-filter:blur(6px)}
.hint.on{display:block}
.cam3d{position:absolute;right:10px;top:10px;display:flex;flex-direction:column;gap:8px}
.cam3d .iconbtn{background:rgba(12,16,18,.62);color:#fff;box-shadow:none;backdrop-filter:blur(6px)}
.cam3d .iconbtn.on{color:var(--accent)}
.maplibregl-ctrl-attrib{font-size:10px!important;background:rgba(255,255,255,.72)!important}

.transport{display:flex;align-items:center;gap:10px;flex-wrap:wrap}
.time{font-family:'JetBrains Mono',monospace;font-size:13px;color:var(--muted);min-width:96px}
.time b{color:var(--text)}
.durbox{margin-left:auto;display:flex;align-items:center;gap:6px;padding:0 12px;height:36px;border-radius:18px;box-shadow:var(--sh-in);color:var(--muted)}
.durbox input{width:46px;text-align:center;font-weight:700;color:var(--text);-moz-appearance:textfield}
.durbox input::-webkit-outer-spin-button,.durbox input::-webkit-inner-spin-button{-webkit-appearance:none}
.durbox i{font-style:normal;font-size:12px}

/* ----- Dòng thời gian ----- */
.timeline{flex:none;max-height:210px;overflow:auto;border-radius:18px;box-shadow:var(--sh-in);padding:8px 10px 10px;position:relative;user-select:none;-webkit-user-select:none;touch-action:pan-y}
.tl-grid{display:grid;grid-template-columns:96px 1fr;row-gap:4px;position:relative}
.tl-name{font-size:11.5px;color:var(--muted);display:flex;align-items:center;gap:5px;min-width:0;height:26px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;cursor:pointer}
.tl-name .ms{font-size:15px}
.tl-name.sel{color:var(--accent);font-weight:700}
.tl-track{position:relative;height:26px;border-radius:8px;background:var(--row-hover)}
.tl-ruler{position:relative;height:22px;cursor:ew-resize}
.tl-ruler i{position:absolute;top:0;font-style:normal;font-size:10px;color:var(--muted);transform:translateX(-50%);font-family:'JetBrains Mono',monospace}
.tl-ruler i::after{content:"";position:absolute;left:50%;top:14px;height:6px;width:1px;background:var(--line)}
.tl-bar{position:absolute;top:3px;bottom:3px;border-radius:7px;box-shadow:var(--sh-pill);min-width:10px;display:flex;align-items:center;padding:0 8px;font-size:11px;font-weight:600;color:#fff;overflow:hidden;white-space:nowrap;cursor:grab;touch-action:none}
.tl-bar.sel{outline:2px solid var(--accent);outline-offset:1px}
.tl-bar .h{position:absolute;top:0;bottom:0;width:10px;cursor:ew-resize}
.tl-bar .h.l{left:0}.tl-bar .h.r{right:0}
.tl-key{position:absolute;top:50%;width:16px;height:16px;margin:-8px 0 0 -8px;background:var(--accent);transform:rotate(45deg);border-radius:3px;cursor:grab;box-shadow:var(--sh-pill);touch-action:none}
.tl-key.sel{outline:2px solid var(--accent-2);outline-offset:2px}
.tl-head{position:absolute;top:0;bottom:0;width:2px;background:var(--down);pointer-events:none;z-index:3}
.tl-head::before{content:"";position:absolute;top:0;left:-5px;border:6px solid transparent;border-top-color:var(--down)}

/* ----- Bảng bên phải ----- */
.panel{display:flex;flex-direction:column;min-height:0;border-radius:22px;box-shadow:var(--sh-out);background:var(--panel);overflow:hidden}
.tabs{display:flex;gap:4px;padding:10px 10px 6px;overflow-x:auto;flex:none;scrollbar-width:none}
.tabs::-webkit-scrollbar{display:none}
.tabs button{display:flex;flex-direction:column;align-items:center;gap:2px;min-width:58px;padding:7px 8px;border-radius:14px;color:var(--muted);font-size:10.5px;font-weight:600;flex:1}
.tabs button.on{box-shadow:var(--sh-in);color:var(--accent)}
.tabbody{flex:1;min-height:0;overflow:auto;padding:8px 14px 18px;-webkit-overflow-scrolling:touch}
.sec{margin:12px 0 6px;font-size:11px;font-weight:700;letter-spacing:.5px;text-transform:uppercase;color:var(--muted)}
.sec:first-child{margin-top:4px}
.row{display:flex;align-items:center;gap:8px;margin:8px 0}
.row>label,.lab{font-size:12.5px;color:var(--muted);flex:none;min-width:84px}
.in,.sel{height:38px;padding:0 12px;border-radius:12px;box-shadow:var(--sh-in);width:100%;min-width:0;color:var(--text)}
select.in{appearance:none;-webkit-appearance:none;padding-right:30px;background-image:linear-gradient(45deg,transparent 50%,var(--muted) 50%),linear-gradient(135deg,var(--muted) 50%,transparent 50%);background-position:calc(100% - 17px) 16px,calc(100% - 12px) 16px;background-size:5px 5px;background-repeat:no-repeat}
textarea.in{height:auto;padding:9px 12px;resize:vertical;min-height:62px}
input[type=color]{width:42px;height:34px;padding:0;border-radius:10px;box-shadow:var(--sh-in);cursor:pointer;background:transparent;flex:none}
input[type=range]{width:100%;accent-color:var(--accent)}
.chips{display:flex;flex-wrap:wrap;gap:7px;margin:6px 0}
.chip{height:32px;padding:0 12px;border-radius:16px;box-shadow:var(--sh-pill);font-size:12.5px;font-weight:600;color:var(--muted);display:inline-flex;align-items:center;gap:5px}
.chip.on{box-shadow:var(--sh-in);color:var(--accent)}
.note{font-size:12px;color:var(--muted);line-height:1.5;margin:6px 0}
.note b{color:var(--text)}
.box{padding:12px;border-radius:16px;box-shadow:var(--sh-in);margin:8px 0}
.item{display:flex;align-items:center;gap:8px;padding:9px 10px;border-radius:14px;margin:7px 0;box-shadow:var(--sh-pill);cursor:pointer;min-width:0}
.item.sel{box-shadow:var(--sh-in);color:var(--accent)}
.item .nm{flex:1;min-width:0;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;font-weight:600}
.item small{display:block;font-size:11px;color:var(--muted);font-weight:400}
.item .mini{width:30px;height:30px;box-shadow:none}
.dot{width:12px;height:12px;border-radius:50%;flex:none}
.empty{padding:18px 6px;text-align:center;color:var(--muted);font-size:13px}
.prog{height:10px;border-radius:5px;box-shadow:var(--sh-in);overflow:hidden;margin:10px 0}
.prog i{display:block;height:100%;width:0;background:var(--accent);border-radius:5px;transition:width .15s}
video{width:100%;border-radius:14px;margin-top:10px;background:#000;max-height:46vh}
.kcard{border-radius:18px;box-shadow:var(--sh-out);overflow:hidden;margin:12px 0;background:var(--card)}
.kcard img{width:100%;aspect-ratio:16/9;object-fit:cover;display:block;background:#0b1a20}
.kcard .kb{padding:10px 12px}
.kcard h4{font-size:14px;font-weight:700;color:var(--text);white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.kcard .meta{font-size:11.5px;color:var(--muted);margin-top:3px}
.kcard .acts{display:flex;gap:8px;margin-top:10px}
.tag{display:inline-block;padding:2px 8px;border-radius:10px;box-shadow:var(--sh-in);font-size:11px;color:var(--muted);margin:2px 4px 0 0}

#toast{position:fixed;left:50%;bottom:calc(22px + env(safe-area-inset-bottom));transform:translate(-50%,30px);opacity:0;pointer-events:none;background:#14191b;color:#fff;padding:11px 18px;border-radius:14px;font-size:13px;max-width:min(92vw,520px);transition:.25s;z-index:60;box-shadow:0 8px 24px rgba(0,0,0,.4)}
#toast.on{opacity:1;transform:translate(-50%,0)}
#modal{position:fixed;inset:0;background:var(--overlay);z-index:50;display:grid;place-items:center;padding:18px}
#modal[hidden]{display:none}
#modal .dlg{width:min(440px,100%);border-radius:22px;background:var(--bg);box-shadow:var(--sh-out);padding:20px}
#modal h3{font-size:17px;margin-bottom:8px;color:var(--text)}
#modal .acts{display:flex;gap:10px;justify-content:flex-end;margin-top:16px;flex-wrap:wrap}

/* ----- Máy tính bảng ----- */
@media (max-width:1180px){
  .work{grid-template-columns:78px minmax(0,1fr) 300px;gap:12px}
  .brand p{display:none}
}
/* ----- Điện thoại / iPad dọc: bảng chuyển xuống dưới, khung xem trước ở trên ----- */
@media (max-width:860px){
  body{overflow:auto}
  #app{height:auto;min-height:100dvh;padding-bottom:max(14px,env(safe-area-inset-bottom))}
  .top{flex-wrap:wrap;gap:10px}
  .seg{order:3;width:100%;justify-content:center}
  .seg button{flex:1;justify-content:center}
  .top-actions{gap:6px}
  .top-actions .btn .lbl{display:none}
  .top-actions .btn{padding:0;width:42px}
  .work{display:flex;flex-direction:column;gap:12px;flex:none}
  .tools{flex-direction:row;overflow-x:auto;padding:4px 2px 8px}
  .tools button{flex:1 0 74px;min-height:62px}
  .stage-col{display:contents}
  .sticky{flex:none;position:sticky;top:0;z-index:6;background:var(--bg);padding:max(4px,env(safe-area-inset-top)) 0 8px;margin:0 -2px;gap:8px;box-shadow:0 10px 14px -12px rgba(0,0,0,.35)}
  .stage{flex:none;height:min(44vh,430px);padding:8px}
  .timeline{max-height:170px}
  .panel{box-shadow:none;background:transparent;overflow:visible}
  .tabbody{overflow:visible;padding:8px 2px 28px}
  .transport .btn .lbl{display:none}
  .transport .btn{padding:0;width:36px}
}
@media (max-width:860px) and (orientation:landscape){.stage{height:70vh}.sticky{position:static}}
@media (prefers-reduced-motion:reduce){*{transition:none!important;animation:none!important}}
