/* =============================================
   wanxiaoT Admin — CodeTime-inspired light theme
   ============================================= */

:root {
  --bg: #f5f6f8;
  --card: #ffffff;
  --card-border: rgba(0, 0, 0, 0.08);
  --text: #1a1a2e;
  --muted: #6b7280;
  --text-faint: #9ca3af;
  --brand: #3b82f6;
  --brand-hover: #2563eb;
  --brand-soft: rgba(59, 130, 246, 0.08);
  --danger: #ef4444;
  --danger-hover: #dc2626;
  --border: rgba(0, 0, 0, 0.08);
  --border-strong: rgba(0, 0, 0, 0.14);
  --surface-alt: #f0f1f3;
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "Inter", sans-serif;
  --font-mono: "SF Mono", Consolas, "Cascadia Mono", monospace;
  --radius-lg: 12px;
  --radius-md: 10px;
  --radius-sm: 8px;
}

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

body {
  min-height: 100vh;
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text);
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  line-height: 1.5;
}

.bg-orb { display: none; }

/* ---- Shell ---- */
.shell {
  max-width: 1060px;
  margin: 28px auto;
  padding: 0 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* ---- Panel / Card ---- */
.card, .panel {
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-lg);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04), 0 4px 12px rgba(0, 0, 0, 0.03);
}

.panel-section { padding: 20px 22px; }

/* ---- Page Head (CodeTime-style) ---- */
.page-head {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 20px;
  padding: 22px 24px;
  align-items: end;
}

.head-meta {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.meta-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 11px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-alt);
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.meta-chip strong {
  color: var(--text);
  font-weight: 600;
}

/* ---- Eyebrow (CodeTime-style section label) ---- */
.eyebrow {
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 11px;
  font-family: var(--font-mono);
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

/* ---- Typography ---- */
.kicker {
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--brand);
  font-size: 11px;
  font-weight: 700;
  font-family: var(--font-mono);
}

h1 {
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text);
}

h2 {
  margin: 0 0 14px;
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
}

.muted { color: var(--muted); font-size: 13px; }

.page-copy {
  margin-top: 6px;
  max-width: 600px;
  color: var(--muted);
  font-size: 13px;
}

/* ---- Section Head (CodeTime title + copy layout) ---- */
.section-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

.section-head h2 { margin: 0; }

.section-copy {
  color: var(--muted);
  font-size: 12px;
  max-width: 320px;
  text-align: right;
  flex-shrink: 0;
}

/* ---- Tabs ---- */
.tabs {
  display: flex;
  gap: 6px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 0;
}

.tab-btn {
  background: transparent;
  color: var(--muted);
  padding: 10px 16px;
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
  font-size: 14px;
  font-weight: 600;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: all 0.15s ease;
}

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

.tab-btn.active {
  background: transparent;
  color: var(--brand);
  border-bottom-color: var(--brand);
}

.tab-pane {
  display: none;
  flex-direction: column;
  gap: 16px;
}

.tab-pane.active {
  display: flex;
  animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ---- Forms ---- */
.add-form, .config-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.config-category-tabs {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  padding: 6px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface-alt);
}

.config-cat-btn {
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  border-radius: var(--radius-sm);
  padding: 7px 12px;
  font-size: 13px;
  font-weight: 600;
  transition: all 0.15s ease;
}

.config-cat-btn:hover {
  background: var(--brand-soft);
  color: var(--text);
}

.config-cat-btn.active {
  background: #ffffff;
  color: var(--brand);
  border-color: var(--card-border);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
}

.config-cat-pane {
  display: none;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px;
  background: var(--card);
  gap: 14px;
  flex-direction: column;
}

.config-cat-pane.active { display: flex; }

.form-group {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.config-inline-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(220px, 1fr));
  gap: 12px;
}

.config-inline-row .inline-item { min-width: 0; }

.form-group label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}

.help {
  margin: 0;
  font-size: 12px;
  color: var(--muted);
}

