@import url("https://fonts.googleapis.com/css2?family=Outfit:wght@300;400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap");

/* =========================================
   1. Design System Tokens
   ========================================= */
:root {
  /* 主色调 - 从 Indigo 转为 Blue-Violet */
  --primary: #7c5cfc;
  --primary-hover: #6a4de8;
  --primary-light: rgba(124, 92, 252, 0.12);
  --primary-glow: rgba(124, 92, 252, 0.3);

  /* 强调色 - 更柔和的色调 */
  --accent-purple: #a78bfa;
  --accent-pink: #f472b6;
  --accent-cyan: #22d3ee;
  --accent-blue: #60a5fa;
  --accent-green: #34d399;
  --accent-orange: #fbbf24;
  --accent-red: #f87171;

  /* 背景色 - 更温暖的深色调 */
  --bg-body: #0c0e1a;
  --bg-surface: rgba(22, 27, 45, 0.85);
  --bg-surface-hover: rgba(35, 42, 65, 0.7);
  --bg-elevated: rgba(30, 36, 58, 0.9);
  --bg-sidebar: rgba(14, 17, 30, 0.95);

  /* 文字色 */
  --text-main: #eef0f6;
  --text-secondary: #8b92a8;
  --text-muted: #5a6178;

  /* 边框色 */
  --border-color: rgba(139, 146, 168, 0.1);
  --border-highlight: rgba(139, 146, 168, 0.2);

  /* 阴影 */
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.15);
  --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.2);
  --shadow-lg: 0 16px 48px rgba(0, 0, 0, 0.3);
  --shadow-glow: 0 0 24px rgba(124, 92, 252, 0.12);

  /* 间距 */
  --space-xs: 4px;
  --space-sm: 8px;
  --space-md: 16px;
  --space-lg: 24px;
  --space-xl: 32px;
  --space-2xl: 48px;

  /* 圆角 */
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-xl: 20px;

  /* 过渡 */
  --transition-fast: all 0.15s ease;
  --transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  --transition-slow: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* =========================================
   2. Reset & Base Styles
   ========================================= */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: 'Outfit', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background-color: var(--bg-body);
  background-image: radial-gradient(ellipse at 50% 0%, rgba(124, 92, 252, 0.06) 0%, transparent 60%);
  color: var(--text-main);
  min-height: 100vh;
  display: flex;
  overflow-x: hidden;
  line-height: 1.6;
}

/* Scrollbar Polish */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: rgba(139, 146, 168, 0.2);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: rgba(139, 146, 168, 0.4);
}

a {
  text-decoration: none;
  color: inherit;
}

h1,
h2,
h3,
h4,
h5,
h6 {
  color: var(--text-main);
  font-weight: 600;
  letter-spacing: -0.02em;
}

/* =========================================
   3. Sidebar
   ========================================= */
.sidebar {
  width: 260px;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  height: 100vh;
  position: fixed;
  z-index: 50;
  transition: transform 0.3s ease;
}

.sidebar-header {
  padding: 24px 20px;
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo {
  width: 36px;
  height: 36px;
  background: linear-gradient(135deg, var(--primary), var(--accent-purple));
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 1.2rem;
  color: white;
  box-shadow: 0 4px 12px rgba(124, 92, 252, 0.3);
}

.sidebar-header .title {
  font-size: 1.15rem;
  font-weight: 600;
  background: linear-gradient(to right, #eef0f6, var(--accent-purple));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.sidebar-menu {
  flex: 1;
  list-style: none;
  padding: 0 12px;
  margin-top: 10px;
}

.sidebar-item {
  margin-bottom: 6px;
}

.sidebar-link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  color: var(--text-secondary);
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  font-weight: 500;
  transition: var(--transition);
  position: relative;
  overflow: hidden;
}

.sidebar-link:hover {
  color: var(--text-main);
  background: rgba(255, 255, 255, 0.03);
}

.sidebar-link.active {
  background: var(--primary-light);
  color: var(--primary);
  font-weight: 600;
}

.sidebar-link.active::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 3px;
  background: var(--primary);
  border-radius: 0 2px 2px 0;
}

