/* ==========================================================================
   Patch — design system
   Tokens first, then primitives, then components. No inline styles in
   templates: if you need something here, add a class.
   ========================================================================== */

/* ── Reset ───────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
img, svg { display: block; max-width: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
button { background: none; border: none; cursor: pointer; }
a { color: inherit; text-decoration: none; }
[hidden] { display: none !important; }

/* ── Tokens ──────────────────────────────────────────────────────────── */
:root {
  /* Neutral ramp — cool near-black, not navy */
  --bg:          #08080c;
  --bg-sunken:   #050508;
  --elev-1:      #0f0f16;
  --elev-2:      #15151f;
  --elev-3:      #1c1c28;

  --line:        rgba(255, 255, 255, 0.07);
  --line-strong: rgba(255, 255, 255, 0.13);

  --fg:          #f4f4f8;
  --fg-muted:    #9d9dae;
  --fg-subtle:   #62626f;

  /* Brand — one vivid accent, used sparingly */
  --accent:      #9d6bff;
  --accent-hi:   #b48cff;
  --accent-lo:   #7c3aed;
  --accent-soft: rgba(157, 107, 255, 0.13);
  --accent-line: rgba(157, 107, 255, 0.35);
  --pink:        #f472b6;

  /* Semantic */
  --success:      #4ade80;
  --success-soft: rgba(74, 222, 128, 0.12);
  --warn:         #fbbf24;
  --warn-soft:    rgba(251, 191, 36, 0.12);
  --danger:       #fb7185;
  --danger-soft:  rgba(251, 113, 133, 0.12);

  /* Spacing — 4px base. Use these, not magic rem values. */
  --s1: 0.25rem;  --s2: 0.5rem;   --s3: 0.75rem;  --s4: 1rem;
  --s5: 1.25rem;  --s6: 1.5rem;   --s8: 2rem;     --s10: 2.5rem;
  --s12: 3rem;    --s16: 4rem;    --s20: 5rem;

  /* Radii */
  --r-sm: 6px;  --r: 10px;  --r-lg: 14px;  --r-xl: 20px;  --r-full: 999px;

  /* Elevation — shadow + a top inner highlight so surfaces catch light */
  --sh-1: 0 1px 2px rgba(0,0,0,.4), inset 0 1px 0 rgba(255,255,255,.03);
  --sh-2: 0 4px 16px -4px rgba(0,0,0,.5), inset 0 1px 0 rgba(255,255,255,.04);
  --sh-3: 0 16px 48px -12px rgba(0,0,0,.7), inset 0 1px 0 rgba(255,255,255,.05);
  --sh-glow: 0 8px 32px -8px rgba(124, 58, 237, .45);

  /* Motion */
  --ease: cubic-bezier(.4, 0, .2, 1);
  --ease-out: cubic-bezier(.16, 1, .3, 1);
  --dur: 150ms;

  /* Layout */
  --nav-h: 56px;
  --side-w: 244px;
  --content-max: 1080px;

  --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    transition-duration: .01ms !important;
  }
}