.input-text {
  width: 100%;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 13px;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.input-text:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

textarea#tokenInput {
  width: 100%;
  height: 80px;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 13px;
  resize: vertical;
}

textarea#refreshBundleInput {
  width: 100%;
  min-height: 140px;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 12px;
  resize: vertical;
}

textarea#cookieInput {
  width: 100%;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 13px;
  resize: vertical;
}

#refreshBundleFile { color: var(--muted); }

.refresh-status {
  margin-top: 8px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-alt);
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.refresh-status .table-wrapper { margin-top: 6px; }
.refresh-profiles-table { font-size: 12px; }
.refresh-profiles-table th,
.refresh-profiles-table td { padding: 8px; }

/* ---- Dialogs ---- */
.dialog-modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.25);
  backdrop-filter: blur(6px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 950;
  padding: 20px;
}

.dialog-modal.open { display: flex; }

.dialog-card {
  width: min(760px, 100%);
  max-height: calc(100vh - 40px);
  overflow-y: auto;
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-lg);
  padding: 20px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.12);
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-size: 14px;
  color: var(--text);
}

/* ---- Actions / Buttons ---- */
.actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

button {
  background: var(--brand);
  color: #ffffff;
  border: none;
  border-radius: var(--radius-sm);
  padding: 9px 18px;
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
  transition: all 0.15s ease;
}

button:hover {
  background: var(--brand-hover);
  box-shadow: 0 2px 8px rgba(59, 130, 246, 0.2);
}

button.secondary {
  background: var(--surface-alt);
  color: var(--text);
  border: 1px solid var(--border);
}

button.secondary:hover {
  background: #e5e7eb;
  border-color: var(--border-strong);
  box-shadow: none;
}

button.danger {
  background: transparent;
  color: var(--danger);
  border: 1px solid var(--danger);
  padding: 6px 12px;
  font-size: 12px;
}

button.danger:hover {
  background: var(--danger);
  color: #fff;
  box-shadow: none;
}

button.small {
  padding: 6px 12px;
  font-size: 12px;
  background: var(--surface-alt);
  color: var(--text);
  border: 1px solid var(--border);
}

button.small:hover {
  background: #e5e7eb;
  box-shadow: none;
}

.msg { font-size: 13px; }

/* ---- List Head ---- */
.list-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.list-head h2 { margin: 0; }

.input-select {
  min-width: 120px;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 7px 10px;
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 12px;
}

.input-select:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

/* ---- Stats Grid (CodeTime-style) ---- */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 12px;
}

.stat-card {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface-alt);
  padding: 16px 18px;
  min-height: 100px;
}

.stat-label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 10px;
}

.stat-value {
  color: var(--text);
  font-size: clamp(22px, 3vw, 28px);
  line-height: 1.1;
  font-weight: 700;
  letter-spacing: -0.03em;
}

.stat-note {
  margin-top: 10px;
  color: var(--text-faint);
  font-size: 12px;
}

/* ---- Token Summary ---- */
.token-summary {
  display: flex;
  align-items: center;
  gap: 20px;
  margin: -4px 0 12px;
  color: var(--muted);
  font-size: 13px;
}

.token-summary strong {
  color: var(--text);
  font-size: 15px;
  font-weight: 700;
}

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

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

#logsTable, #runningLogsTable { table-layout: auto; }

#logsTable th:nth-child(1), #logsTable td:nth-child(1),
#runningLogsTable th:nth-child(1), #runningLogsTable td:nth-child(1) { width: 70px; }

#logsTable th:nth-child(2), #logsTable td:nth-child(2),
#runningLogsTable th:nth-child(2), #runningLogsTable td:nth-child(2),
#logsTable th:nth-child(4), #logsTable td:nth-child(4),
#runningLogsTable th:nth-child(4), #runningLogsTable td:nth-child(4),
#logsTable th:nth-child(8), #logsTable td:nth-child(8),
#runningLogsTable th:nth-child(8), #runningLogsTable td:nth-child(8) { width: auto; white-space: nowrap; }

