/* ========================================
   MCPRACK DESIGN SYSTEM
   Vitex Software — "cyber hippies" / Západ slunce (sunset)
   Dark evening sky by default; light "dawn" via data-theme="light"
   ======================================== */

:root {
  /* Brand accents (sunset) */
  --p1: #ff6f9f;          /* pink */
  --p2: #5ee7ff;          /* turquoise */
  --p3: #ff9d57;          /* orange */
  --p4: #ffd166;          /* gold */
  --p5: #b69cff;          /* lavender */

  /* Functional Colors mapped to brand accents */
  --color-admin: var(--p2);
  --color-catalog: var(--p4);
  --color-vault: var(--p5);
  --color-registry: var(--p3);
  --color-proxy: var(--p2);
  --color-primary: var(--p1);

  /* Semantic Colors */
  --color-success: #3dd6a5;
  --color-warning: var(--p4);
  --color-error: #ff6b7a;
  --color-info: var(--p2);

  /* Surfaces — dark evening sky */
  --color-bg: #1d1440;
  --color-bg-secondary: rgba(255, 255, 255, 0.06);
  --color-bg-tertiary: rgba(255, 255, 255, 0.1);
  --color-surface: #2a1a55;
  --color-border: rgba(255, 160, 200, 0.22);
  --color-border-secondary: rgba(255, 160, 200, 0.44);
  --color-text: #fff4f8;
  --color-text-secondary: #cdbbe0;
  --color-text-tertiary: #9a88b8;
  --color-text-inverse: #ffffff;
  --color-accent: var(--p1);
  --color-accent-2: var(--p3);

  /* Spacing — compact defaults (was xs/sm/md/lg/xl/2xl = .25/.5/1/1.5/2/3) */
  --space-xs: 0.2rem;
  --space-sm: 0.375rem;
  --space-md: 0.75rem;
  --space-lg: 1rem;
  --space-xl: 1.25rem;
  --space-2xl: 1.75rem;

  /* Typography — Sora + Caveat (Vitex brand) */
  --font-family-base: "Sora", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-family-hand: "Caveat", cursive;
  --font-family-mono: "SF Mono", Monaco, "Cascadia Code", "Roboto Mono", Consolas, monospace;
  --font-size-xs: 0.7rem;
  --font-size-sm: 0.8125rem;
  --font-size-base: 0.9375rem;
  --font-size-lg: 1.05rem;
  --font-size-xl: 1.15rem;
  --font-size-2xl: 1.35rem;
  --font-size-3xl: 1.6rem;
  --font-size-4xl: 1.9rem;
  --font-weight-normal: 300;
  --font-weight-medium: 500;
  --font-weight-semibold: 600;
  --font-weight-bold: 600;

  /* Sizing */
  --border-radius-sm: 0.375rem;
  --border-radius-md: 0.5rem;
  --border-radius-lg: 0.75rem;
  --border-radius-xl: 0.875rem;
  --border-radius-full: 9999px;
  --header-h: 52px;

  /* Shadows */
  --shadow-sm: 0 10px 30px -18px rgba(0, 0, 0, 0.6);
  --shadow-md: 0 18px 50px rgba(20, 5, 40, 0.35);
  --shadow-lg: 0 20px 60px rgba(20, 5, 40, 0.45);

  /* Transitions */
  --transition-fast: 150ms ease-in-out;
  --transition-normal: 250ms ease-in-out;
  --transition-slow: 350ms ease-in-out;

  /* Z-index */
  --z-dropdown: 10;
  --z-modal: 100;

  /* Container */
  --max-width: 1200px;

  color-scheme: dark;
}

/* Light "dawn" — matches vitexsoftware.com data-theme="light" */
:root[data-theme="light"] {
  --p1: #e2447c;
  --p2: #0a9fc2;
  --p3: #e8702a;
  --p4: #c98f00;
  --p5: #7a5ce6;

  --color-admin: var(--p2);
  --color-catalog: var(--p4);
  --color-vault: var(--p5);
  --color-registry: var(--p3);
  --color-proxy: var(--p2);
  --color-primary: var(--p1);

  --color-success: #0d9f6e;
  --color-warning: var(--p4);
  --color-error: #d9384a;
  --color-info: var(--p2);

  --color-bg: #fff6f1;
  --color-bg-secondary: rgba(255, 255, 255, 0.66);
  --color-bg-tertiary: rgba(255, 255, 255, 0.92);
  --color-surface: #fdeae6;
  --color-border: rgba(160, 60, 110, 0.15);
  --color-border-secondary: rgba(160, 60, 110, 0.32);
  --color-text: #2a1640;
  --color-text-secondary: #76618a;
  --color-text-tertiary: #9a88a8;
  --color-text-inverse: #ffffff;

  --shadow-sm: 0 8px 24px -16px rgba(120, 40, 90, 0.18);
  --shadow-md: 0 18px 50px rgba(120, 40, 90, 0.12);
  --shadow-lg: 0 24px 60px rgba(120, 40, 90, 0.16);

  color-scheme: light;
}

/* ========================================
   BASE STYLES
   ======================================== */

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: var(--font-family-base);
  font-size: var(--font-size-base);
  font-weight: var(--font-weight-normal);
  line-height: 1.45;
  color: var(--color-text);
  background-color: var(--color-bg);
  background-image:
    radial-gradient(ellipse 80% 50% at 10% -10%, color-mix(in srgb, var(--p5) 28%, transparent), transparent 55%),
    radial-gradient(ellipse 60% 40% at 90% 0%, color-mix(in srgb, var(--p3) 18%, transparent), transparent 50%),
    radial-gradient(ellipse 50% 30% at 50% 100%, color-mix(in srgb, var(--p1) 12%, transparent), transparent 55%);
  background-attachment: fixed;
  transition: background-color 0.5s, color 0.5s;
}

:root[data-theme="light"] body {
  background-image:
    radial-gradient(ellipse 80% 50% at 10% -10%, color-mix(in srgb, var(--p5) 18%, transparent), transparent 55%),
    radial-gradient(ellipse 60% 40% at 90% 0%, color-mix(in srgb, var(--p3) 14%, transparent), transparent 50%),
    radial-gradient(ellipse 50% 30% at 50% 100%, color-mix(in srgb, var(--p1) 10%, transparent), transparent 55%);
}

/* ========================================
   HEADER & NAVIGATION
   ======================================== */

header {
  background: color-mix(in srgb, var(--color-bg) 84%, transparent);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--color-border);
  box-shadow: 0 1px 0 var(--color-border);
  position: sticky;
  top: 0;
  z-index: 50;
  transition: background-color 0.4s, box-shadow 0.4s;
}

.header-content {
  display: flex;
  align-items: center;
  justify-content: space-between;
  max-width: var(--max-width);
  margin: 0 auto;
  padding: var(--space-sm) var(--space-md);
  min-height: var(--header-h);
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 8px;
  text-decoration: none;
  color: var(--color-text);
  font-weight: 400;
  font-size: 0.95rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  transition: opacity var(--transition-fast);
}

.header-brand > span {
  background: linear-gradient(90deg, var(--p2), var(--p3));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  font-weight: 600;
  letter-spacing: 0.18em;
}

.header-brand:hover {
  opacity: 0.9;
}

