/* Roster Matrix ขั้นที่ 1 (24/9/2569) — หน้าตาเดียวกับหน้าตรวจสอบเวลา · ไม่มี style ฝังในหน้า (CSP style-src 'self') */
:root{
  --navy:#171e2e;--navy2:#1e2739;--red:#c8102e;--ink:#0f172a;--muted:#64748b;
  --line:#e2e8f0;--soft:#f8fafc;
  --ok:#067647;--okbg:#ecfdf3;--bad:#b42318;--badbg:#fef3f2;
  --warn:#b54708;--warnbg:#fffaeb;--warnline:#fec84b;--badline:#fda29b;
  --d-bg:#d1fadf;--d-fg:#05603a;
  --n-bg:#dde3ff;--n-fg:#2d31a6;
  --o-bg:#eef1f5;--o-fg:#667085;
  --h-bg:#fce7f6;--h-fg:#c11574;
  --l-bg:#ede9fe;--l-fg:#6d28d9;
  --x-bg:#fff4db;--x-fg:#b54708;
  --emp:236px;--pat:122px;--day:34px;
  font-family:"Leelawadee UI","Segoe UI",Tahoma,sans-serif;color:var(--ink);
}
*{box-sizing:border-box}
body{margin:0;background:#fff;line-height:1.5}
[hidden]{display:none!important}
button,input,select{font:inherit}
button{cursor:pointer}

.appbar{background:var(--navy);border-bottom:3px solid var(--red);padding:14px 26px;display:flex;align-items:center;justify-content:space-between;gap:16px;flex-wrap:wrap}
.brand strong{display:block;color:#fff;font-size:20px;letter-spacing:.01em}
.brand small{display:block;color:#94a3b8;font-size:11px;letter-spacing:.06em}
.appbar nav{display:flex;gap:10px;flex-wrap:wrap}
.appbar nav a{display:inline-flex;align-items:center;padding:8px 15px;border-radius:9px;background:#232c40;border:1px solid #33405c;color:#e8edf6;text-decoration:none;font-size:13px}
.appbar nav a:hover{border-color:#5b6b8f}
.appbar nav a.on{background:#e8edf6;border-color:#e8edf6;color:var(--navy);font-weight:700}

main{max-width:1680px;margin:0 auto;padding:22px 26px 60px}
h1{font-size:30px;margin:0 0 4px;letter-spacing:-.02em}
.lede{color:var(--muted);font-size:13px;margin:0 0 18px}

.filters{background:var(--soft);border:1px solid var(--line);border-radius:12px;padding:15px;display:flex;flex-wrap:wrap;gap:12px;align-items:flex-end}
.filters label{display:flex;flex-direction:column;gap:5px;font-size:11px;color:var(--muted);font-weight:600}
.filters input,.filters select{height:38px;padding:0 10px;border:1px solid #cbd5e1;border-radius:8px;background:#fff;color:var(--ink);min-width:150px}
.filters .grow{flex:1;min-width:180px}
.monthnav{display:flex;align-items:center;gap:6px}
.monthnav input{min-width:0;width:150px}
.monthnav .nav{height:38px;width:38px;border:1px solid #cbd5e1;border-radius:8px;background:#fff;font-size:18px;line-height:1;color:#334155}
.monthnav .nav:disabled{opacity:.4;cursor:default}
.btn{height:38px;padding:0 16px;border-radius:8px;border:1px solid #cbd5e1;background:#fff;color:#334155;font-weight:600;font-size:13px;display:inline-flex;align-items:center;gap:6px;white-space:nowrap}
.btn:hover{border-color:#94a3b8}
.btn:disabled{opacity:.5;cursor:default}
.btn.active{background:var(--x-bg);border-color:var(--warnline);color:var(--warn)}
.btn.sm{height:34px;padding:0 12px;font-size:12.5px}

.live{display:inline-flex;align-items:center;gap:8px;height:38px;padding:0 14px;border-radius:999px;font-size:12px;font-weight:600;border:1px solid transparent;white-space:nowrap}
.live i{width:9px;height:9px;border-radius:50%;flex:0 0 9px}
.live.fresh{background:var(--okbg);color:var(--ok);border-color:#a6f4c5}
.live.fresh i{background:var(--ok)}
.live.loading{background:#eff5ff;color:#175cd3;border-color:#b2ddff}
.live.loading i{background:#175cd3;animation:pulse 1s infinite}
.live.error{background:var(--badbg);color:var(--bad);border-color:var(--badline)}
.live.error i{background:var(--bad)}
@keyframes pulse{0%{box-shadow:0 0 0 0 currentColor;opacity:1}70%{box-shadow:0 0 0 7px transparent;opacity:.55}100%{box-shadow:0 0 0 0 transparent;opacity:1}}

.summary{display:flex;flex-wrap:wrap;gap:10px;margin:16px 0 4px}
.stat{flex:1;min-width:128px;background:#fff;border:1px solid var(--line);border-radius:11px;padding:11px 13px}
.stat strong{display:block;font-size:22px;line-height:1.2}
.stat span{display:block;font-size:11px;color:var(--muted);margin-top:2px}
.stat.d strong{color:var(--d-fg)} .stat.n strong{color:var(--n-fg)} .stat.o strong{color:#475467}
.stat.l strong{color:var(--l-fg)} .stat.bad strong{color:var(--bad)} .stat.warn strong{color:var(--warn)}
.stat.sel{background:var(--soft)}
.hint{font-size:11.5px;color:var(--muted);margin:0 0 8px}

.k{position:relative;display:inline-grid;place-items:center;width:26px;height:20px;border-radius:5px;font-size:11px;font-weight:700;font-style:normal}
.meaning{border:1px solid var(--line);border-radius:12px;background:#fff;margin:4px 0 10px}
.meaning summary{cursor:pointer;padding:9px 14px;font-weight:700;font-size:13px;list-style:none;display:flex;align-items:center;gap:8px}
.meaning summary::-webkit-details-marker{display:none}
.meaning summary::before{content:"▸";color:#64748b;transition:transform .15s}
.meaning[open] summary::before{transform:rotate(90deg)}
.meaning summary small{font-weight:400;color:var(--muted)}
.meaning ul{list-style:none;margin:0;padding:0 14px 12px;display:grid;grid-template-columns:repeat(auto-fill,minmax(250px,1fr));gap:8px 16px}
.meaning li{display:flex;gap:10px;align-items:flex-start;font-size:12px;color:var(--muted);line-height:1.35}
.meaning li .k{flex:0 0 38px;width:38px;height:24px}
.meaning li b{display:block;color:var(--ink);font-size:12.5px}

.toolbar{display:flex;align-items:center;justify-content:space-between;gap:10px 16px;flex-wrap:wrap;margin:4px 0 10px}
.toolbar .left{font-size:12.5px;color:var(--muted)}
.toolbar .right{display:flex;align-items:center;gap:8px}
.error{background:var(--badbg);color:var(--bad);border:1px solid var(--badline);border-radius:10px;padding:10px 14px;margin:0 0 10px;font-size:13px}

.table-wrap{border:1px solid var(--line);border-radius:12px;overflow:auto;max-height:calc(100vh - 200px);min-height:380px}
table.rm{border-collapse:separate;border-spacing:0;font-size:12px}
.rm th,.rm td{white-space:nowrap}
.rm thead th{position:sticky;top:0;z-index:3;background:var(--navy2);color:#fff;font-weight:600;font-size:12px;padding:6px 0;text-align:center;height:46px}
.rm th.emp,.rm th.pat,.rm th.gl,.rm th.fl{position:sticky;background:#fff;text-align:left;font-weight:400;z-index:2}
.rm th.emp{left:0;width:var(--emp);min-width:var(--emp);max-width:var(--emp);padding:0 10px;border-right:1px solid var(--line)}
.rm th.pat{left:var(--emp);width:var(--pat);min-width:var(--pat);max-width:var(--pat);padding:0 8px;border-right:2px solid #d5dde8}
.rm thead th.emp,.rm thead th.pat{z-index:6;background:var(--navy2);color:#fff;font-weight:600}
.rm thead th.emp small{font-weight:400;color:#9fb0cc;margin-left:6px}
.rm th.day{width:var(--day);min-width:var(--day);max-width:var(--day);cursor:pointer;user-select:none;border-right:1px solid #2a3449}
.rm th.day b{display:block;font-size:14px;line-height:1.1}
.rm th.day small{display:block;font-size:10px;color:#9fb0cc;font-weight:400}
.rm th.day.we small{color:#fda4af}
.rm th.day:hover{background:#2a3550}
.rm th.day.sel{background:#3a4867;box-shadow:inset 0 -3px 0 var(--warnline)}
.rm th.day.today{background:var(--red)}
.rm th.day.today small{color:#ffe4e8}

.rm tbody th.emp,.rm tbody th.pat{border-bottom:1px solid #eef2f6;height:32px}
.rm tbody tr.e:hover th.emp,.rm tbody tr.e:hover th.pat{background:#f8fafc}
.who{display:block;width:calc(var(--emp) - 20px);border:0;background:none;padding:0;text-align:left;color:inherit;overflow:hidden}
.who strong{display:block;font-size:12.5px;line-height:1.25;overflow:hidden;text-overflow:ellipsis}
.who small{display:block;font-size:10.5px;color:var(--muted);line-height:1.2;overflow:hidden;text-overflow:ellipsis}
.who small .left{color:#970c15;font-weight:700}
.who:hover strong{color:var(--red);text-decoration:underline}
.pc{display:block;width:calc(var(--pat) - 16px);overflow:hidden}
.pc b{display:block;font-size:12px;line-height:1.2;overflow:hidden;text-overflow:ellipsis}
.pc small{display:block;font-size:10px;color:var(--muted);line-height:1.2;overflow:hidden;text-overflow:ellipsis}
.pc.miss b{color:var(--warn)}
.pc.reg b{color:#3f9b6a}

.rm td{border-bottom:1px solid #eef2f6;border-right:1px solid #f0f3f7;padding:0;height:32px;width:var(--day);min-width:var(--day);max-width:var(--day);text-align:center;font-weight:700;font-size:11px;position:relative;overflow:hidden}
.rm td.c{cursor:pointer}
.rm td.c:hover{outline:2px solid var(--navy);outline-offset:-2px;z-index:1}
.rm td.empty{max-width:none;width:auto;height:120px;text-align:left;padding-left:20px;color:var(--muted);font-weight:400;font-size:13px}
.k-D{background:var(--d-bg);color:var(--d-fg)}
.k-N{background:var(--n-bg);color:var(--n-fg)}
.k-O{background:var(--o-bg);color:var(--o-fg)}
.k-H{background:var(--h-bg);color:var(--h-fg)}
.k-L{background:var(--l-bg);color:var(--l-fg)}
.k-X{background:var(--x-bg);color:var(--x-fg);outline:1px dashed #f5b945;outline-offset:-3px}
.k-Z{background:#fff;color:#cbd5e1}
.rm td.k-O,.k.k-O{font-size:10px;letter-spacing:.02em}
.reg.k-D,.reg.k-N{background:#f3fbf6;color:#3f9b6a}
.reg::before{content:"";position:absolute;left:6px;right:6px;bottom:5px;border-bottom:1.5px dotted currentColor}
.req::after{content:"";position:absolute;top:3px;right:3px;width:7px;height:7px;border-radius:50%;background:#f79009;box-shadow:0 0 0 1.5px #fff}
.adj::before{content:"";position:absolute;top:0;left:0;border-top:9px solid var(--navy);border-right:9px solid transparent}
.rm td.past{opacity:.5}
.rm td.tcol{box-shadow:inset 2px 0 0 rgba(200,16,46,.6),inset -2px 0 0 rgba(200,16,46,.6)}
.rm td.scol{background-image:linear-gradient(rgba(250,204,21,.2),rgba(250,204,21,.2))}
.rm.code td.c,.rm.time td.c{font-size:10px;letter-spacing:-.02em}
/* เวลางาน (26/9/2569): เข้าบรรทัดบน ออกบรรทัดล่าง ช่องกว้างขึ้นนิดเดียว ยังเห็นครบเดือน */
.rm.hours{--day:38px}
.rm.hours td.c{white-space:pre-line;font-size:10px;line-height:1.1;letter-spacing:-.02em}

.rm tr.g th.gl{left:0;width:calc(var(--emp) + var(--pat));min-width:calc(var(--emp) + var(--pat));max-width:calc(var(--emp) + var(--pat));padding:0 10px;border-right:2px solid #d5dde8;border-bottom:1px solid var(--line);height:34px}
.rm tr.g1 th.gl{background:#eef2f7}
.rm tr.g2 th.gl{background:#f8fafc;padding-left:26px}
.rm tr.g td{border-bottom:1px solid var(--line);font-size:10px;line-height:1.1;cursor:default}
.rm tr.g1 td{background:#eef2f7}
.rm tr.g2 td{background:#f8fafc}
.rm tr.g td b{display:block;color:var(--d-fg)}
.rm tr.g td i{display:block;font-style:normal;color:var(--n-fg);font-weight:700}
.rm tr.g td.gx::after{content:"";position:absolute;left:50%;bottom:2px;width:5px;height:5px;margin-left:-2.5px;border-radius:50%;background:#f79009}
.gt{display:flex;align-items:center;gap:8px;width:100%;border:0;background:none;padding:0;text-align:left;color:var(--ink);font-weight:700;font-size:12.5px;overflow:hidden}
.gt .car{flex:0 0 12px;color:#64748b;transition:transform .15s;font-size:10px}
.closed .gt .car{transform:rotate(-90deg)}
.gt .nm{overflow:hidden;text-overflow:ellipsis}
.gc{flex:0 0 auto;font-weight:600;font-size:10.5px;color:#475569;background:#fff;border:1px solid var(--line);border-radius:999px;padding:0 7px}
.gw{flex:0 0 auto;font-weight:700;font-size:10.5px;color:var(--warn);background:var(--x-bg);border:1px solid var(--warnline);border-radius:999px;padding:0 7px}

/* 4/10/2569: แถวรวม 6 แถว (เพิ่ม "มาทำงาน") สูงแถวละ 20px = ความสูงรวมเท่า 5 แถวเดิม · พนักงานไม่ถูกเบียด */
.rm tfoot th,.rm tfoot td{position:sticky;background:#f8fafc;height:20px;line-height:20px;padding:0;font-size:11px;z-index:3}
.rm tfoot th.fl{left:0;z-index:6;width:calc(var(--emp) + var(--pat));min-width:calc(var(--emp) + var(--pat));padding:0 10px;font-weight:700;border-right:2px solid #d5dde8;background:#f8fafc}
.rm tfoot tr.f0 > *{bottom:100px;border-top:2px solid #d5dde8}
.rm tfoot tr.f1 > *{bottom:80px}
.rm tfoot tr.f2 > *{bottom:60px}
.rm tfoot tr.f3 > *{bottom:40px}
.rm tfoot tr.f4 > *{bottom:20px}
.rm tfoot tr.f5 > *{bottom:0}
.rm tfoot .fD{color:var(--d-fg)} .rm tfoot .fN{color:var(--n-fg)} .rm tfoot .fO{color:#475467}
.rm tfoot .fL{color:var(--l-fg)} .rm tfoot .fX{color:var(--warn)}
.rm tfoot tr.fw > *{background:#ecfdf3;color:#05603a;font-weight:700} /* มาทำงาน = กลางวัน + กลางคืน (IT ใช้วางแผนอาหาร) */
.rm tfoot td.scol,.rm tfoot tr.fw td.scol{background:#fff4c2}


.drawer{position:fixed;top:0;right:0;height:100%;width:min(460px,100vw);background:#fff;box-shadow:-18px 0 40px rgba(15,23,42,.2);transform:translateX(105%);transition:transform .22s ease;z-index:60;display:flex;flex-direction:column}
.drawer.open{transform:none}
.dh{background:var(--navy);color:#fff;padding:14px 18px;border-bottom:3px solid var(--red);display:flex;justify-content:space-between;align-items:flex-start;gap:12px}
.dh h2{margin:0;font-size:17px;line-height:1.3}
.dh small{display:block;color:#9fb0cc;font-size:12px;margin-top:2px}
.dh button{flex:0 0 auto;height:32px;padding:0 11px;border-radius:8px;background:#232c40;border:1px solid #33405c;color:#e8edf6;font-size:12.5px}
.db{padding:16px 18px 28px;overflow:auto;flex:1}
.db h3{font-size:12px;color:var(--muted);margin:18px 0 8px;font-weight:700;letter-spacing:.02em}
.daycard{border:1px solid var(--line);border-radius:12px;padding:12px 14px}
.daycard .top{display:flex;align-items:center;gap:12px}
.daycard .big{flex:0 0 46px;width:46px;height:38px;border-radius:9px;font-weight:800;font-size:15px}
.daycard .big.k-O{font-size:12px}
.daycard .top strong{display:block;font-size:15px}
.daycard .top .dt{display:block;font-size:12px;color:var(--muted)}
dl.kv{display:grid;grid-template-columns:96px 1fr;gap:7px 12px;margin:12px 0 0;font-size:12.5px}
dl.kv.flush{margin-top:0}
dl.kv dt{color:var(--muted)}
dl.kv dd{margin:0;font-weight:600}
dl.kv dd small{display:block;font-weight:400;color:var(--muted);font-size:11.5px}
dl.kv dd.warntext{color:var(--warn)}
.notebox{border-radius:10px;padding:9px 11px;font-size:12.5px;margin-top:10px;line-height:1.45}
.notebox.warn{background:var(--warnbg);border:1px solid var(--warnline);color:#7a4b00}
.notebox.info{background:#eff5ff;border:1px solid #b2ddff;color:#175cd3}
.notebox.leave{background:#f5f3ff;border:1px solid #ddd6fe;color:#5b21b6}
.strip{display:grid;grid-template-columns:repeat(14,1fr);gap:3px}
.strip div{text-align:center;min-width:0}
.strip .k{width:100%;height:26px;font-size:9.5px}
.strip small{display:block;font-size:9.5px;color:var(--muted);line-height:1.15;margin-top:2px}
.mini{display:grid;grid-template-columns:repeat(5,1fr);gap:6px}
.mini div{border:1px solid var(--line);border-radius:9px;padding:6px 4px;text-align:center}
.mini b{display:block;font-size:17px;line-height:1.2}
.mini small{font-size:10.5px;color:var(--muted)}
.mini .d b{color:var(--d-fg)} .mini .n b{color:var(--n-fg)} .mini .o b{color:#475467} .mini .l b{color:var(--l-fg)} .mini .x b{color:var(--warn)}
.acts{display:flex;flex-direction:column;gap:8px;margin-top:18px}
.acts a{min-height:40px;border-radius:9px;border:1px solid #cbd5e1;background:#fff;font-weight:600;color:#334155;text-decoration:none;padding:8px 12px;display:flex;align-items:center;justify-content:space-between;gap:8px;font-size:13px}
.acts a:hover{border-color:#94a3b8}
.acts a small{font-weight:400;font-size:11px;opacity:.85}
.acts .ro{font-size:12px;color:var(--muted);margin:4px 0 0}

.tip{position:fixed;z-index:80;pointer-events:none;background:#0f172a;color:#fff;font-size:12px;padding:6px 9px;border-radius:7px;box-shadow:0 8px 20px rgba(15,23,42,.25);white-space:nowrap;display:none}

@media(max-width:820px){
  :root{--emp:150px;--pat:76px;--day:32px}
  .appbar{padding-left:16px;padding-right:16px}
  main{padding:16px 16px 50px}
  h1{font-size:24px}
  .filters label{flex:1 1 100%}
  .filters input,.filters select{min-width:0;width:100%}
  .monthnav input{flex:1;width:auto}
  .stat{min-width:calc(50% - 5px)}
  .table-wrap{max-height:72vh}
}

/* ---------- ขั้นที่ 2: โหมดแก้ Roster (ADMIN-Roster / ผู้ดูแลระบบ) ---------- */
.btn.edit{background:var(--navy);border-color:var(--navy);color:#fff}
.btn.edit.on{background:#f79009;border-color:#f79009;color:#fff}
.meaning li.edit-only{display:none}
body.editing .meaning li.edit-only{display:flex}
.editbar{display:flex;flex-wrap:wrap;align-items:center;gap:8px 14px;background:#fff8eb;border:1px solid #fbd38d;border-radius:12px;padding:10px 12px;margin:0 0 10px}
.editbar .eb-info{min-width:190px}
.editbar .eb-info b{display:block;font-size:13px;color:#5c3800}
.editbar .eb-info span{font-size:12px;color:#7a4b00}
.editbar .eb-actions{display:flex;flex-wrap:wrap;gap:6px;align-items:center}
.editbar button{height:34px;padding:0 12px;border-radius:8px;border:1px solid #cbd5e1;background:#fff;font-weight:700;font-size:12.5px;color:#334155}
.editbar button.k-D{background:var(--d-bg);color:var(--d-fg);border-color:#a6f4c5}
.editbar button.k-N{background:var(--n-bg);color:var(--n-fg);border-color:#c7d2fe}
.editbar button.k-O{background:var(--o-bg);color:#475467;border-color:#d0d5dd}
.editbar button.primary{background:var(--red);border-color:var(--red);color:#fff}
.editbar button:disabled,.editbar select:disabled{opacity:.45;cursor:default}
.editbar select{height:34px;border:1px solid #cbd5e1;border-radius:8px;background:#fff;padding:0 8px;font-size:12.5px;max-width:260px}
.editbar .eb-save{margin-left:auto;display:flex;align-items:center;gap:8px;font-size:12.5px;color:#7a4b00;flex-wrap:wrap}
.editbar .eb-help{flex-basis:100%;font-size:11.5px;color:#8a6a2e}
.rm td.draft,.k.draft{box-shadow:inset 0 0 0 2px #f79009}
body.editing .rm td.c{cursor:cell}
body.editing .rm td.lock,.k.lock{background-image:repeating-linear-gradient(135deg,rgba(71,84,103,.2) 0 2px,transparent 2px 6px);cursor:not-allowed}
.rm td.selc{background-image:linear-gradient(rgba(23,92,211,.24),rgba(23,92,211,.24));box-shadow:inset 0 0 0 2px #175cd3}
.rm td.selc.draft{box-shadow:inset 0 0 0 2px #175cd3,inset 0 0 0 4px #f79009}
.acts button{min-height:40px;border-radius:9px;border:1px solid var(--navy);background:var(--navy);color:#fff;font-weight:600;text-align:left;padding:8px 12px;display:flex;align-items:center;justify-content:space-between;gap:8px;font-size:13px}
.acts button:disabled{opacity:.6;cursor:not-allowed;background:#fff;color:#334155;border-color:#cbd5e1}
.acts button small{font-weight:400;font-size:11px;opacity:.85}

dialog.dlg{border:0;border-radius:14px;padding:0;width:min(560px,94vw);box-shadow:0 24px 60px rgba(15,23,42,.3)}
dialog.dlg::backdrop{background:rgba(15,23,42,.35)}
.dlg header{background:var(--navy);color:#fff;padding:12px 16px;border-bottom:3px solid var(--red);display:flex;justify-content:space-between;align-items:center}
.dlg header h2{margin:0;font-size:16px}
.dlg header .x{background:#232c40;border:1px solid #33405c;color:#e8edf6;border-radius:8px;height:30px;padding:0 10px}
.dlg-body{padding:14px 16px;display:flex;flex-direction:column;gap:10px;font-size:13px;max-height:70vh;overflow:auto}
.dlg-body p{margin:0}
.dlg-body label{display:flex;flex-direction:column;gap:4px;font-size:12px;color:var(--muted);font-weight:600}
.dlg-body label small{font-weight:400}
.dlg-body select,.dlg-body input,.dlg-body textarea{height:38px;padding:0 10px;border:1px solid #cbd5e1;border-radius:8px;background:#fff;color:var(--ink);font:inherit}
.dlg-body textarea{height:auto;padding:8px 10px;resize:vertical}
.dlg-body .two{display:grid;grid-template-columns:minmax(0,1fr) minmax(0,1fr);gap:10px}
.dlg-body select,.dlg-body input:not([type=radio]){width:100%;min-width:0}
.dlg-note{font-size:12px;color:var(--muted)}
.dlg-err{font-size:12.5px;color:var(--bad);font-weight:600;background:var(--badbg);border:1px solid var(--badline);border-radius:8px;padding:8px 10px}
.dlg-result{background:var(--soft);border:1px solid var(--line);border-radius:10px;padding:10px 12px;font-size:12.5px;line-height:1.5}
.dlg-result b{color:var(--ink)}
.dlg-result ul{margin:6px 0 0;padding-left:18px}
.dlg footer{display:flex;justify-content:flex-end;gap:8px;padding:0 16px 16px;flex-wrap:wrap}
.dlg footer button{height:38px;padding:0 16px;border-radius:8px;border:1px solid #cbd5e1;background:#fff;font-weight:600;color:#334155}
.dlg footer button.primary{background:var(--red);border-color:var(--red);color:#fff}
.dlg footer button:disabled{opacity:.5;cursor:wait}
.toast{position:fixed;left:50%;bottom:24px;transform:translateX(-50%);background:#0f172a;color:#fff;padding:11px 18px;border-radius:10px;font-size:13px;box-shadow:0 12px 30px rgba(15,23,42,.25);z-index:90;max-width:min(92vw,680px)}
.toast.error{background:#912018}
@media(max-width:820px){.editbar .eb-save{margin-left:0}.dlg-body .two{grid-template-columns:1fr}}

/* ---------- 3 ปุ่ม (26/9/2569): 1 สร้างกะ · 2 สร้าง Roster · 3 ตั้งรอบให้คนที่เลือก ---------- */
.editbar .eb-steps{display:flex;align-items:center;gap:6px;flex-wrap:wrap;padding:4px 6px;border-radius:10px;background:#fff;border:1px dashed #f5b35c}
.editbar .eb-steps i{font-style:normal;color:#b54708;font-weight:700}
.editbar button.eb-step{display:inline-flex;align-items:center;gap:6px;border-color:#94a3b8;color:var(--navy)}
.editbar button.eb-step b{display:inline-grid;place-items:center;width:20px;height:20px;border-radius:50%;background:var(--navy);color:#fff;font-size:11px}
.editbar button.eb-step.go.ready{background:var(--navy);border-color:var(--navy);color:#fff}
.editbar button.eb-step.go.ready b{background:#fff;color:var(--navy)}
.editbar .eb-help b{color:#5c3800}
dialog.dlg.wide{width:min(720px,94vw)}
.dlg-body select.big,.dlg-body input.big{height:44px;font-size:17px;font-weight:700;letter-spacing:.02em}
.dlg-body .q{margin:0;font-size:13.5px;font-weight:700;color:var(--ink)}
.dlg-body .q small{font-weight:400;color:var(--muted);font-size:12px;margin-left:4px}
.dlg-body .warntext{color:var(--warn);font-weight:600}
.who-line{background:var(--soft);border:1px solid var(--line);border-radius:10px;padding:8px 11px;font-size:12.5px;color:#334155}
.step{display:flex;gap:10px;align-items:flex-start}
.step .n{flex:0 0 26px;height:26px;border-radius:50%;background:var(--red);color:#fff;display:grid;place-items:center;font-weight:700;font-size:13px;margin-top:1px}
.step .sb{flex:1;min-width:0;display:flex;flex-direction:column;gap:7px}
/* ปุ่มเลือกแบบเม็ดยา (พัก · สลับ) และชิป (ทำกี่วัน หยุดกี่วัน) — วงกลมเลือกซ่อนไว้ แต่ยังกดด้วยแป้นพิมพ์ได้ */
.pills,.chips{display:flex;flex-wrap:wrap;gap:8px;align-items:center}
.pills-label{font-size:12px;color:var(--muted);font-weight:600;margin-right:2px}
.dlg-body label.pill,.dlg-body label.chip,.dlg-body label.tcard{position:relative;display:inline-flex;flex-direction:row;gap:0;font-size:13px;color:inherit;font-weight:600}
.dlg-body label.pill input,.dlg-body label.chip input,.dlg-body label.tcard input{position:absolute;opacity:0;width:1px;height:1px;margin:0;padding:0;border:0;pointer-events:none}
.pill span,.chip span{display:inline-flex;align-items:center;gap:4px;min-height:40px;padding:0 15px;border:1.5px solid #cbd5e1;border-radius:999px;background:#fff;color:#334155;cursor:pointer;user-select:none}
.chip span{border-radius:10px;min-width:104px;justify-content:center;font-weight:500}
.chip span b{font-size:16px;color:var(--ink)}
.pill input:checked+span,.chip input:checked+span{border-color:var(--navy);background:var(--navy);color:#fff}
.chip input:checked+span b{color:#fff}
.pill input:focus-visible+span,.chip input:focus-visible+span,.tcard input:focus-visible+.tc{outline:2px solid #175cd3;outline-offset:2px}
/* สรุปกะ (ปุ่ม 1) */
.sum{border-radius:12px;padding:10px 14px;display:flex;flex-direction:column;gap:2px;border:1px solid var(--line)}
.sum b{font-size:13px}
.sum strong{font-size:22px;letter-spacing:.02em;line-height:1.25}
.sum strong small{font-size:12.5px;font-weight:600;letter-spacing:0}
.sum span{font-size:12.5px;color:#334155}
.sum.d{background:var(--d-bg);border-color:#a6f4c5;color:var(--d-fg)}
.sum.n{background:var(--n-bg);border-color:#c7d2fe;color:var(--n-fg)}
.sum.bad{background:var(--badbg);border-color:var(--badline);color:var(--bad)}
.dlg-note.same{background:var(--warnbg);border:1px solid var(--warnline);border-radius:8px;padding:7px 10px;color:#7a4b00}
/* แถบรอบ: ยาวตามจำนวนวัน (ตั้ง flex-grow ด้วย JS) */
.look{display:flex;flex-direction:column;gap:6px;background:var(--soft);border:1px solid var(--line);border-radius:12px;padding:10px 12px}
.cyc{display:flex;gap:3px;min-height:52px}
.cyc .seg{flex:1 1 0;min-width:72px;border-radius:8px;padding:6px 8px;display:flex;flex-direction:column;justify-content:center;line-height:1.25;overflow:hidden}
.cyc .seg b{font-size:12.5px;white-space:nowrap}
.cyc .seg small{font-size:11.5px;white-space:nowrap;opacity:.9}
.seg.k-D{background:var(--d-bg);color:var(--d-fg)}
.seg.k-N{background:var(--n-bg);color:var(--n-fg)}
.seg.k-O{background:#e4e7ec;color:#475467}
.cyc.mini{min-height:8px;gap:2px;margin-top:4px;width:100%}
.cyc.mini .seg{min-width:8px;padding:0;border-radius:3px;height:8px}
/* การ์ดเลือก Roster (ปุ่ม 3) */
.tpl-pick{display:grid;grid-template-columns:repeat(auto-fill,minmax(210px,1fr));gap:8px}
.dlg-body label.tcard{display:flex}
.tcard .tc{flex:1;display:flex;flex-direction:column;gap:1px;border:1.5px solid #cbd5e1;border-radius:12px;padding:9px 12px;background:#fff;cursor:pointer;font-weight:400}
.tcard .tc b{font-size:14.5px;color:var(--ink)}
.tcard .tc small{font-size:12px;color:#475467}
.tcard .tc small.nw{white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.tcard input:checked+.tc{border-color:var(--navy);box-shadow:inset 0 0 0 1.5px var(--navy);background:#f5f7fb}
.tcard input:checked+.tc b::before{content:"✓ ";color:var(--ok)}
.tadd{min-height:44px;border:1.5px dashed #94a3b8;border-radius:12px;background:#fff;color:var(--navy);font-weight:700;font-size:13px}
.tadd:hover{border-color:var(--navy)}
/* รายการ Roster ที่มีแล้ว (ปุ่ม 2) */
.tpl-list ul{list-style:none;margin:6px 0 0;padding:0;display:flex;flex-direction:column;gap:6px}
.tpl-list li{display:flex;align-items:center;justify-content:space-between;gap:10px;border:1px solid var(--line);border-radius:10px;padding:7px 10px}
.tpl-list li div{min-width:0;display:flex;flex-direction:column}
.tpl-list li small{font-size:12px;color:var(--muted)}
.tpl-list li button{height:32px;padding:0 12px;border-radius:8px;border:1px solid var(--badline);background:#fff;color:var(--bad);font-weight:600;flex:0 0 auto}
.dlg-result p{margin:0 0 4px}
.dlg-result .ok{color:var(--ok)}
.dlg-result .bad{color:var(--bad)}
@media(max-width:820px){.tpl-pick{grid-template-columns:1fr}.cyc .seg{min-width:58px;padding:5px 6px}.cyc .seg b{font-size:11.5px}}
/* รอบ 2 (26/9/2569): ปุ่ม 2 กรอกจำนวนวันเอง (− / +) · ปุ่ม 3 รอบพื้นฐานของระบบ */
.num{display:flex;flex-direction:column;gap:4px;min-width:0}
.num-label{font-size:12px;color:var(--muted);font-weight:600}
.stepper{display:flex;align-items:stretch;border:1px solid #cbd5e1;border-radius:10px;overflow:hidden;height:46px;background:#fff}
.stepper button{flex:0 0 46px;border:0;background:var(--soft);font-size:20px;font-weight:700;color:var(--navy)}
.stepper button:hover{background:#e8edf6}
.dlg-body .stepper input{flex:1;border:0;border-radius:0;height:auto;text-align:center;font-size:20px;font-weight:700;padding:0;min-width:0;width:100%;-moz-appearance:textfield;appearance:textfield}
.stepper input::-webkit-inner-spin-button,.stepper input::-webkit-outer-spin-button{-webkit-appearance:none;margin:0}
.base-row{display:flex;flex-direction:column;gap:6px;margin-top:10px}
.pill.sm span{min-height:32px;padding:0 11px;font-size:12px;font-weight:500}

/* ---------- เน้นตาราง (3/10/2569 เจ้าของ: "โจทย์เดียวกันครับ" — แบบหน้าตรวจสอบเวลา / Matrix รหัส) ----------
   หัวเรื่องซ่อน (โปรแกรมอ่านหน้าจอยังอ่านได้) · ตัวกรองแถวเดียว ป้ายซ่อน · ตัวเลขเป็นแถบบาง ป้ายสั้น (คำเต็มชี้ดู)
   · จัดกลุ่ม / แสดงในช่อง / ปุ่มแก้ อยู่แถวเดียวกับตัวเลข · ความหมายตัวอักษรพับไว้ · ตารางสูงพอดีจอ (JS ตั้งตามที่เหลือ) */
.sr-only{position:absolute;width:1px;height:1px;padding:0;margin:-1px;overflow:hidden;clip:rect(0,0,0,0);white-space:nowrap;border:0}
main{max-width:none;padding:10px 16px 12px} /* 4/10/2569: ไม่มีกล่องคำอธิบายท้ายหน้าแล้ว · ล่าง 12px = ช่องว่างของ fitTable (หน้าไม่เลื่อน) */
main>.lede{display:none}
.filters{padding:8px 10px;gap:8px;align-items:center;border-radius:10px}
.filters label{flex-direction:row;align-items:center;gap:6px;white-space:nowrap}
.filters input,.filters select{height:34px;min-width:0;font-size:12.5px}
.filters select{max-width:190px}
.filters .grow{min-width:170px}
.monthnav{gap:4px}
.monthnav input{width:140px}
.monthnav .nav{height:34px;width:34px}
.btn{height:34px;padding:0 12px;font-size:12.5px}
.live{height:34px;padding:0 12px;font-size:11.5px}
.slim{display:flex;align-items:center;gap:8px 10px;flex-wrap:wrap;margin:8px 0}
.slim .summary{margin:0;gap:6px;flex:0 1 auto;align-items:center}
.slim .tools{display:inline-flex;align-items:center;gap:8px;flex:0 0 auto}
#summary .stat{flex:0 0 auto;min-width:0;display:inline-flex;flex-direction:row-reverse;align-items:baseline;gap:5px;padding:3px 10px;border-radius:999px}
#summary .stat strong{font-size:14px;line-height:1.3}
#summary .stat span{font-size:11.5px;margin:0}
#summary .sday{font-size:11.5px;font-weight:700;color:#334155;border-left:1px solid #cbd5e1;padding-left:8px;margin-left:2px;white-space:nowrap}
#summary .sel+.mo{margin-left:8px}
.slim .toolbar{margin:0;flex:1 1 auto;gap:8px 12px}
.slim .toolbar .left{font-size:12px}
.slim .toolbar .right{flex-wrap:wrap;margin-left:auto}
.slim label.view{display:inline-flex;align-items:center;gap:6px;font-size:11px;color:var(--muted);font-weight:600;white-space:nowrap}
.slim label.view select{height:34px;padding:0 8px;border:1px solid #cbd5e1;border-radius:8px;background:#fff;color:var(--ink);font-size:12.5px;max-width:200px}
.slim .meaning{margin:0;flex:0 0 auto;border-radius:999px}
.slim .meaning summary{padding:6px 12px;font-size:12px}
.slim .meaning:not([open]) summary small{display:none}
.slim .meaning[open]{flex:1 1 100%;order:9;border-radius:12px}
.meaning .hint{margin:0 14px 10px}
.table-wrap{max-height:calc(100vh - 240px);min-height:320px}
@media(max-width:820px){
  main{padding:12px 12px 40px}
  .filters label{flex:1 1 calc(50% - 4px)}
  .filters label.month,.filters label.grow{flex:1 1 100%}
  .filters select{max-width:none}
  .monthnav input{flex:1;width:auto}
  .slim .toolbar .right{margin-left:0}
  .table-wrap{max-height:72vh;min-height:0}
}

/* 5/10/2569 เจ้าของเลือกแบบ ก: ปุ่ม "ตามหน่วยงาน" ในแถบตัวเลข + ลิ้นชักขวา จำนวนคนแต่ละหน่วยงานของวันที่เลือก (ปิดได้ ตารางหลักไม่เสียพื้นที่)
   สีตามภาพร่างที่เจ้าของเลือก: D น้ำเงิน · N ม่วง · D+N เขียว (เหมือนแถว "มาทำงาน") · ลา ส้ม · ! แดง · ตารางเลื่อนในลิ้นชัก (.db) หัวตารางค้างบน */
#summary .ubtn{flex:0 0 auto;height:30px;padding:0 12px;border-radius:8px;border:1px solid #175cd3;background:#eff5ff;color:#175cd3;font-size:12px;font-weight:700;white-space:nowrap}
#summary .ubtn:hover{background:#d1e9ff}
#summary .ubtn.on{box-shadow:0 0 0 3px #b2ddff}
#summary .ubtn+.mo{margin-left:8px}
.unav{display:flex;align-items:center;justify-content:space-between;gap:8px;margin:0 0 10px}
.unav .uday{display:inline-flex;align-items:center;gap:6px;min-width:0}
.unav b{font-size:14px;white-space:nowrap}
.unav button{height:30px;padding:0 10px;border-radius:8px;border:1px solid #cbd5e1;background:#fff;color:#334155;font-size:12px;font-weight:600;white-space:nowrap}
.unav button:hover:not(:disabled){border-color:#94a3b8}
.unav button:disabled{opacity:.4;cursor:default}
.unote{margin:0 0 8px;font-size:12px;color:#175cd3}
.ut{width:100%;border-collapse:collapse;font-size:12.5px}
.ut thead th{position:sticky;top:0;z-index:1;background:var(--navy2);color:#fff;font-weight:600;font-size:11px;padding:6px;text-align:right;white-space:nowrap}
.ut thead th:first-child{text-align:left}
.ut thead th.w{background:#ecfdf3;color:#05603a}
.ut td,.ut tbody th,.ut tfoot th{height:26px;padding:0 6px;border-bottom:1px solid #eef2f6}
.ut td{text-align:right;font-weight:600;white-space:nowrap;font-variant-numeric:tabular-nums}
.ut tbody th,.ut tfoot th{text-align:left;font-weight:500;line-height:1.25}
.ut .ulink{border:0;background:none;padding:2px 0;margin:0;color:var(--ink);text-align:left}
.ut .ulink:hover{color:#175cd3;text-decoration:underline}
.ut td.d{color:#175cd3} .ut td.n{color:#6938ef} .ut td.o{color:#344054} .ut td.l{color:#b54708} .ut td.x{color:#b42318}
.ut td.w{background:#ecfdf3;color:#05603a;font-weight:700}
.ut tr.on th,.ut tr.on td{background:#fff4c2}
.ut tr.on .ulink{font-weight:700}
.ut tfoot th,.ut tfoot td{height:28px;border-top:2px solid #d5dde8;border-bottom:0;background:#f8fafc;font-weight:700}
.ut .uempty{text-align:left;color:var(--muted);font-weight:400}
.uhint{margin:10px 0 0;font-size:11px;line-height:1.5;color:var(--muted)}
