[hidden] { display: none !important; }
:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --text: #1d2330;
  --muted: #667085;
  --line: #e3e6ec;
  --primary: #2357c6;
  --primary-soft: #e8eefb;
  --ok: #1a7f4b;
  --ok-soft: #e4f4ea;
  --warn: #a15c00;
  --warn-soft: #fff3df;
  --bad: #b42318;
  --bad-soft: #fdecea;
  --c-workday: #2357c6;
  --c-hwork: #7a4cc2;
  --c-hot: #c2410c;
  --radius: 10px;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.55 'IBM Plex Sans Thai', system-ui, sans-serif;
}
h1 { font-size: 22px; margin: 0 0 4px; font-weight: 600; }
h2 { font-size: 17px; margin: 0 0 12px; font-weight: 600; }
.sub { color: var(--muted); margin: 0 0 20px; }
main { max-width: 1120px; margin: 0 auto; padding: 24px 16px 64px; }

.topbar {
  display: flex; align-items: center; gap: 24px; flex-wrap: wrap;
  background: var(--surface); border-bottom: 1px solid var(--line);
  padding: 10px 24px; position: sticky; top: 0; z-index: 5;
}
.brand { font-weight: 600; color: var(--primary); }
#subnav { max-width: 1120px; margin: 0 auto; padding: 16px 16px 0; display: flex; gap: 6px; flex-wrap: wrap; }
#subnav a { text-decoration: none; color: var(--muted); padding: 6px 14px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface); font-size: 14px; }
#subnav a.active { color: #fff; background: var(--primary); border-color: var(--primary); }
.login-card { max-width: 380px; margin: 8vh auto 0; }
.clock-btns { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 16px 0 8px; }
.clock-btns button { padding: 18px 10px; font-size: 18px; font-weight: 600; border-radius: 12px; }
.clock-btns .in { background: var(--ok); border-color: var(--ok); color: #fff; }
.clock-btns .out { background: #c2410c; border-color: #c2410c; color: #fff; }
.badge.absent, .badge.not_in { background: var(--bad-soft); color: var(--bad); }
.badge.present, .badge.working { background: var(--ok-soft); color: var(--ok); }
.badge.leave, .badge.off { background: #f3ecfc; color: #6b3fb0; }
.secret { font: 600 22px/1.2 ui-monospace, Consolas, monospace; letter-spacing: 2px; background: #f4f6f9; border: 1px dashed var(--line); border-radius: 8px; padding: 12px; text-align: center; user-select: all; }
nav { display: flex; gap: 4px; flex: 1; flex-wrap: wrap; }
nav a {
  text-decoration: none; color: var(--muted); padding: 6px 12px; border-radius: 8px;
}
nav a.active { background: var(--primary-soft); color: var(--primary); font-weight: 500; }
.who { display: flex; gap: 10px; align-items: center; color: var(--muted); font-size: 14px; }

.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 20px; margin-bottom: 16px;
}
.grid { display: grid; gap: 16px; }
.grid.two { grid-template-columns: minmax(0, 5fr) minmax(0, 7fr); }
@media (max-width: 860px) { .grid.two { grid-template-columns: 1fr; } }

.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 16px; }
@media (max-width: 720px) { .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.stat .label { color: var(--muted); font-size: 13px; display: flex; align-items: center; gap: 6px; }
.stat .value { font-size: 22px; font-weight: 600; margin-top: 2px; font-variant-numeric: tabular-nums; }
.stat .extra { color: var(--muted); font-size: 12.5px; }
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }
.dot.workday_ot { background: var(--c-workday); }
.dot.holiday_work { background: var(--c-hwork); }
.dot.holiday_ot { background: var(--c-hot); }

label { display: block; font-size: 13.5px; color: var(--muted); margin-bottom: 4px; }
input, select, textarea {
  font: inherit; color: inherit; width: 100%;
  border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; background: #fff;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary-soft); border-color: var(--primary); }
textarea { resize: vertical; min-height: 70px; }
.field { margin-bottom: 14px; }
.row { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 12px; }

button {
  font: inherit; cursor: pointer; border-radius: 8px; padding: 8px 16px;
  border: 1px solid var(--line); background: var(--surface); color: var(--text);
}
button:hover { border-color: #c7ccd6; }
button.primary { background: var(--primary); border-color: var(--primary); color: #fff; font-weight: 500; }
button.primary:hover { background: #1c49a8; }
button.ok { background: var(--ok); border-color: var(--ok); color: #fff; }
button.bad { color: var(--bad); border-color: #f1c4bf; }
button.small { padding: 4px 10px; font-size: 13.5px; }
button.link { border: 0; background: none; color: var(--primary); padding: 0; }
button:disabled { opacity: .5; cursor: not-allowed; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 500; font-size: 13px; background: #fafbfc; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
tfoot td { font-weight: 600; border-top: 2px solid var(--line); }
.table-wrap { overflow-x: auto; }

.badge {
  display: inline-block; font-size: 12.5px; padding: 1px 9px; border-radius: 999px;
  background: #eef0f3; color: var(--muted); white-space: nowrap;
}
.badge.pending { background: var(--warn-soft); color: var(--warn); }
.badge.approved { background: var(--ok-soft); color: var(--ok); }
.badge.rejected { background: var(--bad-soft); color: var(--bad); }
.badge.holiday { background: #f3ecfc; color: #6b3fb0; }
.badge.yes { background: var(--ok-soft); color: var(--ok); }

.alert { border-radius: 8px; padding: 10px 12px; font-size: 14px; margin: 10px 0; }
.alert.warn { background: var(--warn-soft); color: var(--warn); }
.alert.bad { background: var(--bad-soft); color: var(--bad); }
.alert.info { background: var(--primary-soft); color: #1c3f8c; }

.preview { border: 1px dashed var(--line); border-radius: 8px; padding: 12px; margin-bottom: 14px; font-size: 14px; }
.preview .line { display: flex; justify-content: space-between; gap: 12px; padding: 2px 0; }
.preview .line span:last-child { font-variant-numeric: tabular-nums; }

.meter { height: 8px; background: #eceef2; border-radius: 99px; overflow: hidden; margin: 6px 0 4px; }
.meter > div { height: 100%; background: var(--primary); border-radius: 99px; }
.meter.over > div { background: var(--bad); }

.req { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 16px; padding: 16px 0; border-bottom: 1px solid var(--line); }
.req:last-child { border-bottom: 0; }
.req .meta { color: var(--muted); font-size: 13.5px; }
.req .split { display: flex; gap: 14px; flex-wrap: wrap; font-size: 13.5px; margin-top: 6px; }
.req .split span { display: inline-flex; align-items: center; gap: 5px; }
.req .decide { display: flex; flex-direction: column; gap: 8px; min-width: 200px; }
@media (max-width: 640px) { .req { grid-template-columns: 1fr; } }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 16px; flex-wrap: wrap; }
.tabs button { border: 0; border-bottom: 2px solid transparent; border-radius: 0; background: none; color: var(--muted); padding: 8px 14px; }
.tabs button.active { color: var(--primary); border-color: var(--primary); font-weight: 500; }

.switch { position: relative; display: inline-block; width: 42px; height: 24px; vertical-align: middle; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; background: #cfd4dc; border-radius: 99px; transition: .15s; cursor: pointer; }
.switch span::before { content: ''; position: absolute; width: 18px; height: 18px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: .15s; }
.switch input:checked + span { background: var(--ok); }
.switch input:checked + span::before { transform: translateX(18px); }
.switch input:focus-visible + span { outline: 2px solid var(--primary); outline-offset: 2px; }

.datefield { display: inline-flex; align-items: center; gap: 4px; width: 100%; position: relative; }
.datefield .dtext { flex: 1; min-width: 7.2em; }
.datefield .dbtn { padding: 6px 9px; line-height: 1; }
.datefield .dpick { position: absolute; right: 0; bottom: 0; width: 1px; height: 1px; opacity: 0; pointer-events: none; border: 0; padding: 0; }

.days { display: flex; gap: 6px; flex-wrap: wrap; }
.days label { display: inline-flex; align-items: center; gap: 4px; border: 1px solid var(--line); border-radius: 8px; padding: 4px 10px; color: var(--text); cursor: pointer; margin: 0; }
.days input { width: auto; }


dialog { border: 0; border-radius: 12px; padding: 0; width: min(640px, calc(100vw - 32px)); box-shadow: 0 20px 50px rgba(0,0,0,.2); }
dialog::backdrop { background: rgba(20,24,33,.4); }
dialog .body { padding: 20px; max-height: 80vh; overflow: auto; }
dialog .foot { padding: 12px 20px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 8px; }

.empty { color: var(--muted); padding: 20px 0; text-align: center; }
.muted { color: var(--muted); }
.nowrap { white-space: nowrap; }

#toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  background: #1d2330; color: #fff; padding: 10px 16px; border-radius: 8px; font-size: 14px;
  opacity: 0; pointer-events: none; transition: opacity .2s; max-width: calc(100vw - 32px);
}
#toast.show { opacity: 1; }

/* ---------- แดชบอร์ด ---------- */
:root {
  /* สีของแต่ละเรื่อง ใช้ตรงกันทั้งการ์ด กราฟ ปฏิทิน และตาราง — ตรวจแล้วว่าแยกกันออกแม้ตาบอดสี
     มาสาย/ขาดงานใช้สีสถานะ (เตือน/วิกฤต) และมีตัวอักษรกำกับเสมอ ไม่ใช้สีอย่างเดียว */
  --d-ontime: #bfe5c6;
  --d-late: #fab219;
  --d-absent: #d03b3b;
  --d-sick: #6b3fb0;
  --d-other: #ab8fe6;
  --d-early: #2a78d6; /* ออกก่อนเวลา: สีส้มสถานะใกล้สีมาสายเกินไป จึงใช้ฟ้าที่แยกจากทุกสีได้ */
  --d-axis: #c3c7cf;
}
.filters { display: flex; flex-wrap: wrap; gap: 8px 16px; align-items: center; margin-bottom: 12px; }
.filters > span { display: inline-flex; flex-wrap: wrap; align-items: center; gap: 8px; max-width: 100%; }
.filters label { margin: 0; white-space: nowrap; }
.filters select { min-width: 0; max-width: 100%; }
.period, .prange { display: inline-flex; flex-wrap: wrap; align-items: center; gap: 6px 8px; max-width: 100%; }
#pfBtn.pf-on { background: var(--warn-soft); border-color: #f0d3a6; color: var(--warn); font-weight: 500; }
.pf-group { border: 1px solid var(--line); border-radius: 8px; padding: 4px 12px 6px; margin: 0 0 10px; }
.pf-group legend { font-size: 13px; color: var(--muted); padding: 0 4px; }
.pf-item { display: flex; gap: 10px; align-items: center; color: var(--text); font-size: 14px; padding: 6px 0; margin: 0; cursor: pointer; }
.pf-item input { width: auto; flex: none; }
.d-range { font-size: 13.5px; margin: 0 0 12px; }
#dBody { transition: opacity .15s; }
#dBody.loading { opacity: .5; pointer-events: none; }
.kpis { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 12px; margin-bottom: 16px; }
@media (max-width: 1000px) { .kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (max-width: 560px) { .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.kpi .value { font-size: 26px; line-height: 1.3; font-variant-numeric: normal; }
.kpi .value .unit { font-size: 14px; font-weight: 500; color: var(--muted); }
.kpi .key { width: 10px; height: 10px; border-radius: 3px; display: inline-block; flex: none; }
.delta { font-size: 12.5px; color: var(--muted); margin: 2px 0; }
.delta.good { color: var(--ok); }
.delta.bad { color: var(--bad); }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 8px 16px; flex-wrap: wrap; margin-bottom: 14px; }
.card-head h2 { margin: 0; }
.chart-note { font-size: 12.5px; margin: 10px 0 0; }

.multiples { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 20px 24px; }
.multiples.wide { grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
.tpanel { margin: 0; min-width: 0; }
.tpanel figcaption { font-size: 14px; font-weight: 500; margin-bottom: 6px; }
.tchart { display: flex; }
.tcol { flex: 1; min-width: 24px; display: flex; flex-direction: column; outline: none; border-radius: 6px; }
.tcol:hover, .tcol:focus-visible { background: #f2f4f7; }
.tcol:focus-visible { box-shadow: 0 0 0 2px var(--primary); }
.tplot { height: 120px; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; border-bottom: 1px solid var(--d-axis); }
.tval { font-size: 12px; color: var(--muted); line-height: 16px; margin-bottom: 4px; font-variant-numeric: tabular-nums; }
.tbar { width: min(24px, 60%); border-radius: 4px 4px 0 0; }
.tbar.partial { opacity: .5; }
.tcol:hover .tbar, .tcol:focus-visible .tbar { filter: brightness(1.08) saturate(1.1); }
.txl { font-size: 12px; color: var(--muted); text-align: center; padding-top: 4px; white-space: nowrap; }
.tcol.sel .txl { color: var(--text); font-weight: 600; }

.viz-tip { position: fixed; z-index: 50; pointer-events: none; background: #1d2330; color: #d7dbe3; font-size: 12.5px; line-height: 1.45;
  padding: 7px 10px; border-radius: 8px; max-width: 260px; box-shadow: 0 6px 18px rgba(0, 0, 0, .18); }
.viz-tip strong { display: block; color: #fff; font-size: 13.5px; font-weight: 600; }

/* ปฏิทินการมาทำงาน */
.mx-legend { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 12.5px; color: var(--muted); }
.mx-legend span { display: inline-flex; align-items: center; gap: 6px; }
.mx-legend .mx-cell { width: 16px; height: 16px; font-size: 10px; }
.mx-wrap { overflow-x: auto; padding: 3px 3px 6px; }
.mx { --mx-name: 150px; display: grid; gap: 2px; width: max-content; outline: none; border-radius: 6px; }
.mx:focus-visible { box-shadow: 0 0 0 2px var(--primary); }
@media (max-width: 600px) { .mx { --mx-name: 96px; } }
.mx-row { display: grid; grid-template-columns: var(--mx-name) repeat(var(--mx-n), 22px); gap: 2px; align-items: center; }
.mx-name { position: sticky; left: 0; z-index: 3; background: var(--surface); padding-right: 8px; min-width: 0; }
.mx-name .link { font-size: 13.5px; color: var(--text); text-align: left; max-width: 100%; display: block;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mx-name .link:hover { color: var(--primary); text-decoration: underline; }
.mx-head { align-items: end; margin-bottom: 2px; }
.mx-day { font-size: 11px; color: var(--muted); text-align: center; line-height: 1.3; font-variant-numeric: tabular-nums; }
.mx-day.today { color: var(--text); font-weight: 600; }
.mx-month { display: block; height: 15px; text-align: left; white-space: nowrap; overflow: visible; color: var(--text); font-weight: 500; }
.mx-dow { display: block; }
.mx-cell { width: 22px; height: 22px; border-radius: 4px; display: inline-flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 600; line-height: 1; font-style: normal; color: #1d2330; position: relative; }
.mx-cell.c-ontime { background: var(--d-ontime); }
.mx-cell.c-late { background: var(--d-late); }
.mx-cell.c-absent { background: var(--d-absent); color: #fff; }
.mx-cell.c-sick { background: var(--d-sick); color: #fff; }
.mx-cell.c-other { background: var(--d-other); }
.mx-cell.c-early { background: var(--d-early); color: #fff; }
.mx-cell.c-off::after { content: ''; width: 4px; height: 4px; border-radius: 50%; background: #aab1bd; }
.mx-cell.c-notin { border: 1.5px dashed #98a1b0; }
.mx-cell.c-none { background: repeating-linear-gradient(135deg, transparent 0 3px, #eceef2 3px 4px); }
.mx-cell[class*='half-']::before { content: ''; position: absolute; top: 0; right: 0; border-top-right-radius: 4px;
  border-style: solid; border-width: 0 9px 9px 0; border-color: transparent var(--half) transparent transparent; }
.mx-cell.half-sick { --half: var(--d-sick); }
.mx-cell.half-other { --half: var(--d-other); }
.mx-row .mx-cell.today { box-shadow: 0 0 0 1px var(--surface), 0 0 0 2px #98a1b0; }
.mx-row .mx-cell:hover, .mx-row .mx-cell.active { box-shadow: 0 0 0 1px var(--surface), 0 0 0 3px var(--text); z-index: 2; }

/* ตารางรายบุคคล */
.dtable .sm { color: var(--muted); font-size: 12px; }
.ibar { height: 4px; background: #eef0f3; border-radius: 2px; margin: 5px 0 0 auto; width: 64px; overflow: hidden; }
.ibar i { display: block; height: 100%; border-radius: 0 2px 2px 0; }
.th-sort { border: 0; background: none; padding: 0; color: inherit; font: inherit; cursor: pointer; white-space: nowrap; }
.th-sort:hover { color: var(--text); border: 0; }
.th-sort.on { color: var(--text); font-weight: 600; }
