:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --surface-2: #f0f3f7;
  --ink: #1b1f27;
  --muted: #667085;
  --faint: #c2c8d2;
  --line: #e3e7ee;
  --accent: #06a94d;
  --accent-ink: #ffffff;
  --accent-soft: #e5f7ec;
  --warn: #b45309;
  --warn-soft: #fff4e5;
  --danger: #c0352b;
  --danger-soft: #fdeceb;
  --radius: 12px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1218;
    --surface: #171b23;
    --surface-2: #1f2430;
    --ink: #e8ebf1;
    --muted: #98a2b3;
    --faint: #3a4252;
    --line: #272d3a;
    --accent: #2fd07a;
    --accent-ink: #06210f;
    --accent-soft: #12301f;
    --warn: #f5a524;
    --warn-soft: #33260c;
    --danger: #ff6b60;
    --danger-soft: #3a1a18;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", "Noto Sans Thai", "Thonburi", "Leelawadee UI", sans-serif;
}
h1, h2, h3 { margin: 0; line-height: 1.25; }
h2 { font-size: 17px; }
h3 { font-size: 15px; }
a { color: var(--accent); }
small, .muted { color: var(--muted); }
.mono { font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 12.5px; }
.hidden { display: none !important; }

/* layout */
.wrap { max-width: 980px; margin: 0 auto; padding: 0 16px 48px; }
.topbar { background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.topbar .wrap { display: flex; align-items: center; gap: 12px; padding-top: 12px; padding-bottom: 12px; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 17px; margin-right: auto; }
.brand img { width: 28px; height: 28px; border-radius: 7px; }
.tabs { display: flex; gap: 2px; overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab { border: 0; background: none; color: var(--muted); font: inherit; padding: 8px 14px; border-radius: 8px; cursor: pointer; white-space: nowrap; }
.tab:hover { background: var(--surface-2); }
.tab[aria-selected="true"] { color: var(--ink); background: var(--surface-2); font-weight: 600; }
main.wrap { padding-top: 20px; display: grid; gap: 16px; align-content: start; }

/* surfaces */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.card > header { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.card > header h2, .card > header h3 { margin-right: auto; }
.grid { display: grid; gap: 12px; }
.stats { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.stat .v { font-size: 24px; font-weight: 700; line-height: 1.2; }
.stat .l { color: var(--muted); font-size: 13px; }
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.row.spread { justify-content: space-between; }
.stack { display: grid; gap: 10px; }

/* banner */
.banner { border-radius: var(--radius); padding: 12px 16px; border: 1px solid var(--line); display: grid; gap: 2px; }
.banner.ok { background: var(--accent-soft); border-color: transparent; }
.banner.warn { background: var(--warn-soft); border-color: transparent; }
.banner.bad { background: var(--danger-soft); border-color: transparent; }
.banner b { font-weight: 600; }

/* controls */
button, .btn {
  font: inherit; cursor: pointer; border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  padding: 7px 14px; border-radius: 9px; min-height: 36px; white-space: nowrap;
}
button:hover { background: var(--surface-2); }
button.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; font-weight: 600; }
button.primary:hover { filter: brightness(1.06); }
button.danger { color: var(--danger); }
button.small { padding: 4px 10px; min-height: 30px; font-size: 13px; }
button:disabled { opacity: .55; cursor: default; }
button:focus-visible, input:focus-visible, .tab:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
input[type="text"], input[type="password"], input[type="number"], input[type="url"] {
  font: inherit; width: 100%; padding: 8px 12px; border-radius: 9px; border: 1px solid var(--line);
  background: var(--surface); color: var(--ink); min-height: 38px;
}
label.field { display: grid; gap: 4px; font-size: 13px; color: var(--muted); }
.switch { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; user-select: none; }
.switch input { appearance: none; width: 38px; height: 22px; border-radius: 11px; background: var(--faint); position: relative; cursor: pointer; transition: background .15s; margin: 0; flex: none; }
.switch input::after { content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: transform .15s; }
.switch input:checked { background: var(--accent); }
.switch input:checked::after { transform: translateX(16px); }
.switch input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* chips */
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 2px 10px; border-radius: 999px; font-size: 12.5px; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.chip.ok { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.chip.warn { background: var(--warn-soft); color: var(--warn); font-weight: 600; }
.chip.bad { background: var(--danger-soft); color: var(--danger); font-weight: 600; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; }

/* stock matrix */
.matrix-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { color: var(--muted); font-weight: 500; font-size: 13px; }
tr:last-child td { border-bottom: 0; }
table.matrix th, table.matrix td { text-align: center; }
table.matrix th:first-child, table.matrix td:first-child { text-align: left; }
.cell { display: inline-block; min-width: 44px; padding: 2px 10px; border-radius: 8px; font-size: 13px; }
.cell.yes { background: var(--accent-soft); color: var(--accent); font-weight: 700; }
.cell.no { color: var(--faint); }
.cell.unk { color: var(--muted); }
.store-title { font-weight: 600; margin: 14px 0 4px; }
.store-title:first-child { margin-top: 0; }

/* bits */
.avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--surface-2); object-fit: cover; flex: none; }
.empty { color: var(--muted); padding: 24px 0; text-align: center; }
.list > * + * { border-top: 1px solid var(--line); }
.list > * { padding: 10px 0; }
.bar { height: 8px; border-radius: 4px; background: var(--surface-2); overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--accent); }
.bar.hot > i { background: var(--warn); }
.copy { display: flex; gap: 8px; }
.copy input { font-family: ui-monospace, Menlo, monospace; font-size: 13px; }
details > summary { cursor: pointer; color: var(--muted); padding: 6px 0; }
.tight td, .tight th { padding: 6px 8px; }

/* login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login .card { width: 100%; max-width: 360px; display: grid; gap: 14px; }
.login img { width: 44px; height: 44px; border-radius: 11px; }

/* toasts */
#toasts { position: fixed; left: 0; right: 0; bottom: 16px; display: grid; gap: 8px; justify-items: center; pointer-events: none; padding: 0 16px; z-index: 20; }
.toast { background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 10px; box-shadow: 0 6px 24px rgba(0,0,0,.25); max-width: 480px; }
.toast.bad { background: var(--danger); color: #fff; }

@media (max-width: 700px) {
  .topbar .wrap { gap: 8px; }
  .tabs { order: 3; flex-basis: 100%; }
  .stat .v { font-size: 20px; }
  th, td { padding: 8px 6px; }
  .hide-sm { display: none; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