.sidebar-footer {
  padding: 24px 20px;
  border-top: 1px solid var(--border-highlight);
  background: rgba(0, 0, 0, 0.15);
}

.sidebar-footer-stats {
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid var(--border-highlight);
  border-radius: var(--radius-md);
  padding: 14px;
  margin-bottom: 16px;
}

.footer-stat-item {
  display: flex;
  justify-content: space-between;
  font-size: 0.85rem;
  margin-bottom: 8px;
}

.footer-stat-item:last-child {
  margin-bottom: 0;
}

.footer-stat-label {
  color: var(--text-muted);
}

.footer-stat-value {
  font-weight: 600;
  color: var(--text-main);
}

.footer-stat-value.normal {
  color: var(--accent-green);
}

.footer-stat-value.abnormal {
  color: var(--accent-red);
}

/* =========================================
   4. Main Content Area
   ========================================= */
.main-content {
  flex: 1;
  margin-left: 260px;
  /* matches sidebar width */
  padding: var(--space-xl) var(--space-2xl);
  animation: fadeUp 0.5s ease-out;
}

@keyframes fadeUp {
  from {
    opacity: 0;
    transform: translateY(10px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.header-section {
  margin-bottom: var(--space-2xl);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.header-section h1 {
  font-size: 2rem;
  margin-bottom: 8px;
}

.header-section p {
  color: var(--text-secondary);
  font-size: 1rem;
}

/* =========================================
   5. Components: Cards & Stats
   ========================================= */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 24px;
  margin-bottom: var(--space-2xl);
}

.stat-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 24px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  transition: var(--transition);
  position: relative;
  overflow: hidden;
}

.stat-card:hover {
  transform: translateY(-4px);
  border-color: var(--border-highlight);
  box-shadow: var(--shadow-md), var(--shadow-glow);
}

.stat-info .label {
  font-size: 0.875rem;
  color: var(--text-secondary);
  font-weight: 500;
  margin-bottom: 8px;
  display: block;
}

.stat-info .value {
  font-size: 2rem;
  font-weight: 700;
  color: var(--text-main);
  line-height: 1.2;
}

.stat-icon {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-lg);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  transition: var(--transition);
}

.stat-icon.total {
  background: rgba(96, 165, 250, 0.12);
  color: var(--accent-blue);
}

.stat-icon.normal {
  background: rgba(52, 211, 153, 0.12);
  color: var(--accent-green);
}

.stat-icon.abnormal {
  background: rgba(248, 113, 113, 0.12);
  color: var(--accent-red);
}

.stat-icon.selected {
  background: rgba(167, 139, 250, 0.12);
  color: var(--accent-purple);
}

/* =========================================
   6. Components: Tables & Lists
   ========================================= */
.content-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  overflow: hidden;
  /* For rounded corners on table */
  box-shadow: var(--shadow-sm);
}

.toolbar {
  padding: 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--border-color);
  background: var(--bg-elevated);
  flex-wrap: wrap;
  gap: 16px;
}

/* Tabs inside Toolbar */
.filter-tabs {
  display: flex;
  background: rgba(0, 0, 0, 0.25);
  padding: 4px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-highlight);
}

.tab-item {
  padding: 8px 16px;
  border-radius: 6px;
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  color: var(--text-secondary);
  border: none;
  background: transparent;
  transition: var(--transition);
}

.tab-item:hover {
  color: var(--text-main);
}

.tab-item.active {
  background: var(--primary-light);
  color: var(--primary);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
}

/* Table Styles */
.table-wrap {
  width: 100%;
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  min-width: 1000px;
}

/* 账号管理表格自适应 */
.accounts-table {
  table-layout: fixed;
  min-width: 0;
}

.accounts-table th,
.accounts-table td {
  word-break: break-word;
}

