/* =========================================================================
   Reusable components: buttons, cards, forms, toggles, dropdowns/pickers,
   chips, badges, tooltips, modal, toast, skeleton, empty state, stat cards,
   tables, segmented controls, progress.
   ========================================================================= */

/* ------------------------------------------------------------------ buttons */
.btn {
  --btn-bg: var(--bg-card-2);
  --btn-fg: var(--text);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--s-2);
  padding: 0 var(--s-4);
  height: 40px;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  background: var(--btn-bg);
  color: var(--btn-fg);
  font-size: var(--fs-md);
  font-weight: 550;
  cursor: pointer;
  white-space: nowrap;
  transition: transform var(--t-fast) var(--ease), background var(--t) var(--ease),
    border-color var(--t) var(--ease), box-shadow var(--t) var(--ease), opacity var(--t) var(--ease);
  user-select: none;
}
.btn:hover { background: var(--bg-hover); border-color: var(--border-strong); }
.btn:active { transform: translateY(1px) scale(0.985); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }
.btn svg { width: 17px; height: 17px; flex: none; }
.btn { position: relative; }
/* Only the primary button clips, so its sheen stays inside the rounded box.
   Deliberately NOT on .btn: overflow:hidden there would clip any future
   [data-tip] tooltip rendered from a button. */
.btn-primary { overflow: hidden; }

