/* Dashboard design system.
   Palette, radii and fonts come from /theme.css (shared with the public pages);
   everything here builds on those tokens. One token layer, one button system,
   one chip style - no per-page overrides of base components. */

/* ── Tokens ─────────────────────────────────────────────────────────────── */
:root {
  color-scheme: dark;
  --nav-w: 248px;

  /* 4px spacing scale */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-8: 32px;
  --space-10: 40px;

  /* type scale (px-based for predictable density) */
  --fs-xs: 0.75rem;    /* 12 */
  --fs-sm: 0.8125rem;  /* 13 */
  --fs-md: 0.875rem;   /* 14 - body */
  --fs-lg: 1rem;       /* 16 - card titles */
  --fs-xl: 1.25rem;    /* 20 */
  --fs-2xl: 1.75rem;   /* 28 - page titles */
  --lh-tight: 1.25;
  --lh-body: 1.5;

  --radius-sm: 8px;
  --radius-ctl: 10px;
  --radius-pill: 999px;

  /* controls */
  --ctl-h: 40px;
  --ctl-h-sm: 32px;

  /* surfaces */
  --surface: var(--card-bg);
  --surface-2: rgba(255, 255, 255, 0.03);
  --sunken: rgba(4, 10, 20, 0.5);
  --hover: rgba(255, 255, 255, 0.05);
  --border-strong: rgba(147, 168, 198, 0.3);
  --overlay: rgba(3, 8, 16, 0.72);
  --nav-bg: linear-gradient(180deg, rgba(14, 27, 49, 0.98), rgba(10, 18, 34, 0.96));

  /* accent */
  --accent: var(--blue);
  --accent-fill: var(--accent-gradient);
  --accent-fill-hover: linear-gradient(135deg, #5cb2ff, #79e9c6);
  --on-accent: #06101e;
  --on-danger: #1b0707;
  --focus: #8ccaff;
  --focus-ring: 0 0 0 3px color-mix(in srgb, var(--blue) 45%, transparent);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.24), 0 6px 16px rgba(0, 0, 0, 0.16);

  /* layout (compact mode shrinks these) */
  --page-pad: var(--space-8);
  --page-gap: var(--space-6);
  --card-pad: var(--space-5);
  --head-pad: var(--space-6);
}

body.theme-light {
  color-scheme: light;
  --surface-2: var(--bg3);
  --sunken: #f7f9fd;
  --hover: rgba(19, 34, 56, 0.05);
  --border-strong: #b9c9e2;
  --overlay: rgba(19, 34, 56, 0.45);
  --nav-bg: linear-gradient(180deg, #ffffff, #f4f8fd);
  --accent-fill: linear-gradient(135deg, #1268cc, #0d7a6e);
  --accent-fill-hover: linear-gradient(135deg, #0f5cb5, #0b6b60);
  --on-accent: #ffffff;
  --on-danger: #ffffff;
  --focus: #1270d8;
  --shadow-sm: 0 1px 2px rgba(25, 39, 64, 0.08), 0 6px 16px rgba(25, 39, 64, 0.06);
}

body.mobile-compact {
  --page-pad: var(--space-4);
  --page-gap: var(--space-4);
  --card-pad: var(--space-4);
  --head-pad: var(--space-4);
}

/* ── Base ───────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { -webkit-text-size-adjust: 100%; }

body {
  font-family: var(--font);
  font-size: var(--fs-md);
  line-height: var(--lh-body);
  color: var(--text);
  background: var(--page-bg);
  background-color: var(--bg);
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

h1, h2, h3 { line-height: var(--lh-tight); font-weight: 700; }
a { color: var(--blue); }
code { font-family: var(--mono); font-size: 0.92em; padding: 1px 5px; border-radius: 6px; background: var(--surface-2); border: 1px solid var(--border); }
button, input, select, textarea { font: inherit; color: inherit; }
img { max-width: 100%; }

:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

.hidden { display: none !important; }
.sr-only {
  position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

* { scrollbar-width: thin; scrollbar-color: var(--bg4) transparent; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--bg4); border-radius: var(--radius-pill); border: 2px solid transparent; background-clip: padding-box; }
::-webkit-scrollbar-thumb:hover { background: var(--blue); border: 2px solid transparent; background-clip: padding-box; }

/* ── Utilities (replace former inline styles) ──────────────────────────── */
.hint { font-size: var(--fs-sm); color: var(--text2); line-height: var(--lh-body); }
.hint-xs { font-size: var(--fs-xs); color: var(--text2); line-height: var(--lh-body); }
.text-warn { color: var(--yellow); }
.text-danger { color: var(--red); }
.text-muted { color: var(--text2); }
.text-sm { font-size: var(--fs-sm); }
.strong { font-weight: 600; }
.justify-center { justify-content: center; }
.section-label { margin-bottom: var(--space-2); font-size: var(--fs-xs); font-weight: 600; color: var(--text2); text-transform: uppercase; letter-spacing: 0.08em; }
.list-item {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-ctl);
  background: var(--sunken);
}
.list-item + .list-item { margin-top: var(--space-2); }
.list-row { padding: var(--space-2) 0; border-bottom: 1px solid var(--border); font-size: var(--fs-sm); }
.list-row:last-child { border-bottom: none; }
.code-block { display: block; margin: var(--space-2) 0; padding: var(--space-2) var(--space-3); word-break: break-all; }
.chat-src { margin-right: var(--space-1); color: var(--blue); }
.sca-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: var(--space-2); font-size: var(--fs-sm); color: var(--text2); }
.admin-table tr.is-selected td { background: color-mix(in srgb, var(--blue) 8%, transparent); }
.text-mono { font-family: var(--mono); }
.break-all { word-break: break-all; }
.cluster { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); }
.cluster-end { align-items: flex-end; }
.input-row { display: flex; align-items: center; gap: var(--space-2); }
.input-row > .input, .input-row > .ui-select { flex: 1 1 auto; min-width: 0; }
.stack { display: flex; flex-direction: column; gap: var(--space-3); }
.grid-auto { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: var(--space-2); }
.flex-1 { flex: 1 1 auto; min-width: 0; }
.mt-1 { margin-top: var(--space-1); }
.mt-2 { margin-top: var(--space-2); }
.mt-3 { margin-top: var(--space-3); }
.mt-4 { margin-top: var(--space-4); }
.mb-0 { margin-bottom: 0 !important; }
.mb-2 { margin-bottom: var(--space-2); }
.mb-3 { margin-bottom: var(--space-3); }
.mb-4 { margin-bottom: var(--space-4); }
.w-auto { width: auto; }
.max-w-xs { max-width: 220px; }
.max-w-sm { max-width: 280px; }
.max-w-md { max-width: 340px; }
.subpanel {
  border: 1px solid var(--border);
  border-radius: var(--radius-ctl);
  background: var(--sunken);
  padding: var(--space-3);
}
.divider { border: none; border-top: 1px solid var(--border); margin: var(--space-4) 0; }

