:root {
  --accent: #5865f2; --accent-hover: #4752c4; --accent-soft: rgba(88, 101, 242, .12); --on-accent: #fff;
  --ok: #1a8d4b; --ok-soft: rgba(35, 165, 90, .13);
  --warn: #9a6400; --warn-soft: rgba(240, 178, 50, .18);
  --danger: #d22d31; --danger-soft: rgba(242, 63, 67, .11);
  --bg: #f2f3f5; --surface: #fff; --surface-2: #f6f7f9; --surface-3: #eceef1;
  --text: #1e1f22; --muted: #5c5e66; --faint: #8b8e96;
  --border: rgba(16, 18, 24, .08); --border-strong: rgba(16, 18, 24, .16);
  --shadow: 0 1px 2px rgba(16, 18, 24, .04), 0 6px 20px rgba(16, 18, 24, .05);
  --radius: 16px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --accent: #6b77f5; --accent-hover: #5865f2; --accent-soft: rgba(107, 119, 245, .18);
    --ok: #4cc77d; --ok-soft: rgba(59, 165, 92, .18);
    --warn: #f3c04f; --warn-soft: rgba(240, 178, 50, .16);
    --danger: #ff6b6e; --danger-soft: rgba(242, 63, 67, .16);
    --bg: #1b1c20; --surface: #26282d; --surface-2: #2e3036; --surface-3: #363840;
    --text: #f2f3f5; --muted: #b5bac1; --faint: #80848e;
    --border: rgba(255, 255, 255, .07); --border-strong: rgba(255, 255, 255, .14);
    --shadow: 0 1px 2px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --accent: #6b77f5; --accent-hover: #5865f2; --accent-soft: rgba(107, 119, 245, .18);
  --ok: #4cc77d; --ok-soft: rgba(59, 165, 92, .18);
  --warn: #f3c04f; --warn-soft: rgba(240, 178, 50, .16);
  --danger: #ff6b6e; --danger-soft: rgba(242, 63, 67, .16);
  --bg: #1b1c20; --surface: #26282d; --surface-2: #2e3036; --surface-3: #363840;
  --text: #f2f3f5; --muted: #b5bac1; --faint: #80848e;
  --border: rgba(255, 255, 255, .07); --border-strong: rgba(255, 255, 255, .14);
  --shadow: 0 1px 2px rgba(0, 0, 0, .25);
  color-scheme: dark;
}

* { box-sizing: border-box }
html, body { margin: 0; min-height: 100% }
body {
  background: var(--bg); color: var(--text);
  font: 15px/1.55 "Segoe UI", "Leelawadee UI", "Noto Sans Thai", system-ui, -apple-system, sans-serif;
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important }
a { color: inherit }
b { font-weight: 650 }
.grow { flex: 1; min-width: 0 }
.muted { color: var(--muted) }
.small { font-size: 13px }
.hint { color: var(--muted); font-size: 13px; line-height: 1.5 }
.mono { font-family: ui-monospace, "Cascadia Code", Consolas, monospace; font-size: 12.5px; overflow-wrap: anywhere }
.ic { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none }
.ic.ok { color: var(--ok) } .ic.danger { color: var(--danger) }

