:root {
  --bg:        #0a0f1c;
  --surface:   #111827;
  --surface-2: #1f2937;
  --surface-3: #374151;
  --border:    #263244;
  --border-soft:#1e2837;
  --text:      #e5e7eb;
  --text-2:    #cbd5e1;
  --dim:       #94a3b8;
  --muted:     #64748b;
  --primary:   #3b82f6;
  --primary-2: #2563eb;
  --green:     #10b981;
  --green-soft:#065f46;
  --yellow:    #f59e0b;
  --red:       #ef4444;
  --purple:    #8b5cf6;
  --cyan:      #06b6d4;
  --shadow-sm: 0 1px 2px rgba(0,0,0,.25);
  --shadow:    0 4px 12px rgba(0,0,0,.35);
  --radius:    8px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Inter", sans-serif;
  font-size: 13px;
  line-height: 1.45;
}

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

code { font-family: "JetBrains Mono", "Cascadia Code", Consolas, monospace; font-size: 11px; }

/* ===== Navbar ===== */
.nav {
  background: linear-gradient(180deg, #131b2e 0%, #0f172a 100%);
  border-bottom: 1px solid var(--border);
  padding: 0 20px;
  display: flex;
  align-items: center;
  gap: 4px;
  height: 48px;
  position: sticky;
  top: 0;
  z-index: 50;
  backdrop-filter: blur(8px);
}
.nav-brand {
  font-weight: 700;
  font-size: 14px;
  letter-spacing: .02em;
  margin-right: 20px;
  color: #e2e8f0;
}
.nav a {
  color: var(--dim);
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  transition: background .12s, color .12s;
}
.nav a:hover { background: rgba(255,255,255,.04); color: var(--text); text-decoration: none; }
.nav a.active { background: var(--surface-2); color: var(--text); }
.nav-user { margin-left: auto; display: flex; align-items: center; gap: 12px; color: var(--dim); font-size: 12px; }
.back-link { font-weight: 500; }

/* ===== Layout ===== */
.wrap { max-width: 1200px; margin: 20px auto; padding: 0 16px; }
.wrap.wide { max-width: 1400px; }

.page-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; }
.page-head h1 { font-size: 18px; margin: 0; font-weight: 600; }
.page-head-actions { display: flex; gap: 8px; }

/* ===== Panel ===== */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 16px;
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}
.panel-title {
  background: linear-gradient(180deg, var(--surface-2), var(--surface));
  padding: 10px 14px;
  font-weight: 600;
  font-size: 13px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.panel-body { padding: 14px; }

/* ===== Brand groups ===== */
.brand-group { margin-bottom: 24px; }
.brand-group-title {
  font-size: 11px;
  text-transform: uppercase;
  color: var(--muted);
  margin: 0 0 10px 0;
  letter-spacing: .08em;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
}
.brand-group-title .count {
  background: var(--surface-2);
  color: var(--dim);
  padding: 1px 7px;
  border-radius: 10px;
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0;
}

.brand-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(360px, 1fr));
  gap: 14px;
}

.brand-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: visible;
  transition: border-color .15s, transform .15s, box-shadow .15s;
  box-shadow: var(--shadow-sm);
}
.brand-card:hover {
  border-color: var(--primary);
  box-shadow: 0 6px 20px rgba(59,130,246,.1);
}

.brand-card-head {
  padding: 12px 14px;
  background: linear-gradient(180deg, rgba(59,130,246,.06), transparent);
  border-bottom: 1px solid var(--border);
  border-radius: 10px 10px 0 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.brand-name { font-weight: 700; font-size: 15px; color: var(--text); letter-spacing: -.01em; }
.brand-cat {
  font-size: 10px;
  padding: 2px 8px;
  border-radius: 10px;
  background: var(--surface-2);
  color: var(--dim);
  text-transform: uppercase;
  letter-spacing: .04em;
}
.cat-select {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--dim);
  padding: 2px 6px;
  border-radius: 10px;
  font-size: 10px;
  font-family: inherit;
  cursor: pointer;
  max-width: 130px;
  text-transform: uppercase;
  letter-spacing: .04em;
}
.cat-select:hover { color: var(--text); border-color: var(--primary); }
.cat-select:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 2px rgba(59,130,246,.15); }

