:root{--bg:#f1f5f9;--panel:#fff;--line:#e2e8f0;--ink:#0f172a;--mute:#64748b;--brand:#2563eb;--danger:#dc2626;--ok:#16a34a}
*{box-sizing:border-box}
html,body{margin:0;height:100%;font-family:'Segoe UI',system-ui,sans-serif;color:var(--ink);background:var(--bg);font-size:14px}
a{color:var(--brand);text-decoration:none}
button,input,select,textarea{font:inherit}
button{cursor:pointer;border:1px solid var(--line);background:#fff;border-radius:6px;padding:6px 12px}
button:hover{background:#f8fafc}
button.primary{background:var(--brand);border-color:var(--brand);color:#fff}
button.primary:hover{background:#1d4ed8}
button.danger{color:var(--danger)}
button.sm{padding:3px 8px;font-size:12px}
input,select,textarea{border:1px solid #cbd5e1;border-radius:6px;padding:6px 8px;background:#fff;max-width:100%}
input[type=color]{padding:0;width:34px;height:28px;border-radius:4px}
label.f{display:block;font-size:12px;color:var(--mute);margin:8px 0 3px}

/* ----- khung admin ----- */
.topbar{height:48px;background:#0f172a;color:#fff;display:flex;align-items:center;gap:16px;padding:0 16px}
.topbar a{color:#cbd5e1}.topbar a:hover{color:#fff}
.topbar .brand{font-weight:700;color:#fff;font-size:16px}
.topbar .sp{flex:1}
.page{padding:20px;max-width:1300px;margin:0 auto}
.card{background:var(--panel);border:1px solid var(--line);border-radius:10px;padding:16px}
.grid{display:grid;grid-template-columns:repeat(auto-fill,minmax(280px,1fr));gap:14px}
.row{display:flex;gap:8px;align-items:center;flex-wrap:wrap}
.tabs{display:flex;gap:4px;border-bottom:1px solid var(--line);margin:14px 0}
.tabs a{padding:8px 14px;border-bottom:2px solid transparent;color:var(--mute)}
.tabs a.on{color:var(--brand);border-color:var(--brand);font-weight:600}
h1,h2,h3{margin:.2em 0}
table.t{width:100%;border-collapse:collapse;background:#fff}
table.t th,table.t td{padding:6px 10px;border-bottom:1px solid var(--line);text-align:left}
table.t th{background:#f8fafc;position:sticky;top:0;font-size:12px;color:var(--mute)}
.scroll{max-height:62vh;overflow:auto;border:1px solid var(--line);border-radius:8px}
.badge{display:inline-block;padding:1px 8px;border-radius:99px;background:#e0e7ff;color:#3730a3;font-size:12px}
.mute{color:var(--mute)}
.modal-bg{position:fixed;inset:0;background:rgba(15,23,42,.5);display:flex;align-items:center;justify-content:center;z-index:50}
.modal{background:#fff;border-radius:12px;padding:20px;width:min(520px,94vw);max-height:90vh;overflow:auto}
.chips label{display:inline-flex;gap:4px;align-items:center;margin:0 10px 6px 0}

/* ----- trình soạn stacking plan ----- */
.editor{display:grid;grid-template-columns:260px 1fr 280px;height:calc(100vh - 48px)}
.editor>aside{background:#fff;overflow:auto;padding:12px}
.editor>aside.l{border-right:1px solid var(--line)}
.editor>aside.r{border-left:1px solid var(--line)}
.editor main{overflow:auto;position:relative;background:#0f172a;display:flex;flex-direction:column}
.toolbar{display:flex;gap:6px;flex-wrap:wrap;align-items:center;padding:8px 12px;background:#fff;border-bottom:1px solid var(--line)}
.canvas{flex:1;overflow:auto;padding:24px}
.pool-floor{margin:6px 0 2px;font-weight:600;font-size:12px;color:var(--mute);display:flex;justify-content:space-between}
.pool-items{display:flex;flex-wrap:wrap;gap:3px}
.pool-item{padding:2px 6px;border:1px solid #cbd5e1;border-radius:4px;font-size:11px;background:#f8fafc;cursor:grab}
.pool-item:hover{background:#dbeafe}
.sw{display:flex;flex-wrap:wrap;gap:4px;margin-top:4px}
.sw i{width:22px;height:22px;border-radius:4px;border:1px solid rgba(0,0,0,.2);cursor:pointer}
.floor-tools{position:absolute;left:100%;top:0;margin-left:8px;display:flex;gap:3px;white-space:nowrap;opacity:0;z-index:5}
.floor-tools button{white-space:nowrap}
.sp-row:hover .floor-tools{opacity:1}

/* ----- stacking plan (dùng chung) ----- */
.sp-panels{display:inline-flex;align-items:flex-start}
.sp-panel{display:flex;flex-direction:column;gap:var(--gap)}
.sp-panel-title{font-size:22px;font-weight:700;padding:4px 0 6px}
.sp-floor-head{font-size:12px;opacity:.7;text-transform:uppercase;letter-spacing:.06em}
.sp-row{display:flex;gap:var(--gap);align-items:flex-start;position:relative}
.sp-floor-label{display:flex;align-items:center;justify-content:center;font-weight:700;background:rgba(255,255,255,.12);border-radius:4px;flex:none;user-select:none}
.sp-cells{display:flex;gap:var(--gap);flex-wrap:nowrap;min-height:20px}
.sp-cell{position:relative;display:flex;align-items:center;justify-content:center;text-align:center;flex:none;overflow:hidden;line-height:1.15;transition:opacity .7s ease,transform .7s ease,filter .7s ease;user-select:none}
.sp-cell-text{white-space:pre-line;padding:0 3px;pointer-events:none}
.sp-cell.missing{outline:2px dashed #f87171}
.sp-cell.sold-hide{opacity:0;transform:scale(.6);pointer-events:none}
.sp-cell.sold-dim{opacity:.18}
.sp-cell.sold-strike{filter:grayscale(1);opacity:.45;text-decoration:line-through}
/* trong admin vẫn thấy ô đã bán mờ để thao tác */
.show-sold .sp-cell.sold-hide{opacity:.22;transform:none;pointer-events:auto}
.show-sold .sp-cell.sold::after{content:attr(data-seq);position:absolute;top:1px;right:3px;font-size:10px;background:#111;color:#fff;border-radius:6px;padding:0 4px}
.editable .sp-cell{cursor:grab;outline:1px solid rgba(255,255,255,.0)}
.editable .sp-cell.spacer{outline:1px dashed rgba(255,255,255,.4)}
.editable .sp-cell.selected{outline:3px solid #f59e0b;z-index:2}
.editable .sp-cell.drop-before{box-shadow:-4px 0 0 0 #22d3ee}
.editable .sp-cell.drop-after{box-shadow:4px 0 0 0 #22d3ee}
.editable .sp-cells.drop-end{outline:2px dashed #22d3ee}
.editable .sp-row.drop-row{box-shadow:0 -3px 0 0 #22d3ee}
.rh{position:absolute;right:0;top:0;bottom:0;width:10px;cursor:ew-resize;background:rgba(0,0,0,.0)}
.sp-cell:hover .rh,.sp-cell.selected .rh{background:rgba(37,99,235,.55)}
.editable .sp-floor-label{cursor:grab}
.rubber{position:absolute;border:1px solid #f59e0b;background:rgba(245,158,11,.15);pointer-events:none;z-index:9}

/* ----- màn hình điều khiển bán ----- */
.sale{display:grid;grid-template-columns:340px 1fr;height:calc(100vh - 48px)}
.sale aside{background:#fff;border-right:1px solid var(--line);padding:14px;overflow:auto}
.sale main{background:#0f172a;overflow:auto;padding:16px}
.sale .big{font-size:22px;padding:8px 10px;width:100%}
.log-item{display:flex;justify-content:space-between;align-items:center;padding:5px 8px;border-bottom:1px solid var(--line)}
.log-item b{display:inline-block;min-width:34px}
.sale .sp-cell{cursor:pointer}
.sale .sp-cell.picking{outline:3px solid #f59e0b}

/* ----- màn hình trình chiếu ----- */
body.display{background:#0f172a;overflow:hidden;color:#fff}
.display-head{position:fixed;top:0;left:0;right:0;text-align:center;padding:10px;font-size:28px;font-weight:800;letter-spacing:.04em;z-index:3}
.display-vp{position:absolute;inset:0;padding-top:0}
.display-hint{position:fixed;bottom:6px;right:10px;font-size:11px;opacity:.35}

.sp-panel-tools{display:flex;justify-content:space-between;align-items:center;gap:8px;font-size:12px;color:#94a3b8;padding-bottom:4px}

body.resizing,body.resizing *{cursor:ew-resize!important;user-select:none!important}
body.resizing .sp-cell{transition:none!important}
.rv{position:absolute;left:0;right:10px;bottom:0;height:8px;cursor:ns-resize}
.sp-cell:hover .rv,.sp-cell.selected .rv{background:rgba(37,99,235,.55)}
body.resizing-v,body.resizing-v *{cursor:ns-resize!important;user-select:none!important}
body.resizing-v .sp-cell{transition:none!important}
.editable .sp-floor-label.selected{outline:3px solid #f59e0b}
.editable .sp-row.drop-row-after{box-shadow:0 3px 0 0 #22d3ee}

.sp-legend{display:flex;flex-wrap:wrap;justify-content:center;gap:8px 26px;padding:10px 16px}
.sp-legend-item{display:flex;align-items:center;gap:8px;font-weight:600}
.sp-legend-item i{display:inline-block;width:1.5em;height:1.2em;border:1px solid rgba(255,255,255,.35)}
.display-legend{position:fixed;left:0;right:0;z-index:3}

/* header màn chiếu */
.sp-header{display:grid;align-items:center;gap:20px;width:100%}
.sp-hslot{display:flex;align-items:center;gap:14px;min-width:0}
.sp-hslot.r{justify-content:flex-end}
.sp-hmid{min-width:0}
.sp-htitle{line-height:1.15;letter-spacing:.03em}
.sp-hsub{opacity:.85;margin-top:2px}
.sp-logo{display:block;max-width:40vw;object-fit:contain}
.display-header{position:fixed;top:0;left:0;right:0;z-index:3}

.rt{position:absolute;left:0;right:10px;top:0;height:8px;cursor:ns-resize}
.sp-cell:hover .rt,.sp-cell.selected .rt{background:rgba(245,158,11,.75)}
body.resizing-span,body.resizing-span *{cursor:ns-resize!important;user-select:none!important}
body.resizing-span .sp-cell{transition:none!important}
.sp-ptitle-wrap{display:flex;align-items:center;gap:6px;flex:1;justify-content:center}
.sp-ptitle{width:60%;min-width:120px;text-align:center;font-weight:700;background:rgba(255,255,255,.95)}

.sp-floor-label{position:relative}
.fl-menu{position:absolute;top:1px;right:1px;padding:0 5px;line-height:15px;font-size:15px;font-weight:700;border-radius:4px;background:rgba(255,255,255,.92);color:#0f172a;border:0;opacity:0;cursor:pointer}
.sp-floor-label:hover .fl-menu,.fl-menu:focus{opacity:1}
.floor-menu{position:fixed;z-index:70;background:#fff;border:1px solid var(--line);border-radius:10px;box-shadow:0 10px 30px rgba(15,23,42,.25);padding:4px;display:flex;flex-direction:column;min-width:240px}
.floor-menu button{text-align:left;border:0;background:none;padding:8px 12px;border-radius:6px}
.floor-menu button:hover{background:#f1f5f9}
.floor-menu button.danger{color:var(--danger)}

/* nút Thao tác nằm ngoài hàng (bên phải), cách mép ô cuối 28px */
.fl-menu{top:50%!important;right:auto!important;left:100%;margin-left:28px;transform:translateY(-50%);padding:3px 10px!important;line-height:18px!important;font-size:12px!important;font-weight:600;white-space:nowrap;opacity:0!important;border:1px solid #cbd5e1!important;transition:opacity .12s}
.sp-row:hover .fl-menu,.fl-menu:focus{opacity:1!important}

/* vùng đệm vô hình bên phải hàng: rê chuột từ ô cuối sang nút không bị mất nút giữa chừng (nhấp vào đây vẫn quét chọn bình thường) */
.editable .sp-row::after{content:'';position:absolute;left:100%;top:0;bottom:0;width:36px}

/* ----- điều khiển bán (bản mới) ----- */
.sale{grid-template-columns:400px 1fr}
.sale aside{display:flex;flex-direction:column;overflow:hidden}
.seq-head{display:grid;grid-template-columns:46px 1fr 30px;gap:6px;font-size:12px;color:var(--mute);padding:4px 0}
#rows{flex:1;overflow:auto;border:1px solid var(--line);border-radius:8px;padding:6px}
.seq-row{display:grid;grid-template-columns:46px 1fr 30px;gap:6px;align-items:center;margin-bottom:4px}
.seq-n{text-align:center;font-weight:700;background:#f1f5f9;border-radius:6px;padding:6px 0}
.seq-row.done .seq-n{background:#16a34a;color:#fff}
.seq-row.done input{background:#dcfce7}
.seq-row.active input{outline:2px solid #f59e0b}
.seq-row.bad input{border-color:#dc2626;background:#fee2e2}
.sale main{display:flex;flex-direction:column;padding:0;overflow:hidden}
.sale-bar{display:flex;gap:6px;align-items:center;padding:8px 12px;background:#fff;border-bottom:1px solid var(--line)}
.sale-plan{flex:1;overflow:auto;padding:16px}

.seq-head,.seq-row{grid-template-columns:46px 1fr 34px 30px!important}
.seq-row .okb{padding:5px 0}

/* một cột nút: ✔ xác nhận khi rê/chọn ô nhập; ✕ bỏ chọn khi STT đã có căn */
.seq-head,.seq-row{grid-template-columns:46px 1fr 34px!important}
.seq-row .act{display:grid;place-items:center}
.seq-row .okb,.seq-row .clr{grid-area:1/1;width:100%;padding:5px 0}
.seq-row .okb{display:none}
.seq-row:hover .okb,.seq-row:focus-within .okb{display:block}
.seq-row.done:not(:has(input[data-dirty])) .okb{display:none!important}
.seq-row:not(.done) .clr,.seq-row:has(input[data-dirty]) .clr{display:none}

/* footer bản quyền: mọi trang quản trị (trừ màn chiếu, là trang riêng) */
.app-footer{position:fixed;left:0;right:0;bottom:0;height:34px;display:flex;align-items:center;justify-content:space-between;padding:0 16px;background:#fff8d5;color:#323232;font-size:12.2px;font-weight:700;z-index:40}
.editor,.sale{height:calc(100vh - 48px - 34px)!important}
.page{padding-bottom:60px}

/* nhiều cột: chừa chỗ bên phải mỗi cột (chỉ trong trình soạn) để nút "Thao tác" không bị cột kế bên che; nút luôn nằm trên */
.editable .sp-panel{padding-right:140px}
.fl-menu{z-index:6}