.header-brand-logo {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.header-brand-logo img,
.header-brand-logo svg {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.header-left {
  display: flex;
  align-items: center;
  gap: var(--space-md);
}

.header-github-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: var(--border-radius-full);
  color: var(--color-text-secondary);
  transition: color var(--transition-fast), background-color var(--transition-fast);
}

.header-github-link:hover {
  color: var(--p2);
  border: 1px solid var(--color-border);
  background-color: var(--color-bg-secondary);
}

.header-nav {
  display: flex;
  align-items: center;
  gap: var(--space-lg);
  margin-left: auto;
  margin-right: var(--space-lg);
}

.header-nav-link {
  color: var(--color-text-secondary);
  text-decoration: none;
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-medium);
  padding: var(--space-sm) var(--space-md);
  border-radius: var(--border-radius-md);
  transition: color var(--transition-fast), background-color var(--transition-fast);
}

.header-nav-link:hover,
.header-nav-link.active {
  color: var(--color-admin);
  background-color: var(--color-bg-tertiary);
}

.header-nav-link.is-admin {
  color: var(--color-admin);
}

.header-user {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  position: relative;
}

.theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: var(--border-radius-full);
  border: 1px solid var(--color-border);
  background-color: var(--color-bg-secondary);
  color: var(--color-text);
  cursor: pointer;
  font-size: var(--font-size-base);
  line-height: 1;
  transition: border-color 0.3s, color 0.3s;
}

.theme-toggle:hover {
  color: var(--p2);
  border-color: var(--p2);
}

/* Dark is brand default — show sun (switch to dawn). Light shows moon. */
.theme-toggle .icon-dark { display: inline; }
.theme-toggle .icon-light { display: none; }

:root[data-theme="light"] .theme-toggle .icon-dark { display: none; }
:root[data-theme="light"] .theme-toggle .icon-light { display: inline; }

.language-switcher {
  display: inline-flex;
  border: 1px solid var(--color-border);
  border-radius: var(--border-radius-full);
  padding: 3px;
  gap: 0 !important;
  margin-right: 0 !important;
}

.language-switcher a {
  font-size: 0.85rem;
  padding: 4px 9px;
  border-radius: var(--border-radius-full);
  text-decoration: none;
  line-height: 1;
}

.language-switcher a.lang-link {
  opacity: 0.5;
}

.language-switcher a.lang-link.active {
  opacity: 1;
}

.header-user-avatar {
  width: 28px;
  height: 28px;
  font-size: var(--font-size-sm);
  border-radius: var(--border-radius-full);
  background: linear-gradient(135deg, var(--p1), var(--p3));
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--color-text-inverse);
  font-weight: var(--font-weight-semibold);
  cursor: pointer;
  transition: transform var(--transition-fast);
}

.header-user-avatar:hover {
  transform: scale(1.05);
}

.header-user-menu {
  position: relative;
  display: inline-block;
}

.header-user-menu-button {
  background: none;
  border: none;
  color: var(--color-text);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  font-size: var(--font-size-sm);
  padding: 0;
  transition: color var(--transition-fast);
}

.header-user-menu-button:hover {
  color: var(--p2);
}

.header-user-menu-dropdown {
  position: absolute;
  top: 100%;
  right: 0;
  background: color-mix(in srgb, var(--color-bg) 94%, transparent);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1px solid var(--color-border);
  border-radius: 14px;
  box-shadow: var(--shadow-lg);
  min-width: 200px;
  margin-top: var(--space-sm);
  padding: 8px;
  display: none;
  z-index: var(--z-dropdown);
}

.header-user-menu-dropdown.show {
  display: block;
}

.header-user-menu-item {
  display: block;
  width: 100%;
  text-align: left;
  padding: 7px 10px;
  color: var(--color-text);
  text-decoration: none;
  border: none;
  background: none;
  cursor: pointer;
  font-size: 0.9rem;
  border-radius: 8px;
  transition: background-color var(--transition-fast), color var(--transition-fast);
}

.header-user-menu-item:hover {
  background-color: var(--color-bg-tertiary);
  color: var(--color-text);
}

.header-user-menu-item.danger {
  color: var(--color-error);
}

.header-user-menu-item.danger:hover {
  background-color: color-mix(in srgb, var(--color-error) 14%, transparent);
}

.header-user-menu-divider {
  height: 1px;
  background-color: var(--color-border);
  margin: var(--space-xs) 0;
}

/* ========================================
   MAIN CONTENT
   ======================================== */

main {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: var(--space-md) var(--space-md);
  min-height: calc(100vh - var(--header-h));
}

/* ========================================
   HEADINGS
   ======================================== */

h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-family-base);
  font-weight: var(--font-weight-semibold);
  font-style: normal;
  letter-spacing: -0.02em;
  line-height: 1.2;
  text-transform: none;
  margin-top: var(--space-lg);
  margin-bottom: var(--space-sm);
}

h1 {
  font-size: var(--font-size-2xl);
  margin-top: 0;
}

h2 {
  font-size: var(--font-size-lg);
  color: var(--color-text);
  border-bottom: 1px solid var(--color-border);
  padding-bottom: var(--space-xs);
}

h3 {
  font-size: var(--font-size-xl);
}

h4 {
  font-size: var(--font-size-base);
}

/* ========================================
   PARAGRAPHS & TEXT
   ======================================== */

p {
  margin-bottom: var(--space-sm);
  color: var(--color-text);
}

p.text-muted {
  color: var(--color-text-secondary);
  font-size: var(--font-size-sm);
}

small {
  font-size: var(--font-size-xs);
  color: var(--color-text-secondary);
}

code {
  background-color: var(--color-bg-tertiary);
  color: var(--p2);
  padding: var(--space-xs) var(--space-sm);
  border-radius: var(--border-radius-sm);
  font-family: var(--font-family-mono);
  font-size: 0.85em;
  font-weight: 500;
}

::selection {
  background: color-mix(in srgb, var(--p3) 40%, transparent);
}

/* ========================================
   LINKS
   ======================================== */

a {
  color: var(--color-accent);
  text-decoration: none;
  text-underline-offset: 3px;
  transition: color var(--transition-fast);
}

a:hover {
  color: var(--p2);
  text-decoration: underline;
}

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

/* ========================================
   BUTTONS
   ======================================== */

button,
input[type="submit"],
input[type="button"],
input[type="reset"],
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-xs);
  padding: 0.4rem 0.85rem;
  border: none;
  border-radius: var(--border-radius-full);
  font-family: var(--font-family-base);
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-medium);
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.3s, background 0.3s, color 0.3s, border-color 0.3s;
  white-space: nowrap;
  text-decoration: none;
  line-height: 1.2;
}

button:hover,
input[type="submit"]:hover,
input[type="button"]:hover,
.btn:hover {
  transform: translateY(-1px);
}

/* Primary Button — sunset gradient */
button:not([class]),
input[type="submit"],
.btn-primary {
  background: linear-gradient(100deg, var(--p1), var(--p3));
  color: var(--color-text-inverse);
  box-shadow: none;
  border: 0;
  margin-top: 0;
}