#logsTable th:nth-child(3), #logsTable td:nth-child(3),
#runningLogsTable th:nth-child(3), #runningLogsTable td:nth-child(3) { width: 62px; white-space: nowrap; }

#logsTable th:nth-child(5), #logsTable td:nth-child(5),
#runningLogsTable th:nth-child(5), #runningLogsTable td:nth-child(5) { width: 500px; }

#logsTable th:nth-child(6), #logsTable td:nth-child(6),
#runningLogsTable th:nth-child(6), #runningLogsTable td:nth-child(6) { width: 190px; }

#logsTable th:nth-child(7), #logsTable td:nth-child(7),
#runningLogsTable th:nth-child(7), #runningLogsTable td:nth-child(7) { min-width: 220px; width: 35%; }

#logsTable td, #runningLogsTable td { padding: 10px 8px; vertical-align: top; }

.log-account-cell { display: block; color: var(--text); line-height: 1.35; }

.log-time-cell { color: var(--muted); line-height: 1.2; white-space: normal; }
.log-time-cell .date { display: block; color: var(--text); }
.log-time-cell .time { display: block; color: var(--muted); }

.log-account-email { color: var(--muted); word-break: break-all; }

.log-model-cell {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--brand);
  word-break: break-word;
}

.log-prompt-cell {
  color: var(--text);
  line-height: 1.35;
  white-space: normal;
  word-break: break-word;
  overflow-wrap: anywhere;
}