.accounts-table .col-token .token-text {
  display: inline-block;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

th {
  background: var(--bg-elevated);
  color: var(--text-secondary);
  font-weight: 600;
  font-size: 0.85rem;
  padding: 16px 24px;
  text-align: left;
  border-bottom: 1px solid var(--border-color);
}

td {
  padding: 16px 24px;
  border-bottom: 1px solid var(--border-color);
  color: var(--text-main);
  font-size: 0.95rem;
  vertical-align: middle;
  transition: background 0.1s;
}

tr:last-child td {
  border-bottom: none;
}

tr:hover td {
  background: rgba(139, 146, 168, 0.05);
}

/* Tokens / Monospaced text */
.token-text {
  font-family: 'JetBrains Mono', 'Menlo', monospace;
  font-size: 0.85rem;
  color: var(--text-secondary);
  background: rgba(0, 0, 0, 0.25);
  padding: 4px 8px;
  border-radius: 4px;
  border: 1px solid var(--border-highlight);
}

/* Status Badges & Tags */
.tag {
  display: inline-flex;
  align-items: center;
  padding: 4px 8px;
  border-radius: 6px;
  font-size: 0.75rem;
  font-weight: 600;
  line-height: 1;
}

.tag-free {
  background: rgba(52, 211, 153, 0.1);
  color: var(--accent-green);
  border: 1px solid rgba(52, 211, 153, 0.2);
}

.platform-badge {
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 600;
}

.badge-kiro {
  background: rgba(34, 211, 238, 0.12);
  color: var(--accent-cyan);
}

.badge-orchids {
  background: rgba(167, 139, 250, 0.12);
  color: var(--accent-purple);
}

.badge-antigravity {
  background: rgba(251, 191, 36, 0.12);
  color: var(--accent-orange);
}

/* Progress Bars */
.usage-progress-container {
  width: 120px;
  height: 6px;
  background: rgba(139, 146, 168, 0.08);
  border-radius: 3px;
  overflow: hidden;
}

.usage-progress-bar {
  height: 100%;
  border-radius: 3px;
}

.usage-progress-bar.green {
  background: var(--accent-green);
  box-shadow: 0 0 10px rgba(52, 211, 153, 0.3);
}

.usage-progress-bar.orange {
  background: var(--accent-orange);
  box-shadow: 0 0 10px rgba(251, 191, 36, 0.3);
}

.usage-progress-bar.red {
  background: var(--accent-red);
  box-shadow: 0 0 10px rgba(248, 113, 113, 0.3);
}

/* =========================================
   7. Buttons & Inputs
   ========================================= */


/* Inputs */
.form-group {
  margin-bottom: 20px;
}

.form-label {
  display: block;
  margin-bottom: 8px;
  color: var(--text-secondary);
  font-size: 0.9rem;
  font-weight: 500;
}

.input-wrapper {
  position: relative;
}

.input-icon {
  position: absolute;
  left: 16px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-secondary);
  pointer-events: none;
}

.form-input {
  width: 100%;
  padding: 12px 16px;
  font-size: 0.95rem;
  background: rgba(12, 14, 26, 0.5);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  color: var(--text-main);
  transition: var(--transition);
  outline: none;
}

.form-input::placeholder {
  color: var(--text-muted);
}

/* Form input inside wrapper with icon */
.input-wrapper .form-input {
  padding-left: 44px;
  /* Icon spacing */
}

.form-input:focus {
  background: rgba(12, 14, 26, 0.8);
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
}

/* Toggle Switch */
.toggle {
  display: inline-flex;
  align-items: center;
  cursor: pointer;
}

.toggle input {
  display: none;
}

.toggle-slider {
  position: relative;
  width: 44px;
  height: 24px;
  background-color: var(--bg-surface-hover);
  border-radius: 99px;
  transition: .3s;
  border: 1px solid var(--border-color);
}

