:root {
  --bg-primary: #0f1118;
  --bg-secondary: #141824;
  --bg-card: #1c2132;
  --bg-card-hover: #22293d;
  --bg-card-active: #283049;
  --border-color: rgba(255, 255, 255, 0.08);
  --border-active: #6366f1;
  --text-main: #f1f5f9;
  --text-muted: #94a3b8;
  --text-dim: #64748b;
  --accent-primary: #6366f1;
  --accent-secondary: #8b5cf6;
  --accent-cyan: #06b6d4;
  --color-success: #10b981;
  --color-warning: #f59e0b;
  --color-danger: #ef4444;
  --sidebar-width: 230px;
  --header-height: 64px;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji";
}

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

body {
  background-color: var(--bg-primary);
  color: var(--text-main);
  font-family: var(--font-family);
  font-size: 14px;
  line-height: 1.5;
  display: flex;
  height: 100vh;
  overflow: hidden;
  user-select: none;
}

/* Scrollbar */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.15);
  border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.25);
}

/* App Layout */
.app-container {
  display: flex;
  width: 100vw;
  height: 100vh;
  overflow: hidden;
}

/* Sidebar */
.sidebar {
  width: var(--sidebar-width);
  background-color: var(--bg-secondary);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  padding: 16px 12px;
  flex-shrink: 0;
  z-index: 20;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 12px 20px;
  border-bottom: 1px solid var(--border-color);
  margin-bottom: 16px;
}

.brand-icon {
  width: 32px;
  height: 32px;
  border-radius: 8px;
}

.brand-text h1 {
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 0.5px;
  background: linear-gradient(135deg, #a5b4fc 0%, #c084fc 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.brand-badge {
  font-size: 10px;
  padding: 1px 6px;
  border-radius: 10px;
  background: rgba(99, 102, 241, 0.2);
  color: #818cf8;
  font-weight: 600;
}

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

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  border-radius: var(--radius-md);
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.2s ease;
  font-weight: 500;
}

.nav-item:hover {
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-main);
}

.nav-item.active {
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.25) 0%, rgba(139, 92, 246, 0.15) 100%);
  color: #a5b4fc;
  border-left: 3px solid var(--accent-primary);
}

.nav-icon {
  font-size: 18px;
  width: 20px;
  text-align: center;
}

/* Sidebar Footer (Status Badges) */
.sidebar-footer {
  padding-top: 16px;
  border-top: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.status-pill {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  background: rgba(0, 0, 0, 0.2);
  font-size: 12px;
}

.status-pill .label {
  color: var(--text-dim);
  display: flex;
  align-items: center;
  gap: 6px;
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
}

.dot.green { background: var(--color-success); box-shadow: 0 0 8px rgba(16, 185, 129, 0.5); }
.dot.red { background: var(--color-danger); }
.dot.blue { background: var(--accent-cyan); box-shadow: 0 0 8px rgba(6, 182, 212, 0.5); }
.dot.purple { background: var(--accent-secondary); box-shadow: 0 0 8px rgba(139, 92, 246, 0.5); }
.dot.gray { background: var(--text-dim); }

/* Main Content Area */
.main-wrapper {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
  background-color: var(--bg-primary);
}

/* Header */
.top-header {
  height: var(--header-height);
  border-bottom: 1px solid var(--border-color);
  background: rgba(20, 24, 36, 0.7);
  backdrop-filter: blur(12px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  flex-shrink: 0;
  z-index: 10;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 16px;
}

.page-title {
  font-size: 18px;
  font-weight: 600;
  color: var(--text-main);
}

.traffic-pill {
  display: flex;
  align-items: center;
  gap: 12px;
  background: rgba(0, 0, 0, 0.3);
  padding: 6px 14px;
  border-radius: 20px;
  border: 1px solid var(--border-color);
  font-size: 12px;
  font-family: monospace;
}

.traffic-item {
  display: flex;
  align-items: center;
  gap: 4px;
}

.traffic-up { color: #38bdf8; }
.traffic-down { color: #34d399; }

.header-right {
  display: flex;
  align-items: center;
  gap: 16px;
}

/* Quick Toggles in Header */
.quick-control-group {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--bg-card);
  padding: 4px 10px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
}

.toggle-switch-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  cursor: pointer;
}

/* Custom Switch Toggle */
.switch {
  position: relative;
  display: inline-block;
  width: 38px;
  height: 20px;
}
.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}
.slider {
  position: absolute;
  cursor: pointer;
  top: 0; left: 0; right: 0; bottom: 0;
  background-color: #334155;
  transition: .3s cubic-bezier(0.4, 0, 0.2, 1);
  border-radius: 20px;
}
.slider:before {
  position: absolute;
  content: "";
  height: 14px;
  width: 14px;
  left: 3px;
  bottom: 3px;
  background-color: white;
  transition: .3s cubic-bezier(0.4, 0, 0.2, 1);
  border-radius: 50%;
}
input:checked + .slider {
  background-color: var(--accent-primary);
}
input:checked + .slider.cyan {
  background-color: var(--accent-cyan);
}
input:checked + .slider:before {
  transform: translateX(18px);
}

/* Mode Buttons */
.mode-segmented {
  display: flex;
  background: rgba(0, 0, 0, 0.3);
  padding: 3px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
}
.mode-btn {
  padding: 4px 12px;
  font-size: 12px;
  border-radius: 4px;
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.2s;
}
.mode-btn.active {
  background: var(--accent-primary);
  color: #fff;
  font-weight: 600;
  box-shadow: 0 2px 8px rgba(99, 102, 241, 0.4);
}

/* Restart Service Button */
.btn-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  cursor: pointer;
  transition: all 0.2s;
}
.btn-icon:hover {
  background: var(--bg-card-hover);
  border-color: var(--accent-primary);
}

