@font-face { font-family: Sarabun; font-weight: 400; src: url(../vendor/fonts/sarabun-thai-400-normal.woff2) format('woff2'); unicode-range: U+0E01-0E5B, U+200C-200D, U+25CC; font-display: swap; }
@font-face { font-family: Sarabun; font-weight: 700; src: url(../vendor/fonts/sarabun-thai-700-normal.woff2) format('woff2'); unicode-range: U+0E01-0E5B, U+200C-200D, U+25CC; font-display: swap; }
@font-face { font-family: Sarabun; font-weight: 400; src: url(../vendor/fonts/sarabun-latin-400-normal.woff2) format('woff2'); font-display: swap; unicode-range: U+0000-00FF, U+2000-206F, U+20AC, U+2122; }
@font-face { font-family: Sarabun; font-weight: 700; src: url(../vendor/fonts/sarabun-latin-700-normal.woff2) format('woff2'); font-display: swap; unicode-range: U+0000-00FF, U+2000-206F, U+20AC, U+2122; }

:root {
  --ink: #1b2430;
  --ink-2: #566273;
  --ink-3: #8390a0;
  --line: #dde2e8;
  --line-2: #c5ccd6;
  --bg: #f5f6f8;
  --panel: #ffffff;
  --brand: #1f3a5f;
  --brand-2: #2d5a8e;
  --brand-soft: #e8eff7;
  --ok: #1d7a4d;
  --ok-soft: #e3f4ea;
  --warn: #9a6a00;
  --warn-soft: #fdf3d8;
  --bad: #b3352c;
  --bad-soft: #fbe6e4;
  --locked: #eef0f3;
  --radius: 8px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; font: 15px/1.5 Sarabun, 'TH Sarabun New', Tahoma, sans-serif; color: var(--ink); background: var(--bg); }
