:root {
  --bg: #f6f5f1; --surface: #fff; --surface-2: #faf9f6; --border: #e3e1d8; --border-strong: #cfccc0;
  --text: #2c2c2a; --muted: #6b6a64; --faint: #95938b;
  --accent: #534AB7; --accent-weak: #EEEDFE; --accent-strong: #3C3489;
  --red: #A32D2D; --red-weak: #FCEBEB; --amber: #854F0B; --amber-weak: #FAEEDA;
  --green: #3B6D11; --green-weak: #EAF3DE; --teal: #0F6E56; --teal-weak: #E1F5EE;
  --blue: #185FA5; --blue-weak: #E6F1FB; --gray-weak: #F1EFE8;
  --radius: 8px;
  font-family: "Leelawadee UI", "Noto Sans Thai", "Sarabun", Tahoma, "Segoe UI", sans-serif;
  font-size: 15px; color: var(--text); background: var(--bg);
}
* { box-sizing: border-box; }
body { margin: 0; line-height: 1.55; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; font-weight: 600; margin: 0 0 4px; }
h2 { font-size: 17px; font-weight: 600; margin: 0 0 12px; }
h3 { font-size: 15px; font-weight: 600; margin: 0 0 8px; }
.muted { color: var(--muted); } .small { font-size: 13px; } .faint { color: var(--faint); }
.nowrap { white-space: nowrap; } .right { text-align: right; } .center { text-align: center; }

header#top { display: flex; align-items: center; gap: 20px; padding: 0 24px; height: 56px; background: var(--surface);
  border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 5; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 600; white-space: nowrap; }
.logo { width: 24px; height: 24px; border-radius: 6px; background: var(--accent); position: relative; }
.logo::after { content: ""; position: absolute; left: 7px; top: 4px; width: 7px; height: 12px; border: solid #fff;
  border-width: 0 2.5px 2.5px 0; transform: rotate(45deg); }
nav#nav { display: flex; gap: 2px; flex: 1; overflow-x: auto; }
nav#nav a { padding: 6px 12px; border-radius: var(--radius); color: var(--muted); white-space: nowrap; }
nav#nav a:hover { background: var(--surface-2); text-decoration: none; color: var(--text); }
nav#nav a.on { background: var(--accent-weak); color: var(--accent-strong); font-weight: 600; }
nav#nav .badge { margin-left: 4px; }
.who { display: flex; align-items: center; gap: 12px; font-size: 14px; white-space: nowrap; }
.who a { color: var(--text); }

main { max-width: 1240px; margin: 0 auto; padding: 24px; }
.loading { color: var(--muted); padding: 40px; text-align: center; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head .sub { color: var(--muted); font-size: 14px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 18px 20px; margin-bottom: 18px; }
.card.flush { padding: 0; overflow: hidden; }
.card.flush > h2 { padding: 16px 20px 0; }
.grid { display: grid; gap: 18px; }
.grid.two { grid-template-columns: 1fr 1fr; }
.grid.side { grid-template-columns: minmax(0, 1fr) 340px; align-items: start; }
@media (max-width: 900px) { .grid.two, .grid.side { grid-template-columns: 1fr; } header#top { flex-wrap: wrap; height: auto; padding: 10px 16px; } main { padding: 16px; } }

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 18px; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 14px 16px; display: block; color: inherit; }
.kpi:hover { border-color: var(--border-strong); text-decoration: none; }
.kpi .label { font-size: 13px; color: var(--muted); }
.kpi .value { font-size: 28px; font-weight: 600; line-height: 1.2; margin-top: 2px; font-variant-numeric: tabular-nums; }
.kpi .note { font-size: 12px; color: var(--faint); }
.kpi.danger .value { color: var(--red); } .kpi.warn .value { color: var(--amber); } .kpi.ok .value { color: var(--green); }

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: left; font-weight: 600; color: var(--muted); font-size: 13px; padding: 10px 12px; border-bottom: 1px solid var(--border); background: var(--surface-2); white-space: nowrap; }
td { padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: top; }
tr:last-child td { border-bottom: 0; }
tr.click { cursor: pointer; } tr.click:hover td { background: var(--surface-2); }
td .t-title { font-weight: 500; } td .t-sub { font-size: 12.5px; color: var(--muted); }
.empty { padding: 28px; text-align: center; color: var(--faint); }