.btn-primary {
  --btn-bg: linear-gradient(180deg, var(--red-bright), var(--red));
  --btn-fg: var(--text-on-red);
  border-color: transparent;
  box-shadow: 0 6px 20px -8px var(--red-glow-strong);
  font-weight: 600;
}
.btn-primary:hover {
  --btn-bg: linear-gradient(180deg, #ff5a67, var(--red-bright));
  box-shadow: 0 10px 28px -8px var(--red-glow-strong);
  transform: translateY(-1px);
}
.btn-primary:active { transform: translateY(1px) scale(0.985); }
/* One-shot light sweep on hover. Uses ::before because ::after is already
   the loading spinner (.btn.is-loading::after) — reusing it would delete the
   spinner on primary buttons mid-request. */
.btn-primary::before {
  content: "";
  position: absolute; inset: 0;
  background: linear-gradient(105deg, transparent 32%, rgba(255, 255, 255, 0.26) 50%, transparent 68%);
  transform: translateX(-120%);
  transition: transform 620ms var(--ease-out);
  pointer-events: none;
}
.btn-primary:hover::before { transform: translateX(120%); }
.btn-primary.is-loading::before { display: none; }
.btn-danger {
  --btn-bg: transparent;
  --btn-fg: var(--error);
  border-color: rgba(255, 93, 104, 0.4);
}
.btn-danger:hover { --btn-bg: var(--error-bg); border-color: var(--error); }
.btn-ghost { --btn-bg: transparent; border-color: transparent; }
.btn-ghost:hover { --btn-bg: var(--bg-hover); border-color: var(--border); }
.btn-subtle { --btn-bg: var(--red-tint); --btn-fg: var(--red-bright); border-color: var(--border-red); }
.btn-subtle:hover { --btn-bg: var(--red-tint); box-shadow: var(--ring); }
.btn-sm { height: 32px; padding: 0 var(--s-3); font-size: var(--fs-sm); border-radius: var(--r-xs); }
.btn-lg { height: 48px; padding: 0 var(--s-6); font-size: var(--fs-lg); }
.btn-block { width: 100%; }
.btn-icon { width: 40px; padding: 0; }
.btn-icon.btn-sm { width: 32px; }

.btn-discord {
  --btn-bg: #5865f2;
  --btn-fg: #fff;
  border-color: transparent;
}
.btn-discord:hover { --btn-bg: #4a57e0; }
.btn-discord.is-authenticating {
  --btn-bg: #5865f2;
  overflow: hidden; pointer-events: none;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.12), 0 10px 30px -10px rgba(88, 101, 242, 0.82);
  animation: discordButtonCommit 560ms cubic-bezier(0.22, 0.76, 0.28, 1) both;
}
.btn-discord.is-authenticating::before {
  content: ""; width: 15px; height: 15px; flex: none;
  border: 2px solid rgba(255, 255, 255, 0.42); border-top-color: #fff;
  border-radius: 50%; animation: spin 620ms linear infinite;
}
.btn-discord.is-authenticating::after {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(105deg, transparent 28%, rgba(255, 255, 255, 0.28) 50%, transparent 72%);
  transform: translateX(-120%); animation: discordButtonSweep 520ms var(--ease-out) forwards;
  pointer-events: none;
}
@keyframes discordButtonCommit {
  45% { transform: translateY(-2px) scale(1.012); }
  to { transform: translateY(-1px) scale(0.99); }
}
@keyframes discordButtonSweep { to { transform: translateX(120%); } }

/* spinner shown inside a loading button */
.btn.is-loading { color: transparent !important; pointer-events: none; position: relative; }
.btn.is-loading::after {
  content: "";
  position: absolute;
  width: 16px; height: 16px;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  color: var(--text);
  animation: spin 0.6s linear infinite;
}
.btn-primary.is-loading::after { color: var(--text-on-red); }

/* ------------------------------------------------------------------- cards */
.card {
  position: relative;
  background: linear-gradient(180deg, var(--bg-card), var(--bg-card-2));
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: var(--s-5);
  box-shadow: var(--shadow-md);
  transition: box-shadow var(--t), transform var(--t) var(--ease);
}
.card::before {
  content: "";
  position: absolute;
  inset: -1px;
  padding: 1px;
  pointer-events: none;
  border-radius: inherit;
  background: linear-gradient(115deg, rgba(229, 57, 69, 0.52), rgba(229, 57, 69, 0.08) 28%, rgba(255, 255, 255, 0.08) 48%, rgba(229, 57, 69, 0.10) 68%, rgba(229, 57, 69, 0.34));
  background-size: 220% 220%;
  background-position: 0% 50%;
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  -webkit-mask-composite: xor;
  mask-composite: exclude;
  opacity: 0.72;
  transition: opacity 420ms var(--ease), background-position 700ms var(--ease-out);
}
.card:hover { box-shadow: var(--shadow-md), 0 12px 34px -26px var(--red-glow-strong); }
.card:hover::before { opacity: 1; background-position: 100% 50%; }
.card-tight { padding: var(--s-4); }
.card-head {
  display: flex; align-items: center; flex-wrap: wrap; gap: var(--s-3);
  margin-bottom: 0;
}

/* Uniform spacing between stacked blocks — one rule that works through the
   panel → gate → card nesting instead of many fragile adjacent selectors. */
.panel > * + *, .card > * + *, [data-gate] > * + * { margin-top: var(--s-4); }
/* toggle lists keep their own divider spacing; number-pair grids stay tight */
.toggle-row + .toggle-row { margin-top: 0; }
.grid-2 > *, .grid-3 > *, .grid-auto > *, .stat-row > *, .server-grid > *,
.role-grid > *, .module-grid > *, .bypass-grid > *, .lb-list > *,
.logs-list > *, .person-list > *, .ticket-list > * { margin-top: 0; }
.card-head h3 { margin: 0; }
.card-head .card-head-icon {
  width: 38px; height: 38px; flex: none;
  display: grid; place-items: center;
  border-radius: var(--r-sm);
  background: var(--red-tint);
  color: var(--red-bright);
}
.card-head .card-head-actions { margin-left: auto; display: flex; gap: var(--s-2); }
/* Its own row, full width -- a subtitle sharing the title's row squeezes the
   title into whatever space is left, wrapping it onto two lines in narrower
   (side-by-side) cards while single-line siblings stay short, breaking the
   grid's row-height symmetry. */
.card-sub { flex: 1 1 100%; color: var(--text-2); font-size: var(--fs-sm); margin-top: 2px; }

/* section heading inside a settings panel */
.section-title {
  display: flex; align-items: center; gap: var(--s-3);
  margin: var(--s-2) 0 0;
  font-size: var(--fs-lg); font-weight: 600;
}
.section-title:first-child { margin-top: 0; }
.section-title::before {
  content: none;
}
.section-title.no-accent::before { content: none; }
.section-link {
  margin-left: var(--s-2); font-size: var(--fs-sm); color: var(--red-bright); cursor: pointer;
  font-weight: 500; text-decoration: underline; text-underline-offset: 2px;
}
.section-note { color: var(--text-2); font-size: var(--fs-sm); margin: calc(-1 * var(--s-2)) 0 0; max-width: 78ch; }

/* ------------------------------------------------------------------ badges */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 2px 9px;
  border-radius: var(--r-pill);
  font-size: var(--fs-xs); font-weight: 600; letter-spacing: 0.02em;
  border: 1px solid var(--border);
  background: var(--bg-card-2);
  color: var(--text-2);
}
.badge-red { color: var(--red-bright); background: var(--red-tint); border-color: var(--border-red); }
.badge-success { color: var(--success); background: var(--success-bg); border-color: rgba(50, 213, 131, 0.35); }
.badge-warning { color: var(--warning); background: var(--warning-bg); border-color: rgba(245, 196, 81, 0.35); }
.badge-error { color: var(--error); background: var(--error-bg); border-color: rgba(255, 93, 104, 0.35); }
.badge-dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }

/* status dot for live connection */
.conn-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--text-muted); transition: background var(--t), box-shadow var(--t); flex: none; }
.conn-dot.live { background: var(--success); box-shadow: 0 0 0 3px var(--success-bg); }

/* ------------------------------------------------------------------- forms */
.field { display: flex; flex-direction: column; gap: var(--s-2); min-width: 0; }
.field > label, .field-label {
  font-size: var(--fs-sm); font-weight: 550; color: var(--text);
  display: flex; align-items: center; gap: var(--s-2);
}
.field small, .field .hint { color: var(--text-2); font-size: var(--fs-xs); line-height: 1.45; }
.field code { background: var(--bg-input); padding: 1px 5px; border-radius: 4px; color: var(--red-bright); }

