/* ============================================
   百灵AI网关 - Admin 管理面板样式
   品牌色:
   主色: #0F2B46 (深海蓝)
   灵动色: #38BDF8 (亮青)
   强调色: #2DD4BF (青碧)
   背景: #f0f2f5 (浅灰)
   卡片: #ffffff
   ============================================ */

:root {
  --primary: #0F2B46;
  --primary-light: #1a3f5f;
  --accent: #38BDF8;
  --accent-hover: #0ea5e9;
  --emerald: #2DD4BF;
  --emerald-hover: #14b8a6;
  --bg: #f0f2f5;
  --card: #ffffff;
  --text: #1e293b;
  --text-secondary: #64748b;
  --text-light: #94a3b8;
  --border: #e2e8f0;
  --border-light: #f1f5f9;
  --danger: #ef4444;
  --danger-hover: #dc2626;
  --warning: #f59e0b;
  --success: #10b981;
  --info: #3b82f6;
  --sidebar-width: 240px;
  --header-height: 56px;
  --radius: 8px;
  --radius-lg: 12px;
  --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.06);
  --shadow-lg: 0 4px 12px rgba(0,0,0,0.1);
  --transition: all 0.2s ease;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  line-height: 1.5;
  overflow: hidden;
  height: 100vh;
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); }

/* ===== Layout ===== */
.app-layout {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* ===== Sidebar ===== */
.sidebar {
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  background: var(--primary);
  color: #fff;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 16px 20px;
  height: var(--header-height);
  border-bottom: 1px solid rgba(255,255,255,0.08);
  flex-shrink: 0;
}

.sidebar-brand svg {
  flex-shrink: 0;
}

.sidebar-brand h1 {
  font-size: 16px;
  font-weight: 600;
  letter-spacing: 0.5px;
  white-space: nowrap;
}

.sidebar-nav {
  flex: 1;
  padding: 12px 0;
  overflow-y: auto;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 20px;
  color: rgba(255,255,255,0.65);
  cursor: pointer;
  transition: var(--transition);
  border-left: 3px solid transparent;
  font-size: 14px;
}

.nav-item:hover {
  color: #fff;
  background: rgba(255,255,255,0.06);
}

.nav-item.active {
  color: #fff;
  background: rgba(56, 189, 248, 0.12);
  border-left-color: var(--accent);
}

.nav-item svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

.sidebar-footer {
  padding: 12px 20px;
  border-top: 1px solid rgba(255,255,255,0.08);
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.sidebar-footer .user-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 600;
  color: var(--primary);
  flex-shrink: 0;
}

.sidebar-footer .user-info {
  flex: 1;
  min-width: 0;
}

.sidebar-footer .user-name {
  font-size: 13px;
  font-weight: 500;
  color: #fff;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sidebar-footer .user-role {
  font-size: 11px;
  color: rgba(255,255,255,0.5);
}

.btn-logout {
  background: none;
  border: 1px solid rgba(255,255,255,0.2);
  color: rgba(255,255,255,0.7);
  padding: 4px 10px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 12px;
  transition: var(--transition);
}

.btn-logout:hover {
  background: rgba(255,255,255,0.1);
  color: #fff;
  border-color: rgba(255,255,255,0.4);
}

/* ===== Main Content ===== */
.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
}

.main-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  height: var(--header-height);
  background: var(--card);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.main-header h2 {
  font-size: 18px;
  font-weight: 600;
  color: var(--primary);
}

.main-header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.content-area {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
}

/* ===== Pages ===== */
.admin-page {
  display: none;
}

.admin-page.active {
  display: block;
}

/* ===== Cards ===== */
.card {
  background: var(--card);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 20px;
  margin-bottom: 20px;
}

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

.card-header h3 {
  font-size: 15px;
  font-weight: 600;
  color: var(--primary);
}

/* ===== Stats Grid ===== */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--card);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 20px;
  position: relative;
  overflow: hidden;
}

.stat-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
}

.stat-card:nth-child(1)::before { background: var(--accent); }
.stat-card:nth-child(2)::before { background: var(--emerald); }
.stat-card:nth-child(3)::before { background: var(--warning); }
.stat-card:nth-child(4)::before { background: var(--info); }

.stat-label {
  font-size: 12px;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 8px;
}

.stat-value {
  font-size: 28px;
  font-weight: 700;
  color: var(--primary);
}

/* ===== Tables ===== */
.table-wrapper {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
}

thead th {
  background: var(--border-light);
  padding: 10px 12px;
  text-align: left;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-bottom: 2px solid var(--border);
  white-space: nowrap;
}