button:not([class]):hover,
input[type="submit"]:hover,
.btn-primary:hover {
  background: linear-gradient(100deg, var(--p1), var(--p3));
  color: var(--color-text-inverse);
  box-shadow: 0 10px 34px -8px color-mix(in srgb, var(--p3) 70%, transparent);
  transform: translateY(-1px);
}

button:not([class]):focus-visible,
input[type="submit"]:focus-visible,
.btn-primary:focus-visible {
  outline: 2px solid var(--p1);
  outline-offset: 2px;
}

button:not([class]):disabled,
input[type="submit"]:disabled,
.btn-primary:disabled {
  background: var(--color-text-tertiary);
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

/* Secondary Button — outlined glass */
.btn-secondary {
  background-color: transparent;
  color: var(--color-text);
  border: 1.5px solid var(--color-border-secondary);
  margin-top: 0;
}

.btn-secondary:hover {
  border-color: var(--p2);
  color: var(--p2);
  background-color: transparent;
}

/* Success Button */
.btn-success {
  background-color: var(--color-success);
  color: var(--color-text-inverse);
  margin-top: 0;
}

.btn-success:hover {
  filter: brightness(1.08);
}

/* Danger Button */
.btn-danger {
  background-color: var(--color-error);
  color: var(--color-text-inverse);
  margin-top: 0;
}

.btn-danger:hover {
  filter: brightness(1.08);
}

/* Small Button */
.btn-sm {
  padding: var(--space-xs) var(--space-md);
  font-size: var(--font-size-xs);
  margin-top: 0;
}

.btn-sm:not([class]) {
  margin-top: 0;
}

/* Inline Form Button */
form.inline button {
  margin-top: 0;
}

/* ========================================
   FORMS
   ======================================== */

form {
  margin: var(--space-md) 0;
}

.form-group {
  margin-bottom: var(--space-lg);
}

label {
  display: block;
  margin-bottom: var(--space-sm);
  font-weight: var(--font-weight-medium);
  color: var(--color-text);
  margin-top: var(--space-md);
}

label small {
  font-weight: var(--font-weight-normal);
}

input[type="text"],
input[type="password"],
input[type="email"],
input[type="url"],
input[type="number"],
input[type="date"],
input[type="time"],
input[type="search"],
select,
textarea {
  width: 100%;
  padding: var(--space-sm) var(--space-md);
  border: 1px solid var(--color-border);
  border-radius: 12px;
  font-family: var(--font-family-base);
  font-size: var(--font-size-base);
  color: var(--color-text);
  background-color: var(--color-bg-secondary);
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast), background-color var(--transition-fast);
}

input[type="text"]:focus,
input[type="password"]:focus,
input[type="email"]:focus,
input[type="url"]:focus,
input[type="number"]:focus,
input[type="date"]:focus,
input[type="time"]:focus,
input[type="search"]:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--p1);
  background-color: var(--color-bg-tertiary);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--p1) 30%, transparent);
}

textarea {
  resize: vertical;
  min-height: 8rem;
  font-family: var(--font-family-mono);
}

/* Checkbox */
input[type="checkbox"],
input[type="radio"] {
  cursor: pointer;
  width: 18px;
  height: 18px;
  accent-color: var(--color-admin);
}

input[type="checkbox"]:focus-visible,
input[type="radio"]:focus-visible {
  outline: 2px solid var(--color-admin);
  outline-offset: 2px;
}

/* ========================================
   ENHANCED FORM STYLES - Card-based Layout
   ======================================== */

.form-container {
  border: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: var(--space-md);
}

.form-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-md);
  margin-bottom: var(--space-lg);
  flex-wrap: wrap;
}

.form-header h1 {
  margin: 0;
  flex: 1;
  min-width: 200px;
}

.server-icon-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-sm);
  text-align: center;
}

.server-icon-container .server-icon {
  border-radius: var(--border-radius-lg);
  background: var(--color-bg-secondary);
  padding: var(--space-sm);
  box-shadow: var(--shadow-sm);
}

.form-card {
  background: var(--color-bg-secondary);
  border: 1px solid var(--color-border);
  border-radius: var(--border-radius-xl);
  padding: var(--space-md);
  box-shadow: var(--shadow-sm);
  backdrop-filter: blur(6px);
  transition: box-shadow var(--transition-normal), border-color var(--transition-normal);
}

.form-card:hover {
  box-shadow: var(--shadow-md);
  border-color: var(--color-border-secondary);
}

.form-card-title {
  font-size: var(--font-size-lg);
  font-weight: var(--font-weight-semibold);
  color: var(--color-text);
  margin: 0 0 var(--space-md) 0;
  padding-bottom: var(--space-sm);
  border-bottom: 1px solid var(--color-border);
}

.form-card-description {
  color: var(--color-text-secondary);
  font-size: var(--font-size-sm);
  margin-bottom: var(--space-md);
  line-height: 1.45;
}

.form-group {
  margin-bottom: var(--space-md);
}

.form-group:last-child {
  margin-bottom: 0;
}

.form-control {
  width: 100%;
  padding: var(--space-sm) var(--space-md);
  border: 1px solid var(--color-border);
  border-radius: 12px;
  font-family: var(--font-family-base);
  font-size: var(--font-size-base);
  color: var(--color-text);
  background-color: var(--color-bg-secondary);
  transition: all var(--transition-fast);
}

.form-control:hover {
  border-color: var(--color-border-secondary);
}

.form-control:focus {
  outline: none;
  border-color: var(--p1);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--p1) 30%, transparent);
  background-color: var(--color-bg-tertiary);
}

.form-control:disabled,
.form-control:read-only {
  background-color: var(--color-bg-secondary);
  color: var(--color-text-secondary);
  cursor: not-allowed;
  opacity: 0.7;
}

label {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  margin-bottom: var(--space-sm);
  font-weight: var(--font-weight-medium);
  color: var(--color-text);
}

label small {
  font-weight: var(--font-weight-normal);
  color: var(--color-text-secondary);
}

.label-text {
  flex: 1;
}

.label-badge {
  display: inline-block;
  background: var(--color-bg-tertiary);
  color: var(--color-text-secondary);
  font-size: var(--font-size-xs);
  font-weight: var(--font-weight-semibold);
  padding: 0.25rem 0.625rem;
  border-radius: var(--border-radius-full);
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

.label-badge.required {
  background: rgba(220, 38, 38, 0.1);
  color: var(--color-error);
}

.form-hint {
  display: block;
  font-size: var(--font-size-sm);
  color: var(--color-text-secondary);
  margin-top: var(--space-sm);
  line-height: 1.5;
}

.form-hint strong {
  color: var(--color-text);
  font-weight: var(--font-weight-semibold);
}

.form-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: var(--space-md);
}

.checkbox-group {
  padding: var(--space-sm) var(--space-md);
  background: var(--color-bg-secondary);
  border-radius: var(--border-radius-md);
  border-left: 3px solid var(--color-admin);
}

.checkbox-group label {
  margin-bottom: 0;
  cursor: pointer;
}

.checkbox-group input[type="checkbox"] {
  width: 20px;
  height: 20px;
  margin-right: var(--space-sm);
  accent-color: var(--color-admin);
}

.checkbox-group .form-hint {
  margin-left: 28px;
  margin-top: var(--space-xs);
}