/* ── Base ────────────────────────────────────────────────────────────── */
body {
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-feature-settings: "cv11", "ss01";
  font-variant-ligatures: contextual;
  background: var(--bg);
  color: var(--fg);
  min-height: 100vh;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

::selection { background: var(--accent-lo); color: #fff; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--r-sm);
}

/* Scrollbars */
* { scrollbar-width: thin; scrollbar-color: var(--elev-3) transparent; }
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-thumb {
  background: var(--elev-3);
  border-radius: var(--r-full);
  border: 3px solid transparent;
  background-clip: content-box;
}
*::-webkit-scrollbar-thumb:hover { background: #2a2a3a; background-clip: content-box; }

/* ── Typography ──────────────────────────────────────────────────────── */
.t-display {
  font-size: clamp(2.5rem, 6vw, 4rem);
  font-weight: 700;
  letter-spacing: -0.035em;
  line-height: 1.05;
}
.t-h1 { font-size: 1.5rem;   font-weight: 650; letter-spacing: -0.02em;  line-height: 1.25; }
.t-h2 { font-size: 1.125rem; font-weight: 600; letter-spacing: -0.012em; line-height: 1.3; }
.t-h3 { font-size: 0.9375rem;font-weight: 600; letter-spacing: -0.006em; }
.t-body  { font-size: 0.9375rem; }
.t-sm    { font-size: 0.875rem; }
.t-xs    { font-size: 0.8125rem; }
.t-label {
  font-size: 0.6875rem;
  font-weight: 650;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--fg-subtle);
}
.t-muted  { color: var(--fg-muted); }
.t-subtle { color: var(--fg-subtle); }
.t-accent { color: var(--accent); }
.t-lead   { font-size: 1.0625rem; line-height: 1.65; color: var(--fg-muted); }

.t-grad {
  background: linear-gradient(120deg, var(--fg) 20%, var(--accent-hi) 65%, var(--pink));
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

code, .code {
  font-family: var(--mono);
  font-size: 0.85em;
  background: var(--elev-2);
  border: 1px solid var(--line);
  padding: 0.1em 0.4em;
  border-radius: var(--r-sm);
  color: var(--accent-hi);
  white-space: nowrap;
}

/* ── Icons ───────────────────────────────────────────────────────────── */
.i {
  width: 1.125em;
  height: 1.125em;
  flex-shrink: 0;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.75;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.i-lg { width: 1.5em; height: 1.5em; }
.i-xl { width: 2rem;  height: 2rem; stroke-width: 1.5; }

/* ── Buttons ─────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--s2);
  height: 36px;
  padding: 0 var(--s4);
  border-radius: var(--r-sm);
  font-size: 0.875rem;
  font-weight: 550;
  letter-spacing: -0.005em;
  white-space: nowrap;
  cursor: pointer;
  transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease),
              color var(--dur) var(--ease), transform var(--dur) var(--ease),
              box-shadow var(--dur) var(--ease), opacity var(--dur) var(--ease);
}
.btn:active { transform: translateY(0.5px) scale(0.99); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: 0.45; pointer-events: none; }

.btn-primary {
  background: linear-gradient(180deg, var(--accent) 0%, var(--accent-lo) 100%);
  color: #fff;
  box-shadow: var(--sh-1), 0 2px 12px -4px rgba(124,58,237,.5);
}
.btn-primary:hover {
  background: linear-gradient(180deg, var(--accent-hi) 0%, var(--accent) 100%);
  box-shadow: var(--sh-2), var(--sh-glow);
}

.btn-secondary {
  background: var(--elev-2);
  color: var(--fg);
  border: 1px solid var(--line-strong);
  box-shadow: var(--sh-1);
}
.btn-secondary:hover { background: var(--elev-3); border-color: rgba(255,255,255,.2); }

.btn-ghost { color: var(--fg-muted); }
.btn-ghost:hover { background: var(--elev-2); color: var(--fg); }

.btn-danger {
  background: var(--danger-soft);
  color: var(--danger);
  border: 1px solid rgba(251,113,133,.28);
}
.btn-danger:hover { background: rgba(251,113,133,.2); border-color: var(--danger); }

.btn-sm { height: 30px; padding: 0 var(--s3); font-size: 0.8125rem; border-radius: var(--r-sm); }
.btn-lg { height: 44px; padding: 0 var(--s6); font-size: 0.9375rem; }
.btn-block { width: 100%; }

.btn-icon { width: 32px; height: 32px; padding: 0; border-radius: var(--r-sm); }
.btn-icon.btn-sm { width: 28px; height: 28px; }

/* ── App shell ───────────────────────────────────────────────────────── */
.topbar {
  position: sticky;
  top: 0;
  z-index: 60;
  height: var(--nav-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s4);
  padding: 0 var(--s5);
  background: rgba(8, 8, 12, 0.72);
  backdrop-filter: blur(16px) saturate(1.6);
  -webkit-backdrop-filter: blur(16px) saturate(1.6);
  border-bottom: 1px solid var(--line);
}
.topbar-left, .topbar-right { display: flex; align-items: center; gap: var(--s3); min-width: 0; }
.topbar-left { flex: 1; }
.topbar-right { flex-shrink: 0; }
.crumb { display: inline-flex; align-items: center; gap: var(--s3); min-width: 0; }

.brand {
  display: inline-flex;
  align-items: center;
  gap: var(--s2);
  font-weight: 650;
  font-size: 0.9375rem;
  letter-spacing: -0.01em;
}
.brand-mark {
  width: 26px;
  height: 26px;
  border-radius: 7px;
  display: grid;
  place-items: center;
  color: #fff;
  background: linear-gradient(140deg, var(--accent-hi), var(--accent-lo) 60%, var(--pink));
  box-shadow: 0 2px 10px -2px rgba(124,58,237,.7), inset 0 1px 0 rgba(255,255,255,.3);
}
.brand-mark .i { width: 15px; height: 15px; stroke-width: 2; }

.crumb-sep { color: var(--fg-subtle); }

/* User chip */
.user-chip {
  display: inline-flex;
  align-items: center;
  gap: var(--s2);
  padding: var(--s1) var(--s2) var(--s1) var(--s1);
  border-radius: var(--r-full);
  border: 1px solid transparent;
  transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease);
}
.user-chip:hover { background: var(--elev-2); border-color: var(--line); }
.user-chip img, .avatar {
  width: 26px; height: 26px;
  border-radius: 50%;
  object-fit: cover;
  background: var(--elev-3);
}
.avatar-lg { width: 44px; height: 44px; }
.avatar-fallback {
  display: grid; place-items: center;
  font-weight: 650; font-size: 0.8125rem;
  color: var(--fg-muted);
  background: var(--elev-3);
  border-radius: 50%;
}

/* Shell layout */
.shell {
  display: grid;
  grid-template-columns: var(--side-w) minmax(0, 1fr);
  align-items: start;
}
.sidebar {
  position: sticky;
  top: var(--nav-h);
  height: calc(100vh - var(--nav-h));
  overflow-y: auto;
  padding: var(--s4) var(--s3) var(--s8);
  border-right: 1px solid var(--line);
  background: var(--bg-sunken);
}
.main {
  min-width: 0;
  padding: var(--s8) var(--s8) var(--s20);
}

/* Backdrop for the mobile drawer. Hidden outright above the breakpoint so it
   can never take part in layout — as an in-flow element it would otherwise
   consume a grid column. */
.sidebar-scrim { display: none; }
.main-inner { max-width: var(--content-max); margin: 0 auto; }

/* Server switcher in sidebar */
.server-switch {
  display: flex;
  align-items: center;
  gap: var(--s3);
  width: 100%;
  padding: var(--s2);
  border-radius: var(--r);
  border: 1px solid var(--line);
  background: var(--elev-1);
  margin-bottom: var(--s5);
  transition: border-color var(--dur) var(--ease), background var(--dur) var(--ease);
}
.server-switch:hover { border-color: var(--line-strong); background: var(--elev-2); }
.server-switch .meta { min-width: 0; flex: 1; text-align: left; }
.server-switch .meta strong {
  display: block; font-size: 0.875rem; font-weight: 600;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.server-switch .meta span { font-size: 0.75rem; color: var(--fg-subtle); }

/* Nav items */
.nav-group { margin-bottom: var(--s5); }
.nav-group > .t-label { padding: 0 var(--s3) var(--s2); display: block; }

.nav-item {
  position: relative;
  display: flex;
  align-items: center;
  gap: var(--s3);
  width: 100%;
  padding: var(--s2) var(--s3);
  border-radius: var(--r-sm);
  color: var(--fg-muted);
  font-size: 0.875rem;
  font-weight: 500;
  text-align: left;
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
}
.nav-item .i { color: var(--fg-subtle); transition: color var(--dur) var(--ease); }
.nav-item:hover { background: var(--elev-2); color: var(--fg); }
.nav-item:hover .i { color: var(--fg-muted); }
.nav-item.active { background: var(--accent-soft); color: var(--accent-hi); font-weight: 550; }
.nav-item.active .i { color: var(--accent); }
.nav-item.active::before {
  content: "";
  position: absolute;
  left: calc(var(--s3) * -1 - 1px);
  top: 50%;
  transform: translateY(-50%);
  width: 3px;
  height: 18px;
  border-radius: 0 3px 3px 0;
  background: var(--accent);
}
.nav-item .trail { margin-left: auto; color: var(--fg-subtle); }

/* ── Page header ─────────────────────────────────────────────────────── */
.page-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--s4);
  flex-wrap: wrap;
  margin-bottom: var(--s6);
}
.page-head h1 { font-size: 1.375rem; font-weight: 650; letter-spacing: -0.02em; }
.page-head p  { color: var(--fg-muted); font-size: 0.875rem; margin-top: var(--s1); }
.page-head .actions { display: flex; gap: var(--s2); }

/* ── Cards ───────────────────────────────────────────────────────────── */
.card {
  background: var(--elev-1);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--sh-1);
  margin-bottom: var(--s5);
  overflow: hidden;
}
.card-head {
  display: flex;
  align-items: center;
  gap: var(--s3);
  padding: var(--s4) var(--s5);
  border-bottom: 1px solid var(--line);
}
.card-head .i { color: var(--accent); }
.card-head h2 { font-size: 0.9375rem; font-weight: 600; letter-spacing: -0.008em; }
.card-head p  { font-size: 0.8125rem; color: var(--fg-muted); margin-top: 1px; }
.card-head .actions { margin-left: auto; display: flex; gap: var(--s2); }
.card-body { padding: var(--s5); }
.card-body > :last-child { margin-bottom: 0; }
.card-foot {
  padding: var(--s3) var(--s5);
  border-top: 1px solid var(--line);
  background: var(--bg-sunken);
  display: flex;
  align-items: center;
  gap: var(--s3);
}
.card-note {
  display: flex;
  gap: var(--s3);
  padding: var(--s3) var(--s4);
  border-radius: var(--r);
  background: var(--elev-2);
  border: 1px solid var(--line);
  font-size: 0.8125rem;
  color: var(--fg-muted);
  line-height: 1.6;
}
.card-note .i { color: var(--fg-subtle); margin-top: 2px; }

