/* ========================================
   Proxy Pool Management - Cloudflare Pages
   ======================================== */

:root {
  --primary: #4f6ef7;
  --primary-dark: #3a56d4;
  --primary-light: #6b85ff;
  --bg-dark: #0f1117;
  --bg-card: #1a1d27;
  --bg-card-hover: #22263a;
  --bg-input: #262a3e;
  --border: #2d3250;
  --text: #e4e6ed;
  --text-secondary: #8b8fa7;
  --text-muted: #5a5e75;
  --success: #22c55e;
  --warning: #f59e0b;
  --danger: #ef4444;
  --info: #3b82f6;
  --radius: 8px;
  --radius-lg: 12px;
  --shadow: 0 2px 12px rgba(0,0,0,0.3);
  --transition: 0.2s ease;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', sans-serif;
  background: var(--bg-dark);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.6;
}

/* Scrollbar */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg-dark); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ========================================
   Login Page
   ======================================== */
.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: linear-gradient(135deg, var(--bg-dark) 0%, #1a1d2e 100%);
}

.login-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 40px;
  width: 400px;
  max-width: 90vw;
  box-shadow: var(--shadow);
}

.login-card .btn-primary {
  width: 100%;
}

.login-card h1 {
  font-size: 24px;
  text-align: center;
  margin-bottom: 8px;
  color: var(--text);
}

.login-card .subtitle {
  text-align: center;
  color: var(--text-secondary);
  margin-bottom: 32px;
  font-size: 14px;
}

.form-group {
  margin-bottom: 20px;
}

.form-group label {
  display: block;
  font-size: 14px;
  font-weight: 500;
  margin-bottom: 6px;
  color: var(--text-secondary);
}

.form-group input {
  width: 100%;
  padding: 10px 14px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 14px;
  outline: none;
  transition: border-color var(--transition);
}

.form-group input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(79, 110, 247, 0.15);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 20px;
  border: none;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
  text-decoration: none;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
}

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

.btn-primary:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
}

.btn-sm {
  padding: 6px 12px;
  font-size: 12px;
}

.btn-danger {
  background: var(--danger);
  color: #fff;
}

.btn-danger:hover {
  background: #dc2626;
}

.btn-success {
  background: var(--success);
  color: #fff;
}

.btn-success:hover {
  background: #16a34a;
}

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

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

.btn-outline.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.login-error {
  background: rgba(239, 68, 68, 0.1);
  border: 1px solid rgba(239, 68, 68, 0.3);
  color: var(--danger);
  padding: 10px 14px;
  border-radius: var(--radius);
  font-size: 13px;
  margin-bottom: 16px;
  display: none;
}

/* ========================================
   Dashboard Layout
   ======================================== */
.dashboard {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 240px;
  background: var(--bg-card);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

.sidebar-header {
  padding: 20px;
  border-bottom: 1px solid var(--border);
}

.sidebar-header h2 {
  font-size: 18px;
  color: var(--text);
}

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

.sidebar-nav {
  flex: 1;
  padding: 12px 8px;
  list-style: none;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  margin-bottom: 2px;
  border-radius: var(--radius);
  cursor: pointer;
  transition: all var(--transition);
  color: var(--text-secondary);
  font-size: 14px;
  font-weight: 400;
  user-select: none;
}

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

.nav-item.active {
  background: rgba(79, 110, 247, 0.12);
  color: var(--primary-light);
  font-weight: 500;
}

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

.sidebar-footer {
  padding: 16px 20px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

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

.sidebar-footer .logout-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 13px;
  padding: 4px 8px;
  border-radius: 4px;
  transition: all var(--transition);
}

.sidebar-footer .logout-btn:hover {
  color: var(--danger);
  background: rgba(239, 68, 68, 0.1);
}

/* ========================================
   Main Content
   ======================================== */
.main-content {
  flex: 1;
  padding: 24px 32px;
  overflow-y: auto;
  max-height: 100vh;
}

.page-header {
  margin-bottom: 24px;
}

.page-header h1 {
  font-size: 22px;
  font-weight: 600;
}

.page-header p {
  color: var(--text-secondary);
  font-size: 14px;
  margin-top: 4px;
}

.page {
  display: none;
}

.page.active {
  display: block;
}

/* ========================================
   Cards
   ======================================== */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  margin-bottom: 16px;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.card-title {
  font-size: 16px;
  font-weight: 600;
}

/* ========================================
   Subscription Input
   ======================================== */
.subscription-input-area {
  display: flex;
  gap: 12px;
  margin-bottom: 16px;
}

.subscription-input-area input {
  flex: 1;
  padding: 10px 14px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 14px;
  outline: none;
  transition: border-color var(--transition);
}

.subscription-input-area input:focus {
  border-color: var(--primary);
}

.subscription-input-area .btn {
  white-space: nowrap;
  flex-shrink: 0;
  padding: 10px 16px;
}

.subscription-source-form input[type="text"] {
  flex: 0 1 260px;
}

.subscription-select-bar span {
  color: var(--text-muted);
  font-size: 12px;
  margin-left: 8px;
}

.subscription-table-wrap {
  overflow-x: auto;
}

.subscription-table th:nth-child(2) {
  min-width: 180px;
}

.subscription-table th:nth-child(3) {
  min-width: 280px;
}

.subscription-name {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  font-weight: 500;
}

.subscription-name span:last-child {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.subscription-link,
.subscription-link-sub {
  max-width: 420px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text-secondary);
  font-size: 12px;
  font-family: 'SF Mono', 'Menlo', monospace;
}

.subscription-link-sub {
  margin-top: 4px;
  color: var(--text-muted);
}

.subscription-updated {
  margin-top: 4px;
  color: var(--text-muted);
  font-size: 11px;
}

.subscription-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  min-width: 180px;
}