.env-rows-wrapper {
  background: var(--color-bg-secondary);
  border: 1px solid var(--color-border);
  border-radius: var(--border-radius-md);
  padding: var(--space-sm) var(--space-md);
  margin-bottom: var(--space-md);
}

.env-rows-actions {
  display: flex;
  gap: var(--space-sm);
  flex-wrap: wrap;
}

.form-actions {
  display: flex;
  gap: var(--space-sm);
  padding-top: var(--space-md);
  border-top: 1px solid var(--color-border);
  margin-top: var(--space-md);
}

.btn-lg {
  padding: 0.55rem 1.1rem;
  font-size: var(--font-size-base);
  font-weight: var(--font-weight-semibold);
  min-width: 140px;
}

/* Responsive Design */
@media (max-width: 768px) {
  .form-header {
    flex-direction: column;
    gap: var(--space-lg);
  }

  .form-card {
    padding: var(--space-md);
  }

  .form-row {
    grid-template-columns: 1fr;
  }

  .form-actions {
    flex-direction: column;
  }

  .btn-lg {
    width: 100%;
  }
}

/* ========================================
   TABLES
   ======================================== */

table {
  width: 100%;
  border-collapse: collapse;
  margin: var(--space-md) 0;
  font-size: var(--font-size-sm);
}

th,
td {
  padding: var(--space-xs) var(--space-sm);
  text-align: left;
  border-bottom: 1px solid var(--color-border);
}

th {
  background-color: var(--color-bg-secondary);
  font-weight: var(--font-weight-semibold);
  color: var(--color-text);
}

tr:hover {
  background-color: var(--color-bg-secondary);
}

tr.row-warn {
  background-color: rgba(217, 119, 6, 0.1);
}

/* ========================================
   SECTIONS
   ======================================== */

.section {
  background-color: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--border-radius-lg);
  padding: var(--space-md);
  margin-bottom: var(--space-md);
}

.section h1,
.section h2,
.section h3,
.section h4 {
  margin-top: 0;
}

/* ========================================
   SERVER ROW / CARD LAYOUT
   ======================================== */

.server-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: var(--space-sm);
}

.server-row {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: var(--space-xs);
  padding: var(--space-sm);
  background-color: var(--color-bg-secondary);
  border: 1px solid var(--color-border);
  border-radius: var(--border-radius-lg);
  backdrop-filter: blur(6px);
  transition: border-color 0.3s, transform 0.3s, box-shadow 0.3s;
}

.server-row:hover {
  border-color: var(--color-border-secondary);
  box-shadow: var(--shadow-sm);
  transform: translateY(-1px);
}

.server-row-header {
  display: flex;
  align-items: center;
  gap: var(--space-xs);
}

.server-icon {
  width: 24px;
  height: 24px;
  flex-shrink: 0;
  object-fit: contain;
}

.server-checkbox {
  flex-shrink: 0;
  width: 18px;
  height: 18px;
}

.server-info {
  flex: 1;
  cursor: pointer;
  min-width: 0;
}

.server-row-footer {
  display: flex;
  align-items: center;
  gap: var(--space-xs);
  flex-wrap: wrap;
}

.meta {
  flex: 1;
}

.label {
  font-weight: var(--font-weight-semibold);
  color: var(--color-text);
  font-size: var(--font-size-sm);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.desc {
  font-size: var(--font-size-xs);
  color: var(--color-text-secondary);
}

.server-transport {
  display: inline-block;
  padding: var(--space-xs) var(--space-sm);
  background-color: var(--color-bg-tertiary);
  color: var(--color-text-secondary);
  border-radius: var(--border-radius-md);
  font-size: var(--font-size-xs);
  font-weight: var(--font-weight-medium);
}

.server-transport.stdio {
  background-color: rgba(16, 185, 129, 0.1);
  color: var(--color-catalog);
}

.server-transport.http {
  background-color: rgba(139, 92, 246, 0.1);
  color: var(--color-vault);
}

.server-actions {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  flex-shrink: 0;
}

/* ========================================
   ACTION LINKS / CLIENT DOWNLOAD CARDS
   ======================================== */

.action-links {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: var(--space-sm);
}

.client-card {
  padding: var(--space-sm) var(--space-md);
  border: 1px solid var(--color-border);
  border-radius: var(--border-radius-md);
}

.client-card h4 {
  margin-top: 0;
  margin-bottom: var(--space-xs);
}

.client-card p {
  margin-bottom: var(--space-sm);
}

.client-card-actions {
  display: flex;
  gap: var(--space-sm);
  flex-wrap: wrap;
}

/* ========================================
   INDIVIDUAL CONNECTOR ROWS (name/URL copy, catalog page)
   ======================================== */

.connector-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
}

.connector-row {
  display: flex;
  flex-direction: column;
  gap: var(--space-xs);
  padding: var(--space-sm) var(--space-md);
  border: 1px solid var(--color-border);
  border-radius: var(--border-radius-md);
  background-color: var(--color-bg-secondary);
}

.connector-label {
  font-weight: var(--font-weight-semibold);
  font-size: var(--font-size-sm);
}

.connector-content {
  display: flex;
  align-items: stretch;
  gap: var(--space-sm);
  min-height: 0;
}

/* Square icon column: stretches to the height of the name/URL fields,
   then aspect-ratio makes width match that height. */
.connector-icon-wrap {
  position: relative;
  flex: 0 0 auto;
  align-self: stretch;
  aspect-ratio: 1 / 1;
  min-height: 2.5rem;
  max-height: 3rem;
}

.connector-icon {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  border-radius: var(--border-radius-md);
}

.connector-fields {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: var(--space-xs);
  justify-content: center;
}

.connector-field {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  flex-wrap: wrap;
}

.connector-field-label {
  flex-shrink: 0;
  width: 3.5em;
  font-size: var(--font-size-xs);
  color: var(--color-text-secondary);
}

.connector-value {
  flex: 1;
  min-width: 0;
  overflow-x: auto;
  white-space: nowrap;
  padding: var(--space-xs) var(--space-sm);
  background-color: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--border-radius-sm);
  font-size: var(--font-size-xs);
}

.aggregate-url {
  font-size: calc(var(--font-size-xs) * 2);
}

/* ========================================
   PER-SERVER CONNECTOR POPUP (catalog page)
   ======================================== */

.connector-popup {
  z-index: var(--z-modal);
  width: min(480px, calc(100vw - 2 * var(--space-lg)));
  padding: var(--space-lg);
  background-color: var(--color-surface);
  color: var(--color-text);
  border: 1px solid var(--color-border);
  border-radius: var(--border-radius-lg);
  box-shadow: var(--shadow-lg);
}

.connector-popup::backdrop {
  background-color: rgb(0 0 0 / 0.5);
}

.connector-popup-title {
  margin-top: 0;
  margin-bottom: var(--space-md);
}

.connector-popup .connector-field {
  margin-bottom: var(--space-sm);
}

.connector-popup-actions {
  display: flex;
  justify-content: flex-end;
  margin-top: var(--space-md);
}

/* ========================================
   CONFIG FILE PATHS (download/view pages)
   ======================================== */

.config-paths {
  margin-top: var(--space-sm);
  border: 1px solid var(--color-border);
  border-radius: var(--border-radius-md);
  padding: var(--space-sm) var(--space-md);
  background-color: var(--color-bg-secondary);
}

