:root {
  --navy: #14122b;
  --navy-2: #1d1a3b;
  --navy-3: #2a2650;
  --gold: #d9be8a;
  --gold-2: #c9a15a;
  --ink: #1d1b29;
  --muted: #6c6878;
  --line: #e6e2da;
  --bg: #f6f4ef;
  --card: #fff;
  --ok: #2f9e6a;
  --bad: #c8453b;
  --hot: #fff6e3;
  --r: 14px;
  --side: 232px;
  font-family: "IBM Plex Sans Thai", "Leelawadee UI", system-ui, sans-serif;
  color: var(--ink);
  background: var(--bg);
  -webkit-text-size-adjust: 100%;
}
* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; background: var(--bg); font-size: 15px; line-height: 1.55; }
[hidden] { display: none !important; }
button, input, select { font: inherit; color: inherit; }
a { color: inherit; }
h1, h2 { margin: 0; line-height: 1.3; }
.ic { width: 20px; height: 20px; flex: none; }
.ic.sm { width: 16px; height: 16px; }
:focus-visible { outline: 2.5px solid var(--gold-2); outline-offset: 2px; }

/* ---------- ปุ่ม ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--line); background: #fff; border-radius: 11px; padding: 10px 16px; font-weight: 600; cursor: pointer; text-decoration: none; min-height: 42px; }
.btn:hover { border-color: #cfc8bb; }
.btn.primary { background: var(--navy); border-color: var(--navy); color: #f5f0e6; }
.btn.primary:hover { background: var(--navy-3); }
.btn.small { padding: 6px 12px; min-height: 34px; font-size: 14px; }
.btn.wide { width: 100%; }
.btn:disabled { opacity: .55; cursor: default; }
.icon-btn { display: grid; place-items: center; width: 36px; height: 36px; border-radius: 10px; border: 1px solid transparent; background: transparent; cursor: pointer; color: var(--muted); }
.icon-btn:hover { background: #fff; border-color: var(--line); color: var(--ink); }

/* ---------- เริ่มต้น / เข้าสู่ระบบ ---------- */
.boot { min-height: 100vh; display: grid; place-items: center; background: var(--navy); }
.boot img { border-radius: 14px; animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .5; } }
.gate { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; background: var(--navy) url(img/arch.svg) 0 0 / 96px 144px; }
.gate-card { width: 100%; max-width: 360px; background: #fff; border-radius: 20px; padding: 30px 26px 26px; display: grid; gap: 14px; box-shadow: 0 30px 60px -30px rgba(0, 0, 0, .6); }
.gate-logo { justify-self: center; border-radius: 18px; }
.gate-wm { justify-self: center; }
.gate-sub { margin: -8px 0 6px; text-align: center; color: var(--muted); font-size: 14px; }
label { display: grid; gap: 5px; }
label > span { font-size: 13.5px; color: var(--muted); font-weight: 500; }
input:not([type=checkbox]), select { width: 100%; border: 1px solid var(--line); border-radius: 11px; padding: 10px 12px; background: #fff; min-height: 44px; }
input:focus, select:focus { border-color: var(--gold-2); outline: none; box-shadow: 0 0 0 3px rgba(201, 161, 90, .25); }
.err { margin: 0; min-height: 1em; color: var(--bad); font-size: 14px; }
.err:empty { display: none; }

/* ---------- โครงแอป ---------- */
.app { display: grid; grid-template-columns: var(--side) minmax(0, 1fr); min-height: 100vh; }
.side { position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; background: var(--navy); color: #e9e4f2; padding: 18px 12px 14px; }
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 18px; text-decoration: none; font-size: 16px; color: #f5f0e6; }
.brand img { border-radius: 9px; }
.brand b { color: var(--gold); font-weight: 700; }
.nav { display: grid; gap: 2px; align-content: start; flex: 1; overflow-y: auto; }
.nav a { position: relative; display: flex; align-items: center; gap: 11px; padding: 9px 10px; border-radius: 10px; text-decoration: none; color: #cfc9dc; font-weight: 500; }
.nav a img { border-radius: 6px; }
.nav a:hover { background: var(--navy-2); color: #fff; }
.nav a.on { background: var(--navy-3); color: #fff; box-shadow: inset 3px 0 0 var(--gold); }
.nav a.off { opacity: .55; }
.nav .s { display: none; }
.nav hr { border: 0; border-top: 1px solid var(--navy-3); margin: 10px 6px; width: auto; }
.badge { margin-left: auto; min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px; background: var(--gold); color: var(--navy); font: 700 12px/20px inherit; font-style: normal; text-align: center; }
.me { position: relative; border-top: 1px solid var(--navy-3); padding-top: 12px; }
.me-btn { display: flex; align-items: center; gap: 10px; width: 100%; padding: 6px 8px; border: 0; border-radius: 10px; background: transparent; color: #e9e4f2; cursor: pointer; text-align: left; }
.me-btn:hover { background: var(--navy-2); }
.avatar { display: grid; place-items: center; width: 32px; height: 32px; flex: none; border-radius: 50%; background: var(--gold); color: var(--navy); font-weight: 700; }
.me-s { display: none; }
.me-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.menu { position: absolute; left: 0; right: 0; bottom: calc(100% + 6px); background: #fff; color: var(--ink); border-radius: 12px; padding: 6px; box-shadow: 0 16px 40px -12px rgba(0, 0, 0, .45); display: grid; z-index: 30; }
.menu button { border: 0; background: transparent; text-align: left; padding: 10px 12px; border-radius: 8px; cursor: pointer; }
.menu button:hover { background: var(--bg); }
.menu .m-only { display: none; }

.main { min-width: 0; }
.view { padding: 26px 30px 40px; max-width: 1180px; }
.head { display: flex; align-items: center; gap: 10px; margin-bottom: 18px; flex-wrap: wrap; }
.head h1 { font-size: 24px; margin-right: auto; }
.head .at { color: var(--muted); font-size: 13px; }
.empty { color: var(--muted); padding: 30px 0; }
.hint { color: var(--muted); font-size: 13.5px; margin: -8px 0 16px; }

/* ---------- ภาพรวม ---------- */
.todo { background: var(--navy); color: #f5f0e6; border-radius: var(--r); padding: 16px 18px; margin-bottom: 18px; background-image: linear-gradient(90deg, var(--navy) 55%, rgba(20, 18, 43, .88)), url(img/arch.svg); background-size: auto, 96px 144px; }
.todo h2 { display: flex; align-items: center; gap: 7px; font-size: 15px; color: var(--gold); margin-bottom: 10px; }
.todo.calm h2 { margin: 0; color: #cfc9dc; font-weight: 500; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { display: inline-flex; align-items: center; gap: 7px; padding: 6px 12px 6px 7px; border-radius: 999px; background: var(--navy-3); text-decoration: none; font-size: 14px; }
.chip img { border-radius: 5px; }
.chip b { color: var(--gold); }
.chip:hover { background: #3a3566; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 16px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--r); padding: 16px; min-width: 0; }
.card.sk { height: 210px; background: linear-gradient(90deg, #fff, #f1eee8, #fff); background-size: 200% 100%; animation: sk 1.2s linear infinite; }
@keyframes sk { to { background-position: -200% 0; } }
.card.muted { background: #fbfaf7; }
.ch { display: flex; align-items: center; gap: 11px; margin-bottom: 10px; }
.ch img { border-radius: 9px; }
.ch b { display: block; font-size: 15.5px; }
.ch small { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 12.5px; }
.go { margin-left: auto; display: grid; place-items: center; width: 34px; height: 34px; border-radius: 10px; color: var(--muted); }
.go:hover { background: var(--bg); color: var(--ink); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); display: inline-block; flex: none; }
.dot.ok { background: var(--ok); }
.dot.bad { background: var(--bad); }
.note { color: var(--muted); font-size: 14px; margin: 4px 0 12px; }
.note.bad { color: var(--bad); }
.stats { list-style: none; margin: 0; padding: 0; display: grid; }
.stats li > a, .stats li > .row { display: flex; align-items: center; gap: 8px; padding: 9px 8px; border-radius: 9px; text-decoration: none; }
.stats li + li { border-top: 1px solid #f0ede7; }
.stats li > a:hover { background: var(--bg); }
.stats .lb { color: var(--muted); }
.stats .vl { margin-left: auto; font-weight: 700; font-variant-numeric: tabular-nums; }
.stats .vl small { font-weight: 500; color: var(--muted); }
.stats .ic { color: #b8b2a6; }
.stats li.zero .vl { color: #b8b2a6; font-weight: 500; }
.stats li.hot > a, .stats li.hot > .row { background: var(--hot); }
.stats li.hot .lb { color: var(--ink); font-weight: 500; }
.stats li.hot .vl { color: #a3741f; }
.sites { margin-top: 22px; }
.sites h2 { font-size: 14px; color: var(--muted); font-weight: 600; margin-bottom: 8px; }
.site-row { display: flex; flex-wrap: wrap; gap: 8px; }
.site { display: inline-flex; align-items: center; gap: 7px; padding: 7px 12px; background: #fff; border: 1px solid var(--line); border-radius: 999px; text-decoration: none; font-size: 13.5px; }
.site small { color: var(--muted); }

/* ---------- หน้าระบบที่ฝังไว้ ---------- */
.view.sys { padding: 0; max-width: none; height: 100vh; display: flex; flex-direction: column; }
.sysbar { display: flex; align-items: center; gap: 10px; padding: 8px 12px 8px 18px; background: #fff; border-bottom: 1px solid var(--line); min-height: 52px; }
.sysbar img { border-radius: 7px; }
.sysbar .st { margin-left: auto; font-size: 13px; color: var(--muted); display: flex; align-items: center; gap: 6px; max-width: 46vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sysbar .st::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--gold-2); flex: none; }
.sysbar .st.ok::before { background: var(--ok); }
.sysbar .st.bad { color: var(--bad); }
.sysbar .st.bad::before { background: var(--bad); }
.view.sys iframe { flex: 1; width: 100%; border: 0; background: #fff; }
.view:not(.sys) .sysbar { margin: -26px -30px 18px; }

/* ---------- ทีมงาน / ประวัติ ---------- */
.list { display: grid; gap: 8px; }
.person { display: flex; align-items: center; gap: 12px; width: 100%; padding: 12px 14px; border: 1px solid var(--line); background: #fff; border-radius: 12px; cursor: pointer; text-align: left; }
.person:hover { border-color: #cfc8bb; }
.person.off { opacity: .55; }
.who { display: grid; min-width: 0; }
.who small { color: var(--muted); font-size: 13px; }
.tags { margin-left: auto; display: flex; gap: 5px; flex-wrap: wrap; justify-content: flex-end; }
.tag { font-size: 12px; padding: 2px 8px; border-radius: 999px; background: #f1eee8; color: #a8a293; text-decoration: line-through; }
.tag.on { background: #ecf6f0; color: #23784f; text-decoration: none; }
.log { list-style: none; margin: 0; padding: 0; background: #fff; border: 1px solid var(--line); border-radius: 12px; }
.log li { padding: 10px 14px; font-size: 14px; }
.log li + li { border-top: 1px solid #f0ede7; }
.log time { display: inline-block; min-width: 118px; color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }
.log span { color: var(--muted); }

/* ---------- กล่องโต้ตอบ ---------- */
.dlg { border: 0; border-radius: 18px; padding: 0; width: min(440px, calc(100vw - 24px)); box-shadow: 0 30px 70px -20px rgba(0, 0, 0, .5); }
.dlg::backdrop { background: rgba(20, 18, 43, .55); }
.dlg form { display: grid; gap: 13px; padding: 22px; max-height: calc(100vh - 40px); overflow-y: auto; }
.dlg h2 { font-size: 19px; }
fieldset { border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px 4px; margin: 0; display: grid; gap: 8px; }
legend { font-size: 13.5px; color: var(--muted); padding: 0 4px; font-weight: 500; }
.lk { grid-template-columns: 22px 92px minmax(0, 1fr); align-items: center; gap: 9px; }
.lk img { border-radius: 5px; }
.lk > span { color: var(--ink); font-size: 14px; }
.sw { display: flex; align-items: center; gap: 9px; cursor: pointer; min-height: 40px; }
.sw > span { color: var(--ink); font-size: 14px; flex: 1; }
.sw input { position: absolute; opacity: 0; pointer-events: none; }
.sw i { width: 42px; height: 24px; border-radius: 12px; background: #d9d4ca; position: relative; transition: background .15s; flex: none; }
.sw i::after { content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; transition: transform .15s; }
.sw input:checked + i { background: var(--ok); }
.sw input:checked + i::after { transform: translateX(18px); }
.sw input:focus-visible + i { outline: 2.5px solid var(--gold-2); outline-offset: 2px; }
.lk.sw { display: grid; grid-template-columns: 22px minmax(0, 1fr) 42px; }
fieldset .hint { margin: -4px 0 6px; font-size: 12.5px; }
.acts { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px); background: var(--navy); color: #fff; padding: 10px 18px; border-radius: 12px; opacity: 0; pointer-events: none; transition: .2s; z-index: 50; max-width: calc(100vw - 32px); }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.bad { background: var(--bad); }

/* ---------- มือถือ: เมนูไปอยู่ล่างจอ ---------- */
@media (max-width: 860px) {
  .app { grid-template-columns: minmax(0, 1fr); padding-bottom: calc(62px + env(safe-area-inset-bottom)); }
  .side { position: fixed; top: auto; bottom: 0; left: 0; right: 0; height: auto; z-index: 20; flex-direction: row; align-items: stretch; padding: 4px 4px calc(4px + env(safe-area-inset-bottom)); }
  .brand { display: none; }
  .nav { display: flex; flex: 1; gap: 0; overflow-x: auto; scrollbar-width: none; }
  .nav a { flex: 1 0 auto; min-width: 58px; flex-direction: column; gap: 2px; padding: 6px 4px; font-size: 11px; justify-content: center; }
  .nav a.on { box-shadow: inset 0 -2px 0 var(--gold); }
  .nav a .ic, .nav a img { width: 22px; height: 22px; }
  .nav .l { display: none; }
  .nav .s { display: block; white-space: nowrap; }
  .nav hr { display: none; }
  .nav a[data-v=team], .nav a[data-v=log] { display: none; }
  .menu .m-only { display: block; }
  .badge { position: absolute; top: 2px; left: calc(50% + 6px); margin: 0; min-width: 17px; height: 17px; line-height: 17px; font-size: 10.5px; padding: 0 4px; }
  .me { border: 0; padding: 0; display: flex; }
  .me-btn { flex-direction: column; justify-content: center; gap: 2px; padding: 6px 8px; width: auto; }
  .me-btn .avatar { width: 24px; height: 24px; font-size: 12px; }
  .me-name { display: none; }
  .me-s { display: block; font-size: 11px; color: #cfc9dc; }
  .menu { left: auto; right: 4px; width: 200px; }
  .view { padding: 18px 16px 28px; }
  .head h1 { font-size: 20px; }
  .view.sys { height: calc(100vh - 62px - env(safe-area-inset-bottom)); height: calc(100dvh - 62px - env(safe-area-inset-bottom)); }
  .view:not(.sys) .sysbar { margin: -18px -16px 16px; }
  .grid { grid-template-columns: minmax(0, 1fr); }
  .person { flex-wrap: wrap; }
  .tags { margin-left: 44px; justify-content: flex-start; }
  .log time { display: block; }
  .toast { bottom: calc(76px + env(safe-area-inset-bottom)); }
}