/* ---------- shell ---------- */
.app { display: grid; grid-template-columns: 252px minmax(0, 1fr); min-height: 100vh }
.sidebar {
  position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 4px;
  padding: 18px 12px 14px; background: var(--surface); border-right: 1px solid var(--border); overflow-y: auto;
}
.brand { display: flex; gap: 11px; align-items: center; padding: 2px 8px 18px }
.brand b { display: block; font-size: 15px; line-height: 1.3 }
nav { display: flex; flex-direction: column; gap: 2px; flex: 1 }
.nav-item {
  display: flex; align-items: center; gap: 12px; padding: 9px 12px; border-radius: 10px;
  color: var(--muted); text-decoration: none; font-weight: 600; font-size: 14.5px;
}
.nav-item:hover { background: var(--surface-2); color: var(--text) }
.nav-item.active { background: var(--accent-soft); color: var(--accent) }
.nav-item .count { margin-left: auto; background: var(--danger); color: #fff; font-size: 12px; border-radius: 999px; padding: 0 7px; min-width: 20px; text-align: center; line-height: 20px }
.me { display: flex; align-items: center; gap: 10px; padding: 12px 6px 0; border-top: 1px solid var(--border); margin-top: 8px }
.me b { display: block; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis }
.main { min-width: 0; display: flex; flex-direction: column }
.topbar {
  position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 12px; padding: 13px 28px;
  background: color-mix(in srgb, var(--bg) 82%, transparent); backdrop-filter: blur(12px); border-bottom: 1px solid var(--border);
}
.topbar h1 { font-size: 19px; margin: 0; font-weight: 700; white-space: nowrap }
.topbar .menu { display: none }
.top-actions { display: flex; gap: 6px }
.content { padding: 24px 28px 72px; max-width: 1180px; width: 100%; margin: 0 auto; display: flex; flex-direction: column; gap: 18px }
.scrim { display: none }

/* ---------- building blocks ---------- */
.grid { display: grid; gap: 18px }
.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)) }
.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)) }
.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)) }
.grid.tight { gap: 14px }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); min-width: 0 }
.card.attention { border-color: color-mix(in srgb, var(--warn) 45%, transparent) }
.card-head { display: flex; align-items: center; gap: 10px; padding: 16px 20px 2px; flex-wrap: wrap }
.card-head h2 { font-size: 16px; margin: 0; font-weight: 700 }
.card-body { padding: 12px 20px 18px }
.card-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 0 20px 18px }
.stack { display: flex; flex-direction: column; gap: 10px }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 14px }

.stat { display: flex; align-items: center; gap: 14px; padding: 16px 18px; text-decoration: none }
.stat:hover { border-color: var(--border-strong) }
.stat-icon { width: 42px; height: 42px; border-radius: 12px; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent) }
.stat-icon .ic { width: 21px; height: 21px }
.stat .label { color: var(--muted); font-size: 13px }
.stat .value { font-size: 26px; font-weight: 750; line-height: 1.15 }

.hero { display: flex; align-items: center; gap: 14px; margin-bottom: 14px }
.title-lg { font-size: 18px; font-weight: 700 }
.chips { display: flex; gap: 6px; flex-wrap: wrap }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 8px; background: var(--surface-2); border: 1px solid var(--border); font-size: 13px; font-weight: 600; color: var(--muted) }
.chip .ic { width: 15px; height: 15px }