/* ── Buttons: one system ───────────────────────────────────────────────── */
.btn {
  --btn-h: var(--ctl-h);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: var(--btn-h);
  padding: 0 var(--space-4);
  border: 1px solid transparent;
  border-radius: var(--radius-ctl);
  font-size: var(--fs-md);
  font-weight: 600;
  line-height: 1.2;
  white-space: nowrap;
  text-decoration: none;
  cursor: pointer;
  user-select: none;
  transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease, box-shadow 0.15s ease, transform 0.1s ease;
}
.btn-sm { --btn-h: var(--ctl-h-sm); padding: 0 var(--space-3); font-size: var(--fs-sm); }
.btn-block { width: 100%; }
.btn-icon { width: var(--btn-h); padding: 0; flex-shrink: 0; }
.btn:active:not(:disabled):not([aria-disabled="true"]) { transform: scale(0.98); }
.btn:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.btn:disabled,
.btn[aria-disabled="true"] { opacity: 0.5; cursor: not-allowed; box-shadow: none; }

/* primary: one per action group */
.btn-primary {
  background: var(--accent-fill);
  color: var(--on-accent);
  box-shadow: 0 6px 18px color-mix(in srgb, var(--blue) 26%, transparent);
}
.btn-primary:hover:not(:disabled) { background: var(--accent-fill-hover); }

/* secondary: neutral, the default */
.btn-secondary {
  background: var(--surface-2);
  border-color: var(--border-strong);
  color: var(--text);
}
.btn-secondary:hover:not(:disabled) {
  background: color-mix(in srgb, var(--blue) 12%, transparent);
  border-color: color-mix(in srgb, var(--blue) 55%, transparent);
}
.btn-secondary.active,
.btn-secondary[aria-pressed="true"] {
  background: color-mix(in srgb, var(--blue) 18%, transparent);
  border-color: color-mix(in srgb, var(--blue) 60%, transparent);
}

/* danger: tonal, fills on hover */
.btn-danger {
  background: color-mix(in srgb, var(--red) 12%, transparent);
  border-color: color-mix(in srgb, var(--red) 45%, transparent);
  color: var(--red);
}
.btn-danger:hover:not(:disabled) { background: var(--red); border-color: var(--red); color: var(--on-danger); }

/* ghost: low-emphasis */
.btn-ghost { background: transparent; color: var(--text2); }
.btn-ghost:hover:not(:disabled) { background: var(--hover); color: var(--text); }

@media (pointer: coarse) {
  .btn-sm { --btn-h: 38px; }
}

/* ── Layout shell ──────────────────────────────────────────────────────── */
.app-shell { display: flex; flex: 1; width: 100%; min-height: 0; }

.sidebar {
  position: relative;
  width: var(--nav-w);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--nav-bg);
  border-right: 1px solid var(--border);
}

.nav-logo {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-6) var(--space-4) var(--space-4);
  color: inherit;
  text-decoration: none;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(180deg, color-mix(in srgb, var(--blue) 10%, transparent), transparent);
  transition: background-color 0.15s ease;
}
.nav-logo:hover .nav-brand { color: var(--blue); }
.nav-logo:focus-visible { outline-offset: -2px; }
.nav-mark {
  width: 44px;
  height: 44px;
  border-radius: 14px;
  display: grid;
  place-items: center;
  flex-shrink: 0;
  background: var(--accent-fill);
  color: var(--on-accent);
  font-size: var(--fs-md);
  font-weight: 800;
  letter-spacing: 0.06em;
  box-shadow: 0 10px 24px color-mix(in srgb, var(--blue) 24%, transparent);
}
.nav-kicker { display: block; font-size: var(--fs-xs); text-transform: uppercase; letter-spacing: 0.14em; color: var(--text2); }
.nav-brand { display: block; font-size: var(--fs-lg); font-weight: 700; transition: color 0.15s ease; }

.nav-items {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  padding: var(--space-3);
  flex: 1;
  min-height: 0;
  overflow-y: auto;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  width: 100%;
  min-height: 44px;
  padding: 0 var(--space-3);
  border: none;
  border-radius: var(--radius-ctl);
  background: transparent;
  color: var(--text2);
  font-size: var(--fs-md);
  font-weight: 600;
  text-align: left;
  cursor: pointer;
  transition: background-color 0.15s ease, color 0.15s ease;
}
.nav-item svg { width: 18px; height: 18px; flex-shrink: 0; }
.nav-item:hover { background: var(--hover); color: var(--text); }
.nav-item.active {
  background: color-mix(in srgb, var(--blue) 16%, transparent);
  color: var(--text);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--blue) 30%, transparent);
}
.nav-item.active svg { color: var(--blue); }
.nav-sep { border: none; border-top: 1px solid var(--border); margin: var(--space-2) var(--space-1); }

.nav-stats,
.user-panel {
  margin: 0 var(--space-3) var(--space-3);
  padding: var(--space-3) var(--space-4);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
}
.nav-stats { background: var(--surface-2); font-size: var(--fs-sm); color: var(--text2); }
.ns-row { display: flex; justify-content: space-between; }
.ns-row + .ns-row { margin-top: var(--space-1); }
.ns-online { color: var(--green); font-weight: 700; }
.user-panel { display: flex; flex-direction: column; gap: var(--space-2); background: var(--panel-glow); }
.user-panel .name { font-size: var(--fs-md); font-weight: 700; overflow: hidden; text-overflow: ellipsis; }
.user-panel .meta { font-size: var(--fs-xs); color: var(--text2); margin-top: calc(var(--space-1) * -1); }
.user-panel-actions { display: flex; flex-direction: column; gap: var(--space-2); }

