/* ------------------------------------------------------------------ tokens */
:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --border: #e2e5ea;
  --text: #151922;
  --muted: #667085;
  --accent: #5865f2;
  --accent-soft: color-mix(in srgb, var(--accent) 12%, transparent);
  --accent-contrast: #ffffff;
  --ok: #12a150;
  --warn: #c98200;
  --danger: #d92d3a;
  --ok-soft: color-mix(in srgb, var(--ok) 14%, transparent);
  --warn-soft: color-mix(in srgb, var(--warn) 16%, transparent);
  --danger-soft: color-mix(in srgb, var(--danger) 13%, transparent);
  --sidebar: #12151c;
  --sidebar-text: #aab2c0;
  --sidebar-active: #ffffff;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.05), 0 1px 3px rgba(16, 24, 40, 0.06);
  --shadow-lg: 0 12px 32px rgba(16, 24, 40, 0.18);
  --radius: 12px;
  --mono: ui-monospace, "Cascadia Code", "SF Mono", Consolas, monospace;
  color-scheme: light;
}
:root[data-panel="22"] { --accent: #0d9488; }

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e1015; --surface: #161a21; --surface-2: #1d222b; --border: #272d38;
    --text: #eceff5; --muted: #98a2b3; --accent-contrast: #ffffff;
    --ok: #3ec27a; --warn: #e0a928; --danger: #f0616b;
    --sidebar: #0a0c10; --shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
    color-scheme: dark;
  }
  :root[data-panel="22"]:not([data-theme="light"]) { --accent: #2dd4bf; --accent-contrast: #04211e; }
  :root[data-panel="mf"]:not([data-theme="light"]) { --accent: #7983f5; }
}
:root[data-theme="dark"] {
  --bg: #0e1015; --surface: #161a21; --surface-2: #1d222b; --border: #272d38;
  --text: #eceff5; --muted: #98a2b3; --accent-contrast: #ffffff;
  --ok: #3ec27a; --warn: #e0a928; --danger: #f0616b;
  --sidebar: #0a0c10; --shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
  color-scheme: dark;
}
:root[data-theme="dark"][data-panel="22"] { --accent: #2dd4bf; --accent-contrast: #04211e; }
:root[data-theme="dark"][data-panel="mf"] { --accent: #7983f5; }

/* ------------------------------------------------------------------ base */
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 14px/1.55 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, p { margin: 0; }
h1 { font-size: 22px; font-weight: 650; letter-spacing: -0.01em; }
h2 { font-size: 15px; font-weight: 600; }
h3 { font-size: 13px; font-weight: 600; }
a { color: var(--accent); }
code { font-family: var(--mono); font-size: 12px; background: var(--surface-2); padding: 1px 6px; border-radius: 6px; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.hidden { display: none !important; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
svg.i { width: 18px; height: 18px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ------------------------------------------------------------------ login */
.login {
  min-height: 100vh; display: grid; place-items: center; padding: 20px;
  background:
    radial-gradient(60% 50% at 20% 10%, color-mix(in srgb, var(--accent) 22%, transparent), transparent 70%),
    radial-gradient(50% 40% at 90% 90%, color-mix(in srgb, var(--accent) 14%, transparent), transparent 70%),
    var(--bg);
}
.login-card {
  width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 16px; padding: 32px 28px; text-align: center; box-shadow: var(--shadow-lg); display: grid; gap: 14px;
}
.logo {
  width: 52px; height: 52px; border-radius: 14px; margin: 0 auto; display: grid; place-items: center;
  background: var(--accent); color: var(--accent-contrast);
}
.logo svg.i { width: 26px; height: 26px; }

/* ------------------------------------------------------------------ shell */
.shell { display: grid; grid-template-columns: 248px minmax(0, 1fr); min-height: 100vh; }
.sidebar {
  background: var(--sidebar); color: var(--sidebar-text); display: flex; flex-direction: column;
  padding: 16px 12px; position: sticky; top: 0; height: 100vh; z-index: 20;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 18px; color: #fff; }
.brand .logo { width: 34px; height: 34px; border-radius: 10px; margin: 0; }
.brand .logo svg.i { width: 18px; height: 18px; }
.brand b { display: block; font-size: 14px; line-height: 1.2; }
.brand span { font-size: 12px; color: var(--sidebar-text); }
.nav { display: grid; gap: 2px; }
.nav a {
  display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 8px; color: inherit;
  text-decoration: none; font-weight: 500; transition: background .12s, color .12s;
}
.nav a:hover { background: rgba(255, 255, 255, 0.06); color: #fff; }
.nav a.active { background: color-mix(in srgb, var(--accent) 22%, transparent); color: var(--sidebar-active); }
.nav a.active svg.i { color: var(--accent); }
.nav .count { margin-left: auto; font-size: 11px; background: rgba(255, 255, 255, 0.1); color: #fff; padding: 1px 7px; border-radius: 99px; }
.sidebar-foot { margin-top: auto; display: grid; gap: 10px; padding-top: 14px; border-top: 1px solid rgba(255, 255, 255, 0.08); }
.user { display: flex; align-items: center; gap: 10px; padding: 0 4px; color: #fff; min-width: 0; }
.user b { display: block; font-size: 13px; line-height: 1.2; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user span { font-size: 11.5px; color: var(--sidebar-text); }
.foot-actions { display: flex; gap: 6px; }
.foot-actions .btn { flex: 1; background: rgba(255, 255, 255, 0.06); border-color: transparent; color: #d7dce6; }
.foot-actions .btn:hover { background: rgba(255, 255, 255, 0.12); }
.topbar { display: none; }
.scrim { display: none; }
.content { min-width: 0; padding: 28px 32px 64px; max-width: 1180px; width: 100%; margin: 0 auto; }
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; margin-bottom: 22px; }
.page-head p { color: var(--muted); margin-top: 2px; }
.page-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.stack { display: grid; gap: 16px; align-content: start; }
.grid { display: grid; gap: 16px; }
.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)); }
.split { grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); align-items: start; }

/* ------------------------------------------------------------------ cards */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 14px 18px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.card-head p { color: var(--muted); font-size: 12.5px; }
.card-body { padding: 18px; }
.card-body.flush { padding: 0; }
.tile { padding: 16px 18px; display: grid; gap: 4px; }
.tile .label { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 12.5px; font-weight: 500; }
.tile .value { font-size: 24px; font-weight: 650; letter-spacing: -0.02em; line-height: 1.2; }
.tile .sub { color: var(--muted); font-size: 12px; }
.tile .label svg.i { width: 16px; height: 16px; }

/* ------------------------------------------------------------------ controls */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 8px 14px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text); font: inherit; font-weight: 550;
  cursor: pointer; text-decoration: none; transition: background .12s, border-color .12s, opacity .12s; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-contrast); }
.btn.primary:hover { filter: brightness(1.08); background: var(--accent); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.danger:hover { filter: brightness(1.08); background: var(--danger); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.sm { padding: 5px 10px; font-size: 12.5px; border-radius: 7px; }
.btn.icon { padding: 8px; }
.spin { animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

input, select, textarea {
  width: 100%; padding: 9px 12px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface);
  color: var(--text); font: inherit; transition: border-color .12s, box-shadow .12s;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
textarea { resize: vertical; min-height: 120px; line-height: 1.5; }
.field { display: grid; gap: 6px; font-weight: 550; font-size: 13px; }
.field > .hint { font-weight: 400; color: var(--muted); font-size: 12.5px; }
.form { display: grid; gap: 16px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row > .grow { flex: 1; min-width: 180px; }
.counter { font-size: 12px; color: var(--muted); text-align: right; font-variant-numeric: tabular-nums; }
.counter.over { color: var(--danger); font-weight: 600; }

.switch { position: relative; width: 38px; height: 22px; flex: none; }
.switch input { position: absolute; inset: 0; opacity: 0; cursor: pointer; margin: 0; width: 100%; height: 100%; z-index: 1; }
.switch i { position: absolute; inset: 0; border-radius: 99px; background: var(--border); transition: background .15s; }
.switch i::after { content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3); transition: transform .15s; }
.switch input:checked + i { background: var(--accent); }
.switch input:checked + i::after { transform: translateX(16px); }
.switch input:focus-visible + i { outline: 2px solid var(--accent); outline-offset: 2px; }

.seg { display: inline-flex; background: var(--surface-2); border-radius: 9px; padding: 3px; gap: 2px; flex-wrap: wrap; }
.seg button { border: 0; background: transparent; color: var(--muted); padding: 6px 12px; border-radius: 7px; font: inherit; font-weight: 550; cursor: pointer; }
.seg button.on { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

/* ------------------------------------------------------------------ status */
.pill { display: inline-flex; align-items: center; gap: 7px; padding: 3px 10px 3px 8px; border-radius: 99px; font-size: 12.5px; font-weight: 600; background: var(--surface-2); color: var(--muted); }
.pill .dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.pill.ok { background: var(--ok-soft); color: var(--ok); }
.pill.ok .dot { animation: pulse 2s ease-in-out infinite; }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.bad { background: var(--danger-soft); color: var(--danger); }
@keyframes pulse { 0%, 100% { box-shadow: 0 0 0 0 color-mix(in srgb, currentColor 50%, transparent); } 50% { box-shadow: 0 0 0 5px transparent; } }
.badge { display: inline-block; padding: 1px 8px; border-radius: 99px; font-size: 11.5px; font-weight: 600; background: var(--accent-soft); color: var(--accent); }
.badge.neutral { background: var(--surface-2); color: var(--muted); }

.checks { list-style: none; margin: 0; padding: 0; }
.checks li { display: flex; gap: 12px; padding: 12px 18px; border-bottom: 1px solid var(--border); align-items: flex-start; }
.checks li:last-child { border-bottom: 0; }
.checks .ic { width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; flex: none; margin-top: 1px; }
.checks .ic svg.i { width: 13px; height: 13px; stroke-width: 3; }
.checks .ok .ic { background: var(--ok-soft); color: var(--ok); }
.checks .bad .ic { background: var(--warn-soft); color: var(--warn); }
.checks b { font-weight: 550; display: block; }

/* ------------------------------------------------------------------ lists / table */
.avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; font-weight: 650; font-size: 13px; flex: none; object-fit: cover; overflow: hidden; }
.avatar.lg { width: 40px; height: 40px; }
.avatar.sq { border-radius: 9px; }
.sidebar .avatar { background: rgba(255, 255, 255, 0.1); color: #fff; }
.people { list-style: none; margin: 0; padding: 0; }
.people li { display: flex; align-items: center; gap: 12px; padding: 11px 18px; border-bottom: 1px solid var(--border); }
.people li:last-child { border-bottom: 0; }
.people .who { min-width: 0; flex: 1; }
.people .who b { display: block; font-weight: 550; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.people .who span { font-size: 12px; color: var(--muted); font-family: var(--mono); }
.empty { padding: 36px 18px; text-align: center; color: var(--muted); display: grid; gap: 6px; justify-items: center; }
.empty svg.i { width: 28px; height: 28px; opacity: .6; }
.empty b { color: var(--text); }

.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { display: flex; gap: 12px; padding: 12px 18px; border-bottom: 1px solid var(--border); align-items: flex-start; }
.timeline li:last-child { border-bottom: 0; }
.timeline .body { min-width: 0; flex: 1; }
.timeline .body b { font-weight: 600; }
.timeline .detail { color: var(--muted); font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; word-break: break-word; }
.timeline time { color: var(--muted); font-size: 12px; white-space: nowrap; }

.picker { position: relative; }
.picker-list { position: absolute; z-index: 15; left: 0; right: 0; top: calc(100% + 4px); background: var(--surface); border: 1px solid var(--border); border-radius: 10px; box-shadow: var(--shadow-lg); max-height: 280px; overflow: auto; padding: 4px; }
.picker-list button { display: flex; width: 100%; align-items: center; gap: 10px; padding: 8px 10px; border: 0; background: transparent; border-radius: 7px; cursor: pointer; text-align: left; color: var(--text); font: inherit; }
.picker-list button:hover, .picker-list button:focus-visible { background: var(--surface-2); }
.picker-list small { color: var(--muted); font-family: var(--mono); }
.chosen { display: flex; align-items: center; gap: 10px; padding: 8px 12px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface-2); }
.chosen .grow { flex: 1; min-width: 0; }

/* ------------------------------------------------------------------ logs */
.logs { background: #0b0d12; color: #d6dbe6; font: 12px/1.6 var(--mono); padding: 14px 16px; border-radius: 0 0 var(--radius) var(--radius); height: 460px; overflow: auto; white-space: pre-wrap; word-break: break-word; }
.logs .ln { display: block; }
.logs .ln.warn { color: #f0c05a; }
.logs .ln.err { color: #ff7b86; }
.logs .ln.dim { color: #7c8596; }
.logs mark { background: #5b4b00; color: #fff; border-radius: 3px; }

/* ------------------------------------------------------------------ messages */
.discord-msg { display: flex; gap: 12px; background: #313338; color: #dbdee1; padding: 14px 16px; border-radius: 10px; font-family: "gg sans", "Segoe UI", system-ui, sans-serif; }
.discord-msg .avatar { width: 40px; height: 40px; background: #5865f2; color: #fff; }
.discord-msg .name { font-weight: 600; color: #fff; }
.discord-msg .tag { background: #5865f2; color: #fff; font-size: 10px; padding: 1px 5px; border-radius: 4px; margin-left: 6px; vertical-align: 1px; font-weight: 600; }
.discord-msg .text { white-space: pre-wrap; word-break: break-word; margin-top: 2px; min-height: 22px; }
.discord-msg .text.ph { color: #80848e; font-style: italic; }
progress { width: 100%; height: 10px; appearance: none; border: 0; border-radius: 99px; overflow: hidden; background: var(--surface-2); }
progress::-webkit-progress-bar { background: var(--surface-2); }
progress::-webkit-progress-value { background: var(--accent); border-radius: 99px; }
progress::-moz-progress-bar { background: var(--accent); }

/* ------------------------------------------------------------------ stats config */
.group-title { padding: 12px 18px 4px; font-size: 11.5px; font-weight: 650; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.toggles { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 10px; padding: 8px 18px 18px; }
.toggle { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); cursor: pointer; transition: border-color .12s, background .12s; }
.toggle:hover { border-color: color-mix(in srgb, var(--accent) 50%, var(--border)); }
.toggle.on { border-color: var(--accent); background: var(--accent-soft); }
.counter-list { list-style: none; margin: 0; padding: 8px; display: grid; gap: 4px; }
.counter-list li { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px; background: var(--surface-2); font-weight: 500; }
.counter-list svg.i { width: 16px; height: 16px; color: var(--muted); }
.savebar { position: sticky; bottom: 16px; display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 12px 16px; border-radius: 12px; background: var(--text); color: var(--bg); box-shadow: var(--shadow-lg); margin-top: 16px; flex-wrap: wrap; }
.savebar .btn.ghost { color: inherit; }

/* ------------------------------------------------------------------ overlay */
.modal-back { position: fixed; inset: 0; background: rgba(8, 10, 14, 0.55); display: grid; place-items: center; padding: 16px; z-index: 50; animation: fade .12s; }
.modal { width: 100%; max-width: 440px; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 22px; box-shadow: var(--shadow-lg); display: grid; gap: 12px; }
.modal .actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 6px; }
.modal pre { margin: 0; background: var(--surface-2); padding: 10px 12px; border-radius: 8px; white-space: pre-wrap; word-break: break-word; font: inherit; max-height: 160px; overflow: auto; }
.toasts { position: fixed; bottom: 18px; right: 18px; display: grid; gap: 8px; z-index: 60; max-width: calc(100vw - 36px); }
.toast { display: flex; gap: 10px; align-items: flex-start; padding: 11px 14px; border-radius: 10px; background: var(--text); color: var(--bg); box-shadow: var(--shadow-lg); animation: rise .18s; max-width: 380px; }
.toast.err { background: var(--danger); color: #fff; }
.toast.ok svg.i { color: var(--ok); }
@keyframes rise { from { transform: translateY(8px); opacity: 0; } }
@keyframes fade { from { opacity: 0; } }
.skeleton { background: linear-gradient(90deg, var(--surface-2), color-mix(in srgb, var(--surface-2) 55%, var(--surface)), var(--surface-2)); background-size: 200% 100%; animation: shimmer 1.2s infinite; border-radius: 8px; min-height: 18px; }
@keyframes shimmer { to { background-position: -200% 0; } }
.sk-tile { height: 92px; border-radius: var(--radius); }

/* ------------------------------------------------------------------ responsive */
@media (max-width: 1000px) {
  .cols-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .split, .cols-3 { grid-template-columns: 1fr; }
}
@media (max-width: 820px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .sidebar { position: fixed; inset: 0 auto 0 0; width: 272px; transform: translateX(-100%); transition: transform .2s; }
  .shell.menu-open .sidebar { transform: none; }
  .shell.menu-open .scrim { display: block; position: fixed; inset: 0; background: rgba(0, 0, 0, 0.5); z-index: 15; }
  .topbar { display: flex; align-items: center; gap: 12px; padding: 10px 16px; background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 10; }
  .topbar b { font-size: 15px; }
  .content { padding: 20px 16px 56px; }
  .cols-2 { grid-template-columns: 1fr; }
}
@media (max-width: 520px) {
  .cols-4 { grid-template-columns: 1fr 1fr; }
  .tile .value { font-size: 20px; }
  .toasts { left: 16px; right: 16px; }
}
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
.callout { display: flex; gap: 12px; padding: 14px 16px; border-radius: 10px; border: 1px solid; font-size: 13.5px; }
.callout > svg.i { margin-top: 2px; }
.callout p { margin-top: 6px; }
.callout.warn { background: var(--warn-soft); border-color: color-mix(in srgb, var(--warn) 45%, transparent); }
.callout.warn > svg.i, .callout.warn b:first-child { color: var(--warn); }
.discord-msg .sig { font-size: 12px; color: #949ba4; margin-top: 4px; }