.avatar { width: 38px; height: 38px; border-radius: 50%; object-fit: cover; flex: none; background: var(--surface-3); display: inline-grid; place-items: center; font-weight: 700; color: var(--muted); font-size: 15px }
.avatar.lg { width: 54px; height: 54px; font-size: 20px }
.avatar.sm { width: 24px; height: 24px; font-size: 11px }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px; height: 36px; padding: 0 14px;
  border-radius: 10px; border: 1px solid var(--border-strong); background: var(--surface); color: var(--text);
  font: inherit; font-size: 14px; font-weight: 650; cursor: pointer; white-space: nowrap; text-decoration: none;
  transition: background .12s, border-color .12s;
}
.btn:hover { background: var(--surface-2) }
.btn:active { transform: translateY(1px) }
.btn.primary { background: var(--accent); border-color: transparent; color: var(--on-accent) }
.btn.primary:hover { background: var(--accent-hover) }
.btn.danger { color: var(--danger) }
.btn.danger.solid { background: var(--danger); border-color: transparent; color: #fff }
.btn.sm { height: 30px; padding: 0 11px; font-size: 13px; border-radius: 9px }
.btn.sm .ic { width: 15px; height: 15px }
.btn:disabled, .btn[data-busy] { opacity: .55; pointer-events: none }
.btn.discord { background: #5865f2; border-color: transparent; color: #fff; width: 100%; height: 46px; font-size: 15px }
.btn.discord:hover { background: #4752c4 }
.icon-btn { width: 34px; height: 34px; display: inline-grid; place-items: center; border-radius: 9px; border: none; background: transparent; color: var(--muted); cursor: pointer; flex: none }
.icon-btn:hover { background: var(--surface-2); color: var(--text) }
.icon-btn.danger:hover { color: var(--danger); background: var(--danger-soft) }

.pill { display: inline-flex; align-items: center; gap: 7px; padding: 4px 12px; border-radius: 999px; font-size: 13px; font-weight: 650; white-space: nowrap }
.pill::before { content: ''; width: 8px; height: 8px; border-radius: 50%; background: currentColor }
.pill.on { background: var(--ok-soft); color: var(--ok) }
.pill.mid { background: var(--warn-soft); color: var(--warn) }
.pill.off { background: var(--danger-soft); color: var(--danger) }
.badge { display: inline-flex; align-items: center; font-size: 12px; padding: 2px 8px; border-radius: 7px; font-weight: 650; background: var(--surface-3); color: var(--muted); white-space: nowrap }
.badge .ic { width: 13px; height: 13px; margin-right: 4px }
.card-head h2 .ic { width: 17px; height: 17px; vertical-align: -3px; color: var(--accent) }
.choice b .ic { width: 16px; height: 16px; color: var(--accent) }
details.advanced { margin-top: 10px }
details.advanced > summary { cursor: pointer; color: var(--muted); font-size: 14px; font-weight: 650; list-style: none; display: flex; align-items: center; gap: 8px; padding: 6px 0 }
details.advanced > summary::-webkit-details-marker { display: none }
details.advanced > summary::before { content: '›'; display: inline-block; width: 14px; font-size: 18px; line-height: 1; transition: transform .15s }
details.advanced[open] > summary::before { transform: rotate(90deg) }
details.card-details { margin: 0; padding: 12px 20px }
details.card-details > summary { color: var(--text) }
.usecases { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 10px; padding: 8px 0 6px }
.usecase { display: flex; flex-direction: column; gap: 4px; padding: 12px 14px; border-radius: 12px; background: var(--surface-2); border: 1px solid var(--border) }
.usecase span { color: var(--muted); font-size: 13px; line-height: 1.5 }
.badge.owner { background: var(--accent-soft); color: var(--accent) }
.badge.dev { background: var(--ok-soft); color: var(--ok) }
.badge.warn { background: var(--warn-soft); color: var(--warn) }
.badge.danger { background: var(--danger-soft); color: var(--danger) }

.row { display: flex; align-items: center; gap: 14px; padding: 12px 0; border-top: 1px solid var(--border) }
.card-body > .row:first-child, .group-label + .row { border-top: 0 }
.row.wrap { flex-wrap: wrap }
.main-text { flex: 1; min-width: 0 }
.main-text .title { font-weight: 650; display: flex; align-items: center; gap: 8px; flex-wrap: wrap }
.main-text .sub { color: var(--muted); font-size: 13px; overflow-wrap: anywhere }
.tags { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end }
.actions { display: flex; gap: 6px; align-items: center }
.group-label { margin: 14px 0 2px; font-size: 12px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; color: var(--faint) }
.group-label:first-child { margin-top: 0 }
.ch-icon, .dev-icon { width: 38px; height: 38px; border-radius: 10px; display: grid; place-items: center; background: var(--surface-2); color: var(--faint); flex: none }
.ch-icon.on { background: var(--ok-soft); color: var(--ok) }

.notice { display: flex; gap: 12px; align-items: center; padding: 12px 14px; border-radius: 12px; font-size: 14px }
.notice > .ic { align-self: flex-start; margin-top: 2px }
.notice.warn { background: var(--warn-soft) } .notice.warn > .ic { color: var(--warn) }
.notice.danger { background: var(--danger-soft) } .notice.danger > .ic { color: var(--danger) }
.notice.ok { background: var(--ok-soft) } .notice.ok > .ic { color: var(--ok) }
.notice.info { background: var(--accent-soft) } .notice.info > .ic { color: var(--accent) }
.banner { display: flex; align-items: center; gap: 12px; padding: 12px 16px; border-radius: 12px; background: var(--accent-soft); color: var(--text); font-weight: 600 }
.banner > .ic { color: var(--accent) }
.empty { color: var(--muted); font-size: 14px; padding: 14px 0; text-align: center }
.loading-row { display: flex; align-items: center; gap: 10px; color: var(--muted); padding: 14px 0; justify-content: center }
.spinner { width: 18px; height: 18px; border-radius: 50%; border: 2.5px solid var(--border-strong); border-top-color: var(--accent); animation: spin .8s linear infinite; display: inline-block }
.boot { min-height: 100vh; display: grid; place-items: center }
.boot .spinner { width: 28px; height: 28px }
@keyframes spin { to { transform: rotate(360deg) } }

/* ---------- forms ---------- */
.field { display: flex; flex-direction: column; gap: 7px; margin-bottom: 16px }
.field > label, .field-label { font-weight: 650; font-size: 14px }
input[type=text], input[type=number], select, textarea {
  height: 40px; padding: 0 12px; border-radius: 10px; border: 1px solid var(--border-strong);
  background: var(--surface-2); color: var(--text); font: inherit; font-size: 14px; outline: none; width: 100%; min-width: 0;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft) }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px }
input:focus-visible { outline: none }
.input-row { display: flex; gap: 8px }
.filter { max-width: 240px; height: 32px !important }

.switch { position: relative; display: inline-flex; flex: none }
.switch input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer }
.switch .track { width: 44px; height: 26px; border-radius: 999px; background: var(--border-strong); transition: background .15s; position: relative }
.switch .track::after { content: ''; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; transition: transform .15s; box-shadow: 0 1px 3px rgba(0, 0, 0, .25) }
.switch input:checked + .track { background: var(--ok) }
.switch input:checked + .track::after { transform: translateX(18px) }
.switch input:disabled { cursor: not-allowed }
.switch input:disabled + .track { opacity: .5 }
.switch input:focus-visible + .track { outline: 2px solid var(--accent); outline-offset: 2px }
.switch-row { display: flex; align-items: center; gap: 16px; padding: 12px 0; border-top: 1px solid var(--border); cursor: pointer }
.switch-row:first-child { border-top: 0 }
.switch-row > span:first-child { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px }