.input, input[type="text"].input, input[type="number"].input, input[type="password"].input,
input[type="search"].input, textarea.input, .field input[type="text"], .field input[type="number"],
.field input[type="password"], .field input[type="search"], .field input[type="datetime-local"],
.field input[type="date"], .field input[type="time"], .field textarea {
  width: 100%;
  min-height: 38px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: 8px 11px;
  color: var(--text);
  font-size: var(--fs-md);
  transition: border-color var(--t) var(--ease), box-shadow var(--t) var(--ease), background var(--t) var(--ease);
}
.field textarea { min-height: 74px; }
/* datetime/date/time popup indicator — match the dark surface */
input[type="datetime-local"]::-webkit-calendar-picker-indicator,
input[type="date"]::-webkit-calendar-picker-indicator,
input[type="time"]::-webkit-calendar-picker-indicator {
  filter: invert(0.85); opacity: 0.65; cursor: pointer;
  transition: opacity var(--t);
}
input[type="datetime-local"]:hover::-webkit-calendar-picker-indicator,
input[type="date"]:hover::-webkit-calendar-picker-indicator,
input[type="time"]:hover::-webkit-calendar-picker-indicator { opacity: 1; }
:root[data-theme="light"] input[type="datetime-local"]::-webkit-calendar-picker-indicator,
:root[data-theme="light"] input[type="date"]::-webkit-calendar-picker-indicator,
:root[data-theme="light"] input[type="time"]::-webkit-calendar-picker-indicator { filter: none; }
.field textarea { min-height: 74px; line-height: 1.5; }
.field input:hover, .field textarea:hover { border-color: var(--border-strong); }
.field input:focus, .field textarea:focus, .input:focus {
  border-color: var(--border-red);
  box-shadow: var(--ring);
  background: var(--bg-elevated);
}
.field input[readonly] { opacity: 0.7; cursor: default; }
.field input.invalid, .input.invalid { border-color: var(--error); box-shadow: 0 0 0 3px var(--error-bg); }
.field-error { color: var(--error); font-size: var(--fs-xs); }

/* inline checkbox label */
label.check {
  display: inline-flex; align-items: center; gap: var(--s-2);
  cursor: pointer; font-size: var(--fs-md); font-weight: 500;
}

/* custom checkbox — gradient fill + animated check + hover glow */
input[type="checkbox"]:not(.switch input) {
  -webkit-appearance: none; -moz-appearance: none; appearance: none;
  width: 20px; height: 20px; flex: none;
  border: 1.5px solid var(--border-strong);
  border-radius: 7px;
  background: var(--bg-input);
  display: grid; place-content: center;
  cursor: pointer;
  transition: background var(--t) var(--ease), border-color var(--t) var(--ease),
    box-shadow var(--t) var(--ease), transform var(--t-fast) var(--ease-out);
}
input[type="checkbox"]:not(.switch input):hover {
  border-color: var(--border-red);
  box-shadow: 0 0 0 3px var(--red-tint-2);
}
input[type="checkbox"]:not(.switch input)::after {
  content: "";
  width: 11px; height: 11px;
  transform: scale(0) rotate(-14deg);
  transition: transform var(--t) var(--ease-out);
  background: var(--text-on-red);
  clip-path: polygon(14% 44%, 0 65%, 40% 100%, 100% 16%, 84% 0, 39% 68%);
}
input[type="checkbox"]:not(.switch input):checked {
  background: linear-gradient(145deg, var(--red-bright), var(--red-hover));
  border-color: transparent;
  box-shadow: 0 4px 12px -4px var(--red-glow-strong);
}
input[type="checkbox"]:not(.switch input):checked::after { transform: scale(1) rotate(0); }
input[type="checkbox"]:not(.switch input):active { transform: scale(0.88); }
input[type="checkbox"]:not(.switch input):focus-visible { box-shadow: var(--ring); }

/* toggle switch — knob travels with a slight overshoot and squashes while
   held, so the control feels physical instead of teleporting between states */
