/* ===== Reset & Base ===== */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --bg-primary: #0a0e1a;
  --bg-secondary: #111827;
  --bg-card: #1a1f35;
  --bg-card-hover: #222845;
  --bg-input: #141828;
  --text-primary: #e2e8f0;
  --text-secondary: #94a3b8;
  --accent: #8b5cf6;
  --accent2: #06b6d4;
  --gradient: linear-gradient(135deg, #8b5cf6, #06b6d4);
  --border: rgba(139, 92, 246, 0.15);
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.3);
  --radius: 10px;
}

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

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

/* ===== Particles Canvas ===== */
#particles {
  position: fixed; top: 0; left: 0; width: 100%; height: 100%;
  z-index: 0; pointer-events: none;
}

/* ===== Login Page ===== */
.login-container {
  position: relative; z-index: 1;
  display: flex; flex-direction: column; align-items: center;
  justify-content: center; min-height: 100vh; padding: 40px 20px;
}

.brand { text-align: center; margin-bottom: 36px; }
.logo { margin-bottom: 14px; }
.brand h1 {
  font-size: 32px; font-weight: 700;
  background: var(--gradient); -webkit-background-clip: text; -webkit-text-fill-color: transparent;
  background-clip: text;
}
.tagline { color: var(--text-secondary); font-size: 14px; margin-top: 8px; }

.auth-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 16px;
  width: 100%; max-width: 440px;
  box-shadow: 0 12px 48px rgba(0, 0, 0, 0.4);
  overflow: hidden;
}

/* Tabs */
.auth-tabs {
  display: flex; padding: 6px; margin: 16px 16px 0;
  background: var(--bg-input); border-radius: 10px;
}
.auth-tab {
  flex: 1; padding: 10px; border: none; border-radius: 8px;
  background: transparent; color: var(--text-secondary);
  font-size: 14px; font-weight: 500; cursor: pointer;
  transition: all 0.2s;
}
.auth-tab:hover { color: var(--text-primary); }
.auth-tab.active {
  background: var(--bg-card); color: var(--text-primary);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

/* Form area */
.auth-forms { padding: 24px 28px 28px; }

.auth-form { display: none; }
.auth-form.active { display: block; }

.input-group { margin-bottom: 16px; }
.input-group label {
  display: block; font-size: 13px; color: var(--text-secondary);
  margin-bottom: 6px; font-weight: 500;
}
.input {
  width: 100%; padding: 11px 14px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--bg-input);
  color: var(--text-primary); font-size: 14px; outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(139, 92, 246, 0.1); }
.input::placeholder { color: var(--text-secondary); }

.error-msg {
  background: rgba(239, 68, 68, 0.1); border: 1px solid rgba(239, 68, 68, 0.25);
  color: #fca5a5; padding: 9px 12px; border-radius: 8px;
  font-size: 13px; margin-bottom: 14px;
}
.success-msg {
  background: rgba(34, 197, 94, 0.1); border: 1px solid rgba(34, 197, 94, 0.25);
  color: #86efac; padding: 9px 12px; border-radius: 8px;
  font-size: 13px; margin-bottom: 14px; word-break: break-all;
}

.btn-primary {
  width: 100%; padding: 14px; border: none; border-radius: 10px;
  background: var(--gradient); color: #fff; font-size: 15px;
  font-weight: 600; cursor: pointer; transition: opacity 0.2s;
  margin-top: 4px;
}
.btn-primary:hover { opacity: 0.9; }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-accent {
  padding: 10px 20px; border: none; border-radius: 8px;
  background: var(--gradient); color: #fff; font-size: 14px;
  font-weight: 600; cursor: pointer; transition: opacity 0.2s;
}
.btn-accent:hover { opacity: 0.9; }
.btn-accent:disabled { opacity: 0.5; cursor: not-allowed; }

.trust-bar {
  margin-top: 24px; display: flex; align-items: center;
  justify-content: center; gap: 20px; flex-wrap: wrap;
}
.trust-item {
  display: flex; align-items: center; gap: 5px;
  font-size: 12px; color: var(--text-secondary);
}