/* Module tile (dashboard overview grid) */
.tiles {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: var(--s3);
}
.tile {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: var(--s2);
  padding: var(--s4);
  border-radius: var(--r);
  background: var(--elev-1);
  border: 1px solid var(--line);
  box-shadow: var(--sh-1);
  transition: border-color var(--dur) var(--ease), transform var(--dur) var(--ease-out),
              box-shadow var(--dur) var(--ease), background var(--dur) var(--ease);
}
.tile:hover {
  border-color: var(--accent-line);
  background: var(--elev-2);
  transform: translateY(-2px);
  box-shadow: var(--sh-2);
}
.tile-icon {
  width: 34px; height: 34px;
  border-radius: 9px;
  display: grid; place-items: center;
  background: var(--accent-soft);
  color: var(--accent-hi);
  border: 1px solid var(--accent-line);
}
.tile h3 { font-size: 0.875rem; font-weight: 600; }
.tile p  { font-size: 0.8125rem; color: var(--fg-muted); line-height: 1.5; }
.tile .status { position: absolute; top: var(--s4); right: var(--s4); }

/* ── Stat ────────────────────────────────────────────────────────────── */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: var(--s3); }
.stat {
  padding: var(--s4);
  border-radius: var(--r);
  background: var(--elev-1);
  border: 1px solid var(--line);
  box-shadow: var(--sh-1);
}
.stat .n {
  font-size: 1.625rem;
  font-weight: 650;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
  line-height: 1.15;
}
.stat .k { font-size: 0.8125rem; color: var(--fg-muted); margin-top: var(--s1); }