.subscription-result {
  margin-top: 16px;
}

/* ========================================
   Node Table
   ======================================== */
.node-controls {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 16px;
  align-items: center;
}

.node-controls .search-box {
  flex: 1;
  min-width: 200px;
  padding: 8px 12px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 13px;
  outline: none;
}

.node-controls .search-box:focus {
  border-color: var(--primary);
}

.node-stats {
  font-size: 13px;
  color: var(--text-secondary);
  margin-left: auto;
}

.node-table-wrap {
  overflow-x: auto;
}

.node-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.node-table th {
  text-align: left;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  color: var(--text-secondary);
  font-weight: 500;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  white-space: nowrap;
  user-select: none;
}

.node-table td {
  padding: 10px 12px;
  border-bottom: 1px solid rgba(45, 50, 80, 0.5);
  vertical-align: middle;
}

.node-table tr:hover td {
  background: rgba(79, 110, 247, 0.04);
}

.node-table .checkbox-cell {
  width: 40px;
  text-align: center;
}

.node-table input[type="checkbox"] {
  accent-color: var(--primary);
  width: 16px;
  height: 16px;
  cursor: pointer;
}

.node-type {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
}

.type-ss { background: rgba(34, 197, 94, 0.15); color: var(--success); }
.type-vmess { background: rgba(59, 130, 246, 0.15); color: var(--info); }
.type-trojan { background: rgba(245, 158, 11, 0.15); color: var(--warning); }
.type-vless { background: rgba(139, 92, 246, 0.15); color: #a78bfa; }
.type-hysteria { background: rgba(239, 68, 68, 0.15); color: var(--danger); }
.type-hysteria2 { background: rgba(236, 72, 153, 0.15); color: #f472b6; }
.type-tuic { background: rgba(20, 184, 166, 0.15); color: #14b8a6; }
.type-unknown { background: rgba(139, 143, 167, 0.15); color: var(--text-secondary); }

.node-name {
  font-weight: 500;
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.node-address {
  color: var(--text-secondary);
  font-size: 12px;
}

.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--text-muted);
}

.empty-state .empty-icon {
  font-size: 48px;
  margin-bottom: 16px;
  opacity: 0.5;
}

.empty-state h3 {
  color: var(--text-secondary);
  margin-bottom: 8px;
}

.empty-state p {
  font-size: 13px;
}

/* ========================================
   Generate Section
   ======================================== */
.generate-options {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 16px;
}

.generated-output {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  font-family: 'SF Mono', 'Menlo', 'Monaco', 'Cascadia Code', monospace;
  font-size: 13px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-all;
  max-height: 400px;
  overflow-y: auto;
  user-select: all;
  cursor: text;
}

.generate-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 16px;
}

/* ========================================
   Routing Rules
   ======================================== */
.rule-mode-selector {
  display: flex;
  gap: 8px;
  margin-bottom: 20px;
}

.rule-mode-btn {
  padding: 8px 16px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 13px;
  transition: all var(--transition);
}

.rule-mode-btn:hover {
  border-color: var(--primary);
  color: var(--text);
}

.rule-mode-btn.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.rule-list {
  list-style: none;
}

.rule-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 8px;
  transition: all var(--transition);
}

.rule-item:hover {
  border-color: var(--primary);
}

.rule-item .rule-type {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  padding: 2px 8px;
  border-radius: 4px;
  min-width: 48px;
  text-align: center;
}

.rule-type.domain { background: rgba(59, 130, 246, 0.15); color: var(--info); }
.rule-type.ip { background: rgba(34, 197, 94, 0.15); color: var(--success); }
.rule-type.geoip { background: rgba(245, 158, 11, 0.15); color: var(--warning); }
.rule-type.final { background: rgba(139, 143, 167, 0.15); color: var(--text-secondary); }

.rule-item .rule-content {
  flex: 1;
  font-size: 13px;
  font-family: 'SF Mono', 'Menlo', monospace;
  color: var(--text);
}

.rule-item .rule-proxy {
  font-size: 12px;
  color: var(--primary);
  padding: 2px 8px;
  background: rgba(79, 110, 247, 0.1);
  border-radius: 4px;
}

.rule-item .rule-actions {
  display: flex;
  gap: 4px;
}

.rule-item .rule-actions button {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 14px;
  transition: all var(--transition);
}

.rule-item .rule-actions button:hover {
  color: var(--danger);
  background: rgba(239, 68, 68, 0.1);
}