main { flex: 1; min-width: 0; min-height: 0; display: flex; flex-direction: column; overflow: hidden; }

.page {
  display: none;
  flex: 1;
  flex-direction: column;
  gap: var(--page-gap);
  overflow-y: auto;
  padding: var(--page-pad) max(var(--page-pad), calc((100% - 1440px) / 2));
}
.page.active { display: flex; }

.page-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  padding: var(--space-5) var(--head-pad);
  border: 1px solid var(--border);
  border-radius: var(--radius-panel);
  background: var(--header-tint);
  box-shadow: var(--shadow-sm);
}
.page-head-copy { display: flex; flex-direction: column; gap: var(--space-1); min-width: 0; }
.page-kicker { font-size: var(--fs-xs); font-weight: 600; text-transform: uppercase; letter-spacing: 0.14em; color: var(--text2); }
.page-title { font-size: var(--fs-2xl); font-weight: 700; letter-spacing: -0.01em; }
.page-subtitle { font-size: var(--fs-md); color: var(--text2); max-width: 60ch; }
.page-actions,
.toolbar-actions,
.admin-actions { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); }

/* ── Cards ─────────────────────────────────────────────────────────────── */
.card {
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  min-width: 0;
}
.card-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-4) var(--card-pad);
  border-bottom: 1px solid var(--border);
}
.card-title { font-size: var(--fs-lg); font-weight: 700; }
.card-subtitle { display: block; margin-top: 2px; font-size: var(--fs-sm); color: var(--text2); }
.card-body { padding: var(--card-pad); }
.card-body.flush { padding: 0; }
.card-note { padding: var(--space-3) var(--card-pad); font-size: var(--fs-sm); color: var(--text2); border-bottom: 1px solid var(--border); }

/* ── Forms ─────────────────────────────────────────────────────────────── */
.form-group { margin-bottom: var(--space-4); min-width: 0; }
.form-group > label,
.field-label { display: block; margin-bottom: 6px; font-size: var(--fs-sm); font-weight: 600; color: var(--text2); }
.form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 0 var(--space-3); }
.field-stack { display: flex; flex-direction: column; gap: 6px; min-width: 110px; }
.field-stack label { font-size: var(--fs-xs); font-weight: 600; color: var(--text2); }