.variant-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  gap: 12px;
  border-top: 1px solid var(--border-soft);
}
.variant-row:first-of-type { border-top: none; }
.variant-row.missing { opacity: 0.55; }
.variant-row.missing:hover { opacity: 0.85; }

.variant-info { display: flex; align-items: center; gap: 10px; min-width: 0; flex: 1; }

/* Toggle switch (active/inactive) */
.switch {
  position: relative;
  display: inline-block;
  width: 32px;
  height: 18px;
  flex-shrink: 0;
  cursor: pointer;
}
.switch input { opacity: 0; width: 0; height: 0; }
.switch .slider {
  position: absolute; inset: 0;
  background: var(--surface-3);
  border-radius: 20px;
  transition: background .15s;
}
.switch .slider::before {
  content: "";
  position: absolute;
  width: 14px; height: 14px;
  left: 2px; bottom: 2px;
  background: #fff;
  border-radius: 50%;
  transition: transform .15s;
  box-shadow: 0 1px 2px rgba(0,0,0,.3);
}
.switch input:checked + .slider { background: var(--green); }
.switch input:checked + .slider::before { transform: translateX(14px); }
.switch input:disabled + .slider { opacity: 0.5; cursor: not-allowed; }
.switch:hover .slider { filter: brightness(1.15); }

/* Status dot for read-only viewers */
.status-dot {
  width: 8px; height: 8px; border-radius: 50%;
  flex-shrink: 0;
  display: inline-block;
}
.status-dot.on  { background: var(--green); box-shadow: 0 0 6px rgba(16,185,129,.5); }
.status-dot.off { background: var(--muted); }

/* Inactive visual state for the whole row */
.variant-row.inactive .variant-icon,
.variant-row.inactive .variant-key { opacity: 0.4; }
.variant-row.inactive .variant-label { color: var(--muted); }

.badge-inactive {
  font-size: 9px;
  font-weight: 700;
  padding: 1px 7px;
  border-radius: 10px;
  background: rgba(239,68,68,.14);
  color: #fca5a5;
  border: 1px solid rgba(239,68,68,.3);
  text-transform: uppercase;
  letter-spacing: .04em;
}
.variant-icon { font-size: 18px; line-height: 1; flex-shrink: 0; }
.variant-meta { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.variant-line-1 { display: flex; align-items: center; gap: 8px; }
.variant-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-2);
  text-transform: capitalize;
  letter-spacing: .02em;
}
.variant-row .variant-icon { opacity: 0.8; }