/* ── Forms ───────────────────────────────────────────────────────────── */
.field { margin-bottom: var(--s5); }
.field:last-child { margin-bottom: 0; }
.field > label {
  display: block;
  font-size: 0.8125rem;
  font-weight: 550;
  color: var(--fg);
  margin-bottom: var(--s2);
}
.field .hint { font-size: 0.8125rem; color: var(--fg-subtle); margin-top: var(--s2); line-height: 1.5; }

.input, .select, .textarea {
  width: 100%;
  background: var(--elev-2);
  border: 1px solid var(--line-strong);
  border-radius: var(--r-sm);
  color: var(--fg);
  padding: 0 var(--s3);
  height: 36px;
  font-size: 0.875rem;
  outline: none;
  transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease),
              background var(--dur) var(--ease);
}
.textarea { height: auto; min-height: 88px; padding: var(--s3); resize: vertical; line-height: 1.6; }
.input::placeholder, .textarea::placeholder { color: var(--fg-subtle); }
.input:hover, .select:hover, .textarea:hover { border-color: rgba(255,255,255,.2); }
.input:focus, .select:focus, .textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
  outline: none;
}

.select {
  appearance: none;
  padding-right: var(--s8);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%239d9dae' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right var(--s3) center;
  background-size: 15px;
  cursor: pointer;
}
.select option { background: var(--elev-2); color: var(--fg); }

.input-group { display: flex; gap: var(--s2); }
.input-group .input { flex: 1; }