.switch { position: relative; display: inline-flex; width: 42px; height: 24px; flex: none; cursor: pointer; }
.switch input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; z-index: 1; }
.switch .slider {
  position: absolute; inset: 0;
  border-radius: var(--r-pill);
  background: var(--bg-hover);
  border: 1px solid var(--border-strong);
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.28);
  transition: background var(--t) var(--ease), border-color var(--t), box-shadow var(--t);
}
.switch .slider::before {
  content: ""; position: absolute;
  width: 18px; height: 18px; left: 2px; top: 2px;
  border-radius: 50%;
  background: var(--text-2);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.45);
  transition: transform var(--t-slow) var(--ease-spring), background var(--t), width var(--t-fast) var(--ease);
}
.switch:hover .slider { border-color: var(--border-red); }
.switch:hover .slider::before { background: var(--text); }
/* press-and-hold stretches the knob toward its destination */
.switch:active .slider::before { width: 23px; }
.switch input:checked + .slider {
  background: linear-gradient(180deg, var(--red-bright), var(--red));
  border-color: transparent;
  box-shadow: 0 0 0 3px var(--red-tint), inset 0 1px 2px rgba(0, 0, 0, 0.2);
}
.switch input:checked + .slider::before { transform: translateX(18px); background: #fff; }
.switch input:checked:active + .slider::before { transform: translateX(13px); }
.switch input:focus-visible + .slider { box-shadow: var(--ring-focus); }
.switch input:disabled + .slider { opacity: 0.5; cursor: not-allowed; }
.switch input:disabled { cursor: not-allowed; }

/* toggle row: label + description + switch on the right */
.toggle-row {
  display: flex; align-items: center; gap: var(--s-4);
  padding: 10px 0;
}
.toggle-row + .toggle-row { border-top: 1px solid var(--border); }
.toggle-row .toggle-copy { min-width: 0; flex: 1; }
.toggle-row .toggle-copy .t-name { font-weight: 550; font-size: var(--fs-md); }
.toggle-row .toggle-copy .t-desc { color: var(--text-2); font-size: var(--fs-xs); }
/* sidebar-foot variant: tighter padding than the settings-panel toggle rows */
.toggle-row-tight { padding: 8px 12px; }
.toggle-row > .switch, .toggle-row > input[type="checkbox"] { margin-left: auto; }

/* -------------------------------------------------------- dropdown / picker */
.picker { min-width: 0; }
.dd { position: relative; min-width: 0; }
.dd-toggle {
  display: flex; align-items: center; gap: var(--s-2);
  width: 100%; min-height: 38px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: 8px 11px;
  cursor: pointer;
  text-align: left;
  transition: border-color var(--t), box-shadow var(--t), background var(--t);
}
.dd-toggle:hover { border-color: var(--border-strong); }
.dd.dd-open .dd-toggle { border-color: var(--border-red); box-shadow: var(--ring); background: var(--bg-elevated); }
.dd-label { flex: 1; display: flex; align-items: center; gap: var(--s-2); min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: var(--fs-md); }
.dd-placeholder { color: var(--text-muted); }
.dd-caret { color: var(--text-2); transition: transform var(--t); font-size: 0.7em; }
.dd.dd-open .dd-caret { transform: rotate(180deg); }
.dd-add .dd-toggle { background: transparent; border-style: dashed; color: var(--text-2); }

.dd-menu {
  position: absolute; z-index: var(--z-dropdown);
  top: calc(100% + 6px); left: 0; right: 0;
  max-height: 264px; overflow-y: auto;
  background: var(--bg-elevated);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-sm);
  box-shadow: var(--shadow-lg);
  padding: 5px;
  animation: ddIn var(--t) var(--ease-out);
  transform-origin: top;
}
.dd-menu.dd-menu-up { top: auto; bottom: calc(100% + 6px); transform-origin: bottom; }
.dd-menu.dd-menu-portal { position: fixed; right: auto; bottom: auto; z-index: calc(var(--z-toast) + 1); }
@keyframes ddIn { from { opacity: 0; transform: translateY(-6px) scale(0.98); } to { opacity: 1; transform: none; } }

/* ---- custom date + time picker (replaces the unstylable native
   datetime-local popup with a menu built the same way the channel/role
   dropdowns are). ---- */
