/* ECA KPI — standalone frontend styles. Black frame layout, v12 look. */
*{box-sizing:border-box}
html,body{margin:0;height:100%;font-family:system-ui,-apple-system,"Segoe UI",Roboto,Arial,sans-serif;background:#0b0b0e;color:#eee}
button{cursor:pointer;font:inherit}
input,select,textarea{font:inherit}
.hidden{display:none!important}

/* Login */
.login-wrap{min-height:100vh;display:flex;align-items:center;justify-content:center;background:radial-gradient(600px 400px at 50% 20%,#1c1c22,#0b0b0e);padding:16px}
.login-card{width:380px;max-width:100%;background:#141419;border:1px solid #2a2a33;border-radius:14px;padding:28px;text-align:center}
.login-card img{width:64px;height:64px;object-fit:contain}
.login-card h1{font-size:19px;margin:12px 0 4px}
.login-card p{color:#9a9aa5;font-size:13px;margin:0 0 18px}
.login-card input{width:100%;padding:11px 12px;border-radius:8px;border:1px solid #33333e;background:#0e0e12;color:#eee;margin-bottom:10px}
.btn{border:0;border-radius:8px;padding:10px 16px;background:#e8a33d;color:#111;font-weight:600}
.btn:hover{filter:brightness(1.1)}
.btn.ghost{background:#22222a;color:#eee;border:1px solid #33333e}
.btn.small{padding:6px 10px;font-size:13px}
.err{color:#ff6b6b;font-size:13px;min-height:18px;margin:8px 0 0}
.ok-msg{color:#7dd87d;font-size:13px;margin:8px 0 0}

/* App shell — black frame fixed to the screen */
.shell{display:flex;height:100vh;overflow:hidden;background:#000}
.menu{width:250px;flex:0 0 250px;background:#111114;border-right:1px solid #22222a;display:flex;flex-direction:column;overflow-y:auto}
.menu .brand{display:flex;align-items:center;gap:10px;padding:14px;border-bottom:1px solid #22222a}
.menu .brand img{width:34px;height:34px;object-fit:contain}
.menu .brand b{font-size:14px;line-height:1.2}
.menu h3{font-size:11px;letter-spacing:.08em;text-transform:uppercase;color:#8a8a95;margin:16px 12px 6px}
.menu-item{display:flex;align-items:center;gap:6px;width:calc(100% - 16px);margin:1px 8px;padding:8px 10px;border:0;border-radius:8px;background:transparent;color:#d5d5dc;text-align:left;font-size:14px;white-space:nowrap;overflow:hidden}
.menu-item:hover{background:#1e1e25}
.menu-item.active{background:#2a2a12;color:#ffd27a}
.menu-item .t{flex:1;overflow:hidden;text-overflow:ellipsis}
.menu-item .dots{flex:0 0 auto;border:0;background:transparent;color:#999;font-size:16px;line-height:1;padding:2px 6px;border-radius:6px;visibility:hidden}
.menu-item:hover .dots,.menu-item.active .dots{visibility:visible}
.menu .add{margin:6px 8px;background:#1e1e25;color:#eee;border:1px dashed #3a3a44;border-radius:8px;padding:7px}
.menu .ver{margin-top:auto;padding:12px;font-size:12px;color:#777}
.main{flex:1;min-width:0;display:flex;flex-direction:column;background:#000}
.topbar{display:flex;align-items:center;gap:12px;padding:12px 18px;border-bottom:1px solid #22222a;background:#0e0e12}
.topbar img{width:32px;height:32px;object-fit:contain}
.topbar b{font-size:15px}
.topbar .sp{flex:1}
.topbar .who{font-size:13px;color:#aaa}
.page{flex:1;min-height:0;overflow:auto;padding:16px 18px}
.frame{background:#0e0e12;border:1px solid #26262e;border-radius:12px;padding:16px;min-height:100%}
.frame h2{margin:0 0 12px;font-size:18px}
.meta{font-size:12px;color:#8a8a95;margin-bottom:10px}
.meta b{color:#7dd87d}

/* Filters */
.filters{display:flex;flex-wrap:wrap;gap:10px;margin-bottom:12px}
.filter{position:relative}
.filter>button{background:#1a1a20;border:1px solid #33333e;color:#eee;border-radius:8px;padding:8px 12px;min-width:130px;text-align:left}
.filter .drop{position:absolute;z-index:20;top:110%;left:0;width:230px;max-height:300px;overflow:auto;background:#1a1a20;border:1px solid #33333e;border-radius:10px;padding:8px;box-shadow:0 8px 30px rgba(0,0,0,.6)}
.filter .drop input{width:100%;padding:7px 9px;border-radius:6px;border:1px solid #33333e;background:#0e0e12;color:#eee;margin:6px 0}
.filter .drop label{display:block;padding:5px 6px;border-radius:6px;font-size:13px;cursor:pointer}
.filter .drop label:hover{background:#26262e}

/* Totals + tables */
.totals{display:flex;gap:12px;flex-wrap:wrap;margin-bottom:12px}
.total{background:#0f2a12;border:1px solid #1f4d24;border-radius:10px;padding:10px 16px;min-width:170px}
.total .l{font-size:12px;color:#9ad89a}
.total .v{font-size:20px;font-weight:700;color:#7dd87d}
.tbl-wrap{overflow:auto;max-height:46vh;border:1px solid #26262e;border-radius:10px;margin-bottom:14px}
table.data{border-collapse:collapse;width:100%;font-size:13px;white-space:nowrap}
table.data th,table.data td{padding:7px 10px;border-bottom:1px solid #22222a;text-align:right}
table.data th:first-child,table.data td:first-child,table.data td.l,table.data th.l{text-align:left}
table.data thead th{position:sticky;top:0;background:#1c1c22;color:#ffb347;z-index:2}
table.data tfoot td{position:sticky;bottom:0;background:#1c1c22;font-weight:700}
.small-grid{display:grid;grid-template-columns:repeat(auto-fit,minmax(240px,1fr));gap:12px}
.small-grid .box{border:1px solid #26262e;border-radius:10px;overflow:hidden}
.small-grid .box h4{margin:0;padding:9px 12px;background:#1a1a20;font-size:13px;color:#ffb347}
.small-grid table.data{font-size:12px}
.small-grid table.data th,.small-grid table.data td{padding:5px 8px}
.small-grid table.data .name{max-width:0;overflow:hidden;text-overflow:ellipsis}

/* Editor toolbars */
.toolbar{display:flex;flex-wrap:wrap;gap:6px;align-items:center;margin-bottom:10px}
.toolbar button,.toolbar select,.toolbar input[type=color]{background:#1e1e25;border:1px solid #33333e;color:#eee;border-radius:7px;padding:6px 9px;font-size:13px}
.toolbar button.on{background:#3a2f10;border-color:#e8a33d;color:#ffd27a}
.toolbar .sep{width:1px;height:22px;background:#33333e;margin:0 4px}
.status{font-size:12px;color:#8a8a95;margin-left:auto}
.text-editor{min-height:300px;background:#fff;color:#111;border-radius:8px;padding:14px;outline:none}
.text-editor:empty:before{content:"Nhập nội dung…";color:#999}

/* Sheet editor */
.sheet-wrap{overflow:auto;border:1px solid #26262e;border-radius:10px;max-height:60vh;background:#fff;color:#111}
table.sheet{border-collapse:collapse;font-size:13px}
table.sheet th,table.sheet td{border:1px solid #d4d4d4;padding:0;min-width:112px}
table.sheet th{background:#f0f0f0;font-weight:600;text-align:center;position:sticky;top:0;z-index:3}
table.sheet th.rowh{position:sticky;left:0;z-index:4;min-width:40px;width:40px}
table.sheet td.rowh{background:#f0f0f0;text-align:center;color:#666;position:sticky;left:0;z-index:2}
table.sheet td{position:relative}
table.sheet td.sel{background:#cfe8ff!important}
table.sheet th.sel{background:#bcd8f5!important}
table.sheet td input,table.sheet td textarea{width:100%;height:100%;border:0;outline:none;padding:5px 7px;font:inherit;background:transparent;resize:none;display:block}
table.sheet td.wrap textarea{white-space:pre-wrap}
table.sheet td.cut input{white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
table.sheet .grip{position:absolute;right:-3px;top:0;width:6px;height:100%;cursor:col-resize;z-index:5}
table.sheet .grip:hover{background:#4caf50}
.merged{background:#eef6ff}

/* Settings tables */
table.set{border-collapse:collapse;width:100%;font-size:13px;background:#141419}
table.set th,table.set td{border:1px solid #2a2a33;padding:8px 10px;text-align:left}
table.set th{background:#1c1c22;color:#ffb347}
table.set input,table.set select{width:100%;background:#0e0e12;border:1px solid #33333e;color:#eee;border-radius:6px;padding:6px 8px}
.role-card{border:1px solid #2a2a33;border-radius:10px;padding:12px;margin-bottom:10px;background:#141419}
.role-card b{color:#ffd27a}
.ctx{position:fixed;z-index:50;background:#1e1e25;border:1px solid #3a3a44;border-radius:8px;box-shadow:0 8px 30px rgba(0,0,0,.6);padding:4px;min-width:140px}
.ctx button{display:block;width:100%;text-align:left;background:transparent;border:0;color:#eee;padding:8px 10px;border-radius:6px}
.ctx button:hover{background:#2e2e38}
.ctx button.danger{color:#ff7b7b}
/* Khung nổi "Nhận dữ liệu mới" — position:fixed nên không đẩy bố cục trang */
.ds-panel{position:fixed;z-index:60;width:440px;max-width:calc(100vw - 32px);background:#1a1a20;border:1px solid #3a3a44;border-radius:12px;box-shadow:0 12px 40px rgba(0,0,0,.7);padding:14px}
@media (max-width:700px){.menu{width:200px;flex-basis:200px}.totals .total{min-width:140px}}
/* Thêm cho v55 — nối vào cuối styles.css v12. */
.menu h3{background:#1c1c22;color:#fff;font-weight:700;padding:7px 12px;margin:14px 0 6px;border-radius:6px}
.menu .ver{color:#777}
.jump-btn{display:none;margin:0 0 12px}
.rate-sums{display:grid;grid-template-columns:2fr 3fr;gap:12px}
.rate-sums .box{border:1px solid #26262e;border-radius:10px;overflow:hidden}
.rate-sums .box h4{margin:0;padding:9px 12px;background:#1a1a20;font-size:13px;color:#ffb347}
.race-grid{display:flex;flex-wrap:wrap;flex-direction:row;gap:14px}
.race-box{border:1px solid #26262e;border-radius:10px;overflow:hidden;max-width:614px}
.race-box h4{margin:0;padding:9px 12px;background:#1a1a20;font-size:13px;color:#ffb347}
.race-scroll{overflow:auto}
.race-box table.data{width:100%}
.race-box table.data th,.race-box table.data td{padding:6px 10px}
.users-scroll{max-height:476px;overflow-y:auto;border:1px solid #2a2a33;border-radius:10px}
.users-scroll table.set{border:0}
.bulk-grid{display:grid;grid-template-columns:1fr 1fr 1fr;gap:10px}
.bulk-grid label{font-size:12px;color:#9a9aa5;display:block;margin-bottom:4px}
.bulk-grid textarea{width:100%;background:#0e0e12;border:1px solid #33333e;color:#eee;border-radius:8px;padding:8px}
.perm-grid{display:grid;grid-template-columns:repeat(auto-fit,minmax(150px,1fr));gap:8px}
.perm-grid label{font-size:13px;color:#c9c9d1}
.perm-grid select{width:100%;background:#0e0e12;border:1px solid #33333e;color:#eee;border-radius:6px;padding:6px 8px;margin-top:4px}
.sheet-tabs{display:flex;gap:4px;align-items:center;margin-top:8px;overflow-x:auto;padding-bottom:4px}
.sheet-tab{background:#1e1e25;border:1px solid #33333e;color:#eee;border-radius:7px 7px 0 0;padding:7px 12px;font-size:13px;white-space:nowrap}
.sheet-tab.on{background:#3a2f10;border-color:#e8a33d;color:#ffd27a}
.sheet-tab.add{border-style:dashed}
.tab-x{background:transparent;border:0;color:#999;padding:2px 4px;font-size:12px}
.zoom-ctl{display:inline-flex;gap:2px;align-items:center}
.zoom-ctl button{background:#1e1e25;border:1px solid #33333e;color:#eee;border-radius:7px;padding:6px 10px;font-size:13px}
.img-list{display:flex;flex-direction:column;gap:16px}
.img-item{border:1px solid #26262e;border-radius:10px;padding:10px;overflow:hidden}
.img-item img{display:block;max-width:100%;height:auto;margin:0 auto}
.img-missing{background:#2a1a1a;border:1px dashed #a33;border-radius:8px;padding:16px;color:#ffb3b3;font-size:13px;text-align:center}
.img-ctl{display:flex;gap:8px;align-items:center;flex-wrap:wrap;margin-top:10px;font-size:13px}
.img-ctl button{background:#1e1e25;border:1px solid #33333e;color:#eee;border-radius:7px;padding:6px 10px}
.img-ctl button.danger{color:#ff7b7b}
.img-ctl input[type=range]{flex:1;min-width:120px}
.tbl-main{max-height:46vh}
@media (max-width:700px){
  .menu{width:200px;flex-basis:200px}
  .totals .total{min-width:140px}
  .jump-btn{display:inline-block}
  .tbl-main{max-height:240px}
  .rate-sums{grid-template-columns:1fr}
  .bulk-grid{grid-template-columns:1fr}
  .race-box{max-width:100%}
  .race-grid{flex-direction:column}
  .race-box table.data{font-size:11px}
  .race-box table.data th,.race-box table.data td{padding:5px 6px}
  .race-t4 .race-scroll{overflow-x:auto}
  .race-t4 table.data{min-width:400px}
  .race-t1 table.data td:nth-child(2),.race-t5 table.data td:nth-child(3){min-width:112px}
  .frame{padding:12px}
  .topbar .who{display:none}
}

/* Thêm cho v70 — thu gọn menu, phiếu lương, QR, tab Ảnh, KPI iPad. */
/* Sidebar collapse (v58/v59): nút ở đầu sidebar; khi thu gọn, nút mở ở đầu vùng nội dung. */
.menu-collapse{display:block;width:calc(100% - 16px);margin:10px 8px 0;padding:7px 10px;background:#1e1e25;color:#c9c9d1;border:1px solid #33333e;border-radius:8px;text-align:left;font-size:13px}
.menu-collapse:hover{background:#26262e}
.open-menu-bar{padding:10px 18px 0}
.shell.menu-collapsed .menu{display:none}

/* Tab Nội dung / Ảnh trên trang Thư viện - Cơ chế (v58). */
.lib-tabs{display:flex;gap:4px;margin-bottom:10px}
.lib-tab{background:#1e1e25;border:1px solid #33333e;color:#eee;border-radius:8px;padding:7px 14px;font-size:13px}
.lib-tab.on{background:#3a2f10;border-color:#e8a33d;color:#ffd27a}

/* Phiếu lương (v61-v65, v67, v70). */
.payslip{max-width:720px;margin:0 auto;background:#141419;border:1px solid #2a2a33;border-radius:12px;padding:20px}
.ps-head{text-align:center;font-weight:700;font-size:15px}
.ps-title{text-align:center;font-size:22px;font-weight:800;color:#ffd27a;margin:6px 0 2px;letter-spacing:.06em}
.ps-month{text-align:center;color:#9a9aa5;font-size:13px;margin-bottom:14px}
.ps-info{display:grid;grid-template-columns:1fr 1fr;gap:6px 16px;border:1px solid #2a2a33;border-radius:8px;padding:10px 12px;margin-bottom:14px;font-size:13px}
.ps-info span{color:#9a9aa5}
.ps-group{margin-bottom:14px}
.ps-group h4{margin:0 0 6px;padding:8px 10px;background:#1a1a20;font-size:13px;color:#ffb347;border-radius:8px}
.ps-line{display:flex;justify-content:space-between;gap:12px;padding:7px 10px;border-bottom:1px solid #22222a;font-size:13px}
.ps-line:last-child{border-bottom:0}
.ps-label{flex:1}
.ps-value{font-weight:600;white-space:nowrap}
.ps-note{font-size:12px;color:#9a9aa5;margin-top:2px}
.ps-qr{background:transparent;border:0;padding:0;font:inherit;font-size:12px;font-weight:700;color:#7db8ff;text-decoration:underline;cursor:pointer}
.ps-qr:hover{color:#a8ccff}

/* Ô chọn có tìm kiếm (Mã NV / Tháng phiếu lương). */
.pick{position:relative}
.pick-label{display:block;font-size:12px;color:#9a9aa5;margin-bottom:4px}
.pick input{width:100%;padding:9px 10px;border-radius:8px;border:1px solid #33333e;background:#0e0e12;color:#eee}
.pick-list{position:absolute;z-index:20;top:110%;left:0;right:0;max-height:260px;overflow:auto;background:#1a1a20;border:1px solid #33333e;border-radius:10px;padding:4px;box-shadow:0 8px 30px rgba(0,0,0,.6)}
.pick-opt{padding:8px 10px;border-radius:6px;font-size:13px;cursor:pointer}
.pick-opt:hover{background:#26262e}
.pick-opt.none{color:#8a8a95;cursor:default}

/* Xem ảnh QR lớn ở giữa màn hình (v70). */
.qr-modal{position:fixed;inset:0;z-index:100;background:rgba(0,0,0,.85);display:flex;align-items:center;justify-content:center;padding:16px}
.qr-box{position:relative;background:#fff;border-radius:12px;padding:14px;max-width:92vw}
.qr-box img{display:block;max-width:min(440px,84vw);max-height:78vh}
.qr-close{position:absolute;top:-12px;right:-12px;width:32px;height:32px;border-radius:50%;border:0;background:#e8a33d;color:#111;font-weight:700;font-size:15px}

/* KPI trên iPad (v60) — dải máy tính bảng 701-1180px: vùng bảng một cột full
   bề ngang như Đua Top; bảng chính 300px; 4 bảng tổng hợp mỗi bảng một hàng
   (288px khi ngang, 272px khi dọc); chữ số 13px; SL DATA 68px, Điểm thực tế 132px. */
@media (min-width:701px) and (max-width:1180px){
  .kpi-main{max-height:300px}
  .kpi-main table.data{font-size:13px}
  .kpi-main table.data th:nth-child(7),.kpi-main table.data td:nth-child(7){min-width:68px}
  .kpi-main table.data th:nth-child(9),.kpi-main table.data td:nth-child(9){min-width:132px}
  #tables .small-grid{grid-template-columns:1fr}
  #tables .small-grid .box{max-height:288px;overflow:auto}
  #tables .small-grid table.data{font-size:13px}
  .totals .total{padding:8px 12px;min-width:130px}
  .totals .total .v{font-size:17px}
}
@media (min-width:701px) and (max-width:1180px) and (orientation:portrait){
  #tables .small-grid .box{max-height:272px}
  .kpi-main table.data{min-width:740px}
}

/* Thêm cho v73 — mục Cá nhân, nút "+" trên thanh tiêu đề mục, ô Mã NV khóa, bảng phép. */
/* Nút "+" nhỏ ở đầu phải thanh tiêu đề đen của mục (thay nút thêm trang gạch đứt cũ). */
.menu h3.sec-head{display:flex;align-items:center;justify-content:space-between;gap:8px}
.menu h3.sec-head span{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.sec-add{flex:0 0 auto;width:22px;height:22px;padding:0;border:1px solid #3a3a44;border-radius:6px;background:transparent;color:#eee;font-size:15px;line-height:1}
.sec-add:hover{background:#26262e}

/* Ô Mã NV khóa cho viewer (v73): chỉ đọc, không gõ được, có ổ khóa. */
.locked-manv{display:flex;align-items:center;gap:8px;padding:0 10px;border-radius:8px;border:1px solid #33333e;background:#1a1a20;color:#c9c9d1}
.locked-manv svg{flex:0 0 auto;color:#8a8a95}
.locked-manv input{flex:1;min-width:0;border:0;background:transparent;color:#eee;padding:9px 0;cursor:not-allowed;outline:none}

/* Bảng Tổng hợp phép tích lũy (v73): lưới đầy đủ — viền dọc + ngang mọi ô,
   tiêu đề dài tự xuống dòng thay vì bị cắt. */
table.data.leave-table{white-space:normal}
.leave-table th,.leave-table td{border:1px solid #33333e;white-space:normal;word-break:break-word;overflow-wrap:break-word}
.leave-table thead th{position:static}
.leave-wrap{max-height:60vh}
@media (max-width:700px){.leave-wrap{max-height:52vh}}
