:root {
  color-scheme: light;
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --line: #dfe3e8;
  --text: #191c20;
  --text-2: #5c6570;
  --accent: #1f6feb;
  --accent-text: #ffffff;
  --accent-soft: #e7f0fe;
  --good: #0a7a2f;
  --warn: #9a6200;
  --bad: #c62828;
  --series-1: #257de0;
  --grid: #e6e9ed;
  --shadow: 0 1px 2px rgba(20, 28, 40, .06), 0 0 0 1px rgba(20, 28, 40, .06);
  --radius: 10px;
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #121418;
    --surface: #191c21;
    --surface-2: #22262c;
    --line: #2f353d;
    --text: #eef0f2;
    --text-2: #9ea7b1;
    --accent: #4c8dff;
    --accent-text: #0b1220;
    --accent-soft: #1b2a44;
    --good: #4cc26f;
    --warn: #e0a83a;
    --bad: #ff7b72;
    --series-1: #338ced;
    --grid: #2a2f36;
    --shadow: 0 0 0 1px rgba(255, 255, 255, .07);
  }
}

* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.55 system-ui, -apple-system, "Segoe UI", "Leelawadee UI", "Noto Sans Thai", Roboto, sans-serif;
}
h1 { font-size: 22px; line-height: 1.3; margin: 0 0 4px; text-wrap: balance; }
h2 { font-size: 16px; margin: 0 0 12px; }
p { margin: 0 0 12px; }
a { color: var(--accent); }
.muted { color: var(--text-2); }
.small { font-size: 13px; }
.num { font-variant-numeric: tabular-nums; }

/* layout */
.top {
  display: flex; align-items: center; gap: 16px; padding: 0 20px; height: 56px;
  background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 10;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 17px; text-decoration: none; color: var(--text); letter-spacing: -.01em; }