.toggle-slider:before {
  content: "";
  position: absolute;
  height: 18px;
  width: 18px;
  left: 3px;
  bottom: 2px;
  background-color: white;
  border-radius: 50%;
  transition: .3s cubic-bezier(0.4, 0.0, 0.2, 1);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.toggle input:checked+.toggle-slider {
  background-color: var(--primary);
  border-color: var(--primary);
}

.toggle input:checked+.toggle-slider:before {
  transform: translateX(19px);
}

/* =========================================
   7.5 Button Polish
   ========================================= */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 24px;
  border-radius: var(--radius-md);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid transparent;
  transition: var(--transition);
  position: relative;
  overflow: hidden;
  letter-spacing: 0.01em;
}

.btn:active {
  transform: translateY(1px);
}

.btn-primary {
  background: linear-gradient(135deg, var(--primary), var(--primary-hover));
  color: white;
  box-shadow: 0 4px 12px rgba(124, 92, 252, 0.3), inset 0 1px 0 rgba(255, 255, 255, 0.1);
}

.btn-primary:hover:not(:disabled) {
  background: linear-gradient(135deg, var(--primary-hover), #5b3dd4);
  box-shadow: 0 6px 16px rgba(124, 92, 252, 0.4), inset 0 1px 0 rgba(255, 255, 255, 0.1);
  transform: translateY(-1px);
}

.btn-outline {
  background: rgba(255, 255, 255, 0.05);
  border-color: var(--border-highlight);
  color: var(--text-main);
}

.btn-outline:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.1);
  border-color: var(--text-secondary);
  color: white;
}

.btn-danger-outline {
  background: rgba(248, 113, 113, 0.05);
  border-color: rgba(248, 113, 113, 0.2);
  color: #f87171;
}

.btn-danger-outline:hover:not(:disabled) {
  background: rgba(248, 113, 113, 0.15);
  border-color: #f87171;
  color: #fca5a5;
  box-shadow: 0 4px 12px rgba(248, 113, 113, 0.2);
}

.btn-icon {
  width: 36px;
  height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
  border-radius: var(--radius-lg);
  transition: var(--transition);
}

.btn-icon:hover {
  background: rgba(255, 255, 255, 0.1);
  color: var(--text-main);
  border-color: var(--border-highlight);
  transform: translateY(-1px);
}

.action-icon {
  width: 32px;
  height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  cursor: pointer;
  transition: var(--transition);
  font-style: normal;
}

.action-icon:hover {
  background: rgba(255, 255, 255, 0.1);
  transform: scale(1.1);
}

/* =========================================
   8. Grok Tools
   ========================================= */
.grok-tools-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
}

.grok-panel {
  background: rgba(0, 0, 0, 0.16);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 16px;
}

.grok-panel h3 {
  font-size: 1.05rem;
  margin-bottom: 6px;
}

.grok-panel p {
  color: var(--text-secondary);
  font-size: 0.9rem;
  margin-bottom: 14px;
}

.grok-form-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 12px;
}

.grok-form-grid .full {
  grid-column: span 4;
}

.grok-kv {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 10px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border-color);
  font-size: 0.88rem;
  color: var(--text-secondary);
}

.grok-kv strong {
  color: var(--text-main);
  font-weight: 600;
}

.imagine-grid {
  columns: 4 260px;
  column-gap: 12px;
  margin-top: 12px;
}

.imagine-card {
  break-inside: avoid;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  margin-bottom: 12px;
  overflow: hidden;
}

.imagine-card img {
  width: 100%;
  display: block;
  cursor: zoom-in;
}

.imagine-meta {
  padding: 8px 10px;
  font-size: 0.78rem;
  color: var(--text-secondary);
  display: flex;
  justify-content: space-between;
}

.cache-list {
  margin-top: 12px;
  max-height: 420px;
  overflow: auto;
  border: 1px solid var(--border-color);
  border-radius: 10px;
}

.cache-list table {
  width: 100%;
}

.cache-list th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--bg-elevated);
}

.cache-list td code {
  color: var(--accent-cyan);
}

/* =========================================
   9. Modals & Toasts
   ========================================= */
