:root {
  --bg: #f4f5f7;
  --panel: #ffffff;
  --ink: #16181d;
  --ink-2: #4a505c;
  --ink-3: #8a909c;
  --line: #e4e6eb;
  --line-2: #eef0f3;
  --accent: #2f5bea;
  --accent-ink: #ffffff;
  --accent-soft: #eaf0ff;
  --ok: #12805c;
  --ok-soft: #e3f5ee;
  --warn: #a35b00;
  --warn-soft: #fdf1e1;
  --bad: #c22f3a;
  --bad-soft: #fde8ea;
  --muted-soft: #eef0f3;
  --side: #10131a;
  --side-ink: #c9ced8;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 19, 26, .05), 0 1px 1px rgba(16, 19, 26, .03);
  --font: "IBM Plex Sans Thai", "Noto Sans Thai", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font-family: var(--font); font-size: 14px; color: var(--ink); background: var(--bg); line-height: 1.5; -webkit-font-smoothing: antialiased; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
code, .mono { font-family: var(--mono); font-size: 12.5px; }
.boot { display: grid; place-items: center; height: 100vh; color: var(--ink-3); }

/* ---------- layout ---------- */
.shell { display: grid; grid-template-columns: 228px 1fr; min-height: 100vh; }
.side { background: var(--side); color: var(--side-ink); padding: 20px 14px; display: flex; flex-direction: column; gap: 4px; position: sticky; top: 0; height: 100vh; }
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 22px; color: #fff; font-weight: 600; letter-spacing: .2px; }
.brand-mark { width: 28px; height: 28px; border-radius: 7px; background: linear-gradient(135deg, #2f5bea, #6f8cff); display: grid; place-items: center; font-size: 14px; }
.brand small { display: block; color: #7d8494; font-weight: 400; font-size: 11.5px; }
.nav-btn { display: flex; align-items: center; gap: 10px; width: 100%; text-align: left; background: none; border: 0; color: var(--side-ink); padding: 9px 10px; border-radius: 8px; cursor: pointer; }
.nav-btn:hover { background: #1b1f29; color: #fff; }
.nav-btn.active { background: #222837; color: #fff; }
.nav-btn svg { width: 17px; height: 17px; opacity: .85; }
.side-foot { margin-top: auto; border-top: 1px solid #222837; padding: 14px 8px 0; font-size: 12.5px; color: #7d8494; }
.side-foot .who { color: var(--side-ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-bottom: 8px; }
.side-foot button { background: none; border: 1px solid #2a3040; color: var(--side-ink); border-radius: 7px; padding: 5px 10px; cursor: pointer; font-size: 12.5px; }
.side-foot button:hover { border-color: #3a4256; color: #fff; }
.main { padding: 26px 32px 60px; min-width: 0; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head h1 { font-size: 21px; margin: 0; font-weight: 600; letter-spacing: -.1px; }
.page-head p { margin: 2px 0 0; color: var(--ink-3); font-size: 13px; }
.demo-banner { background: #fff7e0; border: 1px solid #f1dfa6; color: #6d5200; padding: 8px 14px; border-radius: 8px; margin-bottom: 16px; font-size: 13px; }

/* ---------- primitives ---------- */
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.panel-pad { padding: 18px 20px; }
.panel-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 20px; border-bottom: 1px solid var(--line-2); gap: 12px; flex-wrap: wrap; }
.panel-head h3 { margin: 0; font-size: 14.5px; font-weight: 600; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--line); background: #fff; padding: 7px 13px; border-radius: 8px; cursor: pointer; font-weight: 500; white-space: nowrap; font-size: 13.5px; }
.btn:hover { border-color: #cfd3db; background: #fafbfc; }
.btn:disabled { opacity: .55; cursor: default; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { background: #2549c9; border-color: #2549c9; }
.btn-danger { color: var(--bad); }
.btn-danger:hover { border-color: #f1b9be; background: var(--bad-soft); }
.btn-sm { padding: 4px 9px; font-size: 12.5px; border-radius: 7px; }
.btn-ghost { border-color: transparent; background: none; }
.btn-ghost:hover { background: var(--muted-soft); border-color: transparent; }
.input, select.input, textarea.input { width: 100%; border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; background: #fff; outline: none; }
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
textarea.input { resize: vertical; min-height: 64px; }
label.field { display: block; }
label.field > span { display: block; font-size: 12.5px; color: var(--ink-2); margin-bottom: 4px; font-weight: 500; }
.hint { font-size: 12px; color: var(--ink-3); margin-top: 4px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.stack { display: flex; flex-direction: column; gap: 14px; }
.muted { color: var(--ink-3); }
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 500; white-space: nowrap; background: var(--muted-soft); color: var(--ink-2); }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .8; }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }
.badge.info { background: var(--accent-soft); color: var(--accent); }
.badge.plain::before { display: none; }
.tag { display: inline-block; padding: 1px 7px; border-radius: 5px; background: var(--muted-soft); color: var(--ink-2); font-size: 11.5px; }

/* switch */
.switch { position: relative; display: inline-flex; align-items: center; gap: 8px; cursor: pointer; user-select: none; font-size: 13px; }
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch .track { width: 34px; height: 20px; background: #cfd3db; border-radius: 999px; position: relative; transition: background .15s; flex: none; }
.switch .track::after { content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; background: #fff; border-radius: 50%; transition: transform .15s; box-shadow: 0 1px 2px rgba(0,0,0,.2); }
.switch input:checked + .track { background: var(--ok); }
.switch input:checked + .track::after { transform: translateX(14px); }

/* segmented */
.seg { display: inline-flex; background: var(--muted-soft); border-radius: 8px; padding: 2px; }
.seg button { border: 0; background: none; padding: 5px 11px; border-radius: 6px; cursor: pointer; font-size: 13px; color: var(--ink-2); }
.seg button.on { background: #fff; color: var(--ink); box-shadow: var(--shadow); font-weight: 500; }
.seg.live button.on[data-v="live"] { background: var(--ok); color: #fff; }

/* tabs */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin-bottom: 18px; }
.tabs button { border: 0; background: none; padding: 9px 14px; cursor: pointer; color: var(--ink-3); border-bottom: 2px solid transparent; margin-bottom: -1px; font-weight: 500; }
.tabs button.on { color: var(--ink); border-color: var(--accent); }
.tabs button .count { color: var(--ink-3); font-weight: 400; margin-left: 4px; }

/* ---------- data page ---------- */
.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; padding: 12px 14px; margin-bottom: 16px; }
.filters .input { width: auto; padding: 6px 9px; font-size: 13px; }
.filters .sep { width: 1px; height: 22px; background: var(--line); }
.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 0; margin-bottom: 16px; overflow: hidden; }
.kpi { padding: 16px 20px; position: relative; }
.kpi + .kpi { border-left: 1px solid var(--line-2); }
.kpi .lbl { font-size: 12.5px; color: var(--ink-3); }
.kpi .val { font-size: 27px; font-weight: 600; letter-spacing: -.5px; margin-top: 2px; font-variant-numeric: tabular-nums; }
.kpi .rate { font-size: 12px; color: var(--ink-2); margin-top: 2px; }
.kpi .rate b { font-weight: 600; }
.kpi .arrow { position: absolute; left: -9px; top: 50%; transform: translateY(-50%); width: 18px; height: 18px; background: #fff; border: 1px solid var(--line-2); border-radius: 50%; display: grid; place-items: center; font-size: 10px; color: var(--ink-3); z-index: 1; }
.chart-wrap { padding: 8px 16px 14px; }
.chart-legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12.5px; color: var(--ink-2); }
.chart-legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }
.chart svg { display: block; width: 100%; height: auto; }
.chart .tip { position: absolute; pointer-events: none; background: var(--side); color: #fff; font-size: 12px; padding: 7px 10px; border-radius: 7px; white-space: nowrap; transform: translate(-50%, -100%); margin-top: -8px; z-index: 5; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
.tbl th { text-align: left; font-weight: 500; color: var(--ink-3); font-size: 12px; padding: 9px 12px; border-bottom: 1px solid var(--line); background: #fafbfc; white-space: nowrap; position: sticky; top: 0; }
.tbl td { padding: 9px 12px; border-bottom: 1px solid var(--line-2); vertical-align: middle; }
.tbl tr.clickable { cursor: pointer; }
.tbl tr.clickable:hover td { background: #fafbfd; }
.tbl td.num, .tbl th.num { text-align: right; font-variant-numeric: tabular-nums; }
.tbl .cid { font-family: var(--mono); font-size: 12px; max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: inline-block; vertical-align: middle; }
.tbl .page { max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: inline-block; vertical-align: middle; color: var(--ink-2); }
.tbl tr.detail td { background: #f8f9fb; padding: 12px 16px 14px; }
.tbl-scroll { overflow-x: auto; }
.empty { padding: 40px 20px; text-align: center; color: var(--ink-3); }
.pager { display: flex; justify-content: space-between; align-items: center; padding: 10px 14px; font-size: 12.5px; color: var(--ink-3); }
.attempts { display: grid; gap: 8px; }
.attempt { background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; display: grid; grid-template-columns: 140px 1fr; gap: 4px 12px; font-size: 12.5px; }
.attempt dt { color: var(--ink-3); }
.attempt dd { margin: 0; word-break: break-all; }

/* ---------- settings ---------- */
.card-list { display: grid; gap: 16px; }
.src-card .panel-head h3 { display: flex; align-items: center; gap: 10px; }
.kv { display: grid; grid-template-columns: 170px 1fr; gap: 12px 18px; align-items: start; padding: 18px 20px; }
.kv > dt { color: var(--ink-2); font-size: 13px; font-weight: 500; padding-top: 7px; }
.kv > dd { margin: 0; min-width: 0; }
.copy-field { display: flex; align-items: stretch; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: #fafbfc; }
.copy-field code { flex: 1; padding: 7px 10px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.copy-field button { border: 0; border-left: 1px solid var(--line); background: #fff; padding: 0 12px; cursor: pointer; font-size: 12.5px; color: var(--ink-2); white-space: nowrap; }
.copy-field button:hover { background: var(--accent-soft); color: var(--accent); }
.code-block { position: relative; background: #0f1219; color: #d7dbe4; border-radius: 9px; overflow: hidden; }
.code-block .cb-head { display: flex; align-items: center; justify-content: space-between; padding: 8px 12px; background: #161a23; font-size: 12px; color: #9aa1b0; }
.code-block .cb-head button { background: #232937; border: 0; color: #d7dbe4; padding: 4px 10px; border-radius: 6px; cursor: pointer; font-size: 12px; }
.code-block .cb-head button:hover { background: #2f5bea; color: #fff; }
.code-block pre { margin: 0; padding: 12px 14px; overflow: auto; max-height: 320px; font-family: var(--mono); font-size: 12px; line-height: 1.55; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; padding: 5px; border: 1px solid var(--line); border-radius: 8px; background: #fff; min-height: 38px; align-items: center; }
.chip { display: inline-flex; align-items: center; gap: 4px; background: var(--accent-soft); color: var(--accent); border-radius: 6px; padding: 2px 4px 2px 8px; font-size: 12.5px; }
.chip button { border: 0; background: none; cursor: pointer; color: inherit; padding: 0 4px; font-size: 14px; line-height: 1; }
.chips input { border: 0; outline: none; flex: 1; min-width: 140px; padding: 3px 4px; }
.health { display: flex; gap: 22px; flex-wrap: wrap; font-size: 13px; }
.health b { font-weight: 600; font-variant-numeric: tabular-nums; }
.result-box { margin-top: 10px; border-radius: 8px; padding: 10px 12px; font-size: 12.5px; }
.result-box.ok { background: var(--ok-soft); color: #0b5d42; }
.result-box.bad { background: var(--bad-soft); color: #8e1f28; }
.result-box pre { margin: 6px 0 0; white-space: pre-wrap; word-break: break-all; font-family: var(--mono); font-size: 11.5px; }
details.more > summary { cursor: pointer; color: var(--ink-2); font-weight: 500; padding: 4px 0; list-style: none; }
details.more > summary::-webkit-details-marker { display: none; }
details.more > summary::before { content: "▸ "; color: var(--ink-3); }
details.more[open] > summary::before { content: "▾ "; }
.steps { margin: 0 0 12px; padding-left: 18px; color: var(--ink-2); font-size: 13px; }
.steps li { margin: 2px 0; }
.live-warn { background: var(--warn-soft); color: var(--warn); border-radius: 8px; padding: 8px 12px; font-size: 12.5px; }

/* ---------- modal / toast / login ---------- */
.modal-bg { position: fixed; inset: 0; background: rgba(16, 19, 26, .45); display: grid; place-items: center; z-index: 50; padding: 20px; }
.modal { background: #fff; border-radius: 12px; width: 100%; max-width: 480px; box-shadow: 0 20px 50px rgba(0,0,0,.2); }
.modal h3 { margin: 0; padding: 18px 20px 4px; font-size: 16px; }
.modal .body { padding: 12px 20px 4px; display: grid; gap: 12px; }
.modal .foot { display: flex; justify-content: flex-end; gap: 8px; padding: 16px 20px 18px; }
#toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); z-index: 60; display: grid; gap: 8px; }
.toast { background: var(--side); color: #fff; padding: 9px 16px; border-radius: 9px; font-size: 13px; box-shadow: 0 8px 24px rgba(0,0,0,.18); animation: tin .2s ease; }
.toast.bad { background: var(--bad); }
@keyframes tin { from { opacity: 0; transform: translateY(6px); } }
.login { min-height: 100vh; display: grid; place-items: center; padding: 20px; background: radial-gradient(1200px 600px at 20% -10%, #e3e9ff, transparent), var(--bg); }
.login-card { width: 100%; max-width: 380px; padding: 30px 28px; }
.login-card .brand { color: var(--ink); padding: 0 0 18px; }
.login-card h2 { margin: 0 0 4px; font-size: 19px; }
.login-card p { margin: 0 0 18px; color: var(--ink-3); font-size: 13px; }
.err { color: var(--bad); font-size: 12.5px; min-height: 18px; }

@media (max-width: 1100px) { .kpis { grid-template-columns: repeat(2, 1fr); } .kpi:nth-child(3) { border-left: 0; } .kpi:nth-child(n+3) { border-top: 1px solid var(--line-2); } .kpi .arrow { display: none; } }
@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: static; height: auto; flex-direction: row; align-items: center; padding: 10px 12px; overflow-x: auto; }
  .brand { padding: 0 12px 0 4px; } .brand small { display: none; }
  .side-foot { margin: 0 0 0 auto; border: 0; padding: 0; display: flex; gap: 8px; align-items: center; } .side-foot .who { display: none; }
  .main { padding: 18px 14px 50px; }
  .kv { grid-template-columns: 1fr; gap: 4px; } .kv > dt { padding-top: 10px; }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
}

/* ---- v2 ---- */
.ws-pick{display:flex;flex-direction:column;gap:5px;margin:0 0 14px;padding:10px 12px;border:1px solid #2a3040;border-radius:10px;background:#161b26;font-size:12.5px}
.ws-pick span{color:#7d8494;font-size:10.5px;text-transform:uppercase;letter-spacing:.06em}
.ws-pick b{font-weight:600;color:#fff}
.ws-pick select.input{width:100%;padding:6px 8px;font-size:13px;background:#1d2330;color:#fff;border-color:#2a3040}
.group-title{font-size:14px;font-weight:600;margin:18px 0 10px;display:flex;align-items:center;gap:8px}
.group-title:first-of-type{margin-top:4px}
.group-title .count{font-size:11.5px;color:var(--ink-3,#8a909c);font-weight:500;background:var(--line-2);border-radius:999px;padding:1px 8px}
textarea.input{width:100%;resize:vertical;line-height:1.5;font-family:"IBM Plex Mono",monospace;font-size:12.5px}
.side-foot button{margin:0 4px 4px 0}