.seg { display: inline-flex; flex-wrap: wrap; background: var(--surface-2); border: 1px solid var(--border); border-radius: 12px; padding: 3px; gap: 2px }
.seg label { position: relative }
.seg input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer }
.seg span { display: block; padding: 6px 13px; border-radius: 9px; font-size: 13px; font-weight: 650; color: var(--muted); cursor: pointer; white-space: nowrap }
.seg input:checked + span { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0, 0, 0, .14) }
.seg input:focus-visible + span { outline: 2px solid var(--accent) }

.choices { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 10px }
.choices.two { grid-template-columns: 1fr 1fr }
.choice { position: relative; display: flex; flex-direction: column; gap: 3px; border: 1.5px solid var(--border-strong); border-radius: 13px; padding: 12px 14px; cursor: pointer; transition: border-color .12s, background .12s }
.choice input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer }
.choice b { display: flex; align-items: center; gap: 8px }
.choice span { color: var(--muted); font-size: 13px; line-height: 1.45 }
.choice:hover { border-color: var(--faint) }
.choice:has(input:checked) { border-color: var(--accent); background: var(--accent-soft) }
.choice.danger:has(input:checked) { border-color: var(--danger); background: var(--danger-soft) }
.choice:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 2px }

.cmd-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 6px 14px; padding: 6px 0 2px }
.check { display: flex; align-items: center; gap: 8px; cursor: pointer; font-size: 14px; padding: 4px 0 }
.check input { width: 17px; height: 17px; accent-color: var(--accent); margin: 0; flex: none }
.user-picks { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 6px 14px; padding: 10px 2px 0 }

.list-edit { display: flex; flex-direction: column; gap: 6px; margin: 4px 0 8px }
.list-item { display: flex; align-items: center; gap: 8px; padding: 5px 6px 5px 12px; border-radius: 10px; background: var(--surface-2); border: 1px solid var(--border) }
.list-item .icon-btn { width: 28px; height: 28px }
.rule-col { display: flex; flex-direction: column; min-width: 0 }
.rule-head { display: flex; flex-direction: column; padding: 10px 12px; border-radius: 11px; margin-bottom: 6px }
.rule-head.allow { background: var(--ok-soft) } .rule-head.ask { background: var(--warn-soft) } .rule-head.deny { background: var(--danger-soft) }

