:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #eef0f3;
  --text: #1b1f24;
  --muted: #616975;
  --border: #dde1e6;
  --accent: #2c6bd6;
  --accent-text: #ffffff;
  --ok: #1d7f47;
  --ok-bg: #e3f3ea;
  --warn: #9a6412;
  --warn-bg: #fbf0dc;
  --bad: #c02f2f;
  --bad-bg: #fbe5e5;
  --radius: 10px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101317;
    --surface: #191d23;
    --surface-2: #232830;
    --text: #e5e8ec;
    --muted: #98a1ac;
    --border: #2d333c;
    --accent: #6b9bf2;
    --accent-text: #0b1220;
    --ok: #55c48e;
    --ok-bg: #15301f;
    --warn: #e2b450;
    --warn-bg: #33280f;
    --bad: #f07a7a;
    --bad-bg: #3a1a1a;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.55 -apple-system, BlinkMacSystemFont, "Sukhumvit Set", Thonburi, "Noto Sans Thai", sans-serif;
}
header.top {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 16px; background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { font-weight: 700; }
.pill { font-size: 13px; padding: 3px 10px; border-radius: 999px; background: var(--surface-2); color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 60vw; }
.pill.ok { background: var(--ok-bg); color: var(--ok); }
.pill.bad { background: var(--bad-bg); color: var(--bad); }
nav.tabs {
  display: flex; gap: 4px; overflow-x: auto; padding: 6px 12px;
  background: var(--surface); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 4; scrollbar-width: none;
}
nav.tabs button {
  border: 0; background: none; padding: 7px 12px; border-radius: 8px; color: var(--muted);
  font: inherit; cursor: pointer; white-space: nowrap;
}
nav.tabs button.active { background: var(--surface-2); color: var(--text); font-weight: 600; }
main { max-width: 1120px; margin: 0 auto; padding: 16px; }
.tab { display: none; }
.tab.active { display: block; }
.grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(min(100%, 320px), 1fr)); }
.span2 { grid-column: 1 / -1; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; min-width: 0; }
.card h3 { margin: 0 0 8px; font-size: 15px; }
h3.gap-top { margin-top: 18px; }
.muted { color: var(--muted); font-size: 13px; }
.gap-top { margin-top: 10px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row.spread { justify-content: space-between; }
.grow { flex: 1 1 220px; }
.btn {
  font: inherit; font-size: 14px; padding: 7px 14px; border-radius: 8px; cursor: pointer;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text);
}
.btn:hover { filter: brightness(0.97); }
.btn.primary { background: var(--accent); color: var(--accent-text); border-color: transparent; font-weight: 600; }
.btn.danger { color: var(--bad); }
.btn.sm { padding: 4px 10px; font-size: 13px; }
.btn:disabled { opacity: 0.5; cursor: default; }
input, select, textarea {
  font: inherit; font-size: 14px; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 8px; padding: 6px 9px; max-width: 100%;
}
textarea { width: 100%; resize: vertical; margin-top: 8px; }
select { max-width: 100%; }
.field { display: inline-flex; gap: 6px; align-items: center; font-size: 14px; flex-wrap: wrap; }
.field.block { display: flex; margin-bottom: 10px; }
.check { display: flex; gap: 6px; align-items: center; font-size: 14px; margin: 6px 0; cursor: pointer; }
code { background: var(--surface-2); padding: 1px 5px; border-radius: 5px; font-size: 12px; word-break: break-all; }
.badge { display: inline-block; font-size: 12px; padding: 1px 8px; border-radius: 999px; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.bad { background: var(--bad-bg); color: var(--bad); }
.bar { height: 10px; background: var(--surface-2); border-radius: 999px; overflow: hidden; margin: 8px 0; }
.bar > span { display: block; height: 100%; background: var(--accent); transition: width 0.4s; }
.bar.warn > span { background: var(--warn); }
.bar.bad > span { background: var(--bad); }
.bar.ok > span { background: var(--ok); }
.warnbox { background: var(--warn-bg); color: var(--warn); padding: 8px 10px; border-radius: 8px; font-size: 13px; margin: 6px 0; }
.steps { margin-top: 12px; font-size: 13px; background: var(--surface-2); border-radius: 8px; padding: 8px 12px; }
.steps div::before { content: "• "; color: var(--muted); }

.mode-grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(min(100%, 280px), 1fr)); }
.mode { border: 1px solid var(--border); border-radius: 8px; padding: 12px; display: flex; flex-direction: column; gap: 8px; align-items: flex-start; }
.mode-title { font-weight: 700; }
.apps { width: 100%; }
.app-row { display: flex; gap: 8px; align-items: center; padding: 3px 0; font-size: 14px; cursor: pointer; }
.app-row.dim .app-name { color: var(--muted); }
.app-info { margin-left: auto; }

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { color: var(--muted); font-weight: 600; font-size: 13px; }
tr.click { cursor: pointer; }
tr.click:hover td { background: var(--surface-2); }
tr.sel td { background: var(--surface-2); }
.table-wrap { overflow-x: auto; }
.num { text-align: right; white-space: nowrap; }