.input {
  display: block;
  width: 100%;
  min-height: var(--ctl-h);
  padding: 0 var(--space-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-ctl);
  background: var(--sunken);
  color: var(--text);
  font-size: var(--fs-md);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
textarea.input { padding: 10px var(--space-3); resize: vertical; line-height: var(--lh-body); }
.input::placeholder { color: color-mix(in srgb, var(--text2) 75%, transparent); }
.input:hover:not(:disabled) { border-color: var(--border-strong); }
.input:focus,
.input:focus-visible { outline: none; border-color: var(--blue); box-shadow: var(--focus-ring); }
.input:disabled { opacity: 0.55; cursor: not-allowed; }
select.input {
  appearance: none;
  -webkit-appearance: none;
  padding-right: var(--space-10);
  cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5l5 5 5-5' fill='none' stroke='%2393a8c6' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  background-size: 12px 8px;
}
select.input option { background: var(--bg2); color: var(--text); }
.input-sm { min-height: var(--ctl-h-sm); font-size: var(--fs-sm); }

input[type="file"].input { padding: 6px; min-height: auto; font-size: var(--fs-sm); color: var(--text2); }
input[type="file"]::file-selector-button {
  margin-right: var(--space-3);
  min-height: var(--ctl-h-sm);
  padding: 0 var(--space-3);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}
input[type="file"]::file-selector-button:hover { border-color: var(--blue); }

.checkbox-row { display: inline-flex; align-items: center; gap: var(--space-2); font-size: var(--fs-md); cursor: pointer; }
.checkbox-row.muted { font-size: var(--fs-sm); color: var(--text2); }
input[type="checkbox"] {
  appearance: none;
  -webkit-appearance: none;
  flex-shrink: 0;
  width: 18px;
  height: 18px;
  margin: 0;
  border: 1px solid var(--border-strong);
  border-radius: 5px;
  background: var(--sunken);
  display: inline-grid;
  place-items: center;
  cursor: pointer;
  vertical-align: middle;
  transition: background-color 0.15s ease, border-color 0.15s ease;
}
input[type="checkbox"]::after {
  content: "";
  width: 4px;
  height: 8px;
  margin-top: -2px;
  border-right: 2px solid var(--on-accent);
  border-bottom: 2px solid var(--on-accent);
  transform: rotate(45deg) scale(0);
  transition: transform 0.12s ease;
}
input[type="checkbox"]:checked { background: var(--accent-fill); border-color: transparent; }
input[type="checkbox"]:checked::after { transform: rotate(45deg) scale(1); }
input[type="checkbox"]:hover { border-color: var(--blue); }
input[type="checkbox"]:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
input[type="checkbox"]:disabled { opacity: 0.5; cursor: not-allowed; }

/* ui-select.js dropdowns */
.ui-select { position: relative; display: block; width: 100%; min-width: 0; }
.ui-select-native { position: absolute !important; inset: 0; width: 100% !important; height: 100% !important; opacity: 0; pointer-events: none; }
.ui-select-trigger {
  position: relative;
  display: flex;
  align-items: center;
  width: 100%;
  padding-right: var(--space-10);
  text-align: left;
  cursor: pointer;
}
.ui-select-trigger::after {
  content: "";
  position: absolute;
  right: 16px;
  top: 50%;
  width: 7px;
  height: 7px;
  border-right: 2px solid var(--text2);
  border-bottom: 2px solid var(--text2);
  transform: translateY(-70%) rotate(45deg);
  transition: transform 0.2s ease;
}
.ui-select.open .ui-select-trigger::after { transform: translateY(-25%) rotate(-135deg); }
.ui-select.open .ui-select-trigger { border-color: var(--blue); box-shadow: var(--focus-ring); }
.ui-select-label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ui-select-list {
  position: fixed;
  z-index: 10000;
  overflow-y: auto;
  padding: 6px;
  border: 1px solid var(--border);
  border-radius: var(--radius-ctl);
  background: var(--bg2);
  box-shadow: var(--shadow-lg);
  animation: uiSelectIn 0.12s ease-out;
}
.ui-select-list.above { animation-name: uiSelectInUp; }
.ui-select-option {
  display: flex;
  align-items: center;
  min-height: 36px;
  padding: 0 var(--space-3);
  border-radius: var(--radius-sm);
  font-size: var(--fs-md);
  white-space: nowrap;
  cursor: pointer;
}
.ui-select-option + .ui-select-option { margin-top: 2px; }
.ui-select-option.active { background: var(--hover); }
.ui-select-option.selected { background: color-mix(in srgb, var(--blue) 18%, transparent); color: var(--text); font-weight: 700; }
.ui-select-option.disabled { opacity: 0.45; cursor: not-allowed; }
.ui-select-group { padding: var(--space-3) var(--space-3) var(--space-1); font-size: var(--fs-xs); font-weight: 700; letter-spacing: 0.1em; text-transform: uppercase; color: var(--text2); }
@keyframes uiSelectIn { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: none; } }
@keyframes uiSelectInUp { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

/* segmented choice (add bot / login method) */
.seg { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); gap: var(--space-2); }
.seg-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: var(--space-3) var(--space-2);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-ctl);
  background: var(--surface-2);
  color: var(--text);
  text-align: center;
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease;
}
.seg-btn strong { font-size: var(--fs-md); }
.seg-btn small { font-size: var(--fs-xs); color: var(--text2); }
.seg-btn:hover:not(:disabled) { border-color: color-mix(in srgb, var(--blue) 55%, transparent); }
.seg-btn.active { background: color-mix(in srgb, var(--blue) 16%, transparent); border-color: var(--blue); }
.seg-btn.active small { color: var(--text); }
.seg-btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ── Chips: badge / status-chip / tag / pill share one shape ───────────── */
.badge, .status-chip, .tag, .profile-pill, .proxy-type-badge, .ign-state, .move-status-pill, .support-msg .cmd {
  --chip: var(--text2);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 22px;
  padding: 0 var(--space-2);
  border: 1px solid color-mix(in srgb, var(--chip) 35%, transparent);
  border-radius: var(--radius-pill);
  background: color-mix(in srgb, var(--chip) 12%, transparent);
  color: var(--chip);
  font-size: var(--fs-xs);
  font-weight: 600;
  line-height: 1.2;
  white-space: nowrap;
}
.badge, .status-chip, .profile-pill, .support-msg .cmd { text-transform: uppercase; letter-spacing: 0.04em; }
.badge-online { --chip: var(--green); }
.badge-offline { --chip: var(--text2); }
.badge-connecting { --chip: var(--yellow); }
.badge-error { --chip: var(--red); }
.badge-kicked { --chip: var(--purple); }
.status-chip-row { display: inline-flex; flex-wrap: wrap; align-items: center; gap: var(--space-1); max-width: 100%; }
.status-chip-info { --chip: var(--blue); }
.status-chip-warn { --chip: var(--yellow); }
.status-chip-error { --chip: var(--red); }
.tag.proxy, .tag.ok { --chip: var(--green); }
.tag.proxy { font-family: var(--mono); font-weight: 500; }
.tag.proxy.shared { --chip: var(--blue); font-family: inherit; font-weight: 600; }
.tag.proxy.shared::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.tag.priority { --chip: var(--yellow); }
.tag.priority-top { --chip: var(--red); }
.tag.uptime { --chip: var(--blue); font-family: var(--mono); }
.tag.uptime.offline { --chip: var(--text2); }
.profile-pill { --chip: var(--blue); }
.support-msg .cmd { --chip: var(--blue); margin-top: var(--space-2); }

.online-dot { width: 7px; height: 7px; border-radius: 50%; display: inline-block; flex-shrink: 0; }
.dot-online { background: var(--green); box-shadow: 0 0 6px var(--green); animation: pulse 2s infinite; }
.dot-connecting { background: var(--yellow); }
.dot-error { background: var(--red); }
.dot-offline { background: var(--text2); }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.4; } }

/* ── Tables ────────────────────────────────────────────────────────────── */
.table-shell { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.bot-table,
.admin-table { width: 100%; border-collapse: collapse; }
.bot-table th,
.admin-table th {
  padding: var(--space-3) var(--space-4);
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  color: var(--text2);
  font-size: var(--fs-xs);
  font-weight: 600;
  letter-spacing: 0.05em;
  text-align: left;
  text-transform: uppercase;
  white-space: nowrap;
}
.bot-table td,
.admin-table td {
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--border);
  font-size: var(--fs-md);
  text-align: left;
  vertical-align: middle;
}
.bot-table tbody tr:last-child td,
.admin-table tbody tr:last-child td { border-bottom: none; }
.bot-table tbody tr:hover td,
.admin-table tbody tr:hover td { background: var(--hover); }
.bot-table .col-check { width: 44px; }
.bot-table td:nth-child(5),
.bot-table td:nth-child(6),
.bot-table td:nth-child(7) { white-space: nowrap; }
.bot-table .actions { display: flex; flex-wrap: wrap; gap: var(--space-1); min-width: 240px; max-width: 380px; }
.admin-table .input,
.admin-table .ui-select { min-width: 110px; }

.admin-user-open,
.support-ticket-open {
  padding: 0;
  border: none;
  background: none;
  color: var(--text);
  font-weight: 600;
  text-align: left;
  cursor: pointer;
  text-underline-offset: 3px;
}
.support-ticket-open { color: var(--blue); }
.admin-user-open:hover,
.support-ticket-open:hover { color: var(--blue); text-decoration: underline; }

.empty { padding: var(--space-10) var(--space-4); text-align: center; color: var(--text2); font-size: var(--fs-md); }

/* ── Dashboard ─────────────────────────────────────────────────────────── */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: var(--space-4); }
.stat-card {
  --stat: var(--blue);
  position: relative;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: var(--space-3);
  min-height: 120px;
  padding: var(--space-5);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}