.brand svg { flex: none; }
.top .spacer { flex: 1; }
.top nav { display: flex; gap: 4px; }
.top nav a, .linkbtn {
  padding: 6px 10px; border-radius: 8px; text-decoration: none; color: var(--text-2); font-weight: 500;
  background: none; border: 0; font: inherit; cursor: pointer; white-space: nowrap;
}
.top nav a:hover, .linkbtn:hover { background: var(--surface-2); color: var(--text); }
.top nav a.on { color: var(--text); background: var(--surface-2); }
.page { max-width: 1080px; margin: 0 auto; padding: 28px 20px 64px; }
.head { display: flex; align-items: flex-end; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.head .grow { flex: 1; min-width: 200px; }
.tabs { display: flex; gap: 2px; box-shadow: inset 0 -1px 0 var(--line); margin-bottom: 24px; overflow-x: auto; overflow-y: hidden; }
.tabs a {
  padding: 10px 14px; text-decoration: none; color: var(--text-2); font-weight: 500; white-space: nowrap;
  border-bottom: 2px solid transparent;
}
.tabs a:hover { color: var(--text); }
.tabs a.on { color: var(--text); border-bottom-color: var(--accent); }

.card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; margin-bottom: 16px; }
.grid { display: grid; gap: 16px; }
.grid.k4 { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.grid.k2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.grid > .card { margin-bottom: 0; }
.grid + .card, .grid + .grid { margin-top: 16px; }

/* stat tiles */
.stat .label { color: var(--text-2); font-size: 13px; }
.stat .value { font-size: 30px; font-weight: 650; line-height: 1.2; font-variant-numeric: tabular-nums; letter-spacing: -.02em; }
.stat .note { color: var(--text-2); font-size: 13px; }

/* forms */
label { display: block; font-weight: 600; font-size: 14px; margin-bottom: 6px; }
.field { margin-bottom: 16px; }
.field .hint { color: var(--text-2); font-size: 13px; margin-top: 4px; }
.field .count { float: right; color: var(--text-2); font-weight: 400; font-size: 13px; font-variant-numeric: tabular-nums; }
input[type=text], input[type=email], input[type=password], input[type=url], input[type=number], input[type=datetime-local], textarea, select {
  width: 100%; padding: 9px 11px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--surface); color: var(--text); font: inherit;
}
textarea { min-height: 88px; resize: vertical; }
input:disabled { background: var(--surface-2); color: var(--text-2); }
input:focus-visible, textarea:focus-visible, select:focus-visible, button:focus-visible, a:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 1px;
}
.check { display: flex; gap: 8px; align-items: flex-start; font-weight: 400; }
.check input { margin-top: 4px; }
.row { display: flex; gap: 12px; flex-wrap: wrap; }
.row > * { flex: 1; min-width: 160px; }
.btn {
  display: inline-flex; align-items: center; gap: 8px; padding: 9px 16px; border-radius: 8px; border: 1px solid transparent;
  background: var(--accent); color: var(--accent-text); font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn:hover { filter: brightness(1.07); }
.btn:disabled { opacity: .55; cursor: default; filter: none; }
.btn.quiet { background: var(--surface); color: var(--text); border-color: var(--line); }
.btn.danger { background: var(--surface); color: var(--bad); border-color: var(--line); }
.btn.sm { padding: 5px 10px; font-size: 13px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.error { color: var(--bad); font-size: 14px; margin: 0 0 12px; }
.notice { background: var(--accent-soft); border-radius: 8px; padding: 12px 14px; margin-bottom: 16px; }

/* tables */
.tablewrap { overflow-x: auto; margin: 0 -20px; padding: 0 20px; }
table { border-collapse: collapse; width: 100%; font-size: 14px; }
th { text-align: left; color: var(--text-2); font-weight: 500; font-size: 13px; padding: 8px 12px 8px 0; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 10px 12px 10px 0; border-bottom: 1px solid var(--line); vertical-align: top; }
tr:last-child td { border-bottom: 0; }
th.r, td.r { text-align: right; font-variant-numeric: tabular-nums; }
td .t { font-weight: 600; overflow-wrap: anywhere; }
td .s { color: var(--text-2); font-size: 13px; overflow-wrap: anywhere; }
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 1px 9px; border-radius: 99px; font-size: 12.500px; font-weight: 600; background: var(--surface-2); color: var(--text-2); white-space: nowrap; }
.pill::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.pill.good { color: var(--good); } .pill.warn { color: var(--warn); } .pill.bad { color: var(--bad); }
.empty { text-align: center; padding: 36px 16px; color: var(--text-2); }
.empty b { display: block; color: var(--text); font-size: 16px; margin-bottom: 4px; }

/* app list */
.applist { display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }
.appcard { display: block; text-decoration: none; color: inherit; background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; }
.appcard:hover { box-shadow: var(--shadow), 0 0 0 2px var(--accent); }
.appcard .name { font-weight: 650; font-size: 16px; overflow-wrap: anywhere; }
.appcard .origin { color: var(--text-2); font-size: 13px; overflow-wrap: anywhere; margin-bottom: 14px; }
.appcard .big { font-size: 26px; font-weight: 650; font-variant-numeric: tabular-nums; line-height: 1.2; }

/* code */
pre {
  background: var(--surface-2); border-radius: 8px; padding: 12px 14px; overflow-x: auto; margin: 0 0 8px;
  font: 13px/1.5 ui-monospace, "Cascadia Mono", Consolas, monospace; white-space: pre-wrap; overflow-wrap: anywhere;
}
code { font: 13px ui-monospace, "Cascadia Mono", Consolas, monospace; background: var(--surface-2); padding: 1px 5px; border-radius: 4px; }
ol.steps { padding-left: 0; margin: 0; list-style: none; counter-reset: step; }
ol.steps > li { counter-increment: step; position: relative; padding: 0 0 20px 44px; }
ol.steps > li::before {
  content: counter(step); position: absolute; left: 0; top: 0; width: 28px; height: 28px; border-radius: 50%;
  background: var(--accent-soft); color: var(--accent); font-weight: 700; display: flex; align-items: center; justify-content: center; font-size: 14px;
}
ol.steps > li:last-child { padding-bottom: 0; }

/* notification preview */
.preview { background: var(--surface-2); border-radius: var(--radius); padding: 20px; position: sticky; top: 76px; }
.toastcard { background: var(--surface); border-radius: 10px; box-shadow: 0 6px 24px rgba(0, 0, 0, .16), var(--shadow); overflow: hidden; max-width: 360px; margin: 0 auto; }
.toastcard img.hero { display: block; width: 100%; max-height: 180px; object-fit: cover; }
.toastcard .in { display: flex; gap: 12px; padding: 14px; }
.toastcard .ic { flex: none; width: 40px; height: 40px; border-radius: 8px; background: var(--accent); object-fit: cover; display: flex; align-items: center; justify-content: center; }
.toastcard .tt { font-weight: 650; overflow-wrap: anywhere; }
.toastcard .bb { color: var(--text-2); font-size: 14px; overflow-wrap: anywhere; white-space: pre-wrap; }
.toastcard .dd { color: var(--text-2); font-size: 12px; margin-top: 4px; overflow-wrap: anywhere; }
.compose { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr); gap: 24px; align-items: start; }
@media (max-width: 820px) { .compose { grid-template-columns: 1fr; } .preview { position: static; } }