.rule-item.dragging {
  opacity: 0.5;
  border-style: dashed;
}

.add-rule-form {
  display: flex;
  gap: 8px;
  margin-top: 16px;
  flex-wrap: wrap;
}

.add-rule-form select,
.add-rule-form input {
  padding: 8px 12px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 13px;
  outline: none;
}

.add-rule-form select:focus,
.add-rule-form input:focus {
  border-color: var(--primary);
}

.add-rule-form input[type="text"] {
  flex: 1;
  min-width: 150px;
}

/* ========================================
   Proxy Groups
   ======================================== */
.proxy-group-list {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 16px;
}

.proxy-group-card {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  cursor: pointer;
  transition: all var(--transition);
}

.proxy-group-card:hover {
  border-color: var(--primary);
}

.proxy-group-card .group-name {
  font-weight: 600;
  font-size: 14px;
  margin-bottom: 4px;
}

.proxy-group-card .group-type {
  font-size: 12px;
  color: var(--text-secondary);
}

.proxy-group-card .group-nodes {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 4px;
}

/* ========================================
   Toast
   ======================================== */
.toast-container {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  padding: 12px 20px;
  border-radius: var(--radius);
  background: var(--bg-card);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 10px;
  animation: slideIn 0.3s ease;
  min-width: 280px;
}

.toast.success { border-left: 3px solid var(--success); }
.toast.error { border-left: 3px solid var(--danger); }
.toast.info { border-left: 3px solid var(--info); }
.toast.warning { border-left: 3px solid var(--warning); }

@keyframes slideIn {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

@keyframes fadeOut {
  from { opacity: 1; }
  to { opacity: 0; }
}

/* ========================================
   Modal
   ======================================== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 1000;
  display: none;
  align-items: center;
  justify-content: center;
}

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

.modal {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  width: 600px;
  max-width: 90vw;
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
}

.modal h3 {
  margin-bottom: 16px;
  font-size: 18px;
}

/* ========================================
   Loading Spinner
   ======================================== */
.spinner {
  display: inline-block;
  width: 20px;
  height: 20px;
  border: 2px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

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

/* ========================================
   Responsive
   ======================================== */
@media (max-width: 768px) {
  .sidebar {
    width: 60px;
  }
  .sidebar-header h2,
  .sidebar-header .version,
  .nav-item span,
  .sidebar-footer .user-info {
    display: none;
  }
  .sidebar-header {
    padding: 12px;
    text-align: center;
  }
  .nav-item {
    justify-content: center;
    padding: 12px;
  }
  .nav-item .icon {
    margin: 0;
  }
  .main-content {
    padding: 16px;
  }
  .subscription-input-area {
    flex-direction: column;
  }
  .subscription-source-form input[type="text"] {
    flex-basis: auto;
  }
  .generate-options,
  .proxy-group-list {
    grid-template-columns: 1fr;
  }
}

/* ========================================
   Select All Checkbox
   ======================================== */
.select-all-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 12px;
  font-size: 13px;
}

.select-all-bar input[type="checkbox"] {
  accent-color: var(--primary);
  width: 16px;
  height: 16px;
  cursor: pointer;
}

/* ========================================
   Tabs
   ======================================== */
.tabs {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 20px;
}

.tab-btn {
  padding: 10px 20px;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 14px;
  transition: all var(--transition);
  margin-bottom: -1px;
}

.tab-btn:hover {
  color: var(--text);
}

.tab-btn.active {
  color: var(--primary-light);
  border-bottom-color: var(--primary);
}

.tab-content {
  display: none;
}

.tab-content.active {
  display: block;
}

/* ========================================
   Copy feedback
   ======================================== */
.copy-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-secondary);
  cursor: pointer;
  padding: 4px 10px;
  border-radius: 4px;
  font-size: 12px;
  transition: all var(--transition);
}

.copy-btn:hover {
  border-color: var(--primary);
  color: var(--primary);
}

.copy-btn.copied {
  border-color: var(--success);
  color: var(--success);
}

/* ========================================
   Badge
   ======================================== */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 500;
}

.badge-primary { background: rgba(79, 110, 247, 0.15); color: var(--primary-light); }
.badge-success { background: rgba(34, 197, 94, 0.15); color: var(--success); }

/* ========================================
   Source Filter Bar (节点管理页)
   ======================================== */
.source-filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 12px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}

.source-filter-btn {
  padding: 5px 12px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 14px;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 12px;
  transition: all var(--transition);
  white-space: nowrap;
}

.source-filter-btn:hover {
  border-color: var(--primary);
  color: var(--text);
}

.source-filter-btn.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

/* ========================================
   Source Badge (表格中的来源列)
   ======================================== */
.source-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 11px;
  background: rgba(139, 143, 167, 0.12);
  color: var(--text-secondary);
  max-width: 120px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ========================================
   Remove/Delete button for nodes
   ======================================== */
.btn-icon {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 16px;
  transition: all var(--transition);
}

.btn-icon:hover {
  color: var(--danger);
  background: rgba(239, 68, 68, 0.1);
}