.badge { display: inline-block; padding: 1px 9px; border-radius: 999px; font-size: 12.5px; font-weight: 500; white-space: nowrap; line-height: 1.6; }
.s-draft, .s-cancelled { background: var(--gray-weak); color: #5F5E5A; }
.s-assigned { background: var(--amber-weak); color: var(--amber); }
.s-acknowledged { background: var(--blue-weak); color: var(--blue); }
.s-in_progress { background: var(--accent-weak); color: var(--accent-strong); }
.s-pending_review { background: var(--teal-weak); color: var(--teal); }
.s-done { background: var(--green-weak); color: var(--green); }
.b-red { background: var(--red-weak); color: var(--red); } .b-amber { background: var(--amber-weak); color: var(--amber); }
.b-gray { background: var(--gray-weak); color: #5F5E5A; } .b-green { background: var(--green-weak); color: var(--green); }
.b-accent { background: var(--accent); color: #fff; }
.p-urgent { background: var(--red-weak); color: var(--red); } .p-high { background: var(--amber-weak); color: var(--amber); }

.bar { height: 6px; background: var(--gray-weak); border-radius: 3px; overflow: hidden; min-width: 70px; }
.bar > span { display: block; height: 100%; background: var(--accent); border-radius: 3px; }
.bar.done > span { background: var(--green); }
.pct { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }

button, .btn { font: inherit; font-size: 14px; border: 1px solid var(--border-strong); background: var(--surface); color: var(--text);
  padding: 7px 14px; border-radius: var(--radius); cursor: pointer; display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
button:hover, .btn:hover { background: var(--surface-2); text-decoration: none; }
button.primary, .btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.primary:hover { background: var(--accent-strong); }
button.danger { color: var(--red); border-color: #F09595; }
button.ok { background: var(--green); border-color: var(--green); color: #fff; }
button.link { border: 0; background: none; padding: 0; color: var(--accent); }
button.sm, .btn.sm { padding: 3px 10px; font-size: 13px; }
button:disabled { opacity: .55; cursor: default; }

label.f { display: block; margin-bottom: 12px; }
label.f > span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
label.f > span em { color: var(--red); font-style: normal; }
input, select, textarea { font: inherit; font-size: 14px; width: 100%; padding: 7px 10px; border: 1px solid var(--border-strong); border-radius: var(--radius);
  background: var(--surface); color: var(--text); }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-weak); border-color: var(--accent); }
textarea { min-height: 80px; resize: vertical; }
input[type=checkbox] { width: auto; } input[type=range] { padding: 0; accent-color: var(--accent); }
.check { display: flex; gap: 8px; align-items: center; font-size: 14px; margin-bottom: 8px; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; } .row.three { grid-template-columns: 1fr 1fr 1fr; }
.row.quick { grid-template-columns: 80px minmax(0, 3fr) minmax(0, 1.4fr) 150px 120px auto; align-items: end; }
.row.quick label.f { margin-bottom: 0; }
@media (max-width: 900px) { .row, .row.three, .row.quick { grid-template-columns: 1fr; } }
.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; padding: 14px 20px; border-bottom: 1px solid var(--border); }
.filters label.f { margin: 0; min-width: 150px; }
.filters label.f.grow { flex: 1; min-width: 200px; }

dialog { border: 0; border-radius: 14px; padding: 0; width: min(560px, 94vw); box-shadow: 0 10px 40px rgba(0,0,0,.18); color: var(--text); }
dialog.wide { width: min(780px, 96vw); }
dialog::backdrop { background: rgba(30, 28, 24, .45); }
dialog form { padding: 22px 24px; max-height: 88vh; overflow-y: auto; }
dialog .dlg-foot { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.err { color: var(--red); font-size: 13px; margin-top: 6px; min-height: 0; }
.err:empty { display: none; }
.note-box { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 12px; font-size: 13.5px; }
.secret { font-family: Consolas, monospace; font-size: 18px; background: var(--accent-weak); color: var(--accent-strong);
  padding: 10px 14px; border-radius: var(--radius); user-select: all; text-align: center; margin: 10px 0; }

#toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(20px); background: #2c2c2a; color: #fff;
  padding: 10px 18px; border-radius: var(--radius); font-size: 14px; opacity: 0; transition: .2s; pointer-events: none; z-index: 50; max-width: 90vw; }
#toast.show { opacity: 1; transform: translateX(-50%); }
#toast.bad { background: var(--red); }

.info { display: grid; grid-template-columns: 130px 1fr; gap: 6px 14px; font-size: 14px; }
.info dt { color: var(--muted); } .info dd { margin: 0; }
.detail-text { white-space: pre-wrap; font-size: 14.5px; }
.task-head { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 6px; }
.action-bar { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 16px; padding-top: 16px; border-top: 1px solid var(--border); }

.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { position: relative; padding: 0 0 16px 22px; }
.timeline li::before { content: ""; position: absolute; left: 4px; top: 7px; width: 9px; height: 9px; border-radius: 50%; background: var(--border-strong); }
.timeline li::after { content: ""; position: absolute; left: 8px; top: 18px; bottom: 0; width: 1px; background: var(--border); }
.timeline li:last-child::after { display: none; }
.timeline li.k-approved::before, .timeline li.k-request_extend_approved::before, .timeline li.k-request_transfer_approved::before { background: var(--green); }
.timeline li.k-rejected::before, .timeline li.k-cancelled::before { background: var(--red); }
.timeline li.k-submit::before, .timeline li.k-progress::before { background: var(--accent); }
.timeline .ev-head { font-size: 13.5px; } .timeline .ev-head b { font-weight: 600; }
.timeline .ev-time { font-size: 12px; color: var(--faint); }
.timeline .ev-note { white-space: pre-wrap; font-size: 14px; margin-top: 4px; background: var(--surface-2); border-radius: var(--radius); padding: 8px 10px; }
.files { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.files a { font-size: 13px; background: var(--gray-weak); padding: 2px 10px; border-radius: 999px; color: var(--text); }

.unit-row { display: grid; grid-template-columns: minmax(120px, 1.2fr) 2fr 60px; gap: 12px; align-items: center; padding: 7px 0; font-size: 14px; }
.stack { display: flex; height: 10px; border-radius: 5px; overflow: hidden; background: var(--gray-weak); }
.stack span { display: block; height: 100%; }
.legend { display: flex; gap: 14px; font-size: 12.5px; color: var(--muted); flex-wrap: wrap; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }

.todo { display: flex; justify-content: space-between; gap: 12px; padding: 11px 20px; border-top: 1px solid var(--border); align-items: center; }
.todo:first-of-type { border-top: 0; }
.todo .t-title { font-weight: 500; } .todo .t-sub { font-size: 13px; color: var(--muted); }

/* calendar of due dates */
.cal-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.cal-title h2 { margin: 0; }
.seg { display: inline-flex; border: 1px solid var(--border-strong); border-radius: var(--radius); overflow: hidden; }
.seg button { border: 0; border-radius: 0; padding: 5px 11px; font-size: 13px; }
.seg button + button { border-left: 1px solid var(--border); }
.seg button.on { background: var(--accent-weak); color: var(--accent-strong); font-weight: 600; }
.cal-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); border-top: 1px solid var(--border); border-left: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.cal-wd { font-size: 12.5px; color: var(--muted); text-align: center; padding: 6px 0; background: var(--surface-2); border-right: 1px solid var(--border); border-bottom: 1px solid var(--border); }
.cal-wd:first-child { color: var(--red); }
.cal-day { min-height: 96px; padding: 4px 5px 6px; border-right: 1px solid var(--border); border-bottom: 1px solid var(--border); cursor: pointer; display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.cal-day:hover { background: var(--surface-2); }
.cal-day:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.cal-day.other { background: #fbfaf7; } .cal-day.other .cal-num { color: var(--faint); }
.cal-day.sel { background: var(--accent-weak); box-shadow: inset 0 0 0 1.5px var(--accent); }
.cal-num { font-size: 13px; font-weight: 500; width: 24px; height: 24px; line-height: 24px; text-align: center; border-radius: 50%; font-variant-numeric: tabular-nums; }
.cal-day.today .cal-num { background: var(--accent); color: #fff; }
.cal-chip { display: block; font-size: 12px; line-height: 1.35; padding: 2px 6px; border-radius: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  color: var(--text); background: var(--gray-weak); border-left: 3px solid var(--border-strong); }
.cal-chip:hover { text-decoration: none; filter: brightness(.96); }
.cal-more { font-size: 11.5px; color: var(--muted); padding-left: 4px; }
.t-over { --c: var(--red); --w: var(--red-weak); } .t-new { --c: #BA7517; --w: var(--amber-weak); }
.t-open { --c: var(--accent); --w: var(--accent-weak); } .t-review { --c: var(--teal); --w: var(--teal-weak); }
.t-done { --c: #639922; --w: var(--green-weak); }
.cal-chip[class*="t-"] { background: var(--w); border-left-color: var(--c); }
.cal-chip.t-done { color: var(--muted); text-decoration: line-through; text-decoration-color: rgba(0,0,0,.25); }
.legend i[class*="t-"] { background: var(--c); }
.cal-list { margin-top: 14px; border-top: 1px solid var(--border); padding-top: 12px; }
.cal-list-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 4px; }
.cal-list-head h3 { margin: 0; }
.cal-item { display: flex; gap: 10px; align-items: flex-start; padding: 9px 6px; border-radius: var(--radius); color: var(--text); }
.cal-item:hover { background: var(--surface-2); text-decoration: none; }
.cal-item + .cal-item { border-top: 1px solid var(--border); }
.cal-item .grow { flex: 1; min-width: 0; }
.cal-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--c); margin-top: 7px; flex: none; }
@media (max-width: 700px) { .cal-day { min-height: 56px; } .cal-chip { font-size: 0; padding: 0; height: 6px; border-left-width: 0; } .cal-more { font-size: 10px; } }

/* calendar of due dates */
.cal-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.cal-title h2 { margin: 0; }
.seg { display: inline-flex; border: 1px solid var(--border-strong); border-radius: var(--radius); overflow: hidden; }
.seg button { border: 0; border-radius: 0; padding: 5px 11px; font-size: 13px; }
.seg button + button { border-left: 1px solid var(--border); }
.seg button.on { background: var(--accent-weak); color: var(--accent-strong); font-weight: 600; }
.cal-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); border-top: 1px solid var(--border); border-left: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.cal-wd { font-size: 12.5px; color: var(--muted); text-align: center; padding: 6px 0; background: var(--surface-2); border-right: 1px solid var(--border); border-bottom: 1px solid var(--border); }
.cal-wd:first-child { color: var(--red); }
.cal-day { min-height: 96px; padding: 4px 5px 6px; border-right: 1px solid var(--border); border-bottom: 1px solid var(--border); cursor: pointer; display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.cal-day:hover { background: var(--surface-2); }
.cal-day:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.cal-day.other { background: #fbfaf7; } .cal-day.other .cal-num { color: var(--faint); }
.cal-day.sel { background: var(--accent-weak); box-shadow: inset 0 0 0 1.5px var(--accent); }
.cal-num { font-size: 13px; font-weight: 500; width: 24px; height: 24px; line-height: 24px; text-align: center; border-radius: 50%; font-variant-numeric: tabular-nums; }
.cal-day.today .cal-num { background: var(--accent); color: #fff; }
.cal-chip { display: block; font-size: 12px; line-height: 1.35; padding: 2px 6px; border-radius: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  color: var(--text); background: var(--gray-weak); border-left: 3px solid var(--border-strong); }
.cal-chip:hover { text-decoration: none; filter: brightness(.96); }
.cal-more { font-size: 11.5px; color: var(--muted); padding-left: 4px; }
.t-over { --c: var(--red); --w: var(--red-weak); } .t-new { --c: #BA7517; --w: var(--amber-weak); }
.t-open { --c: var(--accent); --w: var(--accent-weak); } .t-review { --c: var(--teal); --w: var(--teal-weak); }
.t-done { --c: #639922; --w: var(--green-weak); }
.cal-chip[class*="t-"] { background: var(--w); border-left-color: var(--c); }
.cal-chip.t-done { color: var(--muted); text-decoration: line-through; text-decoration-color: rgba(0,0,0,.25); }
.legend i[class*="t-"] { background: var(--c); }
.cal-list { margin-top: 14px; border-top: 1px solid var(--border); padding-top: 12px; }
.cal-list-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 4px; }
.cal-list-head h3 { margin: 0; }
.cal-item { display: flex; gap: 10px; align-items: flex-start; padding: 9px 6px; border-radius: var(--radius); color: var(--text); }
.cal-item:hover { background: var(--surface-2); text-decoration: none; }
.cal-item + .cal-item { border-top: 1px solid var(--border); }
.cal-item .grow { flex: 1; min-width: 0; }
.cal-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--c); margin-top: 7px; flex: none; }
@media (max-width: 700px) { .cal-day { min-height: 56px; } .cal-chip { font-size: 0; padding: 0; height: 6px; border-left-width: 0; } .cal-more { font-size: 10px; } }

.login-wrap { min-height: 80vh; display: grid; place-items: center; }
.login { width: min(380px, 92vw); }
.login .brand { justify-content: center; margin-bottom: 18px; font-size: 18px; }

.status-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; }
.status-dot.on { background: var(--green); } .status-dot.off { background: var(--red); }

.report-head { text-align: center; margin-bottom: 18px; }
.report-head h1 { font-size: 19px; }
.report table td, .report table th { font-size: 13px; padding: 7px 8px; }
.report .group td { background: var(--surface-2); font-weight: 600; }
@media print {
  header#top, .no-print, #toast { display: none !important; }
  body, :root { background: #fff; font-size: 12px; }
  main { max-width: none; padding: 0; }
  .card { border: 0; padding: 0; }
  .report table { page-break-inside: auto; } .report tr { page-break-inside: avoid; }
  .badge { border: 1px solid #ccc; }
}