/* Native colour swatch — strip the chrome so it reads as one of our controls. */
.input-color {
  width: 44px;
  height: 36px;
  padding: 3px;
  background: var(--elev-2);
  border: 1px solid var(--line-strong);
  border-radius: var(--r-sm);
  cursor: pointer;
  flex-shrink: 0;
  transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
.input-color:hover { border-color: rgba(255,255,255,.2); }
.input-color:focus-visible { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.input-color::-webkit-color-swatch-wrapper { padding: 0; }
.input-color::-webkit-color-swatch { border: none; border-radius: 4px; }
.input-color::-moz-color-swatch { border: none; border-radius: 4px; }

/* Toggle rows */
.switch-row {
  display: flex;
  align-items: center;
  gap: var(--s4);
  padding: var(--s4) 0;
  border-bottom: 1px solid var(--line);
}
.switch-row:first-child { padding-top: 0; }
.switch-row:last-child { border-bottom: none; padding-bottom: 0; }
.switch-row .meta { flex: 1; min-width: 0; }
.switch-row .meta strong { display: block; font-size: 0.875rem; font-weight: 550; }
.switch-row .meta span { display: block; font-size: 0.8125rem; color: var(--fg-muted); margin-top: 2px; line-height: 1.5; }

.switch { position: relative; width: 40px; height: 22px; flex-shrink: 0; }
.switch input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.switch-track {
  position: absolute; inset: 0;
  background: var(--elev-3);
  border: 1px solid var(--line-strong);
  border-radius: var(--r-full);
  pointer-events: none;
  transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease);
}
.switch-track::before {
  content: "";
  position: absolute;
  width: 16px; height: 16px;
  left: 2px; top: 2px;
  background: var(--fg-muted);
  border-radius: 50%;
  box-shadow: 0 1px 3px rgba(0,0,0,.5);
  transition: transform var(--dur) var(--ease-out), background var(--dur) var(--ease);
}
.switch input:checked + .switch-track {
  background: linear-gradient(180deg, var(--accent) 0%, var(--accent-lo) 100%);
  border-color: var(--accent);
}
.switch input:checked + .switch-track::before { transform: translateX(18px); background: #fff; }
.switch input:focus-visible + .switch-track { box-shadow: 0 0 0 3px var(--accent-soft); }

/* ── Badges ──────────────────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: var(--s1);
  height: 21px;
  padding: 0 var(--s2);
  border-radius: var(--r-full);
  font-size: 0.75rem;
  font-weight: 550;
  letter-spacing: -0.003em;
  border: 1px solid transparent;
}
.badge .dot { width: 5px; height: 5px; border-radius: 50%; background: currentColor; }
.badge-success { background: var(--success-soft); color: var(--success); border-color: rgba(74,222,128,.25); }
.badge-warn    { background: var(--warn-soft);    color: var(--warn);    border-color: rgba(251,191,36,.25); }
.badge-danger  { background: var(--danger-soft);  color: var(--danger);  border-color: rgba(251,113,133,.25); }
.badge-accent  { background: var(--accent-soft);  color: var(--accent-hi); border-color: var(--accent-line); }
.badge-muted   { background: var(--elev-2);       color: var(--fg-muted); border-color: var(--line); }

/* ── Tables ──────────────────────────────────────────────────────────── */
.table-wrap {
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  overflow: hidden;
  background: var(--elev-1);
  box-shadow: var(--sh-1);
}
.table-scroll { overflow-x: auto; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 0.875rem; }
table.tbl thead th {
  text-align: left;
  padding: var(--s3) var(--s4);
  background: var(--bg-sunken);
  border-bottom: 1px solid var(--line);
  font-size: 0.6875rem;
  font-weight: 650;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--fg-subtle);
  white-space: nowrap;
}
table.tbl tbody td { padding: var(--s3) var(--s4); border-bottom: 1px solid var(--line); vertical-align: middle; }
table.tbl tbody tr:last-child td { border-bottom: none; }
table.tbl tbody tr { transition: background var(--dur) var(--ease); }
table.tbl tbody tr:hover { background: var(--elev-2); }
table.tbl .num { font-variant-numeric: tabular-nums; }
table.tbl .right { text-align: right; }
.row-actions { display: flex; gap: var(--s2); justify-content: flex-end; opacity: 0.55; transition: opacity var(--dur) var(--ease); }
tr:hover .row-actions, .row-actions:focus-within { opacity: 1; }

.swatch { width: 10px; height: 10px; border-radius: 3px; flex-shrink: 0; box-shadow: inset 0 0 0 1px rgba(255,255,255,.15); }

/* ── Empty state ─────────────────────────────────────────────────────── */
.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: var(--s16) var(--s6);
}
.empty-icon {
  width: 52px; height: 52px;
  display: grid; place-items: center;
  border-radius: var(--r-lg);
  background: var(--elev-2);
  border: 1px solid var(--line);
  color: var(--fg-subtle);
  margin-bottom: var(--s4);
}
.empty h3 { font-size: 0.9375rem; font-weight: 600; margin-bottom: var(--s2); }
.empty p  { font-size: 0.875rem; color: var(--fg-muted); max-width: 34ch; line-height: 1.6; margin-bottom: var(--s5); }

/* ── Flash / toast ───────────────────────────────────────────────────── */
.toasts {
  position: fixed;
  top: calc(var(--nav-h) + var(--s3));
  right: var(--s5);
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: var(--s2);
  max-width: 380px;
}
.toast {
  display: flex;
  align-items: flex-start;
  gap: var(--s3);
  padding: var(--s3) var(--s4);
  border-radius: var(--r);
  background: var(--elev-2);
  border: 1px solid var(--line-strong);
  box-shadow: var(--sh-3);
  font-size: 0.875rem;
  animation: toast-in 320ms var(--ease-out) both;
}
.toast .i { margin-top: 1px; }
.toast-success .i { color: var(--success); }
.toast-error   .i { color: var(--danger); }
.toast .close { margin-left: auto; color: var(--fg-subtle); display: grid; place-items: center; }
.toast .close:hover { color: var(--fg); }
@keyframes toast-in {
  from { opacity: 0; transform: translateX(16px) scale(0.97); }
  to   { opacity: 1; transform: none; }
}