.config-paths summary {
  cursor: pointer;
  font-weight: var(--font-weight-medium);
  font-size: var(--font-size-sm);
}

.config-paths table {
  margin: var(--space-sm) 0 var(--space-md) 0;
}

.config-paths table:last-child {
  margin-bottom: 0;
}

.config-paths td {
  padding: var(--space-xs) var(--space-sm);
}

.config-paths td:first-child {
  font-weight: var(--font-weight-medium);
  white-space: nowrap;
  color: var(--color-text-secondary);
}

/* ========================================
   BADGES
   ======================================== */

.badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-xs);
  padding: var(--space-xs) var(--space-sm);
  border-radius: var(--border-radius-full);
  font-size: var(--font-size-xs);
  font-weight: var(--font-weight-medium);
  white-space: nowrap;
}

.badge-success,
.badge-ok {
  background-color: rgba(16, 185, 129, 0.2);
  color: var(--color-success);
}

.badge-warning,
.badge-warn {
  background-color: rgba(217, 119, 6, 0.2);
  color: var(--color-warning);
}

.badge-error {
  background-color: rgba(220, 38, 38, 0.2);
  color: var(--color-error);
}

.badge-info {
  background-color: color-mix(in srgb, var(--p2) 22%, transparent);
  color: var(--color-info);
}

.env-row-required {
  border-left: 4px solid var(--color-warning);
  background-color: color-mix(in srgb, var(--p4) 12%, transparent);
  padding-left: var(--space-sm);
  border-radius: var(--border-radius-sm, 4px);
}

.env-row-missing {
  border-left-color: var(--color-error);
  background-color: color-mix(in srgb, var(--color-error) 14%, transparent);
}

.env-row-missing input[name^="env_value__"] {
  border-color: var(--color-error);
  box-shadow: 0 0 0 1px var(--color-error);
}

.env-row-error {
  border-left: 4px solid var(--color-error);
  background-color: color-mix(in srgb, var(--color-error) 14%, transparent);
  padding-left: var(--space-sm);
  border-radius: var(--border-radius-sm, 4px);
}

.env-row-error input[name^="env_key__"] {
  border-color: var(--color-error);
  box-shadow: 0 0 0 1px var(--color-error);
}

.env-row-error-hint {
  display: block;
  margin: 0 0 var(--space-xs) var(--space-sm);
  color: var(--color-error);
  font-weight: 600;
}

.env-row-missing-hint {
  display: block;
  margin: 0 0 var(--space-xs) var(--space-sm);
  color: var(--color-error);
  font-weight: 600;
}

.env-row-missing-hint[hidden],
.env-row-error-hint[hidden],
.env-missing-summary[hidden] {
  display: none;
}

.env-missing-summary {
  margin-bottom: var(--space-sm);
  padding: var(--space-xs) var(--space-sm);
  border-left: 4px solid var(--color-error);
  background-color: color-mix(in srgb, var(--color-error) 14%, transparent);
  color: var(--color-error);
  font-weight: 600;
  border-radius: var(--border-radius-sm, 4px);
}

.env-row-wrap {
  margin-bottom: var(--space-sm);
}

.env-row-hint {
  display: block;
  margin: 0 0 var(--space-xs) var(--space-sm);
  opacity: 0.85;
}

.badge-admin {
  background-color: color-mix(in srgb, var(--p2) 22%, transparent);
  color: var(--color-admin);
}

.badge-catalog {
  background-color: color-mix(in srgb, var(--p4) 22%, transparent);
  color: var(--color-catalog);
}

.badge-vault {
  background-color: color-mix(in srgb, var(--p5) 22%, transparent);
  color: var(--color-vault);
}

.badge-registry {
  background-color: color-mix(in srgb, var(--p3) 22%, transparent);
  color: var(--color-registry);
}

.badge-proxy {
  background-color: color-mix(in srgb, var(--p2) 22%, transparent);
  color: var(--color-proxy);
}

.badge-stdio {
  background-color: rgba(16, 185, 129, 0.2);
  color: var(--color-catalog);
}

.badge-http {
  background-color: rgba(139, 92, 246, 0.2);
  color: var(--color-vault);
}

