/* THAI SEMCON MANPOWER — โทนม่วงตามต้นแบบ Manpower Record */
:root {
  --bg: #f3f0fa; --surface: #ffffff; --surface-2: #f7f4fd; --border: #e5dff2; --border-2: #d6cdea;
  --text: #1d1035; --muted: #6b6386; --primary: #6d28d9; --primary-2: #9333ea; --primary-soft: #efe7fd;
  --blue: #1d4ed8; --teal: #0d9488; --gold: #fcd34d;
  --ok: #059669; --warn: #b45309; --danger: #dc2626; --day: #f59e0b; --night: #4338ca;
  --radius: 18px; --radius-sm: 12px;
  --shadow: 0 1px 2px rgba(45,20,90,.05), 0 8px 24px rgba(45,20,90,.06);
  --display: "Kanit", "IBM Plex Sans Thai", system-ui, sans-serif;
  --body: "IBM Plex Sans Thai", system-ui, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); font: 15px/1.55 var(--body); min-height: 100vh; }
.hidden { display: none !important; }
h1, h2, h3 { font-family: var(--display); margin: 0; line-height: 1.25; }
h2 { font-size: 20px; font-weight: 700; }
h3 { font-size: 16px; font-weight: 600; margin-bottom: 12px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.nowrap { white-space: nowrap; }
.sub { margin: 4px 0 0; font-size: 14px; }
.eyebrow { margin: 0 0 2px; font: 700 12px/1.2 var(--display); letter-spacing: .14em; color: var(--primary); text-transform: uppercase; }
code, pre { font-family: ui-monospace, Consolas, monospace; font-size: 13px; }
pre { background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 12px; overflow: auto; }
:focus-visible { outline: 3px solid color-mix(in srgb, var(--primary) 45%, transparent); outline-offset: 2px; }

/* ───── controls ───── */
input, select { font: inherit; color: var(--text); background: var(--surface); border: 1.5px solid var(--border-2);
  border-radius: 10px; padding: 8px 12px; min-width: 0; min-height: 40px; }
input:focus, select:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
label { display: flex; flex-direction: column; gap: 5px; font-size: 13px; font-weight: 500; color: var(--muted); }
.btn { font: 600 14px/1 var(--display); letter-spacing: .01em; border: 1.5px solid transparent; border-radius: 999px; padding: 11px 18px;
  cursor: pointer; background: var(--surface-2); color: var(--text); text-decoration: none; display: inline-flex; align-items: center; justify-content: center;
  gap: 6px; white-space: nowrap; transition: transform .12s, box-shadow .12s, filter .12s; }
.btn:hover { filter: brightness(1.05); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: linear-gradient(135deg, var(--primary), var(--primary-2)); color: #fff; box-shadow: 0 4px 14px rgba(109,40,217,.28); }
.btn.ghost { background: var(--surface); border-color: var(--border-2); color: var(--primary); }
.btn.danger { background: var(--surface); color: var(--danger); border-color: color-mix(in srgb, var(--danger) 35%, transparent); }
.btn.warn { background: var(--warn); color: #fff; }
.btn.glass { background: rgba(255,255,255,.16); color: #fff; border-color: rgba(255,255,255,.3); }
.btn.sm { padding: 7px 12px; font-size: 13px; }
.btn:disabled { opacity: .45; cursor: default; box-shadow: none; }
.err { color: var(--danger); min-height: 1.4em; margin: 0; font-size: 14px; }

/* ───── แถบหัว ───── */
.banner { background: linear-gradient(120deg, #4c1d95 0%, #6d28d9 45%, #a21caf 100%); color: #fff; position: relative; overflow: hidden; }
.banner::after { content: ""; position: absolute; inset: 0; pointer-events: none;
  background: radial-gradient(600px 160px at 85% -20%, rgba(255,255,255,.22), transparent 70%),
              repeating-linear-gradient(-45deg, rgba(255,255,255,.035) 0 14px, transparent 14px 28px); }
.banner-in { position: relative; z-index: 1; max-width: 1280px; margin: 0 auto; padding: 22px 24px 26px; display: flex; align-items: center; gap: 16px; }
.brand { display: flex; align-items: center; gap: 14px; min-width: 0; flex: 1; }
.logo { flex: none; width: 52px; height: 52px; border-radius: 16px; display: grid; place-items: center; font: 800 15px var(--display); letter-spacing: .04em;
  color: #4c1d95; background: linear-gradient(160deg, #fff, #ede4ff); box-shadow: 0 6px 18px rgba(30,0,70,.3); }
.brand-t { font: 800 clamp(20px, 3.2vw, 34px)/1.05 var(--display); letter-spacing: .015em; text-transform: uppercase; color: #fff; text-shadow: 0 2px 10px rgba(30,0,70,.25); }
.pro { display: inline-block; font-size: .45em; vertical-align: .55em; padding: 3px 8px; border-radius: 6px; background: var(--gold); color: #4c1d95; letter-spacing: .08em; }
.brand-s { margin: 4px 0 0; font: 600 14px var(--display); letter-spacing: .06em; color: rgba(255,255,255,.82); text-transform: uppercase; }
.banner-r { display: flex; align-items: center; gap: 12px; flex: none; }
.who { display: flex; align-items: center; gap: 10px; font-size: 14px; color: rgba(255,255,255,.9); }
.lang { display: flex; padding: 4px; border-radius: 999px; background: rgba(255,255,255,.16); border: 1px solid rgba(255,255,255,.25); }
.lang button { font: 700 13px var(--display); letter-spacing: .06em; border: 0; background: none; color: rgba(255,255,255,.85); padding: 7px 14px; border-radius: 999px; cursor: pointer; min-height: 32px; }
.lang button[aria-pressed="true"] { background: #fff; color: var(--primary); box-shadow: 0 2px 8px rgba(30,0,70,.2); }

/* ───── เมนูแคปซูล ───── */
.pills { display: flex; justify-content: center; gap: 10px; flex-wrap: wrap; max-width: 1280px; margin: 0 auto; padding: 20px 24px 4px; }
.pills a { font: 600 15px var(--display); padding: 10px 20px; border-radius: 999px; cursor: pointer; color: var(--text); background: var(--surface);
  border: 1.5px solid var(--border); white-space: nowrap; display: inline-flex; align-items: center; gap: 6px; user-select: none; transition: border-color .15s, color .15s; }
.pills a:hover { border-color: var(--primary); color: var(--primary); }
.pills a.active { background: linear-gradient(135deg, var(--primary), var(--primary-2)); color: #fff; border-color: transparent; box-shadow: 0 6px 16px rgba(109,40,217,.28); }
.nav-badge { display: inline-block; min-width: 20px; padding: 0 6px; border-radius: 99px; background: var(--danger); color: #fff; font: 700 12px/20px var(--body); text-align: center; }

main { max-width: 1280px; margin: 0 auto; padding: 18px 24px 120px; }
.page, .board main { display: flex; flex-direction: column; gap: 18px; }
.toolbar { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.page-t { font-size: 26px; font-weight: 700; color: var(--text); }
.filters { display: flex; gap: 8px; flex-wrap: wrap; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); min-width: 0; }
.card-h { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }
.card-h h2, .card-h h3 { margin: 0; }
.grid3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 18px; }
.form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; align-items: end; }
.combo { display: flex; gap: 6px; }
.combo > input, .combo > select { flex: 1; }
.row-actions { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; margin-top: 16px; }

/* ───── บอร์ด: แผงสถิติ ───── */
.hero { border-radius: 22px; padding: 24px; color: #fff; background: linear-gradient(120deg, var(--blue) 0%, #2563eb 35%, var(--teal) 100%);
  box-shadow: 0 14px 34px rgba(29,78,216,.22); display: flex; flex-direction: column; gap: 20px; position: relative; overflow: hidden; }
.hero::before { content: ""; position: absolute; width: 360px; height: 360px; right: -120px; top: -180px; border-radius: 50%; background: rgba(255,255,255,.08); }
.hero-top { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; position: relative; }
.hero .eyebrow { color: var(--gold); }
.hero h2 { font-size: clamp(24px, 3vw, 32px); font-weight: 800; color: #fff; }
.hero-sub { margin: 4px 0 0; color: rgba(255,255,255,.85); font-size: 14px; }
.hero-tools { display: flex; gap: 8px; flex-wrap: wrap; }
.hero-tools input { background: rgba(255,255,255,.95); border-color: transparent; }
.hero-tools input[type=search] { width: 220px; }
.hero-stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; position: relative; }
.hstat { border-radius: 14px; padding: 12px 16px; background: rgba(255,255,255,.12); border: 1px solid rgba(255,255,255,.22); backdrop-filter: blur(4px); }
.hstat span { display: block; font-size: 13px; color: rgba(255,255,255,.85); }
.hstat b { font: 700 30px/1.15 var(--display); color: var(--gold); font-variant-numeric: tabular-nums; }
.hstat.accent { background: rgba(255,255,255,.95); border-color: #fff; }
.hstat.accent span { color: var(--blue); font-weight: 600; }
.hstat.accent b { color: var(--primary); }
.hstat.h-day { box-shadow: inset 0 3px 0 var(--day); } .hstat.h-night { box-shadow: inset 0 3px 0 #a5b4fc; }

/* ───── บอร์ด: การ์ดโครงการ ───── */
.pgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 18px; }
.pcard { position: relative; background: var(--surface); border: 1px solid var(--border); border-radius: 20px; padding: 22px 20px 18px; box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: 14px; cursor: pointer; overflow: hidden; min-width: 0; transition: transform .16s, box-shadow .16s, border-color .16s; }
.pcard::before { content: ""; position: absolute; left: 0; right: 0; top: 0; height: 5px; background: linear-gradient(90deg, var(--primary), var(--primary-2), #db2777); }
.pcard:hover { transform: translateY(-3px); border-color: var(--border-2); box-shadow: 0 16px 32px rgba(45,20,90,.12); }
.pcard.idle { background: var(--surface-2); }
.pcard.idle::before { background: var(--border-2); }
.pc-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.pc-head h3 { margin: 0; font-size: 18px; font-weight: 700; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.pc-num { display: flex; justify-content: space-between; align-items: flex-end; gap: 10px; }
.pc-num b { font: 800 52px/0.95 var(--display); color: var(--primary); font-variant-numeric: tabular-nums; }
.pcard.idle .pc-num b { color: var(--border-2); }
.pc-num span { margin-left: 6px; color: var(--muted); font-weight: 500; }
.pc-trend { display: flex; flex-direction: column; align-items: flex-end; gap: 2px; }
.pc-trend small { font-size: 12px; color: var(--muted); white-space: nowrap; }
.pc-trend small.up { color: var(--ok); font-weight: 600; } .pc-trend small.down { color: var(--danger); font-weight: 600; }
.spark { width: 120px; height: 34px; }
.spark .line { fill: none; stroke: var(--primary-2); stroke-width: 2.2; stroke-linejoin: round; stroke-linecap: round; }
.spark .area { fill: color-mix(in srgb, var(--primary-2) 14%, transparent); }
.spark .dot { fill: var(--primary); }
.split { display: flex; height: 10px; border-radius: 99px; overflow: hidden; background: var(--surface-2); }
.split i { display: block; height: 100%; }
.split-l { display: flex; justify-content: space-between; font-size: 13px; color: var(--muted); margin-top: 6px; }
.split-l span { display: inline-flex; align-items: center; gap: 5px; }
.split-l b { color: var(--text); font-variant-numeric: tabular-nums; }
.pc-list { display: flex; flex-direction: column; gap: 4px; padding-top: 12px; border-top: 1px dashed var(--border-2); }
.pc-list .li { display: flex; justify-content: space-between; gap: 8px; font-size: 14px; }
.pc-list .li span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pc-list .li b { font-variant-numeric: tabular-nums; }
.pc-list .more { color: var(--muted); font-size: 13px; }
.pc-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.pchip { font-size: 12px; padding: 4px 10px; border-radius: 99px; background: var(--primary-soft); color: #4c1d95; white-space: nowrap; max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
.pchip.more { background: var(--surface-2); color: var(--muted); }
.pc-empty { margin: 0; color: var(--muted); font-size: 14px; padding-top: 12px; border-top: 1px dashed var(--border-2); }
.skeleton { min-height: 290px; cursor: default; background: linear-gradient(90deg, var(--surface) 25%, var(--surface-2) 50%, var(--surface) 75%); background-size: 200% 100%; animation: shimmer 1.2s infinite; }
.skeleton::before { display: none; }
@keyframes shimmer { to { background-position: -200% 0; } }

/* ───── นาฬิกาลอย (มุมผู้ดูแล) ───── */
.clock { position: fixed; left: 18px; bottom: 18px; z-index: 40; display: flex; align-items: center; gap: 12px; padding: 12px 18px 12px 12px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 16px; box-shadow: 0 10px 30px rgba(45,20,90,.16); user-select: none;
  -webkit-user-select: none; -webkit-touch-callout: none; touch-action: manipulation; }
.clock small { display: block; font-size: 11px; color: var(--muted); font-weight: 600; }
.clock b { display: block; font: 600 13px/1.2 var(--display); }
.clock strong { display: block; font: 700 22px/1.1 var(--display); color: var(--primary); font-variant-numeric: tabular-nums; letter-spacing: .02em; }
.clock-ic { position: relative; width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center; background: var(--primary-soft); }
.clock-ic svg { width: 24px; height: 24px; fill: none; stroke: var(--primary); stroke-width: 2; stroke-linecap: round; }
.clock-ring { position: absolute; left: 12px; top: 50%; width: 44px; height: 44px; transform: translateY(-50%) rotate(-90deg); pointer-events: none; z-index: 1; }
.clock-ring circle { fill: none; stroke: var(--primary); stroke-width: 3; stroke-dasharray: 126; stroke-dashoffset: 126; opacity: 0; }
.clock.holding .clock-ring circle { opacity: 1; stroke-dashoffset: 0; transition: stroke-dashoffset 2s linear, opacity .1s; }

/* ───── KPI / กราฟ dashboard ───── */
.kpis { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 12px; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 14px 16px; box-shadow: var(--shadow); }
.kpi span { color: var(--muted); font-size: 13px; display: block; }
.kpi b { font: 700 32px/1.15 var(--display); font-variant-numeric: tabular-nums; }
.kpi small { color: var(--muted); font-size: 12px; display: block; }
.kpi.accent { background: linear-gradient(135deg, var(--primary), var(--primary-2)); border-color: transparent; color: #fff; }
.kpi.accent span, .kpi.accent small { color: rgba(255,255,255,.85); }
.kpi.link { cursor: pointer; } .kpi.link:hover { border-color: var(--primary); }
.bars { display: flex; flex-direction: column; gap: 9px; max-height: 320px; overflow: auto; }
.bar { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 3px 8px; font-size: 14px; }
.bar .t { height: 7px; border-radius: 4px; background: var(--surface-2); grid-column: 1 / -1; overflow: hidden; }
.bar .t i { display: block; height: 100%; background: linear-gradient(90deg, var(--primary), var(--primary-2)); border-radius: 4px; }
.bar b { font-variant-numeric: tabular-nums; }
.bar span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.trend { display: flex; align-items: flex-end; gap: 6px; height: 180px; padding-top: 18px; }
.trend .col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px; height: 100%; justify-content: flex-end; min-width: 0; cursor: pointer; }
.trend .stack { width: 100%; max-width: 38px; display: flex; flex-direction: column-reverse; border-radius: 6px 6px 0 0; overflow: hidden; }
.trend .stack i { display: block; }
.trend .v { font-size: 12px; font-variant-numeric: tabular-nums; color: var(--muted); }
.trend .d { font-size: 11px; color: var(--muted); white-space: nowrap; }
.trend .col.sel .d { color: var(--primary); font-weight: 700; }
.legend { font-size: 13px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.lg { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.day { background: var(--day); } .night { background: var(--night); }

/* ───── ตาราง ───── */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { padding: 10px 10px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: middle; }
th { font-weight: 600; color: var(--muted); font-size: 13px; background: var(--surface-2); position: sticky; top: 0; }
th:first-child { border-top-left-radius: 10px; } th:last-child { border-top-right-radius: 10px; }
tfoot td { font-weight: 700; border-bottom: none; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.w-input { width: 130px; }
td input { width: 100%; min-height: 36px; padding: 6px 10px; }
td input.n { text-align: right; }
td input.changed { border-color: var(--warn); background: color-mix(in srgb, var(--warn) 8%, var(--surface)); }
.pill { display: inline-block; font-size: 12px; font-weight: 600; padding: 2px 9px; border-radius: 99px; background: var(--surface-2); color: var(--muted); }
.pill.Day { background: #fef3c7; color: #92400e; }
.pill.Night { background: #e0e7ff; color: var(--night); }
.pill.manual { background: #ffedd5; color: var(--warn); }
.pill.in { color: var(--ok); } .pill.out { color: var(--danger); }
.empty { text-align: center; color: var(--muted); padding: 28px; }

/* ───── sync / settings ───── */
.kv { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin: 8px 0; }
.kv span { width: 90px; color: var(--muted); font-size: 13px; }
.kv code { background: var(--surface-2); border: 1px solid var(--border); padding: 6px 10px; border-radius: 8px; word-break: break-all; flex: 1; min-width: 200px; }
details { margin-top: 10px; } summary { cursor: pointer; color: var(--primary); font-weight: 600; }
.not-admin { display: none; }
body.staff .admin-only { display: none !important; }
body.staff .not-admin { display: block; }
.master ul { list-style: none; padding: 0; margin: 12px 0 0; max-height: 360px; overflow: auto; }
.master li { display: flex; align-items: center; gap: 6px; padding: 7px 0; border-bottom: 1px solid var(--border); font-size: 14px; }
.master li span { flex: 1; overflow: hidden; text-overflow: ellipsis; }
.master li.off span { color: var(--muted); text-decoration: line-through; }

/* ───── ตรวจสอบ ───── */
.prog-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.prog-head b { font: 700 18px var(--display); }
.prog { height: 12px; border-radius: 99px; background: var(--surface-2); margin: 14px 0; overflow: hidden; border: 1px solid var(--border); }
.prog i { display: block; height: 100%; background: linear-gradient(90deg, var(--teal), var(--ok)); border-radius: 99px; transition: width .4s ease; }
.stat-row { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.stat-row div { background: var(--surface-2); border-radius: 12px; padding: 10px 14px; }
.stat-row span { display: block; font-size: 13px; color: var(--muted); }
.stat-row b { font: 700 20px var(--display); font-variant-numeric: tabular-nums; }
.alert { border-color: #fcd9a8; background: #fffaf0; }
.alert table { margin-top: 10px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { font: 500 14px var(--body); border: 1.5px solid var(--border); background: var(--surface); color: var(--text); border-radius: 99px; padding: 6px 12px; cursor: pointer; min-height: 38px; }
.chip span { display: inline-block; min-width: 18px; margin-left: 2px; color: var(--muted); font-weight: 600; }
.chip.active { background: var(--primary); border-color: var(--primary); color: #fff; }
.chip.active span { color: rgba(255,255,255,.85); }
.bulk { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: 14px; }
.w-chk { width: 40px; text-align: center; }
.w-chk input { width: 18px; height: 18px; min-height: 0; cursor: pointer; accent-color: var(--primary); }
th[data-sort] { cursor: pointer; user-select: none; }
th[data-sort]::after { content: ' ↕'; opacity: .35; font-size: 11px; }
th[aria-sort="ascending"]::after { content: ' ▲'; opacity: 1; }
th[aria-sort="descending"]::after { content: ' ▼'; opacity: 1; }
#vTable td input.n { max-width: 110px; }
#vTable tr.sel td { background: var(--primary-soft); }
#vTable tr.st-stale td:first-child { box-shadow: inset 4px 0 0 var(--warn); }
#vTable tr.st-diff td:first-child { box-shadow: inset 4px 0 0 var(--danger); }
#vTable tr.st-done td:first-child { box-shadow: inset 4px 0 0 var(--ok); }
.note-line { display: block; font-size: 12px; color: var(--muted); margin-top: 2px; }
.status { display: inline-flex; align-items: center; gap: 5px; font-size: 13px; font-weight: 600; padding: 3px 10px; border-radius: 99px; white-space: nowrap; }
.status i { font-style: normal; font-weight: 700; }
.status.ok { background: #d1fae5; color: #047857; }
.status.warn { background: #ffedd5; color: var(--warn); }
.status.bad { background: #fee2e2; color: var(--danger); }
.status.idle { background: var(--surface-2); color: var(--muted); }
b.up { color: var(--warn); } b.down { color: var(--danger); }
.link-btn { font: inherit; font-weight: 700; background: none; border: 0; padding: 4px 6px; margin: -4px -6px; color: var(--primary); cursor: pointer; text-decoration: underline; text-underline-offset: 3px; }

/* ───── dialogs ───── */
dialog { border: 0; border-radius: 22px; background: var(--surface); color: var(--text); padding: 24px; width: min(440px, calc(100% - 32px)); box-shadow: 0 30px 80px rgba(30,0,70,.35); }
dialog::backdrop { background: rgba(30,12,60,.5); backdrop-filter: blur(3px); }
dialog.wide { width: min(880px, calc(100% - 32px)); max-height: 88vh; }
#dlgBody { display: flex; flex-direction: column; gap: 10px; margin-top: 12px; }
#dlgBody p { margin: 0; }
.login-dlg form, .admin-gate { display: flex; flex-direction: column; gap: 12px; }
.login-dlg h2, .admin-gate h2 { font-size: 26px; }
.login-dlg p.muted, .admin-gate p.muted { margin: 0; }
.login-dlg input, .admin-gate input { min-height: 50px; font-size: 20px; letter-spacing: 3px; text-align: center; }
.admin-dlg .admin-gate { max-width: 400px; margin: 0 auto; }
.code-form { display: grid; grid-template-columns: 1.3fr 1.1fr 1.3fr .9fr auto; gap: 10px; align-items: end; padding: 16px; border-radius: 14px; background: var(--surface-2); margin-bottom: 14px; }
.code-new { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 18px; border-radius: 14px; margin-bottom: 14px;
  background: linear-gradient(120deg, #ecfdf5, #f0fdfa); border: 1.5px dashed var(--teal); }
.code-new small { display: block; font-size: 13px; }
.code-big { display: block; font: 800 34px/1.1 var(--display); letter-spacing: .18em; color: var(--teal); }
.role { font-size: 12px; font-weight: 700; padding: 3px 10px; border-radius: 99px; }
.role.admin { background: #fae8ff; color: #a21caf; } .role.staff { background: var(--primary-soft); color: var(--primary); }
.role.viewer { background: #e0f2fe; color: #0369a1; }
.role-help { list-style: none; margin: 14px 0 0; padding: 0; display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
.role-help .role { display: inline-block; min-width: 92px; text-align: center; margin-right: 8px; }
/* สิทธิ์ดูอย่างเดียว: ซ่อนปุ่มกรอก/แก้ทั้งหมด */
body.viewer .editor-only, body.viewer #vVerifyAll, body.viewer #page-verify .bulk, body.viewer #vTable .w-chk,
body.viewer #vTable .vok, body.viewer #vTable .vundo { display: none !important; }
body.viewer #vTable .vman:disabled { background: transparent; border-color: transparent; color: var(--text); opacity: 1; }
.code-table tr.off td { opacity: .6; }
h3.sec { font-size: 14px; color: var(--muted); margin: 16px 0 6px; font-weight: 600; }
.proj-trend { display: flex; align-items: flex-end; gap: 8px; height: 130px; }
.proj-trend .col { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; gap: 4px; height: 100%; }
.proj-trend i { display: block; width: 100%; max-width: 40px; background: linear-gradient(180deg, var(--primary-2), var(--primary)); border-radius: 6px 6px 0 0; min-height: 2px; }
.proj-trend .v, .proj-trend .d { font-size: 12px; color: var(--muted); white-space: nowrap; }
.proj-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
#toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; z-index: 100; }
#toast div { background: #2e1065; color: #fff; padding: 11px 20px; border-radius: 999px; box-shadow: 0 8px 24px rgba(30,0,70,.3); font-size: 14px; }
#toast div.bad { background: var(--danger); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}
@media (max-width: 1000px) {
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .kpi.accent { grid-column: 1 / -1; }
  .grid3 { grid-template-columns: 1fr; }
  .hero-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .code-form { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 720px) {
  .banner-in { padding: 16px 16px 18px; flex-wrap: wrap; }
  .logo { width: 42px; height: 42px; border-radius: 12px; font-size: 12px; }
  .brand-s { font-size: 12px; }
  .banner-r { width: 100%; justify-content: space-between; }
  .banner-r .lang { margin-left: auto; }
  .pills { justify-content: flex-start; flex-wrap: nowrap; overflow-x: auto; padding: 14px 16px 4px; scrollbar-width: none; }
  .pills a { font-size: 14px; padding: 9px 16px; }
  main { padding: 14px 16px 120px; }
  .card { padding: 16px; }
  .hero { padding: 18px; border-radius: 18px; }
  .hero-tools { width: 100%; }
  .hero-tools input { flex: 1 1 140px; }
  .hero-tools input[type=search] { width: auto; }
  .hstat b { font-size: 24px; }
  .filters > * { flex: 1 1 140px; }
  .stat-row { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .proj-cols, .code-form { grid-template-columns: 1fr; }
  .trend .d { font-size: 9px; } .trend .v { display: none; }
  .clock { left: 10px; bottom: 10px; padding: 8px 12px 8px 8px; gap: 8px; }
  .clock-ic, .clock-ring { width: 36px; height: 36px; }
  .clock-ring { left: 8px; }
  .clock strong { font-size: 17px; }
  .code-new { flex-direction: column; align-items: flex-start; }
}

/* ───── การ์ดแบบลิงก์ + หน้าโครงการ ───── */
a.pcard { color: inherit; text-decoration: none; }
.pcard .pc-num { align-items: center; }
.pc-foot { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding-top: 12px; border-top: 1px dashed var(--border-2); font-size: 13px; color: var(--muted); }
.pc-go { font: 600 14px var(--display); color: var(--primary); white-space: nowrap; }
.pc-go i { font-style: normal; display: inline-block; transition: transform .15s; }
.pcard:hover .pc-go i, .pcard:focus-visible .pc-go i { transform: translateX(4px); }
.pcard .pc-empty { border-top: 0; padding-top: 0; }
.back { align-self: flex-start; font: 600 14px var(--display); color: var(--primary); cursor: pointer; padding: 8px 14px; margin-bottom: -6px;
  border-radius: 999px; background: var(--surface); border: 1.5px solid var(--border); text-decoration: none; }
.back:hover { border-color: var(--primary); }
#projView { display: flex; flex-direction: column; gap: 18px; }
#projView.hidden { display: none; }
#pvName { font-size: clamp(26px, 3.6vw, 38px); }
.hstat small { display: block; font-size: 12px; color: rgba(255,255,255,.8); margin-top: 2px; }
.hstat.accent small { color: var(--muted); }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }
#pvMatrix th, #pvMatrix td { white-space: nowrap; }
#pvMatrix tbody tr:hover td { background: var(--surface-2); }
@media (max-width: 1000px) { .grid2 { grid-template-columns: 1fr; } }

/* ───── เช็คอินหน้างาน (TSC Register + FaceScan) ───── */
:root { --gate-ink: #170c33; --gate-ink-2: #241449; --tide-in: #a78bfa; --tide-out: #2dd4bf; }
.sources { display: flex; gap: 8px; flex-wrap: wrap; margin-top: -6px; }
.src { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; padding: 6px 12px 6px 10px; border-radius: 99px;
  background: var(--surface); border: 1px solid var(--border); color: var(--muted); max-width: 100%; }
.src b { color: var(--text); font-weight: 600; white-space: nowrap; }
.src .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); flex: none; box-shadow: 0 0 0 3px color-mix(in srgb, var(--ok) 18%, transparent); }
.src.warn .dot { background: var(--warn); box-shadow: 0 0 0 3px color-mix(in srgb, var(--warn) 18%, transparent); }
.src.bad { border-color: color-mix(in srgb, var(--danger) 35%, transparent); color: var(--danger); }
.src.bad .dot { background: var(--danger); box-shadow: 0 0 0 3px color-mix(in srgb, var(--danger) 18%, transparent); }
.src span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* แผงประตู: ตัวเลขคนในพื้นที่ + กราฟน้ำขึ้นน้ำลง (เข้าขึ้นบน ออกลงล่าง) */
.gate { display: grid; grid-template-columns: minmax(220px, 280px) minmax(0, 1fr); gap: 28px; padding: 24px 26px 18px; border-radius: 22px;
  color: #ece8ff; background: radial-gradient(520px 240px at 0% 0%, rgba(167,139,250,.18), transparent 70%), linear-gradient(160deg, var(--gate-ink-2), var(--gate-ink));
  box-shadow: 0 14px 34px rgba(23,12,51,.28); }
.gate .eyebrow { color: var(--gold); }
.gate-now > b { display: block; font: 800 clamp(64px, 9vw, 96px)/.95 var(--display); font-variant-numeric: tabular-nums; letter-spacing: -.02em; color: #fff; margin: 6px 0 14px; }
.gate-sub { display: flex; flex-direction: column; gap: 6px; font-size: 14px; color: rgba(236,232,255,.75); }
.gate-sub span { display: flex; align-items: center; gap: 8px; }
.gate-sub b { margin-left: auto; font: 600 16px var(--display); font-variant-numeric: tabular-nums; color: #fff; }
.sw { width: 10px; height: 10px; border-radius: 3px; display: inline-block; flex: none; }
.sw.in { background: var(--tide-in); } .sw.out { background: var(--tide-out); }
.sw.reg { background: transparent; border: 1.5px dashed rgba(236,232,255,.55); }
.sw.night { background: repeating-linear-gradient(-45deg, rgba(129,140,248,.55) 0 2px, transparent 2px 4px); outline: 1px solid rgba(129,140,248,.4); }
.tide { margin: 0; min-width: 0; display: flex; flex-direction: column; gap: 10px; }
.tide figcaption { display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap; font-size: 13px; color: rgba(236,232,255,.7); }
.tide-key { display: inline-flex; align-items: center; gap: 6px; }
.tide-key .sw:not(:first-child) { margin-left: 8px; }
.tide-plot { display: grid; grid-template-columns: repeat(24, minmax(0, 1fr)); gap: 3px; height: 210px; position: relative; }
.tide-plot .h { display: grid; grid-template-rows: 1fr 1px 1fr 18px; position: relative; border-radius: 6px; min-width: 0; outline: none; }
.tide-plot .h.night { background: repeating-linear-gradient(-45deg, rgba(129,140,248,.10) 0 3px, transparent 3px 7px); }
.tide-plot .h.now { box-shadow: inset 0 0 0 1.5px var(--gold); }
.tide-plot .h.now .lbl { color: var(--gold); font-weight: 700; }
.tide-plot .h:focus-visible { box-shadow: inset 0 0 0 2px #fff; }
.tide-plot .up, .tide-plot .dn { display: flex; justify-content: center; min-height: 0; }
.tide-plot .up { align-items: flex-end; }
.tide-plot .dn { align-items: flex-start; }
.tide-plot .up i, .tide-plot .dn i { display: block; width: 72%; max-width: 22px; transform-origin: bottom; animation: tideUp .6s cubic-bezier(.2,.8,.2,1) backwards; animation-delay: calc(var(--i) * 18ms); }
.tide-plot .up i { background: linear-gradient(180deg, #c4b5fd, var(--tide-in)); border-radius: 4px 4px 1px 1px; }
.tide-plot .dn i { background: linear-gradient(0deg, #5eead4, var(--tide-out)); border-radius: 1px 1px 4px 4px; transform-origin: top; }
.tide-plot .axis { background: rgba(236,232,255,.28); }
.tide-plot .lbl { font: 500 11px/18px var(--body); text-align: center; color: rgba(236,232,255,.5); font-variant-numeric: tabular-nums; white-space: nowrap; }
.tide-plot .h:hover { background-color: rgba(255,255,255,.06); }
.tide-plot .tip { position: absolute; left: 50%; bottom: calc(100% + 4px); transform: translateX(-50%); background: #fff; color: var(--text); font-size: 12px;
  padding: 4px 8px; border-radius: 8px; white-space: nowrap; pointer-events: none; opacity: 0; transition: opacity .12s; z-index: 2; box-shadow: var(--shadow); }
.tide-plot .h:hover .tip, .tide-plot .h:focus .tip { opacity: 1; }
.tide-plot .h:nth-child(-n+3) .tip { left: 0; transform: none; }
.tide-plot .h:nth-child(n+22) .tip { left: auto; right: 0; transform: none; }
.tide-empty { grid-column: 1 / -1; align-self: center; text-align: center; color: rgba(236,232,255,.6); font-size: 14px; }
@keyframes tideUp { from { transform: scaleY(0); } }

/* ทะเบียน vs เข้าพื้นที่ */
.grid-live { display: grid; grid-template-columns: minmax(0, 1.7fr) minmax(0, 1fr); gap: 18px; align-items: start; }
.legend .lg.on { background: var(--primary); }
.legend .lg.came { background: color-mix(in srgb, var(--primary) 32%, white); }
.legend .lg.reg { background: repeating-linear-gradient(-45deg, var(--border-2) 0 2px, var(--surface-2) 2px 4px); outline: 1px solid var(--border-2); }
.ledger { display: flex; flex-direction: column; }
.ledger details { border-top: 1px solid var(--border); margin-top: 0; }
.ledger details:first-child { border-top: 0; }
.ledger summary { color: var(--text); font-weight: 400; list-style: none; cursor: pointer; padding: 12px 4px; display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 6px 12px; align-items: baseline; border-radius: 10px; }
.ledger summary::-webkit-details-marker { display: none; }
.ledger summary:hover .lname { color: var(--primary); }
.ledger .lname { font: 600 16px var(--display); display: flex; align-items: center; gap: 8px; min-width: 0; flex-wrap: wrap; }
.ledger .lname::before { content: ""; width: 7px; height: 7px; border-right: 2px solid var(--muted); border-bottom: 2px solid var(--muted); transform: rotate(-45deg); transition: transform .15s; flex: none; }
.ledger details[open] > summary .lname::before { transform: rotate(45deg); }
.ledger .lnum { font-size: 13px; color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }
.ledger .lnum b { font: 700 18px var(--display); color: var(--text); }
.track { grid-column: 1 / -1; height: 12px; border-radius: 99px; display: flex; overflow: hidden;
  background: repeating-linear-gradient(-45deg, var(--border-2) 0 2px, var(--surface-2) 2px 5px); }
.track i { display: block; height: 100%; transition: width .5s cubic-bezier(.2,.8,.2,1); }
.track .on { background: linear-gradient(90deg, var(--primary), var(--primary-2)); }
.track .came { background: color-mix(in srgb, var(--primary) 32%, white); }
.track.sm { height: 7px; }
.ledger .cos { padding: 2px 4px 14px 19px; display: flex; flex-direction: column; gap: 10px; }
.ledger .co { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px 12px; font-size: 14px; }
.ledger .co > span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ledger .co .lnum b { font-size: 14px; }
.flag { font: 600 11px/1 var(--body); padding: 4px 7px; border-radius: 99px; background: #fef3c7; color: #92400e; white-space: nowrap; }
.flag.alt { background: var(--surface-2); color: var(--muted); }

.sites { display: flex; flex-direction: column; gap: 6px; }
.site { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 2px 12px; padding: 10px 12px; border-radius: 12px; background: var(--surface-2); }
.site .n { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.site .c { font: 700 22px/1 var(--display); font-variant-numeric: tabular-nums; text-align: right; grid-row: span 2; align-self: center; }
.site .c small { display: block; font: 500 11px var(--body); color: var(--muted); margin-top: 4px; }
.site .s { font-size: 12px; color: var(--muted); }
.st { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 600; white-space: nowrap; }
.st::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.st.in { color: var(--ok); } .st.out { color: var(--muted); }
#lQ { min-width: 220px; }

/* ตั้งค่าการเชื่อมต่อ */
.ext-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.ext-grid fieldset { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 14px 16px 4px; margin: 0; display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.ext-grid legend { font: 600 15px var(--display); padding: 0 6px; }
.ext-grid legend small { font: 400 12px var(--body); margin-left: 4px; }
.ext-grid .row-actions { margin-top: 4px; }
.ext-grid .ext-foot { grid-column: 1 / -1; margin-top: 0; }
label.check { flex-direction: row; align-items: center; gap: 8px; color: var(--text); font-size: 14px; }
label.check input { min-height: 0; width: 18px; height: 18px; accent-color: var(--primary); }

@media (max-width: 1000px) {
  .grid-live, .ext-grid { grid-template-columns: 1fr; }
  .gate { grid-template-columns: 1fr; gap: 18px; }
}
@media (max-width: 720px) {
  .gate { padding: 18px 16px 14px; }
  .tide-plot { height: 170px; gap: 1px; }
  .tide-plot .h:not(:nth-child(3n+1)) .lbl { visibility: hidden; }
  #lQ { min-width: 0; width: 100%; }
}
@media (prefers-reduced-motion: reduce) { .tide-plot i { animation: none !important; } .track i { transition: none; } }

/* ───── วันเริ่ม/จบโครงการ ───── */
.ptime { position: relative; border-radius: 14px; padding: 12px 16px; background: rgba(255,255,255,.12); border: 1px solid rgba(255,255,255,.22); display: flex; flex-direction: column; gap: 8px; }
.pt-dates { display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; }
.pt-dates span { display: block; font-size: 12px; color: rgba(255,255,255,.8); }
.pt-dates b { font: 700 17px/1.25 var(--display); color: #fff; }
.pt-end { text-align: right; }
.pt-status { font-size: 13px; font-weight: 600; color: var(--gold); text-align: center; }
.pt-bar { height: 8px; border-radius: 99px; background: rgba(255,255,255,.22); overflow: hidden; }
.pt-bar i { display: block; height: 100%; border-radius: inherit; background: var(--gold); }
.pt-meta, .pt-none { margin: 0; font-size: 13px; color: rgba(255,255,255,.85); }
.pc-title { min-width: 0; }
.pc-dates { margin: 3px 0 0; font-size: 12.5px; color: var(--muted); }
@media (max-width: 560px) {
  .pt-dates { flex-wrap: wrap; }
  .pt-status { order: 3; flex-basis: 100%; text-align: left; }
}