/* Page Container */
.page-content {
  flex: 1;
  padding: 24px;
  overflow-y: auto;
  display: none;
}
.page-content.active {
  display: block;
}

/* Dashboard Page */
.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 18px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  position: relative;
  overflow: hidden;
  transition: transform 0.2s, border-color 0.2s;
}
.stat-card:hover {
  border-color: rgba(99, 102, 241, 0.3);
  transform: translateY(-2px);
}
.stat-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.stat-card-title {
  font-size: 13px;
  color: var(--text-muted);
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 8px;
}
.stat-card-val {
  font-size: 24px;
  font-weight: 700;
  color: var(--text-main);
}
.stat-card-sub {
  font-size: 12px;
  color: var(--text-dim);
}

/* Chart Card */
.chart-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 20px;
  margin-bottom: 24px;
}
.chart-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}
#traffic-chart {
  width: 100%;
  height: 180px;
  display: block;
}

/* Quick Action Banner */
.action-banner {
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.12) 0%, rgba(139, 92, 246, 0.08) 100%);
  border: 1px solid rgba(99, 102, 241, 0.3);
  border-radius: var(--radius-lg);
  padding: 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
}
.banner-info h3 {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 4px;
}
.banner-info p {
  color: var(--text-muted);
  font-size: 13px;
}
.banner-btns {
  display: flex;
  gap: 12px;
}

/* Profiles Page */
.section-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}
.btn-primary {
  background: linear-gradient(135deg, var(--accent-primary) 0%, var(--accent-secondary) 100%);
  color: white;
  border: none;
  padding: 8px 18px;
  border-radius: var(--radius-md);
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: all 0.2s;
  box-shadow: 0 4px 12px rgba(99, 102, 241, 0.3);
}
.btn-primary:hover {
  opacity: 0.95;
  transform: translateY(-1px);
}
.btn-secondary {
  background: var(--bg-card);
  color: var(--text-main);
  border: 1px solid var(--border-color);
  padding: 8px 16px;
  border-radius: var(--radius-md);
  font-weight: 500;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: all 0.2s;
}
.btn-secondary:hover {
  background: var(--bg-card-hover);
  border-color: rgba(255, 255, 255, 0.2);
}

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

.profile-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  position: relative;
  transition: all 0.2s ease;
}
.profile-card:hover {
  border-color: rgba(99, 102, 241, 0.4);
}
.profile-card.active {
  border: 1.5px solid var(--accent-primary);
  background: linear-gradient(180deg, rgba(99, 102, 241, 0.08) 0%, var(--bg-card) 100%);
  box-shadow: 0 0 16px rgba(99, 102, 241, 0.15);
}

.profile-active-tag {
  position: absolute;
  top: 16px;
  right: 16px;
  background: var(--accent-primary);
  color: white;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 12px;
}

.profile-header h3 {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-main);
  margin-bottom: 4px;
}
.profile-url {
  font-size: 12px;
  color: var(--text-dim);
  word-break: break-all;
  max-height: 36px;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Userinfo Traffic Bar */
.traffic-progress-box {
  background: rgba(0, 0, 0, 0.25);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
}
.traffic-progress-info {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 6px;
}
.progress-bar-bg {
  width: 100%;
  height: 6px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 3px;
  overflow: hidden;
}
.progress-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, #38bdf8, #818cf8);
  border-radius: 3px;
  transition: width 0.3s;
}

.profile-meta-row {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--text-dim);
}

.profile-actions {
  display: flex;
  gap: 8px;
  margin-top: 4px;
}
.profile-actions button {
  flex: 1;
  padding: 6px 10px;
  font-size: 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-main);
  cursor: pointer;
  transition: all 0.2s;
}
.profile-actions button:hover {
  background: rgba(255, 255, 255, 0.12);
}
.profile-actions button.btn-use {
  background: rgba(99, 102, 241, 0.2);
  color: #a5b4fc;
  border-color: rgba(99, 102, 241, 0.4);
}
.profile-actions button.btn-use:hover {
  background: var(--accent-primary);
  color: #fff;
}
.profile-actions button.btn-del {
  color: #f87171;
}
.profile-actions button.btn-del:hover {
  background: rgba(239, 68, 68, 0.2);
  border-color: rgba(239, 68, 68, 0.4);
}