.dd-datetime-menu { width: min(300px, calc(100vw - 24px)); max-height: none; overflow: visible; padding: var(--s-3); }
.dd-datetime-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: var(--s-2); }
.dd-datetime-month { font-weight: 600; font-size: var(--fs-sm); }
.dd-datetime-year {
  border: 0; border-bottom: 1px dashed var(--text-muted); padding: 0 1px;
  background: transparent; color: inherit; font: inherit; cursor: text;
}
.dd-datetime-year:hover { color: var(--red-bright); border-bottom-color: currentColor; }
.dd-datetime-year-input {
  width: 58px; padding: 2px 5px; border: 1px solid var(--border-red);
  border-radius: var(--r-xs); background: var(--bg-input); color: var(--text);
  font: inherit; text-align: center; outline: none; box-shadow: var(--ring);
}
.dd-datetime-nav {
  width: 26px; height: 26px; display: grid; place-items: center;
  border: 1px solid var(--border); border-radius: var(--r-xs);
  background: var(--bg-input); color: var(--text-2); cursor: pointer;
  transition: background var(--t), color var(--t), border-color var(--t);
}
.dd-datetime-nav:hover { background: var(--bg-hover); color: var(--text); border-color: var(--border-strong); }
.dd-datetime-weekdays, .dd-datetime-days { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; }
.dd-datetime-weekdays span { text-align: center; font-size: var(--fs-xs); color: var(--text-muted); padding: 4px 0; }
.dd-datetime-day {
  aspect-ratio: 1; display: grid; place-items: center;
  border: none; border-radius: var(--r-xs); background: transparent;
  color: var(--text); font-size: var(--fs-sm); cursor: pointer;
  transition: background var(--t), color var(--t);
}
.dd-datetime-day:hover { background: var(--bg-hover); }
.dd-datetime-day.muted { color: var(--text-muted); }
.dd-datetime-day.today { box-shadow: inset 0 0 0 1px var(--border-red); }
.dd-datetime-day.selected { background: var(--red-bright); color: #fff; }
.dd-datetime-time {
  display: grid; grid-template-columns: auto 48px auto 48px minmax(92px, 1fr); align-items: center; gap: 6px;
  margin-top: var(--s-3); padding-top: var(--s-3); border-top: 1px solid var(--border);
}
.dd-datetime-time-label { font-size: var(--fs-xs); color: var(--text-muted); margin-right: 2px; }
.dd-datetime-num {
  width: 48px; min-width: 48px; min-height: 34px; text-align: center;
  background: var(--bg-input); border: 1px solid var(--border);
  border-radius: var(--r-xs); color: var(--text); font-size: var(--fs-sm);
  padding: 4px;
}
.dd-datetime-ampm { margin-left: 2px; min-width: 0; }
.dd-datetime-ampm button { padding: 5px 10px; font-size: var(--fs-xs); }
.dd-datetime-footer { display: flex; justify-content: space-between; gap: var(--s-2); margin-top: var(--s-3); }
.dd-datetime-action {
  border: none; background: transparent; color: var(--red-bright);
  font-size: var(--fs-sm); font-weight: 500; cursor: pointer; padding: 4px 6px;
}
.dd-datetime-action:hover { text-decoration: underline; }
.dd-search-wrap {
  position: sticky; top: -5px; z-index: 1;
  /* Extends past .dd-menu's own 5px padding on the top/sides so that padding
     strip scrolls under an opaque layer too, instead of staying uncovered
     (which let a scrolled-past item's text peek through above the search box). */
  margin: -5px -5px 0 -5px;
  padding: 5px 5px 0;
  background: var(--bg-elevated);
}
.dd-search {
  width: 100%; margin-bottom: 5px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--r-xs);
  padding: 8px 10px; font-size: var(--fs-sm);
}
.dd-item {
  display: flex; align-items: center; gap: var(--s-2);
  width: 100%; text-align: left;
  padding: 8px 10px;
  border: none; border-radius: var(--r-xs);
  background: transparent; color: var(--text);
  cursor: pointer; font-size: var(--fs-md);
  transition: background var(--t-fast);
}
.dd-item:hover { background: var(--bg-hover); }
.dd-item.dd-selected { background: var(--red-tint); color: var(--red-bright); }
.dd-empty { padding: 10px; text-align: center; color: var(--text-muted); font-size: var(--fs-sm); }
.chip-dot { width: 10px; height: 10px; border-radius: 50%; flex: none; box-shadow: 0 0 0 2px rgba(0,0,0,0.3); }

/* chips (multi-select) */
.chip-picker { display: flex; flex-direction: column; gap: var(--s-2); }
.chip-row { display: flex; flex-wrap: wrap; gap: var(--s-2); }
.chip-row:empty { display: none; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 6px 4px 10px;
  background: var(--bg-card-2);
  border: 1px solid var(--border);
  border-radius: var(--r-pill);
  font-size: var(--fs-sm);
  animation: popIn var(--t) var(--ease-out);
}
.chip-x {
  width: 18px; height: 18px; border: none; border-radius: 50%;
  background: transparent; color: var(--text-2);
  cursor: pointer; font-size: 15px; line-height: 1;
  display: grid; place-items: center;
  transition: background var(--t), color var(--t);
}
.chip-x:hover { background: var(--error-bg); color: var(--error); }
.chip-picker > input[type="text"] {
  width: 100%; background: var(--bg-input);
  border: 1px solid var(--border); border-radius: var(--r-sm);
  padding: 9px 12px; font-size: var(--fs-sm);
}

/* --------------------------------------------------------------- tooltip */
[data-tip] { position: relative; }
[data-tip]::after {
  content: attr(data-tip);
  position: absolute; bottom: calc(100% + 8px); left: 50%;
  transform: translateX(-50%) translateY(4px);
  background: #05060a; color: var(--text);
  border: 1px solid var(--border-strong);
  padding: 6px 10px; border-radius: var(--r-xs);
  font-size: var(--fs-xs); font-weight: 500; white-space: nowrap; max-width: 260px;
  box-shadow: var(--shadow-md);
  opacity: 0; pointer-events: none;
  transition: opacity var(--t), transform var(--t);
  z-index: var(--z-dropdown);
}
[data-tip]:hover::after, [data-tip]:focus-visible::after { opacity: 1; transform: translateX(-50%) translateY(0); }
[data-tip=""]::after { display: none; }

