/* ============================================================
   ChaosVPN Config Editor — Global Styles
   Dark theme with glassmorphism elements and smooth animations
   ============================================================ */

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

/* Ensure the HTML 'hidden' attribute is never overridden by CSS display rules */
[hidden] { display: none !important; }


:root {
  /* Color palette */
  --bg-base:        #0d1117;
  --bg-surface:     #161b22;
  --bg-elevated:    #1c2128;
  --bg-glass:       rgba(22, 27, 34, 0.75);

  --accent:         #7c3aed;
  --accent-hover:   #6d28d9;
  --accent-glow:    rgba(124, 58, 237, 0.35);

  --success:        #22c55e;
  --danger:         #ef4444;
  --warning:        #f59e0b;

  --text-primary:   #e6edf3;
  --text-secondary: #8b949e;
  --text-muted:     #484f58;

  --border:         rgba(255,255,255,0.08);
  --border-focus:   rgba(124, 58, 237, 0.6);

  /* Spacing & Shape */
  --radius-sm:  6px;
  --radius-md:  12px;
  --radius-lg:  20px;

  /* Typography */
  --font: 'Inter', system-ui, -apple-system, sans-serif;

  /* Transitions */
  --ease: cubic-bezier(0.4, 0, 0.2, 1);
}

html, body {
  height: 100%;
  font-family: var(--font);
  background: var(--bg-base);
  color: var(--text-primary);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}


/* ── Glassmorphism utility ─────────────────────────────────── */
.glass {
  background: var(--bg-glass);
  backdrop-filter: blur(20px) saturate(1.4);
  -webkit-backdrop-filter: blur(20px) saturate(1.4);
  border: 1px solid var(--border);
}


/* ── Buttons ───────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid transparent;
  transition: background 0.18s var(--ease), box-shadow 0.18s var(--ease), opacity 0.18s;
  text-decoration: none;
  white-space: nowrap;
}

.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn--primary {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
.btn--primary:hover:not(:disabled) {
  background: var(--accent-hover);
  box-shadow: 0 0 20px var(--accent-glow);
}

.btn--ghost {
  background: transparent;
  color: var(--text-secondary);
  border-color: var(--border);
}
.btn--ghost:hover:not(:disabled) {
  background: var(--bg-elevated);
  color: var(--text-primary);
}

.btn--full { width: 100%; justify-content: center; }


/* ── Spinner ───────────────────────────────────────────────── */
.spinner,
.btn-spinner {
  display: inline-block;
  width: 18px;
  height: 18px;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.75s linear infinite;
}
.spinner {
  width: 36px;
  height: 36px;
  border-width: 3px;
  border-top-color: var(--accent);
  border-color: var(--border);
  border-top-color: var(--accent);
}

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


/* ═══════════════════════════════════════════════════════════
   LOGIN PAGE
═══════════════════════════════════════════════════════════ */
.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  overflow: hidden;
  position: relative;
}

/* Animated background orbs */
.login-bg {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
}

.bg-orb {
  position: absolute;
  border-radius: 50%;
  filter: blur(80px);
  opacity: 0.25;
  animation: float 10s ease-in-out infinite;
}