/* ── Sticky save bar ─────────────────────────────────────────────────── */
.savebar {
  position: fixed;
  left: 50%;
  bottom: var(--s6);
  transform: translate(-50%, calc(100% + var(--s10)));
  z-index: 150;
  display: flex;
  align-items: center;
  gap: var(--s4);
  padding: var(--s3) var(--s3) var(--s3) var(--s5);
  border-radius: var(--r-full);
  background: rgba(21, 21, 31, 0.9);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--line-strong);
  box-shadow: var(--sh-3);
  transition: transform 320ms var(--ease-out), opacity 200ms var(--ease);
  opacity: 0;
  pointer-events: none;
}
.savebar.show { transform: translate(-50%, 0); opacity: 1; pointer-events: auto; }
.savebar .msg { font-size: 0.875rem; color: var(--fg-muted); white-space: nowrap; }
.savebar .msg b { color: var(--fg); font-weight: 600; }
.savebar .group { display: flex; gap: var(--s2); }

/* ── Skeleton ────────────────────────────────────────────────────────── */
.skel {
  background: linear-gradient(90deg, var(--elev-2) 25%, var(--elev-3) 50%, var(--elev-2) 75%);
  background-size: 200% 100%;
  animation: skel 1.4s ease-in-out infinite;
  border-radius: var(--r-sm);
}
@keyframes skel { from { background-position: 200% 0; } to { background-position: -200% 0; } }

/* ── Segmented control / tabs ────────────────────────────────────────── */
.tabs {
  display: flex;
  gap: var(--s1);
  padding: var(--s1);
  background: var(--elev-1);
  border: 1px solid var(--line);
  border-radius: var(--r);
  width: fit-content;
  max-width: 100%;
  overflow-x: auto;
}
.tab {
  padding: var(--s2) var(--s4);
  border-radius: var(--r-sm);
  font-size: 0.875rem;
  font-weight: 550;
  color: var(--fg-muted);
  white-space: nowrap;
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
}
.tab:hover { color: var(--fg); }
.tab.active { background: var(--elev-3); color: var(--fg); box-shadow: var(--sh-1); }

/* ── Landing page ────────────────────────────────────────────────────── */
.hero {
  position: relative;
  overflow: hidden;
  padding: var(--s20) var(--s6) var(--s16);
  text-align: center;
}
/* Ambient light — replaces the flat background */
.hero::before {
  content: "";
  position: absolute;
  top: -30%;
  left: 50%;
  width: min(1100px, 130vw);
  aspect-ratio: 1;
  transform: translateX(-50%);
  background:
    radial-gradient(circle at 50% 50%, rgba(124,58,237,.30), transparent 62%),
    radial-gradient(circle at 68% 38%, rgba(244,114,182,.16), transparent 55%);
  filter: blur(20px);
  pointer-events: none;
  z-index: -1;
}
/* Grid floor for depth */
.hero::after {
  content: "";
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(rgba(255,255,255,.028) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,.028) 1px, transparent 1px);
  background-size: 56px 56px;
  mask-image: radial-gradient(ellipse 80% 60% at 50% 0%, #000 30%, transparent 75%);
  -webkit-mask-image: radial-gradient(ellipse 80% 60% at 50% 0%, #000 30%, transparent 75%);
  pointer-events: none;
  z-index: -1;
}
.hero-inner { max-width: 760px; margin: 0 auto; position: relative; }

.pill {
  display: inline-flex;
  align-items: center;
  gap: var(--s2);
  height: 28px;
  padding: 0 var(--s3);
  border-radius: var(--r-full);
  background: var(--elev-1);
  border: 1px solid var(--line-strong);
  font-size: 0.8125rem;
  color: var(--fg-muted);
  margin-bottom: var(--s6);
  box-shadow: var(--sh-1);
}
.pill .i { width: 14px; height: 14px; color: var(--accent); }

.hero .t-lead { max-width: 56ch; margin: var(--s5) auto var(--s8); }
.hero-cta { display: flex; gap: var(--s3); justify-content: center; flex-wrap: wrap; }

.section { padding: var(--s16) var(--s6); max-width: 1160px; margin: 0 auto; }
.section-head { text-align: center; max-width: 620px; margin: 0 auto var(--s10); }
.section-head h2 { font-size: clamp(1.6rem, 3.4vw, 2.1rem); font-weight: 650; letter-spacing: -0.028em; }
.section-head p  { color: var(--fg-muted); margin-top: var(--s3); font-size: 0.9375rem; line-height: 1.65; }

.feature-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); gap: var(--s4); }
.feature {
  padding: var(--s6);
  border-radius: var(--r-lg);
  background: var(--elev-1);
  border: 1px solid var(--line);
  box-shadow: var(--sh-1);
  transition: border-color var(--dur) var(--ease), transform var(--dur) var(--ease-out);
}
.feature:hover { border-color: var(--line-strong); transform: translateY(-2px); }
.feature .tile-icon { margin-bottom: var(--s4); }
.feature h3 { font-size: 0.9375rem; font-weight: 600; margin-bottom: var(--s2); }
.feature p  { font-size: 0.875rem; color: var(--fg-muted); line-height: 1.65; }