.modal {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(8px);
  z-index: 100;
  align-items: center;
  justify-content: center;
  animation: fadeIn 0.2s ease-out;
}

.modal-content {
  background: var(--bg-elevated);
  border: 1px solid var(--border-highlight);
  border-radius: var(--radius-xl);
  padding: 0;
  /* Remove default padding, use inner sections */
  width: 90%;
  max-width: 480px;
  box-shadow: var(--shadow-lg), 0 0 0 1px rgba(255, 255, 255, 0.03);
  animation: scaleIn 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  position: relative;
  overflow: hidden;
}

.modal-header {
  padding: 24px;
  padding-bottom: 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border-color);
  background: rgba(255, 255, 255, 0.01);
}

.modal-title {
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--text-main);
  margin: 0;
}

.modal-close {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  color: var(--text-secondary);
  font-size: 1.5rem;
  cursor: pointer;
  border-radius: 8px;
  transition: var(--transition);
  line-height: 1;
}

.modal-close:hover {
  background: rgba(255, 255, 255, 0.1);
  color: var(--text-main);
}

.modal form {
  padding: 24px;
}

@keyframes scaleIn {
  from {
    opacity: 0;
    transform: scale(0.95) translateY(10px);
  }

  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

.toast {
  position: relative;
  background: var(--bg-elevated);
  border: 1px solid var(--border-highlight);
  padding: 16px 24px;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg), var(--shadow-glow);
  display: flex;
  align-items: center;
  gap: 12px;
  transform: translateY(20px);
  opacity: 0;
  transition: all 0.5s cubic-bezier(0.16, 1, 0.3, 1);
  max-width: min(420px, calc(100vw - 32px));
  word-break: break-word;
}

.toast.show {
  transform: translateY(0);
  opacity: 1;
}

.toast-container {
  position: fixed;
  right: 24px;
  bottom: 24px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: flex-end;
  z-index: 200;
  pointer-events: none;
}

/* =========================================
   10. Login Page Specifics (Migrated)
   ========================================= */
.login-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 20px;
}

.login-card {
  width: 100%;
  max-width: 440px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-highlight);
  border-radius: var(--radius-xl);
  padding: 48px;
  box-shadow: var(--shadow-lg), var(--shadow-glow);
  animation: fadeUp 0.6s ease-out;
}

.login-body .toast {
  position: fixed;
  right: 24px;
  bottom: 24px;
}

.ambient-bg {
  position: fixed;
  inset: 0;
  z-index: -1;
  overflow: hidden;
  pointer-events: none;
}

.blob {
  position: absolute;
  border-radius: 50%;
  filter: blur(100px);
  opacity: 0.25;
  animation: pulse 10s infinite alternate;
}

.blob-1 {
  width: 450px;
  height: 450px;
  background: var(--primary);
  top: -100px;
  left: -100px;
}

.blob-2 {
  width: 350px;
  height: 350px;
  background: var(--accent-purple);
  bottom: -50px;
  right: -50px;
  animation-delay: -5s;
}

@keyframes pulse {
  0% {
    transform: scale(1);
    opacity: 0.2;
  }

  100% {
    transform: scale(1.1);
    opacity: 0.35;
  }
}

/* =========================================
   11. Responsiveness
   ========================================= */
@media (max-width: 1200px) {
  .grok-form-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .grok-form-grid .full {
    grid-column: span 2;
  }
}

@media (max-width: 760px) {
  .grok-form-grid {
    grid-template-columns: 1fr;
  }

  .grok-form-grid .full {
    grid-column: span 1;
  }
}

@media (max-width: 900px) {
  .sidebar {
    transform: translateX(-100%);
  }

  .sidebar.mobile-open {
    transform: translateX(0);
  }

  .main-content {
    margin-left: 0;
    padding: var(--space-md);
  }

  .header-section {
    flex-direction: column;
    align-items: flex-start;
    gap: var(--space-md);
  }

  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: var(--space-md);
  }

  .toolbar {
    padding: var(--space-md);
  }
}