tbody td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border-light);
  font-size: 13px;
}

tbody tr:hover {
  background: rgba(56, 189, 248, 0.04);
}

tbody tr:last-child td {
  border-bottom: none;
}

/* ===== Buttons ===== */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
  border: none;
  outline: none;
  line-height: 1.4;
}

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

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

.btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
}

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

.btn-danger:hover:not(:disabled) {
  background: var(--danger-hover);
}

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

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

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

.btn-xs {
  padding: 2px 8px;
  font-size: 11px;
}

/* ===== Tags / Badges ===== */
.tag {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 500;
  white-space: nowrap;
}

.tag-active {
  background: rgba(16, 185, 129, 0.1);
  color: var(--success);
}

.tag-disabled {
  background: rgba(239, 68, 68, 0.1);
  color: var(--danger);
}

.tag-admin {
  background: rgba(56, 189, 248, 0.1);
  color: var(--accent);
}

.tag-user {
  background: rgba(100, 116, 139, 0.1);
  color: var(--text-secondary);
}

.tag-unlimited {
  background: rgba(245, 158, 11, 0.1);
  color: var(--warning);
}

.tag-success {
  background: rgba(16, 185, 129, 0.1);
  color: var(--success);
}

.tag-error {
  background: rgba(239, 68, 68, 0.1);
  color: var(--danger);
}

/* ===== Empty State ===== */
.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-light);
}

.empty-state svg {
  margin-bottom: 12px;
  opacity: 0.3;
}

/* ===== Form ===== */
.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
  color: var(--text);
  background: var(--card);
  transition: var(--transition);
  outline: none;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(56, 189, 248, 0.15);
}

.form-group textarea {
  min-height: 80px;
  resize: vertical;
}

.form-group .help-text {
  font-size: 11px;
  color: var(--text-light);
  margin-top: 4px;
}

.form-error {
  color: var(--danger);
  font-size: 13px;
  margin-top: 8px;
}

.form-success {
  color: var(--success);
  font-size: 13px;
  margin-top: 8px;
}

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

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

.modal {
  background: var(--card);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: 90%;
  max-width: 520px;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
}

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

.modal-header h3 {
  font-size: 16px;
  font-weight: 600;
}

.modal-close {
  background: none;
  border: none;
  font-size: 20px;
  color: var(--text-light);
  cursor: pointer;
  padding: 4px;
  line-height: 1;
  border-radius: 4px;
  transition: var(--transition);
}

.modal-close:hover {
  background: var(--border-light);
  color: var(--text);
}

.modal-body {
  padding: 20px;
  overflow-y: auto;
  flex: 1;
}

.modal-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  padding: 12px 20px;
  border-top: 1px solid var(--border);
}

/* ===== Search / Filter Bar ===== */
.filter-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.filter-bar input,
.filter-bar select {
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 13px;
  outline: none;
  transition: var(--transition);
}

.filter-bar input:focus,
.filter-bar select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(56, 189, 248, 0.15);
}

.filter-bar input {
  min-width: 200px;
}

/* ===== Loading ===== */
.loading-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(255,255,255,0.6);
  z-index: 999;
  align-items: center;
  justify-content: center;
}

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

.spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* ===== Toast ===== */
.toast {
  position: fixed;
  top: 20px;
  right: 20px;
  padding: 12px 20px;
  border-radius: var(--radius);
  color: #fff;
  font-size: 13px;
  font-weight: 500;
  z-index: 2000;
  animation: slideIn 0.3s ease;
  box-shadow: var(--shadow-lg);
}

.toast-success {
  background: var(--success);
}

.toast-error {
  background: var(--danger);
}

.toast-warning {
  background: var(--warning);
}

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

/* ===== Pagination / Info Bar ===== */
.table-info {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 0;
  font-size: 12px;
  color: var(--text-secondary);
}

/* ===== Checkbox Switch ===== */
.switch {
  position: relative;
  display: inline-block;
  width: 36px;
  height: 20px;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.switch .slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: #ccc;
  transition: var(--transition);
  border-radius: 20px;
}

.switch .slider::before {
  content: '';
  position: absolute;
  height: 16px;
  width: 16px;
  left: 2px;
  bottom: 2px;
  background: #fff;
  transition: var(--transition);
  border-radius: 50%;
}

.switch input:checked + .slider {
  background: var(--accent);
}

.switch input:checked + .slider::before {
  transform: translateX(16px);
}