.footer {
  border-top: 1px solid var(--line);
  padding: var(--s8) var(--s6);
  margin-top: var(--s10);
}
.footer-inner {
  max-width: 1160px; margin: 0 auto;
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--s4); flex-wrap: wrap;
  font-size: 0.8125rem; color: var(--fg-subtle);
}
.footer-inner a:hover { color: var(--fg-muted); }

/* Server picker */
.server-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: var(--s3); }
.server-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--s3);
  padding: var(--s6) var(--s4);
  border-radius: var(--r-lg);
  background: var(--elev-1);
  border: 1px solid var(--line);
  box-shadow: var(--sh-1);
  text-align: center;
  transition: border-color var(--dur) var(--ease), transform var(--dur) var(--ease-out),
              box-shadow var(--dur) var(--ease), background var(--dur) var(--ease);
}
.server-card:hover {
  border-color: var(--accent-line);
  background: var(--elev-2);
  transform: translateY(-3px);
  box-shadow: var(--sh-2);
}
.server-card img, .server-card .avatar-fallback { width: 56px; height: 56px; font-size: 1.25rem; }
.server-card strong { font-size: 0.875rem; font-weight: 600; }
.server-card .go {
  font-size: 0.8125rem; color: var(--fg-subtle);
  display: inline-flex; align-items: center; gap: var(--s1);
  transition: color var(--dur) var(--ease);
}
.server-card:hover .go { color: var(--accent-hi); }
.server-card:hover .go .i { transform: translateX(2px); }
.server-card .go .i { width: 14px; height: 14px; transition: transform var(--dur) var(--ease-out); }

/* ── Editor layout (embed / panel / automation editors) ──────────────── */
.editor-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 380px;
  gap: var(--s5);
  align-items: start;
}
.editor-side { position: sticky; top: calc(var(--nav-h) + var(--s5)); }
@media (max-width: 1100px) {
  .editor-layout { grid-template-columns: minmax(0, 1fr); }
  .editor-side { position: static; }
}

/* Title you edit in place, in the page header */
.title-input {
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  font: inherit;
  font-size: 1.375rem;
  font-weight: 650;
  letter-spacing: -0.02em;
  color: var(--fg);
  padding: 2px 0;
  outline: none;
  width: 100%;
  max-width: 32ch;
  transition: border-color var(--dur) var(--ease);
}
.title-input:hover { border-bottom-color: var(--line-strong); }
.title-input:focus { border-bottom-color: var(--accent); }

/* Collapsible section */
.collapse { border: 1px solid var(--line); border-radius: var(--r-lg); background: var(--elev-1); margin-bottom: var(--s4); overflow: hidden; }
.collapse-head {
  display: flex;
  align-items: center;
  gap: var(--s3);
  width: 100%;
  padding: var(--s4) var(--s5);
  text-align: left;
  font-size: 0.9375rem;
  font-weight: 600;
  letter-spacing: -0.008em;
  transition: background var(--dur) var(--ease);
}
.collapse-head:hover { background: var(--elev-2); }
.collapse-head .i:first-child { color: var(--accent); }
.collapse-head .chevron { margin-left: auto; color: var(--fg-subtle); transition: transform 200ms var(--ease); }
.collapse[open] .collapse-head .chevron, .collapse.open .collapse-head .chevron { transform: rotate(180deg); }
.collapse-body { padding: 0 var(--s5) var(--s5); }
.collapse:not(.open) .collapse-body { display: none; }

/* Repeatable row (reaction-role entries, automation blocks) */
.entry-row {
  display: flex;
  align-items: center;
  gap: var(--s3);
  background: var(--elev-2);
  border: 1px solid var(--line);
  border-radius: var(--r);
  padding: var(--s3);
  margin-bottom: var(--s2);
}
.entry-row .input, .entry-row .select { height: 32px; font-size: 0.8125rem; }
.drag-handle { color: var(--fg-subtle); cursor: grab; display: grid; place-items: center; }
.drag-handle:active { cursor: grabbing; }