.bg-orb--1 {
  width: 500px;
  height: 500px;
  background: radial-gradient(circle, #7c3aed, transparent 70%);
  top: -150px;
  left: -150px;
}

.bg-orb--2 {
  width: 400px;
  height: 400px;
  background: radial-gradient(circle, #1d4ed8, transparent 70%);
  bottom: -120px;
  right: -120px;
  animation-delay: -5s;
}

@keyframes float {
  0%, 100% { transform: translate(0, 0) scale(1); }
  33%       { transform: translate(20px, -20px) scale(1.05); }
  66%       { transform: translate(-15px, 15px) scale(0.97); }
}

/* Login card */
.login-container {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 400px;
  padding: 20px;
}

.login-card {
  border-radius: var(--radius-lg);
  padding: 40px;
  box-shadow:
    0 0 0 1px var(--border),
    0 20px 60px rgba(0,0,0,0.5),
    0 0 80px rgba(124, 58, 237, 0.07);
  animation: card-in 0.5s var(--ease) both;
}

@keyframes card-in {
  from { opacity: 0; transform: translateY(24px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* Brand section */
.login-brand {
  text-align: center;
  margin-bottom: 32px;
}

.brand-icon {
  font-size: 40px;
  display: block;
  margin-bottom: 10px;
  filter: drop-shadow(0 0 20px var(--accent-glow));
  animation: pulse-icon 3s ease-in-out infinite;
}

@keyframes pulse-icon {
  0%, 100% { filter: drop-shadow(0 0 8px var(--accent-glow)); }
  50%       { filter: drop-shadow(0 0 24px rgba(124,58,237,0.6)); }
}

.brand-name {
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.5px;
  background: linear-gradient(135deg, #e6edf3 30%, #7c3aed);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.brand-sub {
  color: var(--text-secondary);
  font-size: 13px;
  margin-top: 4px;
}

/* Form */
.login-form { display: flex; flex-direction: column; gap: 18px; }

.form-group { display: flex; flex-direction: column; gap: 6px; }

.form-label {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  letter-spacing: 0.02em;
}

.form-input {
  background: var(--bg-base);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 11px 14px;
  color: var(--text-primary);
  font-family: var(--font);
  font-size: 14px;
  transition: border-color 0.18s var(--ease), box-shadow 0.18s var(--ease);
  outline: none;
}

.form-input::placeholder { color: var(--text-muted); }

.form-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.login-error {
  background: rgba(239, 68, 68, 0.12);
  border: 1px solid rgba(239, 68, 68, 0.3);
  border-radius: var(--radius-sm);
  color: #fca5a5;
  font-size: 13px;
  padding: 10px 14px;
  animation: shake 0.35s var(--ease);
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25%       { transform: translateX(-6px); }
  75%       { transform: translateX(6px); }
}


/* ═══════════════════════════════════════════════════════════
   EDITOR PAGE
═══════════════════════════════════════════════════════════ */
.editor-page {
  display: flex;
  flex-direction: row;
  height: 100vh;
  overflow: hidden;
}

/* ── Global Sidebar ─────────────────────────────────────────── */
.global-sidebar {
  width: 250px;
  background: var(--bg-surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  z-index: 20;
}

.global-sidebar .topbar-brand {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}

.global-nav {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 16px 12px;
  overflow-y: auto;
}

.global-nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-family: var(--font);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.18s var(--ease);
  text-align: left;
}

.global-nav-item:hover {
  background: var(--bg-elevated);
  color: var(--text-primary);
}

.global-nav-item.active {
  background: rgba(124, 58, 237, 0.15);
  border-color: rgba(124, 58, 237, 0.4);
  color: #a78bfa;
}

.user-menu-sidebar {
  padding: 16px;
  border-top: 1px solid var(--border);
  border-left: none;
  flex-direction: column;
  align-items: stretch;
  gap: 12px;
}

.user-menu-sidebar .user-name {
  text-align: center;
  margin-bottom: 4px;
}

/* ── Main Wrapper ───────────────────────────────────────────── */
.main-wrapper {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

/* ── Top bar ───────────────────────────────────────────────── */
.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 20px;
  height: 56px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  z-index: 10;
}

.topbar-brand {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.topbar-brand .brand-icon { font-size: 22px; }
.topbar-brand .brand-name { font-size: 16px; font-weight: 700; }
.brand-tag {
  background: rgba(124, 58, 237, 0.2);
  border: 1px solid rgba(124, 58, 237, 0.3);
  border-radius: 4px;
  color: #a78bfa;
  font-size: 11px;
  font-weight: 500;
  padding: 2px 6px;
  letter-spacing: 0.05em;
}

/* Tabs */
.topbar-tabs {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 0 8px;
  margin: 0 8px;
  border-left: 1px solid var(--border);
  border-right: 1px solid var(--border);
}

.tab-btn {
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  cursor: pointer;
  font-family: var(--font);
  font-size: 13px;
  font-weight: 500;
  padding: 6px 14px;
  transition: all 0.18s var(--ease);
}

.tab-btn:hover { color: var(--text-primary); background: var(--bg-elevated); }

.tab-btn--active {
  background: rgba(124, 58, 237, 0.15);
  border-color: rgba(124, 58, 237, 0.4);
  color: #a78bfa;
}

/* Actions area */
.topbar-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-left: auto;
}

/* Save status chip */
.save-status {
  font-size: 13px;
  font-weight: 500;
  padding: 4px 10px;
  border-radius: 20px;
  opacity: 0;
  transition: opacity 0.3s var(--ease);
  white-space: nowrap;
}

.save-status--visible { opacity: 1; }

.save-status--ok {
  background: rgba(34, 197, 94, 0.15);
  border: 1px solid rgba(34, 197, 94, 0.3);
  color: #86efac;
}

.save-status--error {
  background: rgba(239, 68, 68, 0.15);
  border: 1px solid rgba(239, 68, 68, 0.3);
  color: #fca5a5;
}

.save-status--saving {
  background: rgba(124, 58, 237, 0.15);
  border: 1px solid rgba(124, 58, 237, 0.3);
  color: #a78bfa;
}

/* User menu */
.user-menu {
  display: flex;
  align-items: center;
  gap: 8px;
  padding-left: 12px;
  border-left: 1px solid var(--border);
}

.user-name {
  font-size: 13px;
  color: var(--text-secondary);
}

/* ── Editor area ───────────────────────────────────────────── */
.editor-main {
  flex: 1;
  position: relative;
  overflow: hidden;
}

.monaco-container {
  width: 100%;
  height: 100%;
}

/* Loading overlay */
.editor-loading {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  background: var(--bg-base);
  z-index: 5;
  color: var(--text-secondary);
  font-size: 14px;
  transition: opacity 0.3s var(--ease);
}

.editor-loading.hidden {
  opacity: 0;
  pointer-events: none;
}

/* ═══════════════════════════════════════════════════════════
   MODE TOGGLE
═══════════════════════════════════════════════════════════ */
.mode-toggle {
  display: flex;
  background: var(--bg-base);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.btn--toggle {
  background: transparent;
  color: var(--text-secondary);
  border-radius: 0;
  border: none;
  font-size: 13px;
  padding: 6px 16px;
}

.btn--toggle.btn--active {
  background: rgba(124, 58, 237, 0.15);
  color: #a78bfa;
}

.btn--toggle:not(.btn--active):hover {
  background: var(--bg-elevated);
}

/* ═══════════════════════════════════════════════════════════
   GUI EDITOR LAYOUT
═══════════════════════════════════════════════════════════ */
.gui-main {
  display: flex;
  height: 100%;
  width: 100%;
}

.gui-sidebar {
  width: 250px;
  background: var(--bg-surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  flex-shrink: 0;
}

.sidebar-section {
  padding: 16px 12px;
  border-bottom: 1px solid var(--border);
}

.sidebar-title {
  font-size: 11px;
  text-transform: uppercase;
  color: var(--text-muted);
  letter-spacing: 0.05em;
  margin-bottom: 8px;
  padding-left: 8px;
}

.sidebar-menu {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.sidebar-item {
  width: 100%;
  text-align: left;
  background: transparent;
  border: none;
  border-radius: var(--radius-sm);
  padding: 8px;
  color: var(--text-secondary);
  font-size: 13px;
  font-family: var(--font);
  cursor: pointer;
  transition: all 0.15s var(--ease);
}

.sidebar-item:hover {
  background: var(--bg-elevated);
  color: var(--text-primary);
}

.sidebar-item.active {
  background: rgba(124, 58, 237, 0.15);
  color: #a78bfa;
}

.gui-content {
  flex: 1;
  overflow-y: auto;
  padding: 32px;
  background: var(--bg-base);
}

/* Forms & Cards inside GUI Content */
.gui-section-header {
  margin-bottom: 24px;
}

.gui-section-title {
  font-size: 20px;
  font-weight: 600;
  margin-bottom: 4px;
}

.gui-section-desc {
  color: var(--text-secondary);
  font-size: 13px;
}

.gui-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 24px;
  margin-bottom: 24px;
}

.gui-card-title {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
}

.form-row {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 16px;
}

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

.form-label {
  font-size: 13px;
  color: var(--text-secondary);
}

.form-input, .form-select {
  background: var(--bg-base);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  color: var(--text-primary);
  font-size: 13px;
  font-family: inherit;
  width: 100%;
}

.form-input:focus, .form-select:focus {
  border-color: var(--accent);
  outline: none;
  box-shadow: 0 0 0 2px var(--accent-glow);
}

/* Toggle Switch */
.toggle-switch {
  position: relative;
  display: inline-block;
  width: 36px;
  height: 20px;
}
.toggle-switch input {
  opacity: 0;
  width: 0;
  height: 0;
}
.toggle-slider {
  position: absolute;
  cursor: pointer;
  top: 0; left: 0; right: 0; bottom: 0;
  background-color: var(--bg-elevated);
  transition: .4s;
  border-radius: 20px;
  border: 1px solid var(--border);
}
.toggle-slider:before {
  position: absolute;
  content: "";
  height: 14px;
  width: 14px;
  left: 2px;
  bottom: 2px;
  background-color: var(--text-secondary);
  transition: .4s;
  border-radius: 50%;
}
input:checked + .toggle-slider {
  background-color: var(--accent);
  border-color: var(--accent);
}
input:checked + .toggle-slider:before {
  transform: translateX(16px);
  background-color: #fff;
}

/* Arrays / Lists */
.gui-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.gui-list-item {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px;
  display: flex;
  gap: 12px;
  align-items: flex-start;
}

.gui-list-item-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.btn--icon {
  padding: 6px;
  color: var(--text-secondary);
  background: transparent;
}
.btn--icon:hover {
  color: var(--danger);
  background: rgba(239, 68, 68, 0.1);
}

/* Collapsible Outbounds */
details.gui-collapsible-item {
  transition: all 0.3s var(--ease);
  display: block; /* Override default if needed */
}
details.gui-collapsible-item[open] {
  background: var(--bg-surface);
  box-shadow: 0 4px 12px rgba(0,0,0,0.2);
}
.gui-collapsible-summary {
  display: flex;
  justify-content: space-between;
  align-items: center;
  list-style: none; /* Hide default arrow */
  cursor: pointer;
}
.gui-collapsible-summary::-webkit-details-marker {
  display: none; /* Hide default arrow in Safari */
}
.collapsible-icon {
  font-size: 12px;
  color: var(--text-secondary);
  transition: transform 0.3s var(--ease);
}
details[open] .collapsible-icon {
  transform: rotate(180deg);
}

/* ═══════════════════════════════════════════════════════════
   GENERAL / MAIN PANEL
═══════════════════════════════════════════════════════════ */
.main-panel {
  flex: 1;
  overflow-y: auto;
  padding: 32px;
  background: var(--bg-base);
  flex-direction: column;
}

.main-panel-inner {
  max-width: 600px;
}

.main-panel-title {
  font-size: 24px;
  font-weight: 600;
  margin-bottom: 24px;
}

.main-panel-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 24px;
}

.main-panel-label {
  display: block;
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 12px;
  color: var(--text-primary);
}

.main-panel-hint {
  color: var(--text-secondary);
  font-size: 14px;
  margin-bottom: 20px;
  line-height: 1.6;
}

.main-panel-row {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 16px;
}

.main-panel-spinbox {
  background: var(--bg-base);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  color: var(--text-primary);
  font-size: 18px;
  font-family: var(--font);
  font-weight: 600;
  width: 120px;
  outline: none;
  transition: border-color 0.18s var(--ease), box-shadow 0.18s var(--ease);
}

.main-panel-spinbox:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}
/* ═══════════════════════════════════════════════════════════
   SETTINGS PANEL
   ═══════════════════════════════════════════════════════════ */
.settings-form {
  display: flex;
  flex-direction: column;
  gap: 20px;
  max-width: 480px;
  margin-top: 16px;
}

.main-panel-input {
  background: var(--bg-base);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  color: var(--text-primary);
  font-family: var(--font);
  font-size: 14px;
  transition: all 0.18s var(--ease);
  outline: none;
  width: 100%;
}

.main-panel-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.card-title {
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 8px;
  color: var(--text-primary);
}

.form-actions {
  margin-top: 8px;
  display: flex;
  justify-content: flex-start;
}