.badge-users {
  background-color: rgba(59, 130, 246, 0.2);
  color: var(--color-primary, #3b82f6);
}

/* ========================================
   ALERTS / FLASH MESSAGES
   ======================================== */

.flashes {
  list-style: none;
  margin: 0 0 var(--space-md) 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
}

.flashes li {
  padding: var(--space-sm) var(--space-md);
  border-radius: var(--border-radius-md);
  font-size: var(--font-size-sm);
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  box-shadow: var(--shadow-sm);
}

.flash-success {
  background-color: color-mix(in srgb, var(--color-success) 14%, transparent);
  color: var(--color-success);
  border-left: 4px solid var(--color-success);
}

.flash-error {
  background-color: color-mix(in srgb, var(--color-error) 14%, transparent);
  color: var(--color-error);
  border-left: 4px solid var(--color-error);
}

.flash-warning {
  background-color: color-mix(in srgb, var(--color-warning) 14%, transparent);
  color: var(--color-warning);
  border-left: 4px solid var(--color-warning);
}

/* ========================================
   WIZARD / DIAGNOSTIC STEPS
   ======================================== */

ol.wizard {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
  margin: var(--space-md) 0;
  padding: 0;
}

.wizard-step {
  display: flex;
  align-items: flex-start;
  gap: var(--space-sm);
  padding: var(--space-sm) var(--space-md);
  background-color: var(--color-bg-secondary);
  border-left: 3px solid var(--color-border);
  border-radius: var(--border-radius-md);
  transition: all var(--transition-fast);
}

.wizard-step.wizard-ok {
  border-left-color: var(--color-success);
  background-color: rgba(16, 185, 129, 0.05);
}

.wizard-step.wizard-fail {
  border-left-color: var(--color-error);
  background-color: rgba(220, 38, 38, 0.05);
}

.wizard-step.wizard-warn {
  border-left-color: var(--color-warning);
  background-color: rgba(217, 119, 6, 0.05);
}

.wizard-step.wizard-skipped {
  border-left-color: var(--color-border);
  opacity: 0.6;
}

.wizard-icon {
  font-size: var(--font-size-lg);
  flex-shrink: 0;
  width: 1.5rem;
  height: 1.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
}

.wizard-ok .wizard-icon {
  color: var(--color-success);
}

.wizard-fail .wizard-icon {
  color: var(--color-error);
}

.wizard-warn .wizard-icon {
  color: var(--color-warning);
}

.wizard-skipped .wizard-icon {
  color: var(--color-text-tertiary);
}

.wizard-label {
  font-weight: var(--font-weight-semibold);
  color: var(--color-text);
  margin-bottom: var(--space-xs);
}

.wizard-detail {
  font-size: var(--font-size-sm);
  color: var(--color-text-secondary);
}

.wizard-skipped .wizard-detail {
  color: var(--color-text-tertiary);
}

/* ========================================
   UTILITY CLASSES
   ======================================== */

.inline {
  display: inline;
}

.text-center {
  text-align: center;
}

.text-muted {
  color: var(--color-text-secondary);
}

.text-sm {
  font-size: var(--font-size-sm);
}

.text-xs {
  font-size: var(--font-size-xs);
}

/* Spacing & layout utilities (replacements for former inline styles, so
   the CSP can drop style-src 'unsafe-inline') */
.m-0 { margin: 0; }
.mb-0 { margin-bottom: 0; }
.mt-sm { margin-top: var(--space-sm); }
.mt-md { margin-top: var(--space-md); }
.mt-lg { margin-top: var(--space-lg); }
.mb-xs { margin-bottom: var(--space-xs); }
.mb-md { margin-bottom: var(--space-md); }
.mb-lg { margin-bottom: var(--space-lg); }
.mb-2xl { margin-bottom: var(--space-2xl); }
.p-lg { padding: var(--space-lg); }
.w-full { width: 100%; }
.nowrap { white-space: nowrap; }
.table-scroll { overflow-x: auto; }
.flex { display: flex; }
.flex-wrap { flex-wrap: wrap; }
.flex-center { display: flex; align-items: center; }
.flex-gap-sm { display: flex; gap: var(--space-sm); }
.flex-gap { display: flex; gap: var(--space-md); }
.flex-gap-wrap { display: flex; gap: var(--space-md); flex-wrap: wrap; }
.flex-end { display: flex; justify-content: flex-end; gap: var(--space-md); }
.hidden { display: none; }
.block { display: block; }
.cursor-pointer { cursor: pointer; }
.flex-between { justify-content: space-between; }
.align-self-center { align-self: center; }
.inline-flex-center { display: inline-flex; align-items: center; }
.font-medium { font-weight: var(--font-weight-medium); }
.items-end { align-items: end; }
.narrow-hint { max-width: 32ch; }

/* Layout components (same — replacements for former inline styles) */
.card {
  background-color: var(--color-bg-secondary);
  border: 1px solid var(--color-border);
  border-radius: var(--border-radius-lg);
  padding: var(--space-md);
}

.card-tertiary {
  background-color: var(--color-bg-tertiary);
  border-radius: var(--border-radius-lg);
  padding: var(--space-md);
  font-size: var(--font-size-sm);
}

.card-outline {
  border: 1px solid var(--color-border);
  border-radius: var(--border-radius-lg);
  padding: var(--space-md);
}

.note-box {
  padding: var(--space-sm) var(--space-md);
  background: var(--color-bg-secondary);
  border: 1px solid var(--color-border);
  border-radius: var(--border-radius-md);
  font-size: var(--font-size-sm);
}

.auth-card {
  width: 100%;
  max-width: 400px;
  min-width: 0;
  margin: var(--space-xl) auto;
  overflow-wrap: anywhere;
}

.auth-card > .card {
  padding: var(--space-lg);
}

.auth-card ol {
  padding-inline-start: 1.5rem;
}

.auth-card li + li {
  margin-top: var(--space-xs);
}

.auth-card-wide {
  max-width: 480px;
}

.auth-card-header {
  text-align: center;
  margin-bottom: var(--space-lg);
}

.consent-details {
  margin: 0;
  padding-left: 1.25rem;
  line-height: 1.5;
}

.consent-details li + li {
  margin-top: var(--space-sm);
}

.dialog-card {
  max-width: 700px;
  border-radius: var(--border-radius-lg);
  padding: var(--space-lg);
}

.modal-scroll {
  max-height: 60vh;
  overflow-y: auto;
}

.fieldset-card {
  border: 1px solid var(--color-border);
  border-radius: var(--border-radius-lg);
  padding: var(--space-md);
}

.grid-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: var(--space-lg);
  margin-bottom: var(--space-xl);
}

.success-flash {
  display: none;
  padding: var(--space-md);
  background-color: rgba(16, 185, 129, 0.1);
  color: var(--color-success);
  border-radius: var(--border-radius-lg);
  border-left: 4px solid var(--color-success);
  font-size: var(--font-size-sm);
}

.success-flash.show {
  display: block;
}

.btn-pending {
  opacity: 0.6;
  cursor: not-allowed;
}

/* Off-screen scratch element for the execCommand copy fallback
   (copy-connector.js) — must not be visible or focusable. */
.copy-scratch {
  position: fixed;
  opacity: 0;
}

/* Live field validation (server name uniqueness, env rows) */
.input-error {
  border-color: var(--color-error) !important;
  box-shadow: 0 0 0 1px var(--color-error);
}

.field-error-hint {
  display: block;
  margin-top: var(--space-xs);
  color: var(--color-error);
  font-size: var(--font-size-sm);
  font-weight: 600;
}

.field-error-hint[hidden] {
  display: none;
}

.env-row {
  display: flex;
  gap: var(--space-sm);
  align-items: center;
  margin-bottom: var(--space-xs);
}

.env-input-key { flex: 1; }
.env-input-value { flex: 2; }

.env-row-label {
  display: flex;
  align-items: center;
  gap: var(--space-xs);
  white-space: nowrap;
}

/* ========================================
   SERVER FORM STEPPER
   ======================================== */

.stepper {
  margin-bottom: var(--space-lg);
}

.stepper-steps {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-md);
  list-style: none;
  margin: 0 0 var(--space-md);
  padding: 0;
}

.stepper-step {
  display: flex;
  align-items: center;
  gap: var(--space-xs);
  color: var(--color-text-tertiary);
  font-size: var(--font-size-sm);
}

.stepper-step-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background-color: var(--color-border);
}

.stepper-step.active {
  color: var(--color-text);
  font-weight: var(--font-weight-medium);
}

.stepper-step.active .stepper-step-dot {
  background-color: var(--color-primary);
}

.stepper-step.done {
  color: var(--color-text-secondary);
}

.stepper-step.done .stepper-step-dot {
  background-color: var(--color-success);
}

.stepper-actions {
  display: flex;
  gap: var(--space-md);
  justify-content: flex-end;
}

/* [hidden] must win over any display set by a component class */
.form-card[hidden],
.form-actions[hidden],
.stepper[hidden] {
  display: none;
}

/* ========================================
   RESPONSIVE DESIGN
   ======================================== */

@media (max-width: 768px) {
  .header-content {
    padding: var(--space-md);
  }

  .header-nav {
    display: none;
  }

  main {
    padding: var(--space-lg) var(--space-md);
  }

  h1 {
    font-size: var(--font-size-3xl);
  }

  .server-grid {
    grid-template-columns: 1fr;
  }

  .server-actions {
    width: 100%;
    justify-content: flex-start;
  }

  table {
    font-size: var(--font-size-xs);
  }

  th,
  td {
    padding: var(--space-sm);
  }
}

@media (max-width: 480px) {
  h1 {
    font-size: var(--font-size-2xl);
  }

  h2 {
    font-size: var(--font-size-xl);
  }

  input[type="text"],
  input[type="password"],
  input[type="email"],
  select,
  textarea {
    font-size: 16px; /* Prevents zoom on iOS */
  }
}

/* ========================================
   FOOTER
   ======================================== */

.site-footer {
  border-top: 1px solid var(--color-border);
  margin-top: var(--space-lg);
}