.stat-card::before { content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: 3px; background: var(--stat); }
.stat-card:nth-child(2) { --stat: var(--green); }
.stat-card:nth-child(3) { --stat: var(--text2); }
.stat-card:nth-child(4) { --stat: var(--yellow); }
.stat-label { font-size: var(--fs-xs); font-weight: 600; color: var(--text2); text-transform: uppercase; letter-spacing: 0.12em; }
.stat-val { font-size: 2rem; font-weight: 700; line-height: 1; font-variant-numeric: tabular-nums; }
.stat-val.green { color: var(--green); }
.stat-val.red { color: var(--red); }
.stat-val.blue { color: var(--blue); }

/* uptime reliability modal */
.reliability-toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); margin-bottom: var(--space-3); }
.reliability-range-btn { min-width: 56px; }
.reliability-summary { margin-bottom: var(--space-3); font-size: var(--fs-sm); color: var(--text2); }
.reliability-summary strong { color: var(--text); font-size: var(--fs-lg); }
.reliability-chart-box {
  display: flex;
  align-items: flex-end;
  height: 180px;
  padding: var(--space-3) var(--space-3) var(--space-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-ctl);
  background: var(--sunken);
}
.reliability-bars { display: grid; grid-template-columns: repeat(auto-fit, minmax(2px, 1fr)); align-items: end; gap: 2px; width: 100%; height: 100%; }
.reliability-bar { min-height: 3px; border-radius: 2px 2px 0 0; background: color-mix(in srgb, var(--text2) 45%, transparent); }
.reliability-bar.good, .reliability-legend .lg-good { background: var(--green); }
.reliability-bar.mid, .reliability-legend .lg-mid { background: var(--yellow); }
.reliability-bar.bad, .reliability-legend .lg-bad { background: var(--red); }
.reliability-axis { display: flex; justify-content: space-between; margin-top: var(--space-2); font-size: var(--fs-xs); color: var(--text2); }
.reliability-empty { width: 100%; padding-top: 60px; text-align: center; font-size: var(--fs-sm); color: var(--text2); }
.reliability-legend { display: flex; flex-wrap: wrap; gap: var(--space-3); margin-top: var(--space-3); font-size: var(--fs-xs); color: var(--text2); }
.reliability-legend span { display: inline-flex; align-items: center; gap: 6px; }
.reliability-legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; }

/* ── Chat ──────────────────────────────────────────────────────────────── */
.chat-layout { display: grid; grid-template-columns: 240px minmax(0, 1fr); gap: var(--space-4); flex: 1; min-height: 0; }
.chat-sidebar { display: flex; flex-direction: column; gap: var(--space-2); min-height: 0; overflow-y: auto; }
#chat-bot-list { display: flex; flex-direction: column; gap: var(--space-2); }
.chat-bot-item {
  display: block;
  width: 100%;
  padding: var(--space-3);
  border: 1px solid transparent;
  border-radius: var(--radius-ctl);
  background: transparent;
  color: var(--text);
  text-align: left;
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease;
}
.chat-bot-item:hover { background: var(--hover); }
.chat-bot-item.active { background: color-mix(in srgb, var(--blue) 14%, transparent); border-color: color-mix(in srgb, var(--blue) 45%, transparent); }
.chat-bot-item .name { font-size: var(--fs-md); font-weight: 600; }
.chat-bot-item .sub { font-size: var(--fs-xs); color: var(--text2); }
.chat-main { display: flex; flex-direction: column; min-height: 0; }
.chat-body { display: flex; flex-direction: column; gap: var(--space-3); flex: 1; min-height: 0; }
.chat-log-area {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 280px;
  max-height: calc(100dvh - 300px);
  overflow-y: auto;
  padding: var(--space-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-ctl);
  background: var(--sunken);
  font-family: var(--mono);
  font-size: var(--fs-sm);
}
.chat-msg { padding: 2px 0; line-height: var(--lh-body); overflow-wrap: anywhere; }
.chat-msg .time { margin-right: 6px; color: var(--text2); }
.chat-msg.chat .content { color: var(--text); }
.chat-msg.server .content { color: var(--text2); }
.chat-msg.system .content { color: var(--yellow); }
.chat-msg.command .content { color: var(--blue); }
.chat-msg.whisper .content { color: var(--purple); }
.chat-presets { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); margin-top: var(--space-2); }
.chat-preset { display: inline-flex; }
.chat-preset .btn { border-top-right-radius: 0; border-bottom-right-radius: 0; }
.chat-preset .preset-del {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: var(--ctl-h-sm);
  min-height: var(--ctl-h-sm);
  border: 1px solid var(--border-strong);
  border-left: none;
  border-radius: 0 var(--radius-ctl) var(--radius-ctl) 0;
  background: var(--surface-2);
  color: var(--text2);
  font-size: var(--fs-lg);
  cursor: pointer;
}
.chat-preset .preset-del:hover { background: var(--red); border-color: var(--red); color: var(--on-danger); }
.preset-btn { --btn-h: var(--ctl-h-sm); }
.chat-preset-editor { display: flex; flex-wrap: wrap; gap: var(--space-2); margin-top: var(--space-2); }
.chat-preset-editor .input { flex: 1 1 160px; }
.chat-presets-empty { font-size: var(--fs-xs); color: var(--text2); }

/* ── Movement ──────────────────────────────────────────────────────────── */
.move-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: var(--space-4); }
.dpad-wrap { display: flex; justify-content: center; margin-bottom: var(--space-4); }
.dpad { display: grid; grid-template-columns: repeat(3, 72px); grid-template-rows: repeat(3, 48px); gap: var(--space-2); }
.dpad-btn { --btn-h: 48px; padding: 0; font-size: var(--fs-xs); letter-spacing: 0.04em; }
.move-helper-row { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--space-2); margin-bottom: var(--space-4); }
.move-status-pill { min-height: 26px; padding: 0 var(--space-3); }
.actions-row { display: flex; flex-wrap: wrap; gap: var(--space-2); margin-top: var(--space-3); }
.look-row { display: grid; grid-template-columns: 1fr 1fr auto; gap: var(--space-2); }
.runtime-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: var(--space-2); margin-top: var(--space-3); }
.runtime-item, .admin-detail-item, .profile-stat {
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-ctl);
  background: var(--sunken);
}
.runtime-item .k, .admin-detail-item .k, .profile-stat .k { font-size: var(--fs-xs); color: var(--text2); }
.runtime-item .v, .admin-detail-item .v, .profile-stat .v { margin-top: 2px; font-size: var(--fs-md); font-weight: 600; overflow-wrap: anywhere; }
.runtime-line { margin-top: var(--space-2); font-size: var(--fs-sm); color: var(--text2); }