/* Dashed "add another" button */
.btn-add {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--s2);
  width: 100%;
  padding: var(--s3);
  border: 1px dashed var(--line-strong);
  border-radius: var(--r);
  background: none;
  color: var(--fg-subtle);
  font-size: 0.875rem;
  font-weight: 550;
  transition: border-color var(--dur) var(--ease), color var(--dur) var(--ease), background var(--dur) var(--ease);
}
.btn-add:hover { border-color: var(--accent-line); color: var(--accent-hi); background: var(--accent-soft); }

/* Compact file-upload trigger sitting next to a URL field */
.upload-btn {
  display: grid;
  place-items: center;
  width: 36px; height: 36px;
  flex-shrink: 0;
  border-radius: var(--r-sm);
  background: var(--elev-2);
  border: 1px solid var(--line-strong);
  color: var(--fg-muted);
  cursor: pointer;
  transition: border-color var(--dur) var(--ease), color var(--dur) var(--ease);
}
.upload-btn:hover { border-color: var(--accent); color: var(--accent-hi); }

/* ── Modal ───────────────────────────────────────────────────────────── */
.modal {
  position: fixed;
  inset: 0;
  z-index: 300;
  display: grid;
  place-items: center;
  padding: var(--s5);
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  animation: fade-in 160ms var(--ease) both;
}
.modal[hidden] { display: none; }
.modal-box {
  width: 460px;
  max-width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  background: var(--elev-1);
  border: 1px solid var(--line-strong);
  border-radius: var(--r-lg);
  box-shadow: var(--sh-3);
  animation: modal-in 220ms var(--ease-out) both;
}
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes modal-in {
  from { opacity: 0; transform: translateY(8px) scale(0.98); }
  to   { opacity: 1; transform: none; }
}

/* ── Utilities ───────────────────────────────────────────────────────── */
.row { display: flex; align-items: center; gap: var(--s3); }
.row-tight { display: flex; align-items: center; gap: var(--s2); }
.col { display: flex; flex-direction: column; gap: var(--s3); }
.between { justify-content: space-between; }
.wrap { flex-wrap: wrap; }
.push { margin-left: auto; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s4); }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--s4); }
.mt-2 { margin-top: var(--s2); } .mt-4 { margin-top: var(--s4); } .mt-6 { margin-top: var(--s6); }
.mb-2 { margin-bottom: var(--s2); } .mb-4 { margin-bottom: var(--s4); } .mb-6 { margin-bottom: var(--s6); }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.divider { height: 1px; background: var(--line); margin: var(--s5) 0; }

/* ── Responsive ──────────────────────────────────────────────────────── */
@media (max-width: 1024px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed;
    top: var(--nav-h);
    left: 0;
    width: var(--side-w);
    z-index: 80;
    transform: translateX(-100%);
    transition: transform 260ms var(--ease-out);
    box-shadow: var(--sh-3);
  }
  .sidebar.open { transform: none; }
  .sidebar-scrim {
    display: block;
    position: fixed; inset: var(--nav-h) 0 0; z-index: 70;
    background: rgba(0,0,0,.6);
    backdrop-filter: blur(2px);
    opacity: 0; pointer-events: none;
    transition: opacity 200ms var(--ease);
  }
  .sidebar-scrim.show { opacity: 1; pointer-events: auto; }
  .main { padding: var(--s6) var(--s5) var(--s20); }
}
@media (min-width: 1025px) { .menu-btn { display: none; } }

/* The topbar runs out of room first: shed the pieces the sidebar already
   covers (server switcher) before anything is allowed to overflow. */
@media (max-width: 720px) {
  .nav-servers { display: none; }
  .user-chip .user-name { display: none; }
  .user-chip { padding: var(--s1); }
}
@media (max-width: 520px) {
  .crumb { display: none; }
}

@media (max-width: 640px) {
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .main { padding: var(--s5) var(--s4) var(--s20); }
  .topbar { padding: 0 var(--s4); gap: var(--s2); }
  .editor-layout { gap: var(--s4); }
  /* Stacked inputs beat a squeezed row on a phone. */
  .entry-row { flex-wrap: wrap; }
  .entry-row .input, .entry-row .select { flex: 1 1 100% !important; width: auto !important; }
  .entry-row .drag-handle { display: none; }
  .toasts { left: var(--s4); right: var(--s4); max-width: none; }
  .savebar { left: var(--s4); right: var(--s4); transform: translateY(calc(100% + var(--s10))); border-radius: var(--r-lg); }
  .savebar.show { transform: none; }
  .savebar .msg { white-space: normal; }
  .hero { padding: var(--s12) var(--s5) var(--s10); }
  .section { padding: var(--s10) var(--s5); }
}