.site-footer-content {
  display: flex;
  align-items: center;
  justify-content: space-between;
  max-width: var(--max-width);
  margin: 0 auto;
  padding: var(--space-sm) var(--space-md);
  color: var(--color-text-tertiary);
  font-size: var(--font-size-xs);
}

.site-footer-content a {
  color: var(--color-text-secondary);
  text-decoration: none;
}

.site-footer-content a:hover {
  color: var(--color-text);
  text-decoration: underline;
}

/* Loading spinner overlay */
.loading-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: color-mix(in srgb, var(--color-bg) 55%, transparent);
  backdrop-filter: blur(4px);
  z-index: 9999;
  justify-content: center;
  align-items: center;
}

.loading-overlay.active {
  display: flex;
}

.loading-spinner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-md);
}

.spinner {
  width: 60px;
  height: 60px;
  border: 6px solid var(--color-border);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.loading-text {
  font-size: var(--font-size-sm);
  color: var(--color-text-secondary);
  font-weight: 500;
}

/* ========================================
   OVERRIDE EDITOR & KNOWN KEYS
   ======================================== */

.override-rows-wrapper {
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
  margin-bottom: var(--space-md);
}

.override-row-wrap {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--border-radius-md);
  padding: var(--space-sm) var(--space-md);
  transition: border-color var(--transition-fast);
}

.override-row-wrap:hover {
  border-color: var(--color-border-secondary);
}

.override-row {
  display: flex;
  gap: var(--space-sm);
  align-items: center;
  flex-wrap: wrap;
}

.override-col-key {
  flex: 1 1 200px;
}

.override-col-value {
  flex: 2 1 280px;
}

.override-col-opts {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  flex: 0 0 auto;
}

.override-col-actions {
  display: flex;
  align-items: center;
  gap: var(--space-xs);
  flex: 0 0 auto;
}

.override-label-sensitive {
  display: flex;
  align-items: center;
  gap: var(--space-xs);
  font-size: var(--font-size-xs);
  color: var(--color-text-secondary);
  cursor: pointer;
  white-space: nowrap;
}

.override-status-badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  font-size: var(--font-size-xs);
  font-weight: 500;
  border-radius: var(--border-radius-sm);
  white-space: nowrap;
}

.status-inherited {
  background: var(--color-bg-secondary);
  color: var(--color-text-secondary);
  border: 1px solid var(--color-border);
}

.status-overridden {
  background: color-mix(in srgb, var(--color-info) 16%, transparent);
  color: var(--color-info);
  border: 1px solid color-mix(in srgb, var(--color-info) 40%, transparent);
}

.status-custom {
  background: color-mix(in srgb, var(--color-success) 16%, transparent);
  color: var(--color-success);
  border: 1px solid color-mix(in srgb, var(--color-success) 40%, transparent);
}

.known-keys-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--border-radius-lg);
  padding: var(--space-lg);
  margin-bottom: var(--space-xl);
}

.known-keys-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: var(--space-sm);
  margin-top: var(--space-md);
}

.known-key-chip {
  background: var(--color-bg-secondary);
  border: 1px solid var(--color-border);
  border-radius: var(--border-radius-md);
  padding: var(--space-sm) var(--space-md);
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.known-key-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--space-xs);
}

.known-key-name {
  font-family: monospace;
  font-weight: 600;
  font-size: var(--font-size-sm);
}

.known-key-desc {
  font-size: var(--font-size-xs);
  color: var(--color-text-secondary);
  margin: 0;
}

.badge-tag {
  display: inline-block;
  padding: 1px 6px;
  font-size: 10px;
  text-transform: uppercase;
  font-weight: 600;
  border-radius: 4px;
}

.badge-tag-required {
  background: color-mix(in srgb, var(--color-error) 18%, transparent);
  color: var(--color-error);
}

.badge-tag-secret {
  background: color-mix(in srgb, var(--color-warning) 18%, transparent);
  color: var(--color-warning);
}

.badge-tag-admin {
  background: color-mix(in srgb, var(--color-admin) 18%, transparent);
  color: var(--color-admin);
}

/* Known-keys panel scaffolding */
.known-keys-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--space-sm);
  flex-wrap: wrap;
}

.known-keys-title {
  display: flex;
  align-items: baseline;
  gap: var(--space-xs);
  flex-wrap: wrap;
}

.known-key-badges {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}

.known-key-default {
  margin: 0;
  overflow-wrap: anywhere;
}

.known-key-action {
  margin-top: var(--space-xs);
}

/* Override editor page scaffolding */
.override-page-container {
  max-width: 1000px;
}

.override-toolbar {
  align-items: center;
  flex-wrap: wrap;
}

.override-row-required .override-col-key input {
  border-color: var(--color-border-secondary);
}

.override-desc-hint {
  display: block;
  margin: var(--space-xs) 0 0 0;
}

/* Error pages (templates/error.html) */
.error-card {
  max-width: 600px;
  margin: var(--space-2xl) auto;
}

.error-code {
  font-size: 3rem;
  margin-bottom: var(--space-xs);
}

/* TOTP setup: the QR code (inline SVG from mcprack/qr.py) */
.qr-code-wrap {
  display: flex;
  justify-content: center;
  margin: var(--space-md, 1rem) 0;
}
.qr-code {
  display: block;
  width: 100%;
  max-width: 240px;
  height: auto;
  aspect-ratio: 1;
  background: #fff; /* scanners need a light quiet zone, also in dark themes */
  border-radius: 4px;
}

/* ========================================
   APP SHELL — grouped sidebar (UX redesign)
   ======================================== */

.app-shell {
  display: flex;
  align-items: stretch;
  min-height: calc(100vh - var(--header-h));
}

.app-body {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.app-body > main { width: 100%; flex: 1; }

.sidebar {
  width: 216px;
  flex-shrink: 0;
  padding: 10px 8px;
  border-right: 1px solid var(--color-border);
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow-y: auto;
  position: sticky;
  top: var(--header-h);
  align-self: flex-start;
  max-height: calc(100vh - var(--header-h));
}

.nav-group { display: flex; flex-direction: column; gap: 1px; }

.nav-group-title {
  font-size: 10.5px;
  font-weight: var(--font-weight-semibold);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--color-text-tertiary);
  padding: 0 10px 4px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  height: 32px;
  padding: 0 10px;
  border-radius: 8px;
  color: var(--color-text-secondary);
  font-size: var(--font-size-sm);
  text-decoration: none;
  white-space: nowrap;
}

.nav-item:hover { background: var(--color-bg-secondary); color: var(--color-text); text-decoration: none; }

.nav-item.active {
  background: color-mix(in srgb, var(--p1) 16%, transparent);
  color: var(--color-text);
  font-weight: var(--font-weight-medium);
  box-shadow: inset 2px 0 0 var(--p1);
}

.nav-item.active .nav-icon { color: var(--p1); }
.nav-icon { flex-shrink: 0; }
.nav-label { flex: 1; overflow: hidden; text-overflow: ellipsis; }

.sidebar-toggle {
  width: 30px;
  height: 30px;
  padding: 0;
  flex-shrink: 0;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--color-text-secondary);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  margin-right: var(--space-sm);
}
.sidebar-toggle:hover { background: var(--color-bg-tertiary); color: var(--color-text); }

.sidebar-scrim { display: none; }