.footer {
  position: fixed; bottom: 16px; left: 0; right: 0; text-align: center;
  color: var(--text-secondary); font-size: 12px; opacity: 0.5;
}

/* ===== Dashboard Layout ===== */
.dashboard-body { background: var(--bg-primary); }

.dashboard-layout { display: flex; min-height: 100vh; }

/* Sidebar */
.sidebar {
  width: 220px; background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column; position: fixed;
  top: 0; left: 0; bottom: 0; z-index: 10;
}
.sidebar-brand {
  display: flex; align-items: center; gap: 8px;
  padding: 18px 20px; border-bottom: 1px solid var(--border);
}
.sidebar-brand span {
  font-size: 18px; font-weight: 700;
  background: var(--gradient); -webkit-background-clip: text; -webkit-text-fill-color: transparent;
  background-clip: text;
}

.sidebar-nav { flex: 1; padding: 12px 10px; }
.nav-item {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 14px; border-radius: 8px; color: var(--text-secondary);
  font-size: 13px; cursor: pointer; transition: all 0.2s;
  margin-bottom: 2px;
}
.nav-item:hover { background: rgba(139, 92, 246, 0.08); color: var(--text-primary); }
.nav-item.active { background: rgba(139, 92, 246, 0.15); color: var(--text-primary); }