/* --------------------------------------------------------------- skeleton */
.skeleton {
  background: linear-gradient(90deg, var(--bg-card-2) 25%, var(--bg-hover) 50%, var(--bg-card-2) 75%);
  background-size: 840px 100%;
  animation: shimmer 1.4s infinite linear;
  border-radius: var(--r-xs);
}
.skel-line { height: 12px; border-radius: 5px; }
.skel-line.short { width: 45%; }
.content-reveal {
  animation: contentReveal 320ms var(--ease-out) both;
  animation-delay: calc(var(--reveal-i, 0) * 34ms);
}
@keyframes contentReveal {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

/* --------------------------------------------------------------- empty state */
.empty {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; padding: var(--s-9) var(--s-5);
  color: var(--text-2); gap: var(--s-3);
}
.empty .empty-glyph {
  width: 64px; height: 64px; display: grid; place-items: center;
  border-radius: var(--r-lg);
  background: var(--red-tint); color: var(--red-bright);
  margin-bottom: var(--s-2);
}
.empty h3 { color: var(--text); }
.empty p { max-width: 42ch; }

/* --------------------------------------------------------------- stat card */
.stat {
  background: linear-gradient(180deg, var(--bg-card), var(--bg-card-2));
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: var(--s-5);
  display: flex; flex-direction: column; gap: var(--s-2);
  position: relative; overflow: hidden;
  transition: transform var(--t) var(--ease), border-color var(--t), box-shadow var(--t);
}
.stat::before {
  content: ""; position: absolute; inset: 0 0 auto 0; height: 2px;
  background: linear-gradient(90deg, transparent, var(--red-bright), transparent);
  opacity: 0; transition: opacity var(--t);
}
.stat:hover { transform: translateY(-3px); border-color: var(--border-red); box-shadow: var(--shadow-red); }
.stat:hover::before { opacity: 1; }
.stat .stat-icon {
  width: 40px; height: 40px; display: grid; place-items: center;
  border-radius: var(--r-sm); background: var(--red-tint); color: var(--red-bright);
}
.stat .stat-value { font-size: var(--fs-2xl); font-weight: 700; letter-spacing: -0.02em; line-height: 1; }
.stat .stat-label { color: var(--text-2); font-size: var(--fs-xs); text-transform: uppercase; letter-spacing: 0.06em; font-weight: 600; }

/* --------------------------------------------------------------- table */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--r-md); }
table.data { width: 100%; border-collapse: collapse; font-size: var(--fs-sm); min-width: 480px; }
table.data th {
  text-align: left; padding: 11px 14px;
  color: var(--text-2); font-weight: 600; font-size: var(--fs-xs);
  text-transform: uppercase; letter-spacing: 0.05em;
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0;
}
table.data td { padding: 11px 14px; border-bottom: 1px solid var(--border); }
table.data tr:last-child td { border-bottom: none; }
table.data tbody tr { transition: background var(--t-fast); }
table.data tbody tr:hover { background: var(--red-tint-2); }

/* --------------------------------------------------------- segmented control */
.segmented {
  display: inline-flex; gap: 2px; padding: 3px;
  background: var(--bg-input); border: 1px solid var(--border);
  border-radius: var(--r-sm);
}
.segmented button {
  border: none; background: transparent; color: var(--text-2);
  padding: 6px 14px; border-radius: var(--r-xs); cursor: pointer;
  font-size: var(--fs-sm); font-weight: 550;
  transition: background var(--t), color var(--t);
}
.segmented button:hover { color: var(--text); }
.segmented button.active { background: var(--red-tint); color: var(--red-bright); box-shadow: inset 0 0 0 1px var(--border-red); }

/* --------------------------------------------------------------- avatar */
.avatar {
  width: 40px; height: 40px; border-radius: 12px; flex: none;
  object-fit: cover; background: var(--bg-hover);
  display: grid; place-items: center;
  font-size: var(--fs-sm); font-weight: 650; color: var(--text-2);
  border: 1px solid var(--border);
}
.avatar-round { border-radius: 50%; }
.avatar-sm { width: 28px; height: 28px; border-radius: 8px; font-size: var(--fs-xs); }
.avatar-lg { width: 56px; height: 56px; border-radius: 16px; }

/* --------------------------------------------------------------- modal */
.modal-backdrop {
  position: fixed; inset: 0; z-index: var(--z-modal);
  background: rgba(4, 5, 9, 0.80);
  display: grid; place-items: center;
  padding: var(--s-4);
  animation: fadeIn var(--t);
}
.modal {
  width: 100%; max-width: 560px;
  max-height: 90vh; overflow-y: auto;
  background: linear-gradient(180deg, var(--bg-elevated), var(--bg-card));
  border: 1px solid var(--border-strong);
  border-radius: var(--r-xl);
  box-shadow: var(--shadow-lg);
  animation: modalIn var(--t-slow) var(--ease-out);
}
.modal-lg { max-width: 820px; }
@keyframes modalIn { from { opacity: 0; transform: translateY(18px) scale(0.97); } to { opacity: 1; transform: none; } }
.modal-backdrop.is-closing {
  pointer-events: none;
  animation: modalBackdropOut 240ms var(--ease) forwards;
}
.modal-backdrop.is-closing .modal {
  animation: modalOut 240ms cubic-bezier(0.4, 0, 1, 1) forwards;
}
@keyframes modalBackdropOut { to { opacity: 0; } }
@keyframes modalOut {
  from { opacity: 1; transform: translateY(0) scale(1); }
  to { opacity: 0; transform: translateY(20px) scale(0.975); }
}
.modal-head { display: flex; align-items: center; gap: var(--s-3); padding: var(--s-5) var(--s-6); border-bottom: 1px solid var(--border); }
.modal-head h3 { margin: 0; flex: 1; }
.modal-body { padding: var(--s-6); display: flex; flex-direction: column; gap: var(--s-4); }
.modal-foot { display: flex; justify-content: flex-end; gap: var(--s-3); padding: var(--s-4) var(--s-6); border-top: 1px solid var(--border); }
.modal-close {
  width: 32px; height: 32px; border: none; border-radius: var(--r-xs);
  background: transparent; color: var(--text-2); cursor: pointer; font-size: 18px;
  display: grid; place-items: center; transition: background var(--t), color var(--t);
}
.modal-close:hover { background: var(--bg-hover); color: var(--text); }