/* ===== Action Buttons Row ===== */
.action-buttons {
  display: flex;
  gap: 4px;
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
  .sidebar {
    width: 60px;
    min-width: 60px;
  }

  .sidebar-brand h1,
  .sidebar-footer .user-info,
  .nav-item span {
    display: none;
  }

  .nav-item {
    justify-content: center;
    padding: 12px;
  }

  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* ===== Model Tags ===== */
.model-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.model-tags .tag {
  background: rgba(56, 189, 248, 0.08);
  color: var(--accent);
  font-size: 11px;
}

/* ===== Scrollbar ===== */
.content-area::-webkit-scrollbar {
  width: 6px;
}

.content-area::-webkit-scrollbar-track {
  background: transparent;
}

.content-area::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}

.content-area::-webkit-scrollbar-thumb:hover {
  background: var(--text-light);
}

/* ===== Checkbox group ===== */
.checkbox-group {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.checkbox-group label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  background: var(--border-light);
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 12px;
  font-weight: 400;
  text-transform: none;
  letter-spacing: 0;
  transition: var(--transition);
}

.checkbox-group input[type="checkbox"] {
  width: auto;
}

.checkbox-group label:has(:checked) {
  background: rgba(56, 189, 248, 0.12);
  color: var(--accent);
}

/* ===== Confirm Dialog ===== */
.confirm-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0,0,0,0.4);
  z-index: 1001;
  align-items: center;
  justify-content: center;
}

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

.confirm-dialog {
  background: var(--card);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 24px;
  max-width: 400px;
  width: 90%;
  text-align: center;
}

.confirm-dialog p {
  margin-bottom: 20px;
  font-size: 15px;
  color: var(--text);
}

.confirm-dialog .btn-group {
  display: flex;
  justify-content: center;
  gap: 12px;
}

/* ===== Time format ===== */
.time-cell {
  white-space: nowrap;
  font-size: 12px;
  color: var(--text-secondary);
}

/* ===== 管理端登录遮罩 ===== */
.login-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
}
.login-overlay .login-container {
  max-width: 400px;
  width: 90%;
  padding: 40px;
  background: var(--card);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
}
.login-overlay .login-brand { text-align: center; margin-bottom: 32px; }
.login-overlay .login-brand h1 { font-size: 24px; color: var(--primary); }
.login-overlay .form-error { color: var(--danger); font-size: 13px; margin-bottom: 8px; min-height: 20px; }

/* ===== 用户端页面切换 ===== */
.page { display: none; }
.page.active { display: block; }
.content-page { display: none; }
.content-page.active { display: block; }
.top-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  height: 56px;
  background: var(--primary);
  color: #fff;
}
.top-nav .nav-brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 16px;
  font-weight: 600;
}
.top-nav .nav-links { display: flex; gap: 4px; }
.top-nav .nav-link {
  color: rgba(255,255,255,0.7);
  padding: 8px 16px;
  border-radius: 6px;
  transition: all 0.2s;
}
.top-nav .nav-link:hover { color: #fff; background: rgba(255,255,255,0.1); }
.top-nav .nav-link.active { color: #fff; background: rgba(255,255,255,0.15); }
.top-nav .nav-user { display: flex; align-items: center; gap: 12px; }
.login-container {
  max-width: 400px;
  margin: 80px auto;
  padding: 40px;
  background: var(--card);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
}
.login-brand { text-align: center; margin-bottom: 32px; }
.login-brand h1 { font-size: 24px; color: var(--primary); }
.brand-subtitle { color: var(--text-secondary); font-size: 14px; margin-top: 4px; }
.login-form .form-error { color: var(--danger); font-size: 13px; margin-bottom: 8px; min-height: 20px; }
.form-footer { text-align: center; margin-top: 16px; color: var(--text-secondary); font-size: 13px; }
.form-result { padding: 8px 12px; border-radius: 6px; background: rgba(56,189,248,0.1); color: var(--accent); }
.form-result.success { background: rgba(16,185,129,0.1); color: var(--success); }
.form-static { padding: 8px 12px; background: var(--bg); border-radius: 6px; color: var(--text); }
.mt-10 { margin-top: 10px; }
.mt-20 { margin-top: 20px; }
.big-number { font-size: 32px; font-weight: 700; color: var(--primary); }
.info-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 16px; }
.info-item { padding: 12px 16px; background: var(--bg); border-radius: 8px; }
.info-label { display: block; font-size: 12px; color: var(--text-secondary); margin-bottom: 4px; }
.info-value { font-size: 14px; color: var(--text); font-weight: 500; }
.tag-list { display: flex; flex-wrap: wrap; gap: 8px; }
.tag-blue { display: inline-block; padding: 4px 12px; border-radius: 12px; background: rgba(56,189,248,0.15); color: var(--accent); font-size: 13px; }