.sidebar-user {
  display: flex; align-items: center; gap: 8px;
  padding: 14px 16px; border-top: 1px solid var(--border);
}
.user-info { flex: 1; min-width: 0; }
.user-name {
  font-size: 13px; font-weight: 600; color: var(--text-primary);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.user-balance { font-size: 12px; color: var(--accent2); }

.btn-logout {
  padding: 6px; border: 1px solid var(--border); border-radius: 6px;
  background: transparent; color: var(--text-secondary); cursor: pointer;
  transition: all 0.2s; display: flex; align-items: center; justify-content: center;
}
.btn-logout:hover { border-color: #ef4444; color: #fca5a5; }

/* Main Content */
.main-content {
  flex: 1; margin-left: 220px; padding: 40px 48px;
  display: flex; flex-direction: column; align-items: center;
}
.main-content > * {
  width: 100%; max-width: 800px;
}

/* Pages */
.page { display: none; }
.page.active { display: block; }

.page-top {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 20px;
}
.page-top h2 { font-size: 20px; font-weight: 600; }

/* ===== Usage Stats ===== */
.usage-stats { display: flex; flex-direction: column; gap: 24px; }

.usage-summary {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 16px;
}

.usage-note {
  padding: 14px 16px;
  border: 1px solid rgba(6, 182, 212, 0.2);
  border-radius: var(--radius);
  background: rgba(6, 182, 212, 0.08);
  color: var(--text-secondary);
  font-size: 13px;
  line-height: 1.6;
}

.usage-charts {
  display: grid; grid-template-columns: 1fr 1fr; gap: 16px;
}
.chart-card {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 20px;
}
.chart-card h3 {
  font-size: 14px; font-weight: 600; margin-bottom: 16px;
  color: var(--text-primary);
}
.stat-card {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 24px; text-align: center;
}
.stat-label { font-size: 13px; color: var(--text-secondary); margin-bottom: 8px; }
.stat-value { font-size: 28px; font-weight: 700; }
#statCacheTokens { color: var(--accent2); }
#statCacheRate { color: #10b981; }

.usage-table {
  overflow-x: auto;
}
.usage-table h3 {
  font-size: 16px; font-weight: 600; margin-bottom: 12px;
  color: var(--text-primary);
}
.log-table {
  width: 100%; min-width: 640px; border-collapse: collapse;
  background: var(--bg-card); border-radius: var(--radius);
  border: 1px solid var(--border); overflow: hidden;
}
.log-table thead { background: rgba(139, 92, 246, 0.08); }
.log-table th {
  padding: 12px 16px; text-align: left; font-size: 12px;
  font-weight: 600; color: var(--text-secondary);
  text-transform: uppercase; letter-spacing: 0.5px;
}
.log-table td {
  padding: 10px 16px; font-size: 13px; color: var(--text-primary);
  border-top: 1px solid var(--border);
}
.cache-hit-cell { color: var(--accent2) !important; font-weight: 600; }
.log-table tr:hover td { background: rgba(139, 92, 246, 0.04); }
.empty-row { text-align: center; color: var(--text-secondary); padding: 30px !important; }

.log-pagination { display: flex; align-items: center; justify-content: center; gap: 6px; margin-top: 12px; }
.log-pagination .page-btn {
  padding: 6px 12px; border: 1px solid var(--border); border-radius: 6px;
  background: var(--bg-card); color: var(--text-secondary); cursor: pointer;
  font-size: 13px; transition: all 0.2s;
}
.log-pagination .page-btn:hover { border-color: var(--accent); color: var(--accent); }
.log-pagination .page-btn.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.log-pagination .page-btn:disabled { opacity: 0.3; cursor: not-allowed; }
.log-pagination .page-info { font-size: 12px; color: var(--text-secondary); margin: 0 4px; }

/* ===== Chat Page (removed but keep styles if referenced) ===== */
.chat-page { display: none !important; }
.chat-welcome {
  display: flex; flex-direction: column; align-items: center;
  justify-content: center; text-align: center;
  min-height: 60vh; gap: 16px;
}
.chat-welcome h2 { font-size: 28px; font-weight: 600; }
.chat-sub { color: var(--text-secondary); font-size: 15px; }

.chat-messages {
  min-height: 300px; max-height: calc(100vh - 360px);
  overflow-y: auto; padding: 20px 0;
}

.chat-msg { display: flex; gap: 10px; margin-bottom: 18px; }
.chat-msg:last-child { margin-bottom: 0; }
.msg-avatar {
  width: 28px; height: 28px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.msg-content {
  padding: 12px 18px; border-radius: 12px;
  font-size: 15px; line-height: 1.7; max-width: 85%;
  word-wrap: break-word;
}
.chat-msg.user { flex-direction: row-reverse; }
.chat-msg.user .msg-content {
  background: rgba(6, 182, 212, 0.12); border: 1px solid rgba(6, 182, 212, 0.2);
}
.chat-msg.system .msg-content {
  background: rgba(139, 92, 246, 0.1); border: 1px solid rgba(139, 92, 246, 0.15);
}

.chat-bottom {
  border-top: 1px solid var(--border);
  padding-top: 16px; margin-top: 16px;
}

.chat-model-select { margin-bottom: 12px; }
.model-select {
  width: 100%; padding: 10px 14px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--bg-input);
  color: var(--text-primary); font-size: 14px; outline: none;
  cursor: pointer;
}
.model-select:focus { border-color: var(--accent); }

.chat-input-row { display: flex; gap: 10px; align-items: flex-end; }
.chat-input-row textarea {
  flex: 1; padding: 12px 14px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--bg-input);
  color: var(--text-primary); font-size: 14px; resize: none;
  outline: none; font-family: inherit; min-height: 44px; max-height: 120px;
  transition: border-color 0.2s;
}
.chat-input-row textarea:focus { border-color: var(--accent); }

.btn-send {
  padding: 10px 16px; border: none; border-radius: 10px;
  background: var(--gradient); color: #fff; cursor: pointer;
  transition: opacity 0.2s; display: flex; align-items: center;
  justify-content: center; flex-shrink: 0;
}
.btn-send:hover { opacity: 0.9; }
.btn-send:disabled { opacity: 0.5; cursor: not-allowed; }

/* ===== Keys Page ===== */
.keys-list { display: flex; flex-direction: column; gap: 10px; }

.key-card {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 18px; background: var(--bg-card);
  border: 1px solid var(--border); border-radius: var(--radius);
  transition: border-color 0.2s;
}
.key-card:hover { border-color: var(--accent); }
.key-value {
  flex: 1; font-family: 'SF Mono', 'Fira Code', monospace;
  font-size: 13px; color: var(--accent2);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.key-meta { font-size: 12px; color: var(--text-secondary); white-space: nowrap; }
.key-actions { display: flex; gap: 6px; }

.btn-icon {
  padding: 6px 8px; border: 1px solid var(--border); border-radius: 6px;
  background: transparent; color: var(--text-secondary); cursor: pointer;
  transition: all 0.2s; display: flex; align-items: center;
}
.btn-icon:hover { border-color: var(--accent); color: var(--accent); }
.btn-icon.danger:hover { border-color: #ef4444; color: #fca5a5; }

.empty-state {
  display: flex; flex-direction: column; align-items: center;
  justify-content: center; text-align: center; padding: 60px 20px;
  color: var(--text-secondary);
}
.empty-state p { font-size: 16px; margin-bottom: 4px; color: var(--text-primary); }
.empty-state span { font-size: 13px; }

/* ===== Billing Page ===== */
.billing-grid {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px;
}
.billing-card {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 24px; text-align: center;
}
.billing-card.balance { border-color: rgba(139, 92, 246, 0.3); }
.billing-label { font-size: 13px; color: var(--text-secondary); margin-bottom: 8px; }
.billing-value { font-size: 28px; font-weight: 700; }
.billing-value span { background: var(--gradient); -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text; }
.billing-sub { font-size: 12px; color: var(--text-secondary); margin-top: 6px; }
.btn-sm-topup { margin-top: 14px; font-size: 13px; padding: 8px 16px; }

/* Redeem Card */
.redeem-card {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 24px; margin-top: 24px;
}
.redeem-title { font-size: 15px; font-weight: 600; margin-bottom: 14px; color: var(--text-primary); }
.redeem-input-row { display: flex; gap: 10px; align-items: stretch; }
.redeem-input-row .input { flex: 1; }
.redeem-btn { min-width: 80px; }

/* ===== Modal ===== */
.modal-overlay-hidden { display: none; }
.modal-backdrop {
  position: fixed; top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0, 0, 0, 0.6); z-index: 99;
}
.modal {
  position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%);
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 28px;
  width: 90%; max-width: 400px; z-index: 100; box-shadow: var(--shadow);
}
.modal-title { font-size: 18px; font-weight: 600; margin-bottom: 16px; }

.topup-amounts { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.topup-amt {
  padding: 8px 16px; border: 1px solid var(--border); border-radius: 8px;
  background: var(--bg-input); color: var(--text-primary); font-size: 14px;
  cursor: pointer; transition: all 0.2s;
}
.topup-amt:hover, .topup-amt.active { border-color: var(--accent); background: rgba(139, 92, 246, 0.15); }
.topup-custom { margin-bottom: 14px; }
.topup-custom .input { width: 100%; }
.topup-note { font-size: 12px; color: var(--text-secondary); margin-top: 10px; text-align: center; }

/* ===== Responsive ===== */
@media (max-width: 768px) {
  .sidebar { display: none; }
  .main-content { margin-left: 0; padding: 16px; }
  .billing-grid { grid-template-columns: 1fr; }
}

/* ===== Models Page ===== */
.models-content { max-width: 900px; }

.model-table {
  width: 100%; border-collapse: collapse;
  background: var(--bg-card); border-radius: var(--radius);
  border: 1px solid var(--border); overflow: hidden;
  font-size: 13px;
}
.model-table thead { background: rgba(139, 92, 246, 0.08); }
.model-table th {
  padding: 12px 16px; text-align: left; font-size: 12px;
  font-weight: 600; color: var(--text-secondary);
  text-transform: uppercase; letter-spacing: 0.5px;
}
.model-table td {
  padding: 10px 16px; color: var(--text-primary);
  border-top: 1px solid rgba(139, 92, 246, 0.08);
}
.model-table tr:hover td { background: rgba(139, 92, 246, 0.04); }
.model-table code {
  font-family: 'SF Mono', 'Fira Code', monospace;
  color: var(--accent2); background: rgba(6, 182, 212, 0.08);
  padding: 2px 6px; border-radius: 4px; font-size: 12px;
}
.model-table .model-type-code {
  font-family: 'SF Mono', 'Fira Code', monospace;
  color: var(--accent2); background: rgba(6, 182, 212, 0.08);
  padding: 2px 6px; border-radius: 4px; font-size: 12px;
}

.model-group-header td {
  background: rgba(139, 92, 246, 0.06);
  font-weight: 700; font-size: 14px; color: var(--accent);
  padding: 10px 16px !important; letter-spacing: 0.5px;
}

.model-note-text {
  margin-top: 12px; font-size: 13px; color: var(--text-secondary);
  text-align: center;
}
.model-note-text code {
  font-family: 'SF Mono', 'Fira Code', monospace;
  color: var(--accent2); background: rgba(6, 182, 212, 0.08);
  padding: 2px 6px; border-radius: 4px; font-size: 12px;
}

/* ===== Docs Page ===== */
.docs-content { max-width: 700px; margin: 0 auto; }

.doc-section { margin-bottom: 24px; }
.doc-section h3 {
  font-size: 16px; font-weight: 600; color: var(--text-primary);
  margin-bottom: 12px;
}

.doc-card {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 20px;
}

.doc-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 0; border-bottom: 1px solid rgba(139, 92, 246, 0.08);
}
.doc-row:last-child { border-bottom: none; }

.doc-label {
  font-size: 13px; color: var(--text-secondary); font-weight: 500;
  min-width: 90px;
}

.doc-code {
  font-family: 'SF Mono', 'Fira Code', monospace; font-size: 12px;
  color: var(--accent2); background: rgba(6, 182, 212, 0.08);
  padding: 3px 8px; border-radius: 4px; word-break: break-all;
}

.doc-text {
  font-size: 14px; color: var(--text-primary); line-height: 1.7;
}
.doc-subtitle {
  font-size: 13px; font-weight: 600; color: var(--accent);
}
.doc-note {
  font-size: 13px; color: var(--text-secondary);
  background: rgba(139, 92, 246, 0.06); border-left: 3px solid var(--accent);
  padding: 8px 12px; border-radius: 0 6px 6px 0; margin-top: 10px;
}

.doc-details summary {
  display: flex; align-items: center; gap: 10px;
  font-size: 14px; font-weight: 600; color: var(--text-primary);
  cursor: pointer; padding: 12px 16px;
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); transition: all 0.2s;
  list-style: none; user-select: none;
}
.doc-details summary::-webkit-details-marker { display: none; }
.doc-details summary:hover {
  background: var(--bg-card-hover); border-color: var(--accent);
}
.doc-details[open] summary {
  border-radius: var(--radius) var(--radius) 0 0;
  border-bottom-color: transparent;
}