/* ── Accounts ──────────────────────────────────────────────────────────── */
.acc-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: var(--space-4); }
.acc-card {
  display: flex;
  flex-direction: column;
  padding: var(--card-pad);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}
.acc-card-top { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--space-2); margin-bottom: var(--space-3); }
.acc-name { font-size: var(--fs-lg); font-weight: 700; }
.acc-user { margin-top: 2px; font-size: var(--fs-sm); color: var(--text2); }
.acc-meta { display: flex; flex-direction: column; gap: var(--space-1); margin-bottom: var(--space-3); font-size: var(--fs-sm); color: var(--text2); }
.acc-actions { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: var(--space-2); margin-top: auto; padding-top: var(--space-3); }
.acc-actions .btn { width: 100%; }

/* ── Profile ───────────────────────────────────────────────────────────── */
.profile-shell { display: flex; flex-direction: column; gap: var(--space-4); }
.profile-summary-shell {
  padding: var(--space-4);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  background: var(--panel-glow);
  font-size: var(--fs-sm);
  color: var(--text2);
}
.profile-main { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-3); margin-bottom: var(--space-3); }
.profile-avatar {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  flex-shrink: 0;
  overflow: hidden;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-ctl);
  background: var(--bg3);
  color: var(--text);
  font-weight: 700;
}
.profile-avatar img { display: block; width: 100%; height: 100%; object-fit: cover; }
.profile-main-copy { flex: 1; min-width: 180px; }
.profile-kicker { margin-bottom: var(--space-1); font-size: var(--fs-xs); color: var(--text2); text-transform: uppercase; letter-spacing: 0.12em; }
.profile-name-row { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); margin-bottom: var(--space-1); }
.profile-name { font-size: var(--fs-lg); font-weight: 700; color: var(--text); }
.profile-id { font-size: var(--fs-xs); color: var(--text2); }
.profile-stat-grid,
.profile-feature-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: var(--space-2); }
.profile-stat .k { text-transform: uppercase; letter-spacing: 0.08em; }
.profile-feature {
  --chip: var(--text2);
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-ctl);
  background: var(--sunken);
  font-size: var(--fs-xs);
  color: var(--text2);
}
.profile-feature strong { display: block; margin-bottom: 2px; font-size: var(--fs-sm); color: var(--text); }
.profile-feature.active,
.profile-feature.expired,
.profile-feature.off { border-color: color-mix(in srgb, var(--chip) 40%, transparent); background: color-mix(in srgb, var(--chip) 9%, transparent); color: var(--text); }
.profile-feature.active { --chip: var(--green); }
.profile-feature.expired { --chip: var(--yellow); }
.profile-feature.off { --chip: var(--red); }
.profile-feature.active strong { color: var(--green); }
.profile-feature.expired strong { color: var(--yellow); }
.profile-feature.off strong { color: var(--red); }
.profile-section { padding: var(--space-4); border: 1px solid var(--border); border-radius: var(--radius-card); background: var(--surface-2); }
.profile-section-head { display: flex; align-items: center; justify-content: space-between; gap: var(--space-2); margin-bottom: var(--space-3); }
.profile-section-title { font-size: var(--fs-md); font-weight: 700; }
.profile-hint { font-size: var(--fs-sm); color: var(--text2); }
.friend-sharing-output {
  display: flex;
  align-items: center;
  min-height: 36px;
  padding: var(--space-2) var(--space-3);
  border: 1px dashed color-mix(in srgb, var(--yellow) 45%, transparent);
  border-radius: var(--radius-ctl);
  background: color-mix(in srgb, var(--yellow) 7%, transparent);
  color: var(--yellow);
  font-size: var(--fs-sm);
  word-break: break-word;
}
.friend-sharing-output:empty { display: none; }
.secret-output { font-family: var(--mono); font-size: var(--fs-sm); word-break: break-all; color: var(--yellow); }
.secret-output:empty { display: none; }

/* ── Proxies ───────────────────────────────────────────────────────────── */
.proxy-list { display: flex; flex-direction: column; gap: var(--space-3); }
.proxy-item {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-3) var(--space-4);
  padding: var(--space-4) var(--card-pad);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}
.proxy-addr { flex: 1 1 220px; min-width: 0; font-family: var(--mono); font-size: var(--fs-md); overflow-wrap: anywhere; }
.proxy-bots { font-size: var(--fs-xs); color: var(--text2); }
.proxy-target-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: var(--space-2); max-height: 240px; overflow-y: auto; margin-top: var(--space-2); }
.proxy-target-item {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-ctl);
  background: var(--sunken);
  font-size: var(--fs-sm);
  cursor: pointer;
}
.proxy-target-item .meta { font-size: var(--fs-xs); color: var(--text2); }