/* Legacy .variant-tag retained for rich editor page */
.variant-tag {
  font-size: 9px; font-weight: 700; padding: 2px 7px; border-radius: 4px;
  letter-spacing: .06em; text-transform: uppercase;
}
.variant-mobile { background: rgba(16,185,129,.15); color: #6ee7b7; border: 1px solid rgba(16,185,129,.3); }
.variant-desk   { background: rgba(139,92,246,.15); color: #c4b5fd; border: 1px solid rgba(139,92,246,.3); }

.variant-key {
  font-size: 10px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 200px;
}
.variant-rot {
  font-size: 10px;
  color: var(--dim);
  white-space: nowrap;
  cursor: help;
  flex-shrink: 0;
}
.variant-rot::before { content: '⟳ '; opacity: .6; }
.variant-miss { font-size: 11px; color: var(--muted); font-style: italic; }
.variant-actions { display: flex; gap: 4px; flex-wrap: nowrap; align-items: center; position: relative; }

/* Icon-only button (copy loader, overflow trigger) */
.icon-btn {
  width: 28px; height: 28px;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 5px;
  color: var(--text);
  cursor: pointer;
  font-size: 13px;
  font-family: inherit;
  line-height: 1;
  padding: 0;
  transition: background .12s, border-color .12s;
  list-style: none;
}
.icon-btn::-webkit-details-marker { display: none; }
.icon-btn:hover { background: var(--surface-3); border-color: var(--primary); }

/* Overflow menu (details/summary) */
.overflow { position: relative; }
.overflow summary { cursor: pointer; }
.overflow[open] summary { background: var(--primary); border-color: var(--primary); color: #fff; }
.overflow-menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  min-width: 230px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 12px 28px rgba(0,0,0,.5);
  padding: 6px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  z-index: 30;
}
.overflow-menu button {
  text-align: left;
  background: transparent;
  border: none;
  color: var(--text);
  padding: 8px 12px;
  border-radius: 5px;
  font-size: 13px;
  cursor: pointer;
  font-family: inherit;
}
.overflow-menu button:hover { background: var(--surface-2); }
.overflow-menu button.danger { color: #fca5a5; }
.overflow-menu button.danger:hover { background: rgba(239,68,68,.1); }
.overflow-menu .overflow-section {
  font-size: 9px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--muted);
  padding: 6px 12px 4px;
  margin-top: 4px;
  border-top: 1px solid var(--border-soft);
}
.overflow-menu .overflow-section:first-child { border-top: none; margin-top: 0; }

/* Subdomain row inside brand card */
.brand-sub-row {
  padding: 6px 14px;
  background: rgba(255,255,255,.02);
  border-bottom: 1px solid var(--border-soft);
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  font-size: 11px;
}
.brand-sub-row .sub-label {
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .05em;
  font-size: 10px;
  font-weight: 600;
}
.sub-btn {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 2px 8px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 11px;
  font-family: inherit;
}
.sub-btn:hover { border-color: var(--primary); color: var(--primary); }
.sub-btn code { color: inherit; padding: 0; background: transparent; }
.sub-btn em { color: var(--muted); font-style: italic; padding: 0 2px; }
.sub-warn {
  font-size: 10px;
  color: var(--yellow);
  font-style: italic;
}
.icon-btn.disabled { opacity: 0.4; cursor: not-allowed; }

/* ===== Buttons ===== */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  padding: 5px 10px;
  border-radius: 5px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  transition: background .12s, border-color .12s, transform .06s;
  font-family: inherit;
}
.btn:hover { background: var(--surface-3); text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn[disabled] { opacity: 0.4; cursor: not-allowed; }
.btn.blue   { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.blue:hover { background: var(--primary-2); }
.btn.green  { background: var(--green); border-color: var(--green); color: #fff; }
.btn.green:hover { filter: brightness(1.1); }
.btn.red    { background: var(--red); border-color: var(--red); color: #fff; }
.btn.red:hover { filter: brightness(1.1); }
.btn.yellow { background: var(--yellow); border-color: var(--yellow); color: #422006; }
.btn.yellow:hover { filter: brightness(1.1); }
.btn.ghost  { background: transparent; }
.btn.xs     { padding: 3px 8px; font-size: 11px; }
.btn.sm     { padding: 4px 10px; font-size: 12px; }

/* ===== Form ===== */
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; }
.field label { font-size: 11px; color: var(--dim); text-transform: uppercase; letter-spacing: .04em; font-weight: 500; }
.field input, .field select, .field textarea {
  background: #030712;
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 10px;
  border-radius: 5px;
  font-size: 13px;
  font-family: inherit;
}
.field textarea {
  resize: vertical;
  min-height: 160px;
  font-family: "JetBrains Mono", "Cascadia Code", Consolas, monospace;
  font-size: 12px;
  line-height: 1.5;
  tab-size: 2;
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(59,130,246,.15);
}

/* ===== Table ===== */
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 8px 12px; border-bottom: 1px solid var(--border-soft); font-size: 12px; }
th {
  background: var(--surface-2);
  color: var(--dim);
  font-weight: 600;
  text-transform: uppercase;
  font-size: 10px;
  letter-spacing: .05em;
}
tr:hover td { background: rgba(255,255,255,.02); }
td code { background: var(--surface-2); padding: 1px 6px; border-radius: 3px; color: #e0e7ff; }

/* ===== Badge ===== */
.badge { display: inline-block; padding: 2px 8px; border-radius: 10px; font-size: 10px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; }
.badge.role-admin  { background: rgba(239,68,68,.18); color: #fca5a5; border: 1px solid rgba(239,68,68,.3); }
.badge.role-editor { background: rgba(59,130,246,.18); color: #93c5fd; border: 1px solid rgba(59,130,246,.3); }
.badge.role-viewer { background: rgba(100,116,139,.18); color: #cbd5e1; border: 1px solid rgba(100,116,139,.3); }

/* ===== Login ===== */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(ellipse at top, #1e293b 0%, #0a0f1c 50%, #000 100%);
}
.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 32px;
  border-radius: 12px;
  width: 100%;
  max-width: 380px;
  box-shadow: 0 20px 50px rgba(0,0,0,.5);
}
.login-card h1 { margin: 0 0 8px 0; font-size: 20px; font-weight: 700; }
.login-card .sub { color: var(--dim); font-size: 12px; margin-bottom: 20px; }
.login-card .err { background: rgba(239,68,68,.12); color: #fca5a5; padding: 10px 12px; border-radius: 6px; margin-bottom: 14px; font-size: 12px; border: 1px solid rgba(239,68,68,.25); }

/* ===== Terminal output ===== */
.sticky-bottom { position: sticky; bottom: 10px; z-index: 40; }
.term {
  background: #030712;
  color: #86efac;
  padding: 14px;
  font-family: "JetBrains Mono", "Cascadia Code", Consolas, monospace;
  font-size: 12px;
  line-height: 1.55;
  max-height: 340px;
  overflow-y: auto;
  white-space: pre-wrap;
}

/* ===== Dialog ===== */
dialog {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 24px;
  min-width: 420px;
  box-shadow: 0 30px 80px rgba(0,0,0,.6);
}
dialog::backdrop { background: rgba(0,0,0,.6); backdrop-filter: blur(4px); }

/* Reusable confirm/alert dialogs */
.ui-dlg {
  max-width: 480px;
  min-width: 380px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  box-shadow: 0 30px 80px rgba(0,0,0,.6);
  animation: ui-dlg-in .15s ease-out;
}
@keyframes ui-dlg-in {
  from { transform: translateY(-8px) scale(0.98); opacity: 0; }
  to   { transform: translateY(0) scale(1); opacity: 1; }
}
.ui-dlg-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 18px 22px 12px;
}
.ui-dlg-icon {
  width: 34px; height: 34px;
  display: inline-flex; align-items: center; justify-content: center;
  background: rgba(245,158,11,.12);
  color: var(--yellow);
  border: 1px solid rgba(245,158,11,.3);
  border-radius: 50%;
  font-size: 16px;
  flex-shrink: 0;
}
#uiAlertDlg .ui-dlg-icon {
  background: rgba(59,130,246,.12);
  color: var(--primary);
  border-color: rgba(59,130,246,.3);
}
.ui-dlg-title {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
}
.ui-dlg-body {
  padding: 0 22px 16px;
  color: var(--text-2);
  font-size: 13px;
  line-height: 1.55;
}
.ui-dlg-body p { margin: 0 0 10px 0; }
.ui-dlg-list {
  margin: 8px 0 0;
  padding-left: 18px;
  color: var(--dim);
  font-size: 12.5px;
}
.ui-dlg-list li { margin-bottom: 6px; }
.ui-dlg-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 14px 22px;
  background: rgba(255,255,255,.02);
  border-top: 1px solid var(--border-soft);
  border-radius: 0 0 12px 12px;
}
#uiPromptDlg .ui-dlg-icon {
  background: rgba(59,130,246,.12);
  color: var(--primary);
  border-color: rgba(59,130,246,.3);
}
.ui-dlg-label {
  display: block;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--muted);
  margin-bottom: 6px;
  font-weight: 600;
}
.ui-dlg-input {
  width: 100%;
  padding: 10px 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  outline: none;
  transition: border-color .15s;
  box-sizing: border-box;
}
.ui-dlg-input:focus { border-color: var(--primary); }
.ui-dlg-error {
  margin-top: 8px;
  padding: 8px 10px;
  background: rgba(239,68,68,.1);
  border: 1px solid rgba(239,68,68,.3);
  border-radius: 6px;
  color: #fca5a5;
  font-size: 12.5px;
}

/* ===== Back link in edit pages ===== */
.panel-title .back { color: var(--dim); margin-right: 8px; }
.panel-title .back:hover { color: var(--text); }