.doc-details-body {
  padding: 16px; background: var(--bg-card);
  border: 1px solid var(--border); border-top: none;
  border-radius: 0 0 var(--radius) var(--radius);
}

.doc-code-block {
  background: var(--bg-input); border: 1px solid var(--border);
  border-radius: 8px; padding: 14px 16px; margin: 10px 0;
  font-family: 'SF Mono', 'Fira Code', monospace; font-size: 12px;
  line-height: 1.8; overflow-x: auto; white-space: pre;
  color: var(--text-primary);
}
.doc-code-block .doc-comment { color: var(--text-secondary); }

/* Platform Tabs */
.platform-tabs {
  display: flex; gap: 12px; margin: 20px 0 16px;
}
.platform-tab {
  flex: 1; max-width: 160px; padding: 12px 24px;
  border: 2px solid var(--border); border-radius: 12px;
  background: var(--bg-card); color: var(--text-secondary);
  font-size: 14px; font-weight: 500; cursor: pointer;
  transition: all 0.25s ease;
  letter-spacing: 0.5px;
}
.platform-tab:hover {
  border-color: var(--accent); color: var(--text-primary);
  background: var(--bg-card-hover);
}
.platform-tab.active {
  background: var(--gradient); color: #fff;
  border-color: transparent; font-weight: 700;
  box-shadow: 0 4px 20px rgba(139, 92, 246, 0.35);
  transform: translateY(-1px);
}
.platform-content { display: none; }
.platform-content.active { display: block; animation: fadeSlideIn 0.2s ease; }
@keyframes fadeSlideIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ===== Scrollbar ===== */
::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(139, 92, 246, 0.3); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: rgba(139, 92, 246, 0.5); }

/* ===== Spinner ===== */
.spinner {
  display: inline-block; width: 14px; height: 14px;
  border: 2px solid var(--border); border-top-color: var(--accent);
  border-radius: 50%; animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