/* chart */
.viz { position: relative; }
.viz svg { display: block; width: 100%; height: auto; overflow: visible; }
.viz .bar { fill: var(--series-1); }
.viz .hit { fill: transparent; }
.viz .hit:hover + .bar, .viz .bar.on { filter: brightness(1.15); }
.viz .gridline { stroke: var(--grid); stroke-width: 1; }
.viz text { fill: var(--text-2); font-size: 11px; font-variant-numeric: tabular-nums; }
.viz .tip {
  position: absolute; pointer-events: none; background: var(--text); color: var(--bg); border-radius: 6px; padding: 5px 9px;
  font-size: 13px; white-space: nowrap; transform: translate(-50%, -100%); margin-top: -8px; z-index: 2;
}
.viz .tip b { font-variant-numeric: tabular-nums; }
.charthead { display: flex; align-items: baseline; gap: 12px; margin-bottom: 12px; }
.charthead h2 { margin: 0; flex: 1; }
.hbar { display: grid; grid-template-columns: minmax(80px, 140px) 1fr auto; gap: 6px 12px; align-items: center; font-size: 14px; }
.hbar .track { height: 10px; }
.hbar .fill { height: 10px; border-radius: 0 4px 4px 0; background: var(--series-1); min-width: 2px; }
.hbar .v { font-variant-numeric: tabular-nums; text-align: right; }

/* login */
.login { max-width: 380px; margin: 9vh auto 0; padding: 0 20px; }
.login .brand { justify-content: center; margin-bottom: 24px; font-size: 22px; }

/* dialog + toast */
dialog { border: 0; border-radius: 12px; padding: 24px; max-width: 440px; width: calc(100% - 32px); background: var(--surface); color: var(--text); box-shadow: 0 16px 48px rgba(0, 0, 0, .3); }
dialog::backdrop { background: rgba(10, 14, 20, .5); }
dialog h2 { font-size: 18px; }
dialog .actions { justify-content: flex-end; margin-top: 20px; }
#toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 50; }
#toast div { background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 8px; box-shadow: 0 6px 24px rgba(0, 0, 0, .25); }

@media (max-width: 640px) {
  .top { padding: 0 12px; gap: 8px; }
  .page { padding: 20px 12px 48px; }
  .hide-sm { display: none; }
  .top nav a, .linkbtn { padding: 6px 7px; }
}
@media (prefers-reduced-motion: no-preference) {
  .btn, .appcard, .tabs a { transition: filter .12s, box-shadow .12s, color .12s; }
}
@media (max-width: 480px) { .brand .word { display: none; } }