th {
  text-align: left;
  padding: 10px 12px;
  border-bottom: 2px solid var(--border);
  color: var(--muted);
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

td {
  padding: 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.token-val {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--muted);
  word-break: break-all;
}

/* ---- Status Badges ---- */
.status-badge {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.status-active    { background: rgba(34, 197, 94, 0.1);  color: #16a34a; }
.status-exhausted { background: rgba(245, 158, 11, 0.1); color: #d97706; }
.status-invalid   { background: rgba(239, 68, 68, 0.1);  color: #dc2626; }
.status-error     { background: rgba(239, 68, 68, 0.1);  color: #dc2626; }
.status-disabled  { background: rgba(0, 0, 0, 0.05);     color: #9ca3af; }

.log-status-2xx { background: rgba(34, 197, 94, 0.1);  color: #16a34a; }
.log-status-4xx { background: rgba(245, 158, 11, 0.1); color: #d97706; }
.log-status-5xx { background: rgba(239, 68, 68, 0.1);  color: #dc2626; }

.log-state {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
}

.log-state.running { color: #2563eb; background: rgba(59, 130, 246, 0.08); }
.log-state.success { color: #16a34a; background: rgba(34, 197, 94, 0.08); }
.log-state.failed  { color: #dc2626; background: rgba(239, 68, 68, 0.08); }

.log-state-btn { border: 0; cursor: pointer; font: inherit; }
.log-state-btn.failed { border: 1px solid rgba(239, 68, 68, 0.3); background: rgba(239, 68, 68, 0.06); }
.log-state-btn.failed:hover { background: rgba(239, 68, 68, 0.12); }

.icon-spinner {
  width: 10px; height: 10px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}

.icon-check, .icon-error {
  display: inline-flex; align-items: center; justify-content: center;
  width: 12px; height: 12px; font-size: 11px; line-height: 1;
}

.log-row-running { background: rgba(59, 130, 246, 0.03); }

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

/* ---- Action Buttons Grid ---- */
.action-btns {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 5px;
  min-width: 120px;
}

th input[type="checkbox"],
td input[type="checkbox"] { width: 14px; height: 14px; cursor: pointer; }

.action-btns button {
  width: 100%; padding: 3px 5px;
  font-size: 10px; border-radius: 4px;
}

/* ---- Switch ---- */
.switch-btn {
  width: 42px; height: 24px;
  border-radius: 999px;
  border: 1px solid transparent;
  padding: 2px;
  display: inline-flex; align-items: center;
  background: #d1d5db;
  vertical-align: middle;
}
.switch-btn.on  { background: rgba(59, 130, 246, 0.25); border-color: rgba(59, 130, 246, 0.4); }
.switch-btn.off { background: #e5e7eb; border-color: rgba(0, 0, 0, 0.1); }
.switch-btn:disabled { opacity: 0.5; cursor: not-allowed; }

.switch-knob {
  width: 18px; height: 18px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15);
  transform: translateX(0);
  transition: transform 0.15s ease;
}
.switch-btn.on .switch-knob { transform: translateX(18px); }

.switch-text { margin-left: 8px; font-size: 12px; color: var(--muted); }

.empty-state {
  text-align: center;
  padding: 40px !important;
  color: var(--muted);
}

.logs-pagination {
  margin-top: 12px;
  display: flex; align-items: center; justify-content: flex-end; gap: 10px;
}

/* ---- Preview Modal ---- */
.preview-modal {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, 0.3);
  backdrop-filter: blur(6px);
  display: none; align-items: center; justify-content: center;
  z-index: 1000; padding: 20px;
}
.preview-modal.open { display: flex; }

.preview-modal-dialog {
  width: min(1100px, 100%);
  max-height: calc(100vh - 40px);
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-lg);
  padding: 20px;
  display: flex; flex-direction: column; gap: 12px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.12);
}

.preview-close { align-self: flex-end; padding: 6px 12px; font-size: 12px; }

.preview-content {
  display: flex; align-items: center; justify-content: center;
  min-height: 220px; max-height: calc(100vh - 130px);
}

.preview-content img,
.preview-content video {
  max-width: 100%; max-height: calc(100vh - 150px);
  border-radius: var(--radius-sm);
  background: var(--surface-alt);
}

.preview-actions { display: flex; justify-content: flex-end; }

.preview-download {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 80px; padding: 8px 14px;
  border-radius: var(--radius-sm);
  background: var(--surface-alt); color: var(--text);
  text-decoration: none; font-weight: 600; font-size: 13px;
  border: 1px solid var(--border);
}
.preview-download:hover { background: #e5e7eb; }

/* ---- Error Detail Modal ---- */
.error-detail-head {
  display: flex; align-items: center; justify-content: space-between;
}
.error-detail-head h3 { margin: 0; font-size: 16px; color: var(--text); }

.error-detail-content {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-alt);
  padding: 14px;
  max-height: calc(100vh - 220px);
  overflow: auto;
}

.error-detail-content pre {
  margin: 0; white-space: pre-wrap; word-break: break-word;
  color: var(--text); font-family: var(--font-mono); font-size: 12px; line-height: 1.5;
}

/* ---- Toast ---- */
.toast {
  position: fixed; right: 20px; bottom: 20px;
  padding: 10px 16px;
  border-radius: var(--radius-md);
  background: var(--card); color: var(--text);
  border: 1px solid var(--card-border);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.1);
  font-size: 13px; line-height: 1.4;
  z-index: 1200;
  opacity: 0; transform: translateY(8px);
  pointer-events: none;
  transition: opacity 0.18s ease, transform 0.18s ease;
}
.toast.show    { opacity: 1; transform: translateY(0); }
.toast.success { border-color: rgba(34, 197, 94, 0.4); }
.toast.error   { border-color: rgba(239, 68, 68, 0.4); }

/* ---- Responsive ---- */
@media (max-width: 900px) {
  .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .page-head  { grid-template-columns: 1fr; }
  .head-meta  { justify-content: flex-start; }
  .list-head  { flex-direction: column; align-items: flex-start; gap: 10px; }
  .list-head .actions { width: 100%; flex-wrap: wrap; gap: 10px; }
  .section-head { flex-direction: column; align-items: flex-start; }
  .section-copy { text-align: left; max-width: none; }
}

@media (max-width: 560px) {
  .stats-grid { grid-template-columns: 1fr; }
  .config-category-tabs { display: grid; grid-template-columns: 1fr 1fr; }
  .config-inline-row { grid-template-columns: 1fr; }
  .input-select { width: 100%; }
}