button, input, select, textarea { font: inherit; color: inherit; }
h1 { font-size: 22px; margin: 0; }
h2 { font-size: 18px; margin: 0 0 10px; }
h3 { font-size: 16px; margin: 0 0 8px; }
p { margin: 0 0 8px; }
a { color: var(--brand-2); }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 38px; padding: 6px 14px; border: 1px solid var(--line-2); border-radius: var(--radius); background: var(--panel); cursor: pointer; text-decoration: none; color: var(--ink); white-space: nowrap; }
.btn:hover { background: #f0f2f5; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-2); }
.btn.danger { color: var(--bad); border-color: #e4b5b1; }
.btn.small { min-height: 30px; padding: 2px 10px; font-size: 14px; }
.btn.ghost { border-color: transparent; background: transparent; }
:focus-visible { outline: 2px solid var(--brand-2); outline-offset: 1px; }

input[type=text], input[type=number], input[type=date], input[type=password], input[type=url], input[type=search], select, textarea {
  width: 100%; min-height: 38px; padding: 6px 10px; border: 1px solid var(--line-2); border-radius: 6px; background: #fff;
}
textarea { resize: vertical; min-height: 80px; }
label.field { display: block; margin-bottom: 12px; }
label.field > span { display: block; font-size: 14px; color: var(--ink-2); margin-bottom: 3px; }
.check { display: inline-flex; align-items: center; gap: 8px; min-height: 30px; cursor: pointer; }
.check input { width: 17px; height: 17px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 0 14px; }

.shell { display: grid; grid-template-columns: 232px minmax(0, 1fr); min-height: 100%; }
.side { background: var(--brand); color: #dfe7f1; padding: 14px 10px; display: flex; flex-direction: column; gap: 2px; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.side-brand { display: flex; gap: 10px; align-items: center; padding: 2px 8px 12px; color: #fff; font-weight: 700; line-height: 1.25; }
.side-brand img { width: 36px; height: 36px; background: #fff; border-radius: 50%; }
.side h4 { margin: 12px 8px 3px; font-size: 12px; font-weight: 400; color: #9fb2c9; }
.side a { display: block; padding: 7px 10px; border-radius: 6px; color: inherit; text-decoration: none; }
.side a:hover { background: rgba(255,255,255,.09); }
.side a.on { background: rgba(255,255,255,.17); color: #fff; font-weight: 700; }
.side .badge { float: right; background: #e6a23c; color: #1b2430; border-radius: 10px; padding: 0 7px; font-size: 12px; font-weight: 700; }
.main { min-width: 0; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; gap: 12px; padding: 8px 18px; background: var(--panel); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 30; }
.topbar .spacer { flex: 1; }
.menu-btn { display: none; }
.content { padding: 18px; min-width: 0; }
.page-head { display: flex; align-items: flex-start; flex-wrap: wrap; gap: 10px; margin-bottom: 14px; }
.page-head .spacer { flex: 1; }
.muted { color: var(--ink-2); }
.small { font-size: 13.5px; }

.sync { display: inline-flex; align-items: center; gap: 7px; font-size: 13.5px; color: var(--ink-2); background: none; border: 0; cursor: pointer; padding: 4px 8px; border-radius: 6px; }
.sync:hover { background: #f0f2f5; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--ok); }
.dot.off { background: var(--ink-3); }
.dot.busy { background: #e6a23c; }
.dot.bad { background: var(--bad); }

.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 14px; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 12px; }
.card { display: block; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; color: inherit; text-decoration: none; }
a.card:hover { border-color: var(--brand-2); }
.card-title { font-weight: 700; }
.steps { display: flex; gap: 6px; margin-top: 10px; }
.step { flex: 1; font-size: 12.5px; text-align: center; padding: 3px 2px; border-radius: 5px; background: var(--locked); color: var(--ink-2); }

.tag { display: inline-block; padding: 0 8px; border-radius: 10px; font-size: 13px; background: var(--locked); color: var(--ink-2); white-space: nowrap; }
.tag.ok, .step.ok { background: var(--ok-soft); color: var(--ok); }
.tag.warn, .step.warn { background: var(--warn-soft); color: var(--warn); }
.tag.bad, .step.bad { background: var(--bad-soft); color: var(--bad); }
.tag.info, .step.info { background: var(--brand-soft); color: var(--brand); }

.notice { padding: 10px 12px; border-radius: 6px; margin-bottom: 12px; background: var(--brand-soft); color: var(--brand); }
.notice.warn { background: var(--warn-soft); color: var(--warn); }
.notice.bad { background: var(--bad-soft); color: var(--bad); }
.notice.ok { background: var(--ok-soft); color: var(--ok); }
.notice ul { margin: 4px 0 0; padding-left: 20px; }

.tabs { display: flex; gap: 2px; overflow-x: auto; border-bottom: 1px solid var(--line-2); margin-bottom: 14px; }
.tabs a { padding: 8px 13px; text-decoration: none; color: var(--ink-2); border-bottom: 3px solid transparent; white-space: nowrap; }
.tabs a.on { color: var(--brand); border-color: var(--brand); font-weight: 700; }

.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 6px; background: #fff; }
table.data { border-collapse: collapse; width: 100%; font-size: 14.5px; }
table.data th { background: #f1f3f6; text-align: left; font-weight: 700; white-space: nowrap; }
table.data th, table.data td { padding: 6px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.data tr:last-child td { border-bottom: 0; }
table.data td.num, table.data th.num { text-align: center; }

/* ตารางกรอกแบบ Excel */
.grid-toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 8px; font-size: 14px; }
.grid-wrap { position: relative; overflow: auto; max-height: calc(100vh - 235px); min-height: 280px; background: #fff; border: 1px solid var(--line-2); border-radius: 6px; outline: none; }
table.grid { border-collapse: separate; border-spacing: 0; font-size: 14px; }
table.grid th, table.grid td { border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); padding: 0 4px; height: 27px; white-space: nowrap; }
table.grid thead th { position: sticky; background: #eef1f5; z-index: 3; text-align: center; font-weight: 700; font-size: 13px; line-height: 1.2; user-select: none; white-space: normal; }
table.grid td { text-align: center; cursor: cell; background: #fff; }
table.grid td.left { text-align: left; }
table.grid td.ro { background: var(--locked); color: var(--ink-2); cursor: default; }
table.grid td.frozen, table.grid th.frozen { position: sticky; z-index: 2; }
table.grid thead th.frozen { z-index: 4; }
table.grid td.frozen { background: #f8f9fb; cursor: default; }
table.grid td.sel { background: #dce8f7 !important; }
table.grid td.cur { outline: 2px solid var(--brand-2); outline-offset: -2px; }
table.grid td.bad { background: var(--bad-soft); color: var(--bad); font-weight: 700; }
table.grid td.warn { background: var(--warn-soft); color: var(--warn); font-weight: 700; }
table.grid td.good { color: var(--ok); }
table.grid td.off { background: repeating-linear-gradient(45deg, #eceff2, #eceff2 3px, #f6f7f9 3px, #f6f7f9 6px); cursor: default; }
table.grid td.holiday { background: #dfe2e7; color: var(--ink-2); font-size: 11px; cursor: default; }
table.grid th.clickable { cursor: pointer; }
table.grid th.clickable:hover { background: #dce8f7; }
table.grid th .v { writing-mode: vertical-rl; transform: rotate(180deg); display: inline-block; max-height: 110px; font-weight: 400; }
.grid-input { position: absolute; z-index: 10; border: 2px solid var(--brand-2); padding: 0 3px; text-align: center; font: inherit; font-size: 14px; background: #fff; outline: none; min-width: 34px; }
.legend { display: flex; flex-wrap: wrap; gap: 4px 12px; font-size: 13.5px; color: var(--ink-2); }
.legend b { color: var(--ink); }

table.tt th, table.tt td { border: 1px solid var(--line); text-align: center; vertical-align: middle; padding: 5px 6px; min-width: 76px; }
table.tt th:first-child { min-width: 58px; background: #f1f3f6; }
.tt-cell + .tt-cell { border-top: 1px dashed var(--line-2); margin-top: 3px; padding-top: 3px; }
.tt-main { font-weight: 700; font-size: 14px; }
.tt-edit { cursor: pointer; height: 66px; }
.tt-edit:hover { background: var(--brand-soft); }

.check-list { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 3px 16px; font-size: 14.5px; }
.check-list div { display: flex; gap: 7px; }
.check-list .y { color: var(--ok); font-weight: 700; }
.check-list .n { color: var(--ink-3); }

.rounds { display: grid; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); gap: 12px; }
.round { border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.stat-row { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.stat { background: #f4f6f9; border-radius: 6px; padding: 5px 12px; text-align: center; min-width: 54px; }
.stat b { display: block; font-size: 18px; }
.stat span { font-size: 12.5px; color: var(--ink-2); }

.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; background: var(--brand); }
.login-box { width: 100%; max-width: 410px; background: var(--panel); border-radius: 12px; padding: 24px; }
.login-box img { width: 70px; display: block; margin: 0 auto 8px; }
.login-box h1 { text-align: center; margin-bottom: 2px; }
.pin-input { letter-spacing: 10px; text-align: center; font-size: 22px; }

#toasts { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); display: grid; gap: 6px; z-index: 100; width: min(92vw, 500px); }
.toast { background: #1b2430; color: #fff; padding: 10px 14px; border-radius: 8px; box-shadow: 0 4px 14px rgba(0,0,0,.25); }
.toast.bad { background: var(--bad); }
.toast.ok { background: var(--ok); }

.dialog-back { position: fixed; inset: 0; background: rgba(20,28,40,.45); display: grid; place-items: center; padding: 16px; z-index: 90; }
.dialog { background: var(--panel); border-radius: 10px; padding: 20px; width: min(100%, 560px); max-height: 90vh; overflow-y: auto; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; flex-wrap: wrap; }

.print-pick { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 2px 14px; }
.preview { background: #d9dde3; padding: 16px; border-radius: 6px; overflow: auto; }

@media (max-width: 860px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .side { position: fixed; inset: 0 auto 0 0; width: 260px; z-index: 60; transform: translateX(-100%); transition: transform .15s; }
  .shell.menu-open .side { transform: none; }
  .shell.menu-open::after { content: ''; position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 50; }
  .menu-btn { display: inline-flex; }
  .content { padding: 12px; }
  .grid-wrap { max-height: calc(100vh - 200px); }
  .topbar { padding: 6px 12px; gap: 6px; }
  .topbar .small.muted { display: none; }
  .sync { white-space: nowrap; font-size: 12.5px; padding: 4px; }
}