/* ── Support ───────────────────────────────────────────────────────────── */
.support-create-grid { display: grid; grid-template-columns: minmax(200px, 260px) 1fr; gap: 0 var(--space-3); }
.support-thread { display: flex; flex-direction: column; gap: var(--space-3); max-height: 420px; overflow-y: auto; padding: 2px; }
.support-msg { padding: var(--space-3); border: 1px solid var(--border); border-radius: var(--radius-ctl); background: var(--sunken); }
.support-msg.staff { border-color: color-mix(in srgb, var(--blue) 50%, transparent); background: color-mix(in srgb, var(--blue) 8%, transparent); }
.support-msg .head { display: flex; justify-content: space-between; gap: var(--space-2); margin-bottom: var(--space-2); font-size: var(--fs-xs); color: var(--text2); }
.support-msg .body { white-space: pre-wrap; overflow-wrap: anywhere; font-size: var(--fs-md); }
.support-attachments { display: flex; flex-wrap: wrap; gap: var(--space-2); margin-top: var(--space-3); }
.support-attachment {
  width: min(180px, 45vw);
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: var(--radius-ctl);
  background: var(--bg3);
  color: var(--text);
  text-decoration: none;
}
.support-attachment:hover { border-color: var(--blue); }
.support-attachment img { display: block; width: 100%; height: 100px; object-fit: cover; border-bottom: 1px solid var(--border); }
.support-attachment .meta { padding: 6px var(--space-2); font-size: var(--fs-xs); color: var(--text2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.support-command-help { margin: 0 0 var(--space-2); font-size: var(--fs-xs); color: var(--text2); }
.support-command-help:empty { display: none; }
.support-meta-row { display: flex; flex-wrap: wrap; gap: var(--space-2); margin-bottom: var(--space-3); font-size: var(--fs-sm); color: var(--text2); }

/* ── Admin ─────────────────────────────────────────────────────────────── */
.admin-detail-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: var(--space-2); margin-bottom: var(--space-3); }
.key-form { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); align-items: end; gap: var(--space-3); margin-bottom: var(--space-3); }
.key-form .field-wide { grid-column: span 2; }
.settings-block + .settings-block { margin-top: var(--space-6); padding-top: var(--space-6); border-top: 1px solid var(--border); }

/* ── Modals ────────────────────────────────────────────────────────────── */
.modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: none;
  align-items: center;
  justify-content: center;
  padding: var(--space-4);
  background: var(--overlay);
  backdrop-filter: blur(4px);
}
.modal.open { display: flex; }
#modal-admin-password-login { z-index: 3001; }
.modal-box {
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 520px;
  max-height: calc(100dvh - 32px);
  border: 1px solid var(--border);
  border-radius: var(--radius-panel);
  background: var(--bg2);
  box-shadow: var(--shadow-lg);
  animation: modalIn 0.16s ease-out;
}
.modal-sm .modal-box, .modal-box.modal-sm { max-width: 420px; }
.modal-md .modal-box, .modal-box.modal-md { max-width: 600px; }
.modal-lg .modal-box, .modal-box.modal-lg { max-width: 780px; }
.modal-xl .modal-box, .modal-box.modal-xl { max-width: 1000px; }
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-4) var(--space-5);
  border-bottom: 1px solid var(--border);
}
.modal-head h2 { font-size: var(--fs-lg); }
.modal-body { flex: 1; min-height: 0; overflow-y: auto; padding: var(--space-5); }
.modal-foot { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: var(--space-2); padding: var(--space-4) var(--space-5); border-top: 1px solid var(--border); }
.close-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  flex-shrink: 0;
  border: 1px solid transparent;
  border-radius: var(--radius-ctl);
  background: none;
  color: var(--text2);
  font-size: 1.375rem;
  line-height: 1;
  cursor: pointer;
}
.close-btn:hover { background: var(--hover); border-color: var(--border); color: var(--text); }
@keyframes modalIn { from { opacity: 0; transform: translateY(8px) scale(0.99); } to { opacity: 1; transform: none; } }

.step-indicator { display: flex; gap: 6px; margin-bottom: var(--space-5); }
.step-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--border-strong); }
.step-dot.active { background: var(--blue); }

/* Microsoft device code */
.auth-steps { margin: 0 0 var(--space-4); padding-left: var(--space-5); color: var(--text2); }
.auth-steps strong { color: var(--blue); }
.auth-code-display { display: flex; flex-direction: column; align-items: center; gap: var(--space-2); margin: var(--space-5) 0; }
.auth-code {
  display: inline-block;
  padding: var(--space-4) var(--space-6);
  border: 2px solid var(--blue);
  border-radius: var(--radius-card);
  background: var(--sunken);
  color: var(--blue);
  font-family: var(--mono);
  font-size: 2rem;
  font-weight: 700;
  letter-spacing: 0.3em;
  user-select: all;
}
.auth-timer { text-align: center; color: var(--yellow); font-size: var(--fs-md); margin-bottom: var(--space-3); }

/* add bot wizard */
.ab-token { font-family: var(--mono); font-size: var(--fs-sm); min-height: 72px; word-break: break-all; }
.ign-card {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  margin-bottom: var(--space-3);
  padding: var(--space-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-ctl);
  background: color-mix(in srgb, var(--blue) 5%, transparent);
}
.ign-avatar { display: grid; place-items: center; width: 38px; height: 38px; flex-shrink: 0; border-radius: var(--radius-ctl); background: var(--bg3); color: var(--text2); font-weight: 800; }
.ign-copy { flex: 1; min-width: 0; }
.ign-label { font-size: var(--fs-xs); color: var(--text2); text-transform: uppercase; letter-spacing: 0.1em; }
.ign-name { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ign-state:empty { display: none; }
.ign-card[data-state="ok"] { border-color: color-mix(in srgb, var(--green) 45%, transparent); }
.ign-card[data-state="ok"] .ign-avatar { background: var(--accent-fill); color: var(--on-accent); }
.ign-card[data-state="ok"] .ign-state { --chip: var(--green); }
.ign-card[data-state="error"] { border-color: color-mix(in srgb, var(--red) 45%, transparent); }
.ign-card[data-state="error"] .ign-name { white-space: normal; font-weight: 600; font-size: var(--fs-sm); color: var(--red); }
.ign-card[data-state="error"] .ign-state { --chip: var(--red); }
.ign-card[data-state="loading"] .ign-avatar { animation: pulse 1.2s infinite; }
.ab-hint {
  padding: var(--space-3);
  border: 1px solid color-mix(in srgb, var(--blue) 22%, transparent);
  border-radius: var(--radius-ctl);
  background: color-mix(in srgb, var(--blue) 6%, transparent);
  font-size: var(--fs-sm);
  color: var(--text2);
}
.ab-hint:empty { display: none; }
.ab-hint-small { margin-top: var(--space-1); font-size: var(--fs-xs); color: var(--text2); }

/* ── Login gate ────────────────────────────────────────────────────────── */
.login-gate {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: none;
  align-items: center;
  justify-content: center;
  padding: var(--space-4);
  background: var(--page-bg);
  background-color: var(--bg);
}
.login-box {
  width: min(440px, 100%);
  padding: var(--space-8);
  border: 1px solid var(--border);
  border-radius: var(--radius-panel);
  background: var(--bg2);
  box-shadow: var(--shadow-lg);
  text-align: center;
}
.login-box h2 { margin-bottom: var(--space-2); font-size: var(--fs-xl); }
.login-box p { margin-bottom: var(--space-5); color: var(--text2); }

/* ── Toasts ────────────────────────────────────────────────────────────── */
#toasts {
  position: fixed;
  right: var(--space-5);
  bottom: var(--space-5);
  z-index: 10001;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  pointer-events: none;
}
.toast {
  max-width: 360px;
  padding: var(--space-3) var(--space-4);
  border: 1px solid var(--border);
  border-left: 4px solid var(--blue);
  border-radius: var(--radius-ctl);
  background: var(--bg2);
  box-shadow: var(--shadow-lg);
  font-size: var(--fs-sm);
  overflow-wrap: anywhere;
  pointer-events: auto;
  animation: toastIn 0.2s ease;
}
.toast.success { border-left-color: var(--green); }
.toast.error { border-left-color: var(--red); }
.toast.info { border-left-color: var(--blue); }
.toast.warning { border-left-color: var(--yellow); }
@keyframes toastIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ── Footer ────────────────────────────────────────────────────────────── */
.site-footer {
  flex-shrink: 0;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 6px var(--space-5);
  margin-top: 0;
  padding: var(--space-2) var(--space-5);
  border-top: 1px solid var(--border);
  background: var(--bg2);
  color: var(--text2);
  font-size: var(--fs-xs);
}
.site-footer nav { display: flex; gap: var(--space-4); margin: 0; }
.site-footer a { color: var(--text2); }
.site-footer a:hover { color: var(--blue); }
.site-footer p { max-width: 62ch; margin: 0; text-align: center; }