/* Proxies (Nodes) Page */
.proxy-groups-wrap {
  display: flex;
  flex-direction: column;
  gap: 24px;
}
.proxy-group-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 20px;
}
.group-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border-color);
}
.group-title-box {
  display: flex;
  align-items: center;
  gap: 12px;
}
.group-name {
  font-size: 16px;
  font-weight: 600;
}
.group-type-badge {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-muted);
}
.group-now-node {
  font-size: 13px;
  color: #38bdf8;
  font-weight: 500;
}

.nodes-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 10px;
}
.node-item {
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 10px 12px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 6px;
  transition: all 0.2s;
}
.node-item:hover {
  border-color: rgba(99, 102, 241, 0.5);
  background: rgba(99, 102, 241, 0.05);
}
.node-item.selected {
  border-color: var(--accent-primary);
  background: rgba(99, 102, 241, 0.15);
  box-shadow: 0 0 10px rgba(99, 102, 241, 0.2);
}
.node-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.node-name {
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
}
.node-bottom {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.node-proto {
  font-size: 11px;
  color: var(--text-dim);
  text-transform: uppercase;
}
.delay-badge {
  font-size: 11px;
  padding: 1px 6px;
  border-radius: 4px;
  font-family: monospace;
}
.delay-badge.fast { color: #34d399; background: rgba(52, 211, 153, 0.15); }
.delay-badge.medium { color: #fbbf24; background: rgba(251, 191, 36, 0.15); }
.delay-badge.slow { color: #f87171; background: rgba(248, 113, 113, 0.15); }
.delay-badge.timeout { color: var(--text-dim); background: rgba(255, 255, 255, 0.05); }

/* Settings & Logs */
.settings-section {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 20px;
  margin-bottom: 20px;
}
.settings-title {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 16px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border-color);
}
.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
}
.settings-row:last-child {
  border-bottom: none;
}
.settings-label h4 {
  font-size: 14px;
  font-weight: 500;
  margin-bottom: 2px;
}
.settings-label p {
  font-size: 12px;
  color: var(--text-dim);
}

.terminal-box {
  background: #090a0f;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 16px;
  font-family: Consolas, Monaco, monospace;
  font-size: 12px;
  color: #cbd5e1;
  height: 380px;
  overflow-y: auto;
  line-height: 1.6;
}
.log-line {
  margin-bottom: 2px;
  word-break: break-all;
}
.log-line.info { color: #38bdf8; }
.log-line.warning { color: #fbbf24; }
.log-line.error { color: #f87171; }

/* Modal */
.modal-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(6px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 100;
}
.modal-overlay.active {
  display: flex;
}
.modal-box {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  width: 90%;
  max-width: 500px;
  padding: 24px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.modal-header h3 {
  font-size: 18px;
  font-weight: 600;
}
.modal-close {
  background: transparent;
  border: none;
  color: var(--text-dim);
  font-size: 20px;
  cursor: pointer;
}
.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.form-group label {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 500;
}
.form-input {
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  color: var(--text-main);
  font-size: 13px;
  outline: none;
  transition: border-color 0.2s;
}
.form-input:focus {
  border-color: var(--accent-primary);
}
.form-checkbox-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  cursor: pointer;
}
.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  margin-top: 8px;
}

/* Toast */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 200;
}
.toast {
  background: rgba(28, 33, 50, 0.95);
  border: 1px solid var(--border-color);
  border-left: 4px solid var(--accent-primary);
  border-radius: var(--radius-md);
  padding: 12px 18px;
  color: var(--text-main);
  font-size: 13px;
  line-height: 1.5;
  white-space: pre-wrap;
  max-width: 450px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
  transform: translateX(100%);
  animation: slideIn 0.25s forwards;
}
.toast.success { border-left-color: var(--color-success); }
.toast.error { border-left-color: var(--color-danger); }
.toast.info { border-left-color: var(--accent-cyan); }
@keyframes slideIn {
  to { transform: translateX(0); }
}

/* Modal Tabs */
.modal-tabs {
  display: flex;
  gap: 8px;
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 12px;
}
.modal-tab-btn {
  padding: 6px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
  background: var(--bg-card);
  color: var(--text-dim);
  font-size: 13px;
  cursor: pointer;
  transition: var(--transition);
}
.modal-tab-btn:hover {
  color: var(--text-main);
  border-color: var(--accent-primary);
}
.modal-tab-btn.active {
  border-color: var(--accent-primary);
  background: rgba(99, 102, 241, 0.15);
  color: var(--accent-primary);
  font-weight: 500;
}
.drop-zone {
  border: 2px dashed var(--border-color);
  border-radius: var(--radius-md);
  padding: 24px 16px;
  text-align: center;
  cursor: pointer;
  transition: var(--transition);
  background: rgba(0, 0, 0, 0.2);
}
.drop-zone:hover, .drop-zone.dragover {
  border-color: var(--accent-primary);
  background: rgba(99, 102, 241, 0.08);
}
