/* ===== CSS 变量 ===== */
:root {
  --primary: #4a90d9;
  --primary-hover: #357abd;
  --primary-light: #e8f0fe;
  --danger: #e74c3c;
  --danger-hover: #c0392b;
  --success: #27ae60;
  --success-bg: #e8f8f0;
  --gray: #95a5a6;
  --gray-bg: #f0f0f0;
  --gray-hover: #7f8c8d;
  --text: #333333;
  --text-light: #666666;
  --text-muted: #999999;
  --border: #e0e0e0;
  --bg: #f5f7fa;
  --white: #ffffff;
  --shadow: 0 2px 12px rgba(0, 0, 0, 0.1);
  --shadow-sm: 0 1px 4px rgba(0, 0, 0, 0.08);
  --radius: 6px;
  --radius-lg: 10px;
  --transition: 0.2s ease;
}

/* ===== 基础重置 ===== */
*,
*::before,
*::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "PingFang SC", "Microsoft YaHei", sans-serif;
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  line-height: 1.6;
}

a {
  color: var(--primary);
  text-decoration: none;
  transition: color var(--transition);
}

a:hover {
  color: var(--primary-hover);
}

/* ===== 容器 ===== */
.container {
  max-width: 960px;
  margin: 0 auto;
  padding: 24px 20px;
}

/* ===== 页面头部 ===== */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}

.page-header h1 {
  font-size: 22px;
  font-weight: 600;
  color: var(--text);
}

.page-header .back-link {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 14px;
  color: var(--text-light);
  margin-right: 12px;
}

.page-header .back-link:hover {
  color: var(--primary);
}

.page-header .title-group {
  display: flex;
  align-items: center;
}

.page-header .title-group h1 {
  font-size: 20px;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 16px;
}

/* ===== 按钮 ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 16px;
  font-size: 14px;
  font-weight: 500;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
  line-height: 1.4;
}

.btn:hover {
  opacity: 0.9;
}

.btn:active {
  transform: scale(0.97);
}

.btn-primary {
  background: var(--primary);
  color: var(--white);
}

.btn-primary:hover {
  background: var(--primary-hover);
}

.btn-danger {
  background: var(--danger);
  color: var(--white);
}

.btn-danger:hover {
  background: var(--danger-hover);
}

.btn-sm {
  padding: 4px 10px;
  font-size: 12px;
  border-radius: 4px;
}

.btn-gray {
  background: var(--gray-bg);
  color: var(--text-light);
  border: 1px solid var(--border);
}

.btn-gray:hover {
  background: var(--border);
  color: var(--text);
}

.btn-success {
  background: var(--success);
  color: var(--white);
}

.btn-success:hover {
  background: #219a52;
}

.btn-outline {
  background: var(--white);
  color: var(--text-light);
  border: 1px solid var(--border);
}

.btn-outline:hover {
  border-color: var(--primary);
  color: var(--primary);
}

/* ===== 表格 ===== */
.table-wrapper {
  background: var(--white);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

table {
  width: 100%;
  border-collapse: collapse;
}

thead {
  background: var(--primary-light);
}

th {
  padding: 12px 16px;
  text-align: left;
  font-weight: 600;
  font-size: 13px;
  color: var(--text-light);
  white-space: nowrap;
}

td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

tbody tr:nth-child(even) {
  background: #fafbfc;
}

tbody tr:hover {
  background: var(--primary-light);
}

tbody tr:last-child td {
  border-bottom: none;
}

/* 配置码列 */
.code-cell {
  display: flex;
  align-items: center;
  gap: 6px;
}

.code-cell .code-text {
  font-family: "SF Mono", "Consolas", "Monaco", monospace;
  font-size: 12px;
  color: var(--text-light);
  background: var(--gray-bg);
  padding: 2px 8px;
  border-radius: 3px;
  letter-spacing: 0.5px;
}

.code-cell .btn-copy {
  padding: 2px 6px;
  font-size: 12px;
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: 3px;
  color: var(--text-muted);
  cursor: pointer;
  transition: all var(--transition);
}

.code-cell .btn-copy:hover {
  color: var(--primary);
  border-color: var(--primary);
}

/* 操作列 */
.action-cell {
  display: flex;
  align-items: center;
  gap: 6px;
}

/* 状态标签 */
.status-tag {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 500;
}

.status-tag.enabled {
  background: var(--success-bg);
  color: var(--success);
}

.status-tag.disabled {
  background: var(--gray-bg);
  color: var(--gray);
}

/* ===== 弹窗 ===== */
.modal-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.45);
  z-index: 1000;
  justify-content: center;
  align-items: center;
}

.modal-overlay.active {
  display: flex;
}

.modal-card {
  background: var(--white);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  width: 90%;
  max-width: 480px;
  padding: 24px;
  animation: modalIn 0.2s ease;
}