.chat-log { display: flex; flex-direction: column; gap: 10px; margin: 12px 0; }
.msg { border-radius: var(--radius); padding: 10px 14px; max-width: 100%; }
.msg.user { background: var(--accent); color: var(--accent-text); align-self: flex-end; max-width: 85%; }
.msg.assistant { background: var(--surface); border: 1px solid var(--border); }
.msg .meta { font-size: 12px; color: var(--muted); margin-top: 6px; }
.msg.user .meta { color: inherit; opacity: 0.8; }
.msg details { margin-bottom: 6px; font-size: 13px; color: var(--muted); }
.pre { white-space: pre-wrap; word-break: break-word; }
.chat-input { position: sticky; bottom: 8px; }
.chat-input textarea { margin-top: 0; }

.items { margin-top: 10px; max-height: 420px; overflow: auto; border-top: 1px solid var(--border); }
.item { padding: 8px 0; border-bottom: 1px solid var(--border); display: flex; gap: 8px; align-items: flex-start; }
.item .body { flex: 1; min-width: 0; font-size: 14px; }
.item .body .pre { max-height: 4.8em; overflow: hidden; }
.checks label { display: flex; gap: 6px; align-items: center; padding: 3px 0; font-size: 14px; }

.qcard { margin-top: 12px; }
.answers { display: grid; gap: 10px; grid-template-columns: repeat(auto-fit, minmax(min(100%, 280px), 1fr)); margin-top: 10px; }
.answer { border: 1px solid var(--border); border-radius: 8px; padding: 10px; background: var(--surface-2); display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.answer .head { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.answer .resp { max-height: 340px; overflow: auto; font-size: 14px; }
.scores { display: flex; gap: 4px; }
.scores button { width: 34px; height: 30px; border-radius: 6px; border: 1px solid var(--border); background: var(--surface); color: var(--text); cursor: pointer; font: inherit; }
.scores button.on { background: var(--accent); color: var(--accent-text); border-color: transparent; }
.prompt-box { background: var(--surface-2); border-radius: 8px; padding: 8px 10px; font-size: 14px; max-height: 220px; overflow: auto; }

.list-row { display: flex; gap: 8px; align-items: center; margin-bottom: 6px; flex-wrap: wrap; }
.task-edit { border: 1px solid var(--border); border-radius: 8px; padding: 10px; margin-bottom: 10px; }

.overlay {
  position: fixed; inset: 0; z-index: 20; display: flex; align-items: center; justify-content: center;
  padding: 16px; background: var(--bg);
}
#stepup.overlay { background: rgba(0, 0, 0, 0.45); }
.overlay[hidden] { display: none; }
.auth-card { width: min(100%, 420px); display: flex; flex-direction: column; gap: 10px; }
.auth-card h2 { margin: 0; font-size: 20px; }
.auth-card input { width: 100%; margin-top: 6px; }
.btn.big { padding: 12px 16px; font-size: 16px; }
.code-box { margin-top: 10px; padding: 12px; border-radius: 8px; background: var(--surface-2); text-align: center; }
.code-box .code { font: 700 28px/1.3 ui-monospace, SFMono-Regular, Menlo, monospace; letter-spacing: 3px; }
.field.block input.grow, .field.block textarea { flex: 1 1 220px; }

#toast {
  position: fixed; left: 50%; bottom: 18px; transform: translateX(-50%) translateY(20px);
  background: var(--text); color: var(--bg); padding: 9px 16px; border-radius: 10px; font-size: 14px;
  opacity: 0; pointer-events: none; transition: 0.25s; max-width: calc(100vw - 32px);
}
#toast.show { opacity: 1; transform: translateX(-50%); }
#toast.bad { background: var(--bad); color: #fff; }
@media (max-width: 600px) {
  main { padding: 12px 16px; }
  .msg.user { max-width: 92%; }
}