/* Collapsed (desktop): icons only */
.sidebar-collapsed .sidebar { width: 52px; }
.sidebar-collapsed .nav-label,
.sidebar-collapsed .nav-group-title { display: none; }
.sidebar-collapsed .nav-item { justify-content: center; padding: 0; }

/* Mobile: sidebar becomes an overlay */
@media (max-width: 800px) {
  .sidebar {
    position: fixed;
    top: var(--header-h);
    left: 0;
    bottom: 0;
    z-index: 60;
    width: 240px;
    background: var(--color-surface);
    transform: translateX(-100%);
    transition: transform 0.2s;
  }
  .sidebar-open .sidebar { transform: none; box-shadow: var(--shadow-lg); }
  .sidebar-open .sidebar-scrim {
    display: block;
    position: fixed;
    inset: var(--header-h) 0 0 0;
    background: rgba(0, 0, 0, 0.4);
    z-index: 55;
  }
  .sidebar-collapsed .sidebar { width: 240px; }
  .sidebar-collapsed .nav-label,
  .sidebar-collapsed .nav-group-title { display: revert; }
  .sidebar-collapsed .nav-item { justify-content: flex-start; padding: 0 10px; }
}

/* ========================================
   DATATABLES (vendored 1.11.5) — themed with the sunset tokens.
   Default DataTables CSS is not shipped; sort arrows are CSS-only.
   ======================================== */

.dataTables_wrapper { color: var(--color-text-secondary); font-size: var(--font-size-sm); }
.dataTables_wrapper .dataTables_filter,
.dataTables_wrapper .dataTables_length { margin-bottom: var(--space-sm); }
.dataTables_wrapper .dataTables_filter { float: right; }
.dataTables_wrapper .dataTables_length { float: left; }
.dataTables_wrapper .dataTables_filter input {
  margin-left: var(--space-sm);
  height: 30px;
  padding: 0 12px;
  border: 1px solid var(--color-border);
  border-radius: 10px;
  background: var(--color-bg-secondary);
  color: var(--color-text);
}
.dataTables_wrapper .dataTables_filter input:focus {
  outline: none;
  border-color: var(--p1);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--p1) 28%, transparent);
}
.dataTables_wrapper .dataTables_length select {
  height: 30px;
  margin: 0 var(--space-xs);
  border: 1px solid var(--color-border);
  border-radius: 10px;
  background: var(--color-bg-secondary);
  color: var(--color-text);
}
.dataTables_wrapper table.dataTable { clear: both; width: 100%; }
.dataTables_wrapper .dataTables_info { float: left; padding-top: var(--space-md); }
.dataTables_wrapper .dataTables_paginate { float: right; padding-top: var(--space-sm); }
.dataTables_wrapper .dataTables_paginate .paginate_button {
  display: inline-block;
  min-width: 30px;
  margin-left: 2px;
  padding: 4px 10px;
  border: 1px solid transparent;
  border-radius: 999px;
  color: var(--color-text-secondary);
  text-align: center;
  cursor: pointer;
}
.dataTables_wrapper .dataTables_paginate .paginate_button:hover {
  background: var(--color-bg-tertiary);
  color: var(--color-text);
}
.dataTables_wrapper .dataTables_paginate .paginate_button.current {
  background: color-mix(in srgb, var(--p1) 16%, transparent);
  border-color: var(--p1);
  color: var(--color-text);
  font-weight: var(--font-weight-medium);
}
.dataTables_wrapper .dataTables_paginate .paginate_button.disabled {
  opacity: 0.4;
  cursor: default;
  pointer-events: none;
}
.dataTables_wrapper::after { content: ""; display: table; clear: both; }

table.dataTable thead th.sorting,
table.dataTable thead th.sorting_asc,
table.dataTable thead th.sorting_desc { cursor: pointer; position: relative; padding-right: 22px; user-select: none; }
table.dataTable thead th.sorting::after,
table.dataTable thead th.sorting_asc::after,
table.dataTable thead th.sorting_desc::after {
  content: "↕";
  position: absolute;
  right: 6px;
  opacity: 0.35;
  font-size: 0.85em;
}
table.dataTable thead th.sorting_asc::after { content: "↑"; opacity: 1; color: var(--p1); }
table.dataTable thead th.sorting_desc::after { content: "↓"; opacity: 1; color: var(--p1); }

/* ========================================
   USER EDIT PAGE
   ======================================== */

.user-hero { display: flex; align-items: center; gap: var(--space-md); }
.user-hero h1 { margin: 0; }
.user-hero-meta { display: flex; align-items: center; gap: var(--space-sm); flex-wrap: wrap; margin: var(--space-xs) 0; }
.user-hero-avatar {
  width: 56px;
  height: 56px;
  flex-shrink: 0;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 1.5rem;
  font-weight: var(--font-weight-semibold);
  color: var(--color-text-inverse);
  background: linear-gradient(135deg, var(--p1), var(--p3));
  box-shadow: var(--shadow-md);
}

.form-control-inline { width: auto; min-width: 260px; }

/* Allow / Deny segmented radio */
.segmented {
  display: inline-flex;
  border: 1px solid var(--color-border);
  border-radius: 999px;
  overflow: hidden;
  background: var(--color-bg-secondary);
}
.segmented-option { margin: 0; cursor: pointer; }
.segmented-option input { position: absolute; opacity: 0; pointer-events: none; }
.segmented-option span {
  display: block;
  padding: 3px 14px;
  font-size: var(--font-size-sm);
  color: var(--color-text-secondary);
  transition: background 0.2s, color 0.2s;
}
.segmented-option:hover span { color: var(--color-text); }
.segmented-allow input:checked + span { background: color-mix(in srgb, var(--color-success) 28%, transparent); color: var(--color-success); font-weight: var(--font-weight-medium); }
.segmented-deny input:checked + span { background: color-mix(in srgb, var(--color-error) 28%, transparent); color: var(--color-error); font-weight: var(--font-weight-medium); }
.segmented-option input:focus-visible + span { outline: 2px solid var(--p1); outline-offset: -2px; }

.switch-label { display: inline-flex; align-items: center; gap: var(--space-sm); margin: 0; cursor: pointer; }
.switch-label input { accent-color: var(--p1); width: 18px; height: 18px; }

/* ========================================
   SERVER PAGE
   ======================================== */

.server-hero-icon {
  flex-shrink: 0;
  padding: var(--space-sm);
  border-radius: var(--border-radius-lg);
  background: var(--color-bg-secondary);
  box-shadow: var(--shadow-sm);
}
.server-page .lead { font-size: var(--font-size-lg); color: var(--color-text); }
.info-list { display: grid; grid-template-columns: max-content 1fr; gap: var(--space-sm) var(--space-lg); margin: 0 0 var(--space-md); }
.info-list dt { color: var(--color-text-tertiary); font-weight: var(--font-weight-medium); }
.info-list dd { margin: 0; overflow-wrap: anywhere; }
.icon-link { display: inline-flex; border-radius: var(--border-radius-md); }
.icon-link:hover .server-icon { box-shadow: 0 0 0 2px var(--p1); }
.server-page .form-card ul { margin: 0 0 var(--space-md); padding-left: 1.4em; }
.server-page .form-card li { margin-bottom: 2px; }