.url-box { display: flex; align-items: center; gap: 6px; margin-top: 12px; padding: 6px 6px 6px 14px; border-radius: 11px; background: var(--surface-2); border: 1px solid var(--border) }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; margin: 0 -4px }
.table { width: 100%; border-collapse: collapse; font-size: 14px }
.table th { text-align: left; color: var(--muted); font-weight: 650; font-size: 12.5px; padding: 8px 10px; border-bottom: 1px solid var(--border); white-space: nowrap }
.table td { padding: 9px 10px; border-bottom: 1px solid var(--border); vertical-align: top }
.table tr:last-child td { border-bottom: 0 }
.table .when { white-space: nowrap; color: var(--muted) }

/* ---------- dialog & toasts ---------- */
dialog { border: none; border-radius: 18px; padding: 0; width: min(580px, calc(100vw - 24px)); max-height: calc(100vh - 32px); background: var(--surface); color: var(--text); box-shadow: 0 24px 70px rgba(0, 0, 0, .35) }
dialog::backdrop { background: rgba(10, 11, 14, .5); backdrop-filter: blur(2px) }
.modal-head { display: flex; align-items: center; gap: 10px; padding: 18px 20px 6px; font-size: 17px; font-weight: 750 }
.modal-body { padding: 10px 20px 4px; max-height: calc(100vh - 190px); overflow-y: auto }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 20px 18px; flex-wrap: wrap }
.modal-foot .left { margin-right: auto }
.confirm-text { margin: 4px 0 10px; color: var(--muted); line-height: 1.6 }
.toasts { position: fixed; bottom: 20px; right: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 100; pointer-events: none }
.toast { background: var(--text); color: var(--bg); padding: 11px 16px; border-radius: 12px; font-size: 14px; font-weight: 600; box-shadow: 0 8px 28px rgba(0, 0, 0, .22); max-width: 380px; animation: toast-in .18s ease-out }
.toast.ok { background: var(--ok); color: #fff }
.toast.danger { background: var(--danger); color: #fff }
@keyframes toast-in { from { opacity: 0; transform: translateY(6px) } }

/* ---------- login ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px }
.login-card { width: min(420px, 100%); padding: 34px 28px 26px; text-align: center }
.login-card h1 { margin: 14px 0 4px; font-size: 22px }
.login-logo { width: 64px; height: 64px; margin: 0 auto; border-radius: 18px; background: #5865f2; color: #fff; display: grid; place-items: center }
.login-logo .ic { width: 34px; height: 34px }
.login-form { display: flex; flex-direction: column; gap: 10px; margin: 22px 0 12px }
.login-form input { height: 46px; text-align: center; font-size: 15px }
.login-card .notice { text-align: left; margin-top: 12px }

/* ---------- small screens ---------- */
@media (max-width: 900px) {
  .app { grid-template-columns: minmax(0, 1fr) }
  .sidebar { position: fixed; inset: 0 auto 0 0; width: 280px; z-index: 50; transform: translateX(-100%); transition: transform .2s ease; box-shadow: 0 0 50px rgba(0, 0, 0, .3) }
  .app.nav-open .sidebar { transform: none }
  .app.nav-open .scrim { display: block; position: fixed; inset: 0; z-index: 40; background: rgba(0, 0, 0, .45) }
  .topbar { padding: 10px 14px; gap: 8px }
  .topbar .menu { display: inline-grid }
  .topbar h1 { font-size: 17px }
  .top-actions .label { display: none }
  .content { padding: 16px 12px 56px; gap: 14px }
  .cols-2, .cols-3 { grid-template-columns: minmax(0, 1fr) }
  .cols-4 { grid-template-columns: repeat(2, minmax(0, 1fr)) }
  .card-head { padding: 14px 16px 2px }
  .card-body { padding: 10px 16px 16px }
  .card-foot { padding: 0 16px 16px }
  .row { flex-wrap: wrap }
  .row .tags { justify-content: flex-start }
  .choices.two { grid-template-columns: 1fr }
  .toasts { left: 12px; right: 12px; bottom: 12px }
  .toast { max-width: none }
}
@media (max-width: 420px) {
  .stat { padding: 12px }
  .stat-icon { display: none }
  .topbar .pill { padding: 3px 9px; font-size: 12px }
}