/* -------------------------------------------------------- command palette */
.command-trigger { gap: 7px; }
.command-trigger kbd,
.command-palette kbd {
  min-width: 22px; padding: 2px 6px;
  border: 1px solid var(--border-strong); border-bottom-color: color-mix(in srgb, var(--border-strong) 72%, var(--text-muted));
  border-radius: 5px; background: var(--bg-input); color: var(--text-muted);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.04);
  font: 600 10px/1.35 var(--font); text-align: center; white-space: nowrap;
}
.command-backdrop {
  position: fixed; inset: 0; z-index: calc(var(--z-modal) + 2);
  display: grid; place-items: start center; padding: min(14vh, 120px) var(--s-4) var(--s-4);
  background: rgba(4, 5, 9, 0.80);
  animation: commandBackdropIn 200ms var(--ease-out);
}
.command-backdrop.is-closing { animation: commandBackdropOut 180ms var(--ease) forwards; pointer-events: none; }
.command-palette {
  width: min(650px, 100%); overflow: hidden;
  background: linear-gradient(180deg, color-mix(in srgb, var(--bg-elevated) 96%, var(--red-tint)), var(--bg-card));
  border: 1px solid var(--border-strong); border-radius: var(--r-xl);
  box-shadow: 0 28px 80px -22px rgba(0, 0, 0, 0.75), 0 0 0 1px rgba(229, 57, 69, 0.06);
  animation: commandPaletteIn 260ms cubic-bezier(0.22, 0.76, 0.28, 1) both;
}
.command-backdrop.is-closing .command-palette { animation: commandPaletteOut 180ms var(--ease) forwards; }
.command-search { display: flex; align-items: center; gap: var(--s-3); padding: 16px 18px; border-bottom: 1px solid var(--border); color: var(--text-muted); }
.command-input {
  flex: 1; min-width: 0; padding: 0; border: 0; outline: 0;
  background: transparent; color: var(--text); font-size: var(--fs-lg); font-weight: 520;
}
.command-input::placeholder { color: var(--text-muted); }
.command-results { max-height: min(55vh, 480px); overflow-y: auto; padding: var(--s-2); overscroll-behavior: contain; }
.command-group-label { padding: 10px 10px 6px; color: var(--text-muted); font-size: 10px; font-weight: 750; letter-spacing: 0.09em; text-transform: uppercase; }
.command-row {
  display: flex; align-items: center; gap: var(--s-3); width: 100%; padding: 10px;
  border: 1px solid transparent; border-radius: var(--r-sm); background: transparent; color: var(--text); text-align: left; cursor: pointer;
}
.command-row.active { border-color: var(--border-red); background: var(--red-tint); }
.command-icon { width: 36px; height: 36px; flex: none; display: grid; place-items: center; border-radius: 10px; background: var(--bg-input); color: var(--text-2); }
.command-row.active .command-icon { background: var(--red-tint); color: var(--red-bright); }
.command-copy { min-width: 0; flex: 1; display: flex; flex-direction: column; gap: 2px; }
.command-copy strong, .command-copy small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.command-copy strong { font-size: var(--fs-sm); }
.command-copy small { color: var(--text-muted); font-size: var(--fs-xs); }
.command-enter { opacity: 0; color: var(--text-muted); font-size: 10px; font-weight: 650; text-transform: uppercase; transition: opacity var(--t-fast); }
.command-row.active .command-enter { opacity: 1; }
.command-empty { min-height: 180px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; color: var(--text-muted); text-align: center; }
.command-empty strong { color: var(--text); }
.command-empty span { font-size: var(--fs-sm); }
.command-foot { display: flex; align-items: center; gap: var(--s-4); padding: 10px 14px; border-top: 1px solid var(--border); color: var(--text-muted); font-size: 10px; }
.command-foot > span { display: inline-flex; align-items: center; gap: 6px; }
.command-foot-spacer { flex: 1; }
@keyframes commandBackdropIn { from { opacity: 0; } }
@keyframes commandBackdropOut { to { opacity: 0; } }
@keyframes commandPaletteIn { from { opacity: 0; transform: translateY(-16px) scale(0.97); } }
@keyframes commandPaletteOut { to { opacity: 0; transform: translateY(-10px) scale(0.985); } }