@keyframes modalIn {
  from {
    opacity: 0;
    transform: translateY(-20px) scale(0.96);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.modal-card h3 {
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 20px;
  color: var(--text);
}

.modal-card .form-group {
  margin-bottom: 16px;
}

.modal-card label {
  display: block;
  margin-bottom: 6px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-light);
}

.modal-card label .required {
  color: var(--danger);
  margin-left: 2px;
}

.modal-card input,
.modal-card select,
.modal-card textarea {
  width: 100%;
  padding: 8px 12px;
  font-size: 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  outline: none;
  transition: border-color var(--transition);
  font-family: inherit;
}

.modal-card input:focus,
.modal-card select:focus,
.modal-card textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(74, 144, 217, 0.15);
}

.modal-card textarea {
  resize: vertical;
  min-height: 60px;
}

.modal-card .form-row {
  display: flex;
  gap: 12px;
}

.modal-card .form-row .form-group {
  flex: 1;
}

.modal-card .modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 24px;
}

/* 确认弹窗 */
.confirm-card {
  max-width: 380px;
  text-align: center;
}

.confirm-card .confirm-icon {
  font-size: 40px;
  margin-bottom: 12px;
}

.confirm-card .confirm-text {
  font-size: 15px;
  color: var(--text-light);
  margin-bottom: 24px;
  line-height: 1.6;
}

.confirm-card .modal-actions {
  justify-content: center;
}

/* ===== Toast ===== */
.toast-container {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  padding: 10px 20px;
  border-radius: var(--radius);
  font-size: 14px;
  color: var(--white);
  box-shadow: var(--shadow);
  animation: toastIn 0.3s ease, toastOut 0.3s ease 2.7s forwards;
  max-width: 320px;
  word-break: break-all;
}

.toast.success {
  background: var(--success);
}

.toast.error {
  background: var(--danger);
}

.toast.info {
  background: var(--primary);
}

@keyframes toastIn {
  from {
    opacity: 0;
    transform: translateX(40px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@keyframes toastOut {
  from {
    opacity: 1;
    transform: translateX(0);
  }
  to {
    opacity: 0;
    transform: translateX(40px);
  }
}

/* ===== 编辑页 - 基本信息区域 ===== */
.info-section {
  background: var(--white);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: 24px;
  margin-bottom: 24px;
}

.info-section h2 {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 16px;
  color: var(--text);
}

.info-section .form-group {
  margin-bottom: 14px;
}

.info-section label {
  display: block;
  margin-bottom: 6px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-light);
}

.info-section label .required {
  color: var(--danger);
  margin-left: 2px;
}

.info-section input,
.info-section textarea {
  width: 100%;
  padding: 8px 12px;
  font-size: 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  outline: none;
  transition: border-color var(--transition);
  font-family: inherit;
}

.info-section input:focus,
.info-section textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(74, 144, 217, 0.15);
}

.info-section textarea {
  resize: vertical;
  min-height: 60px;
}

.info-section input[readonly] {
  background: var(--gray-bg);
  color: var(--text-muted);
  cursor: default;
}

.code-field {
  display: flex;
  gap: 8px;
  align-items: center;
}

.code-field input {
  flex: 1;
}

.code-field .btn-copy {
  flex-shrink: 0;
  padding: 8px 12px;
  font-size: 13px;
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-muted);
  cursor: pointer;
  transition: all var(--transition);
}

.code-field .btn-copy:hover {
  color: var(--primary);
  border-color: var(--primary);
}

.info-section .btn-save {
  margin-top: 8px;
}

/* ===== 编辑页 - 代理分组卡片 ===== */
.proxy-group {
  background: var(--white);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border);
  margin-bottom: 20px;
  overflow: hidden;
}

.proxy-group-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  background: var(--primary-light);
  border-bottom: 1px solid var(--border);
}

.proxy-group-header h3 {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
}

.proxy-group-body {
  padding: 0;
}

.proxy-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  transition: background var(--transition);
}

.proxy-item:last-child {
  border-bottom: none;
}

.proxy-item:hover {
  background: #fafbfc;
}

.proxy-item .proxy-info {
  display: flex;
  align-items: center;
  gap: 16px;
}

.proxy-item .proxy-name {
  font-weight: 500;
  color: var(--text);
  min-width: 80px;
}

.proxy-item .proxy-address {
  font-family: "SF Mono", "Consolas", "Monaco", monospace;
  font-size: 13px;
  color: var(--text-light);
  background: var(--gray-bg);
  padding: 2px 8px;
  border-radius: 3px;
}

.proxy-item .proxy-actions {
  display: flex;
  gap: 6px;
}

.proxy-empty {
  padding: 24px 20px;
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
}

/* ===== 空状态 ===== */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
}

.empty-state .empty-icon {
  font-size: 48px;
  margin-bottom: 12px;
}

.empty-state p {
  font-size: 15px;
}

/* ===== 加载状态 ===== */
.loading {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-muted);
}