/* ── Responsive ────────────────────────────────────────────────────────── */
@media (max-width: 1100px) {
  :root { --nav-w: 220px; --page-pad: var(--space-6); }
  .page-title { font-size: 1.5rem; }
  .site-footer p { display: none; }
}

@media (max-width: 860px) {
  body { height: auto; min-height: 100dvh; overflow: auto; }
  .app-shell { flex-direction: column; }
  main { overflow: visible; }
  .page { overflow: visible; padding: var(--page-pad); }

  .sidebar {
    position: sticky;
    top: 0;
    z-index: 50;
    width: 100%;
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
  .nav-logo { padding: var(--space-3) var(--space-4); border-bottom: none; background: none; }
  .nav-mark { width: 36px; height: 36px; border-radius: var(--radius-ctl); font-size: var(--fs-xs); }
  .nav-kicker { display: none; }
  .nav-items {
    grid-column: 1 / -1;
    grid-row: 2;
    flex-direction: row;
    gap: var(--space-1);
    padding: 0 var(--space-3) var(--space-3);
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: none;
  }
  .nav-items::-webkit-scrollbar { display: none; }
  .nav-item { width: auto; min-height: 40px; flex-shrink: 0; white-space: nowrap; }
  .nav-sep { display: none; }
  .nav-stats { display: none; }
  .user-panel {
    grid-column: 2;
    grid-row: 1;
    align-self: center;
    margin: 0 var(--space-3) 0 0;
    padding: 0;
    border: none;
    background: none;
  }
  .user-panel .name, .user-panel .meta { display: none; }
  .user-panel-actions { flex-direction: row; }
  .user-panel-actions .btn { width: auto; }

  .chat-layout { grid-template-columns: 1fr; }
  .chat-sidebar { flex-direction: row; overflow-x: auto; }
  .chat-sidebar .divider { display: none; }
  #chat-bot-list { flex-direction: row; }
  .chat-bot-item { width: auto; flex-shrink: 0; }
  .chat-log-area { max-height: 60vh; }
  .support-create-grid { grid-template-columns: 1fr; }
}

@media (max-width: 640px) {
  :root { --page-pad: var(--space-4); --page-gap: var(--space-4); --card-pad: var(--space-4); --head-pad: var(--space-4); }
  .page-title { font-size: var(--fs-xl); }
  .page-header { padding: var(--space-4); }
  .page-actions, .toolbar-actions { width: 100%; }
  .page-actions .btn { flex: 1 1 auto; }
  .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--space-3); }
  .stat-card { min-height: 96px; padding: var(--space-4); }
  .stat-val { font-size: 1.5rem; }
  .move-grid { grid-template-columns: minmax(0, 1fr); }
  .look-row { grid-template-columns: 1fr 1fr; }
  .look-row .btn { grid-column: 1 / -1; }
  .key-form .field-wide { grid-column: 1 / -1; }
  .max-w-xs, .max-w-sm, .max-w-md { max-width: none; }
  .seg { grid-auto-flow: row; }
  .modal { align-items: flex-end; padding: 0; }
  .modal-box { max-width: none !important; max-height: 92dvh; border-radius: var(--radius-panel) var(--radius-panel) 0 0; }
  #toasts { left: var(--space-3); right: var(--space-3); bottom: var(--space-3); }
  .toast { max-width: none; }

  /* bot table becomes a card list */
  .bot-table thead { display: none; }
  .bot-table, .bot-table tbody { display: block; }
  .bot-table tr {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    gap: var(--space-1) var(--space-3);
    padding: var(--space-4);
    border-bottom: 1px solid var(--border);
  }
  .bot-table tbody tr:last-child { border-bottom: none; }
  .bot-table td { display: block; padding: 0; border: none; white-space: normal !important; }
  .bot-table td:first-child { grid-row: span 2; padding-top: 2px; }
  .bot-table td:nth-child(n+3) { grid-column: 2; }
  .bot-table td[data-label]::before { content: attr(data-label) " "; color: var(--text2); font-size: var(--fs-xs); text-transform: uppercase; letter-spacing: 0.05em; margin-right: var(--space-1); }
  .bot-table td.empty { grid-column: 1 / -1; }
  .bot-table tbody tr:hover td { background: none; }
  .bot-table .actions { min-width: 0; max-width: none; margin-top: var(--space-2); }
  body.mobile-compact .bot-table td:nth-child(6),
  body.mobile-compact .bot-table td:nth-child(7) { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}