/* --------------------------------------------------------------- toast */
.toast-region {
  position: fixed; z-index: var(--z-toast);
  bottom: var(--s-5); right: var(--s-5);
  display: flex; flex-direction: column; gap: var(--s-2);
  max-width: min(380px, calc(100vw - 32px));
}
.toast {
  display: flex; align-items: center; gap: var(--s-3);
  background: var(--bg-elevated);
  border: 1px solid var(--border-strong);
  border-left: 3px solid var(--text-muted);
  border-radius: var(--r-sm);
  padding: 12px 14px;
  box-shadow: var(--shadow-lg);
  font-size: var(--fs-sm);
  cursor: pointer;
  animation: toastIn var(--t-slow) var(--ease-out);
}
.toast.leaving { animation: toastOut var(--t) var(--ease) forwards; }
.toast.success { border-left-color: var(--success); }
.toast.error { border-left-color: var(--error); }
.toast.info { border-left-color: var(--info); }
.toast.warning { border-left-color: var(--warning); }
.toast .toast-icon { flex: none; display: grid; place-items: center; }
@keyframes toastIn { from { opacity: 0; transform: translateX(30px); } to { opacity: 1; transform: none; } }
@keyframes toastOut { to { opacity: 0; transform: translateX(30px); } }

/* ------------------------------------------------------- roblox widget */
.roblox-widget {
  position: fixed; z-index: calc(var(--z-toast) - 1);
  right: var(--s-5); bottom: var(--s-5);
  display: flex; flex-direction: column; align-items: flex-end; gap: var(--s-2);
  opacity: 0; transform: translateY(16px);
  transition: opacity var(--t-slow) var(--ease-out), transform var(--t-slow) var(--ease-out);
  pointer-events: none;
}
.roblox-widget.is-shown { opacity: 1; transform: none; pointer-events: auto; }
.roblox-pill {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 8px 14px 8px 10px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  box-shadow: var(--shadow-md);
  color: var(--text-2);
  font-size: var(--fs-sm); font-weight: 600;
  cursor: pointer;
  transition: border-color var(--t), background var(--t), color var(--t), transform var(--t);
}
.roblox-pill:hover { border-color: var(--border-red); color: var(--text); transform: translateY(-1px); }
.roblox-pill.is-verified { color: var(--success); }
.roblox-pill-ic { flex: none; display: grid; place-items: center; }
.roblox-widget.is-expanded .roblox-pill { border-color: var(--border-red); box-shadow: var(--shadow-red); }
.roblox-panel {
  width: min(300px, calc(100vw - 32px));
  background: linear-gradient(180deg, var(--bg-card), var(--bg-card-2));
  border: 1px solid var(--border-strong);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-lg);
  padding: var(--s-4);
  transform-origin: bottom right;
  animation: robloxPanelIn 220ms var(--ease-out) both;
}
.roblox-panel.hidden { display: none; }
@keyframes robloxPanelIn { from { opacity: 0; transform: scale(0.94) translateY(8px); } }
.roblox-panel-body { min-height: 40px; }
.roblox-panel-body > p.muted { margin-bottom: var(--s-3); }
.roblox-linked { display: flex; align-items: center; gap: var(--s-3); }
.roblox-avatar { width: 40px; height: 40px; border-radius: 50%; object-fit: cover; flex: none; }
.roblox-linked-ic { flex: none; display: grid; place-items: center; width: 40px; height: 40px; border-radius: 50%; background: var(--red-tint); color: var(--red-bright); }
.roblox-linked-copy { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.roblox-linked-name { font-size: var(--fs-sm); }
.roblox-panel-body .roblox-linked + .btn { margin-top: var(--s-3); width: 100%; }
@media (max-width: 480px) {
  .roblox-widget { right: var(--s-3); bottom: var(--s-3); }
}

/* --------------------------------------------------------------- misc */
.divider { height: 1px; background: var(--border); border: none; margin: var(--s-5) 0; }
.spinner {
  width: 22px; height: 22px; border: 2px solid var(--border-strong);
  border-top-color: var(--red-bright); border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
.save-pill {
  display: inline-flex; align-items: center; gap: 6px; min-width: 72px;
  font-size: var(--fs-xs); font-weight: 650; color: var(--success);
  opacity: 0; transform: translateY(-4px);
  transition: opacity var(--t), transform var(--t), color var(--t);
}
.save-pill.show { opacity: 1; transform: none; }
.save-pill[data-state="dirty"] { color: var(--warning); }
.save-pill[data-state="saving"] { color: var(--text-2); }
.save-pill[data-state="error"] { color: var(--error); }
.save-pill[data-state="saving"] .save-pill-icon {
  width: 13px; height: 13px; border: 2px solid var(--border-strong); border-top-color: currentColor; border-radius: 50%;
  animation: spin 700ms linear infinite;
}
.save-pill[data-state="saving"] .save-pill-icon svg { display: none; }
.save-pill[data-state="dirty"] .save-pill-icon { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.save-pill[data-state="dirty"] .save-pill-icon svg { display: none; }
.save-pill[data-state="error"] .save-pill-icon svg { display: none; }
.save-pill[data-state="error"] .save-pill-icon::before { content: "!"; font-size: 12px; line-height: 1; }

@media (max-width: 620px) {
  .command-backdrop { padding: var(--s-3); place-items: start center; }
  .command-palette { margin-top: max(8px, env(safe-area-inset-top)); border-radius: var(--r-lg); }
  .command-results { max-height: calc(100vh - 190px); }
  .command-foot > span:last-child { display: none; }
  .command-trigger kbd { display: none; }
}