.loading::after {
  content: "";
  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;
  margin-left: 8px;
  vertical-align: middle;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* ===== 响应式 ===== */
@media (max-width: 768px) {
  .container {
    padding: 16px 12px;
  }

  .page-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
  }

  .page-header h1 {
    font-size: 18px;
  }

  th, td {
    padding: 10px 8px;
    font-size: 13px;
  }

  .code-cell .code-text {
    font-size: 11px;
    max-width: 120px;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .action-cell {
    flex-wrap: wrap;
  }

  .modal-card {
    width: 95%;
    padding: 16px;
  }

  .modal-card .form-row {
    flex-direction: column;
    gap: 0;
  }

  .proxy-item {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
  }

  .proxy-item .proxy-actions {
    align-self: flex-end;
  }
}

@media (max-width: 480px) {
  .table-wrapper {
    overflow-x: auto;
  }

  table {
    min-width: 600px;
  }
}

/* ===== 登录页面 ===== */
.login-body {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

.login-container {
  width: 100%;
  padding: 20px;
}

.login-card {
  background: var(--white);
  border-radius: 16px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.15);
  width: 100%;
  max-width: 420px;
  margin: 0 auto;
  padding: 40px 36px;
  animation: fadeInUp 0.5s ease;
}

@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.login-header {
  text-align: center;
  margin-bottom: 32px;
}

.login-logo {
  margin-bottom: 16px;
}

.login-logo svg {
  display: inline-block;
}

.login-title {
  font-size: 24px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 8px;
}

.login-subtitle {
  font-size: 14px;
  color: var(--text-muted);
}

.login-form .form-group {
  margin-bottom: 20px;
}

.login-form label {
  display: block;
  margin-bottom: 8px;
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
}

.input-wrapper {
  position: relative;
  display: flex;
  align-items: center;
}

.input-icon {
  position: absolute;
  left: 12px;
  color: var(--text-muted);
  pointer-events: none;
  z-index: 1;
}

.input-wrapper input {
  width: 100%;
  padding: 12px 12px 12px 40px;
  font-size: 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  outline: none;
  transition: all var(--transition);
  font-family: inherit;
}

.input-wrapper input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(74, 144, 217, 0.15);
}

.input-wrapper input::placeholder {
  color: var(--text-muted);
}

.password-toggle {
  position: absolute;
  right: 8px;
  background: none;
  border: none;
  padding: 6px;
  cursor: pointer;
  color: var(--text-muted);
  transition: color var(--transition);
  display: flex;
  align-items: center;
  justify-content: center;
}

.password-toggle:hover {
  color: var(--primary);
}

.form-options {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-size: 14px;
  color: var(--text-light);
  user-select: none;
}

.checkbox-label input[type="checkbox"] {
  display: none;
}

.checkbox-custom {
  width: 18px;
  height: 18px;
  border: 2px solid var(--border);
  border-radius: 4px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition);
  flex-shrink: 0;
}

.checkbox-label input[type="checkbox"]:checked + .checkbox-custom {
  background: var(--primary);
  border-color: var(--primary);
}

.checkbox-label input[type="checkbox"]:checked + .checkbox-custom::after {
  content: "";
  width: 10px;
  height: 6px;
  border: 2px solid white;
  border-top: none;
  border-right: none;
  transform: rotate(-45deg);
  margin-top: -2px;
}

.forgot-password {
  font-size: 14px;
  color: var(--primary);
  text-decoration: none;
  transition: color var(--transition);
}

.forgot-password:hover {
  color: var(--primary-hover);
  text-decoration: underline;
}

.error-message {
  background: #fef2f2;
  border: 1px solid #fecaca;
  color: #dc2626;
  padding: 10px 14px;
  border-radius: var(--radius);
  font-size: 14px;
  margin-bottom: 16px;
  animation: shake 0.3s ease;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-5px); }
  75% { transform: translateX(5px); }
}

.btn-login {
  width: 100%;
  padding: 14px;
  font-size: 16px;
  font-weight: 600;
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.btn-login:disabled {
  opacity: 0.7;
  cursor: not-allowed;
}

.btn-loading {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.spinner {
  animation: spin 1s linear infinite;
}

.login-footer {
  text-align: center;
  margin-top: 24px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
}

.login-footer p {
  font-size: 13px;
  color: var(--text-muted);
}

/* ===== 页面头部用户信息 ===== */
.user-info {
  display: flex;
  align-items: center;
  gap: 12px;
}

.user-name {
  font-size: 14px;
  color: var(--text-light);
  font-weight: 500;
}

.btn-logout {
  padding: 6px 14px;
  font-size: 13px;
  background: var(--gray-bg);
  color: var(--text-light);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: all var(--transition);
}

.btn-logout:hover {
  background: var(--danger);
  color: var(--white);
  border-color: var(--danger);
}

/* ===== 登录页面响应式 ===== */
@media (max-width: 480px) {
  .login-card {
    padding: 28px 24px;
  }

  .login-title {
    font-size: 20px;
  }
}

/* ===== 导入配置码弹窗 ===== */
.import-code-desc {
  font-size: 14px;
  color: var(--text-light);
  margin-bottom: 16px;
  line-height: 1.6;
}

.import-code-textarea {
  width: 100%;
  padding: 10px 12px;
  font-size: 12px;
  font-family: "SF Mono", "Consolas", "Monaco", monospace;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  resize: vertical;
  min-height: 80px;
  background: var(--gray-bg);
  color: var(--text);
}
