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

:root {
  --bg: #0a0b10;
  --surface: #12141d;
  --surface2: #1a1d2e;
  --surface3: #222640;
  --border: #252840;
  --accent: #7c6aff;
  --accent-hover: #8f80ff;
  --accent-glow: rgba(124,106,255,0.25);
  --green: #34d399;
  --green-dim: rgba(52,211,153,0.15);
  --red: #f87171;
  --red-dim: rgba(248,113,113,0.12);
  --orange: #fbbf24;
  --blue: #3b82f6;
  --text: #e8ecf4;
  --text2: #a0a8c4;
  --muted: #6b7394;
  --radius: 12px;
  --sidebar-w: 240px;
}

/* ── Light Mode ── */
body.light {
  --bg: #f0f2f8;
  --surface: #ffffff;
  --surface2: #f4f5fb;
  --surface3: #e8eaf5;
  --border: #dde0f0;
  --accent: #6c5ce7;
  --accent-hover: #7d6df0;
  --accent-glow: rgba(108,92,231,0.2);
  --green: #059669;
  --green-dim: rgba(5,150,105,0.1);
  --red: #dc2626;
  --red-dim: rgba(220,38,38,0.08);
  --orange: #d97706;
  --blue: #2563eb;
  --text: #1e2035;
  --text2: #4b5280;
  --muted: #7c82a8;
}

/* Smooth theme transitions */
body, .sidebar, .card, .tool-card, .modal, .stat-card, .input,
.btn, .badge, .session-item, .profile-item, .toast {
  transition: background 0.25s ease, border-color 0.25s ease,
              color 0.15s ease, box-shadow 0.25s ease;
}

/* ── Theme Toggle Button ── */
.theme-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  margin: 8px 12px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 12px;
  cursor: pointer;
  transition: all 0.2s;
  user-select: none;
}

.theme-toggle:hover {
  border-color: var(--accent);
  background: var(--surface3);
}

.theme-toggle-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text2);
}

.theme-pill {
  position: relative;
  width: 52px;
  height: 26px;
  background: var(--surface3);
  border-radius: 13px;
  border: 1px solid var(--border);
  transition: background 0.3s;
  flex-shrink: 0;
}

body.light .theme-pill {
  background: linear-gradient(135deg, #fbbf24, #f59e0b);
  border-color: #f59e0b;
}

body:not(.light) .theme-pill {
  background: linear-gradient(135deg, #4338ca, #7c6aff);
  border-color: #7c6aff;
}

.theme-pill-knob {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 6px rgba(0,0,0,0.3);
  transition: transform 0.3s cubic-bezier(0.34,1.56,0.64,1);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
}

body.light .theme-pill-knob {
  transform: translateX(26px);
}


html { height: 100%; }
body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* ── Sidebar ── */
.sidebar {
  width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

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

.brand-icon {
  width: 40px; height: 40px;
  background: linear-gradient(135deg, var(--accent), #a78bfa);
  border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  font-size: 20px;
  box-shadow: 0 4px 16px var(--accent-glow);
}

.brand-text {
  font-size: 18px; font-weight: 800;
  letter-spacing: 0.3px;
}

.sidebar-nav {
  flex: 1;
  padding: 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

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

.nav-item:hover { background: var(--surface2); color: var(--text); }
.nav-item.active { background: var(--accent); color: #fff; box-shadow: 0 2px 12px var(--accent-glow); }

.sidebar-footer {
  padding: 16px 20px;
  border-top: 1px solid var(--border);
}

.version { font-size: 11px; color: var(--muted); }

/* ── Main Content ── */
.main-content {
  flex: 1;
  overflow-y: auto;
  padding: 32px 40px;
}

.page { display: none; }
.page.active { display: block; }

.page-header { margin-bottom: 28px; }
.page-header h1 { font-size: 28px; font-weight: 800; }
.page-desc { color: var(--muted); font-size: 14px; margin-top: 4px; }

/* ── Stats Grid ── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  display: flex; align-items: center; gap: 16px;
  transition: border-color 0.2s;
}

.stat-card:hover { border-color: var(--accent); }

.stat-icon {
  width: 48px; height: 48px;
  border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}

.stat-value { font-size: 28px; font-weight: 800; }
.stat-label { font-size: 12px; color: var(--muted); margin-top: 2px; }

/* ── Card ── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
}

.card-title { font-size: 16px; font-weight: 700; margin-bottom: 16px; }
.card-subtitle { font-size: 14px; font-weight: 600; margin-top: 24px; margin-bottom: 12px; color: var(--text2); }

/* ── Buttons ── */
.btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 10px 20px;
  border-radius: 10px;
  font-size: 13px; font-weight: 600;
  cursor: pointer;
  border: none;
  transition: all 0.2s;
  font-family: inherit;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 2px 10px var(--accent-glow);
}

.btn-primary:hover { background: var(--accent-hover); transform: translateY(-1px); }

.btn-outline {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text2);
}

.btn-outline:hover { border-color: var(--accent); color: var(--text); }

.btn-sm { padding: 6px 12px; font-size: 12px; border-radius: 8px; }
.btn-danger { background: var(--red-dim); color: var(--red); border: 1px solid rgba(248,113,113,0.2); }
.btn-danger:hover { background: var(--red); color: #fff; }
.btn-green { background: var(--green-dim); color: var(--green); border: 1px solid rgba(52,211,153,0.2); }
.btn-green:hover { background: var(--green); color: #fff; }

.quick-actions { display: flex; gap: 12px; }

/* ── Forms ── */
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: 12px; font-weight: 600; color: var(--muted); margin-bottom: 6px; text-transform: uppercase; letter-spacing: 0.5px; }
.form-row { display: flex; gap: 16px; }
.form-row .form-group { flex: 1; }

.input {
  width: 100%;
  padding: 10px 14px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.2s;
}

.input:focus { border-color: var(--accent); }
.textarea { min-height: 120px; resize: vertical; font-family: 'Menlo', 'Consolas', monospace; font-size: 12px; }
select.input { cursor: pointer; }
.method-hint { font-size: 12px; color: var(--text2); margin: -8px 0 16px; padding: 8px 12px; background: var(--surface3); border-radius: 8px; }

/* ── Tools Grid ── */
.tools-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 16px;
}

.tool-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  transition: all 0.2s;
}

.tool-card:hover { border-color: var(--accent); transform: translateY(-2px); box-shadow: 0 4px 20px rgba(0,0,0,0.3); }
.tool-card.disabled { opacity: 0.5; }

.tool-card-header {
  display: flex; align-items: center; gap: 12px; margin-bottom: 12px;
}

.tool-favicon {
  width: 36px; height: 36px;
  border-radius: 10px;
  background: var(--surface2);
  border: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  overflow: hidden; flex-shrink: 0;
}

.tool-favicon img { width: 22px; height: 22px; }

.tool-card-info { flex: 1; min-width: 0; }
.tool-card-name { font-size: 15px; font-weight: 700; }
.tool-card-domains { font-size: 11px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.tool-card-badges {
  display: flex; gap: 6px; margin-bottom: 12px;
}

.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 8px;
  border-radius: 6px;
  font-size: 10px; font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.badge-proxy { background: rgba(251,191,36,0.12); color: var(--orange); }
.badge-overlay { background: rgba(59,130,246,0.12); color: var(--blue); }
.badge-method { background: var(--surface2); color: var(--text2); }

.tool-card-actions {
  display: flex; align-items: center; gap: 8px; justify-content: space-between;
}

/* ── Toggle ── */
.toggle { position: relative; width: 44px; height: 24px; flex-shrink: 0; }
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle .slider {
  position: absolute; inset: 0;
  background: var(--surface3);
  border-radius: 24px;
  cursor: pointer;
  transition: all 0.25s;
}
.toggle .slider::before {
  content: ''; position: absolute;
  width: 18px; height: 18px;
  left: 3px; bottom: 3px;
  background: var(--muted);
  border-radius: 50%;
  transition: all 0.25s;
}
.toggle input:checked + .slider { background: var(--accent); }
.toggle input:checked + .slider::before { transform: translateX(20px); background: #fff; }

/* ── Sessions List ── */
.sessions-list { display: flex; flex-direction: column; gap: 8px; }

.session-item {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px;
  background: var(--surface2);
  border-radius: 10px;
  border: 1px solid var(--border);
}

.session-item-info { display: flex; align-items: center; gap: 12px; }
.session-item-name { font-weight: 600; font-size: 14px; }
.session-item-meta { font-size: 11px; color: var(--muted); }

/* ── Profiles List ── */
.profiles-list { display: flex; flex-direction: column; gap: 8px; }

.profile-item {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px;
  background: var(--surface2);
  border-radius: 10px;
  border: 1px solid var(--border);
}

.profile-id { font-family: 'Menlo', monospace; font-size: 13px; font-weight: 600; }
.profile-meta { font-size: 11px; color: var(--muted); }

.status-dot-lg {
  width: 10px; height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}
.status-dot-lg.active { background: var(--green); box-shadow: 0 0 8px var(--green); }
.status-dot-lg.inactive { background: var(--red); }

/* ── Proxy Tools ── */
.proxy-tools-list { display: flex; flex-wrap: wrap; gap: 8px; }
.proxy-tool-tag {
  padding: 6px 12px;
  background: rgba(251,191,36,0.1);
  color: var(--orange);
  border-radius: 8px;
  font-size: 12px; font-weight: 600;
  border: 1px solid rgba(251,191,36,0.2);
}

/* ── Modal ── */
.modal-overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(4px);
  z-index: 1000;
  align-items: center; justify-content: center;
}
.modal-overlay.active { display: flex; }

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  width: 560px;
  max-height: 80vh;
  display: flex; flex-direction: column;
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
}

.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
}

.modal-header h2 { font-size: 18px; font-weight: 700; }
.modal-close {
  width: 32px; height: 32px;
  background: var(--surface2);
  border: none; border-radius: 8px;
  color: var(--muted);
  font-size: 20px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.modal-close:hover { background: var(--red-dim); color: var(--red); }

.modal-body { padding: 24px; overflow-y: auto; flex: 1; }
.modal-footer {
  padding: 16px 24px;
  border-top: 1px solid var(--border);
  display: flex; gap: 12px; justify-content: flex-end;
}

/* ── Toast ── */
.toast-container {
  position: fixed; bottom: 24px; right: 24px;
  z-index: 2000;
  display: flex; flex-direction: column; gap: 8px;
}

.toast {
  padding: 12px 20px;
  border-radius: 10px;
  font-size: 13px; font-weight: 600;
  animation: toast-in 0.3s ease;
  box-shadow: 0 4px 20px rgba(0,0,0,0.4);
}

.toast.success { background: var(--green); color: #000; }
.toast.error { background: var(--red); color: #fff; }
.toast.info { background: var(--accent); color: #fff; }

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

/* ── Status Message ── */
.status-msg {
  margin-top: 12px;
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 13px;
  display: none;
}
.status-msg.success { display: block; background: var(--green-dim); color: var(--green); }
.status-msg.error { display: block; background: var(--red-dim); color: var(--red); }

/* ── Loading ── */
.loading { text-align: center; padding: 40px; color: var(--muted); font-size: 14px; }

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 6px; }
::-webkit-scrollbar-thumb:hover { background: var(--muted); }

/* ── Responsive ── */
@media (max-width: 900px) {
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .tools-grid { grid-template-columns: 1fr; }
}

/* ── Proxy Extras ── */
@keyframes spin { to { transform: rotate(360deg); } }
.btn-sm { font-size: 12px; padding: 4px 10px; border-radius: 6px; }

/* ── Tag Input (Pages + CSS Selectors) ── */
.tag-input-container {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 10px;
  min-height: 48px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: flex-start;
  cursor: text;
  transition: border-color 0.2s;
}
.tag-input-container:focus-within { border-color: var(--accent); }

.tag-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.tag-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  background: var(--surface3);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 12px;
  font-family: 'Menlo', 'Consolas', monospace;
  color: var(--text);
  white-space: nowrap;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tag-chip .tag-remove {
  cursor: pointer;
  color: var(--muted);
  font-size: 14px;
  line-height: 1;
  transition: color 0.15s;
  flex-shrink: 0;
}
.tag-chip .tag-remove:hover { color: var(--red); }

.tag-input {
  border: none;
  outline: none;
  background: transparent;
  color: var(--text);
  font-size: 13px;
  font-family: 'Menlo', 'Consolas', monospace;
  flex: 1;
  min-width: 180px;
  padding: 4px 2px;
}
.tag-input::placeholder { color: var(--muted); }

/* Page rule items */
.page-rule-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  background: var(--surface2);
  border-radius: 10px;
  border: 1px solid var(--border);
  margin-bottom: 8px;
}
.page-rule-tool { font-weight: 600; font-size: 14px; display: flex; align-items: center; gap: 10px; }
.page-rule-paths { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }

/* ── Searchable Select ── */
.searchable-select { position: relative; }
.ss-trigger {
  display: flex; align-items: center; justify-content: space-between;
  cursor: pointer; user-select: none;
}
.ss-dropdown {
  display: none;
  position: absolute; top: calc(100% + 4px); left: 0; right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 12px 40px rgba(0,0,0,0.4);
  z-index: 100;
  overflow: hidden;
}
.ss-dropdown.open { display: block; }
.ss-search {
  border-radius: 0 !important;
  border: none !important;
  border-bottom: 1px solid var(--border) !important;
}
.ss-list {
  max-height: 240px;
  overflow-y: auto;
}
.ss-item {
  padding: 10px 14px;
  font-size: 14px;
  cursor: pointer;
  transition: background 0.15s;
  display: flex; align-items: center; gap: 10px;
}
.ss-item:hover { background: var(--surface2); }
.ss-item.active { background: var(--accent); color: #fff; }
.ss-item img { width: 18px; height: 18px; border-radius: 4px; }
.ss-item.hidden { display: none; }
