/* ═══════════════════════════════════════════════════
   XHS Spider Dashboard — Style
   ═══════════════════════════════════════════════════ */

:root {
  --bg: #f5f6fa;
  --surface: #ffffff;
  --border: #e2e5ee;
  --text: #1a1a2e;
  --text-secondary: #6b7280;
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --danger: #dc2626;
  --danger-hover: #b91c1c;
  --warn: #d97706;
  --warn-hover: #b45309;
  --success: #059669;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.06);
  --shadow-md: 0 4px 6px rgba(0,0,0,.07), 0 2px 4px rgba(0,0,0,.06);
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
}

/* ── Header ──────────────────────────── */

.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow);
}
.header-left { display: flex; align-items: baseline; gap: 12px; }
.logo { font-size: 20px; font-weight: 700; color: var(--primary); }
.subtitle { font-size: 13px; color: var(--text-secondary); }
.header-right { display: flex; align-items: center; gap: 10px; }

.status-dot {
  width: 10px; height: 10px; border-radius: 50%; display: inline-block;
}
.status-dot.on { background: var(--success); box-shadow: 0 0 6px var(--success); }
.status-dot.off { background: #d1d5db; }
.status-text { font-size: 13px; color: var(--text-secondary); }

/* ── Tab Bar ─────────────────────────── */

.tab-bar {
  display: flex;
  gap: 0;
  background: var(--surface);
  border-bottom: 2px solid var(--border);
  padding: 0 24px;
}
.tab {
  padding: 12px 20px;
  border: none;
  background: transparent;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-secondary);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: color .15s, border-color .15s;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }

/* ── Main ────────────────────────────── */

.main { max-width: 1200px; margin: 24px auto; padding: 0 24px; }
.tab-content { display: none; }
.tab-content.active { display: block; }

/* ── Cards ───────────────────────────── */

.card-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
}
.card h3 { font-size: 15px; margin-bottom: 12px; color: var(--text); }
.card-body { display: flex; flex-direction: column; gap: 10px; }

/* ── Panel Grid ──────────────────────── */

.panel-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
}
.panel h3 { font-size: 14px; margin-bottom: 12px; }
.panel.full-width { grid-column: 1 / -1; }
.panel-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.panel-header h3 { margin-bottom: 0; }

/* ── Forms ───────────────────────────── */

.form { display: flex; flex-direction: column; gap: 10px; }
.form label { font-size: 13px; color: var(--text-secondary); display: flex; flex-direction: column; gap: 4px; }
.form-row { display: flex; gap: 12px; }
.form-row label { flex: 1; }
.form input, .form select, .form textarea {
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
  font-family: inherit;
  background: var(--bg);
  color: var(--text);
  outline: none;
  transition: border-color .15s;
}
.form input:focus, .form select:focus, .form textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(79,70,229,.15);
}
.form textarea { resize: vertical; font-family: "SF Mono", "Fira Code", monospace; font-size: 13px; }
.checkbox-label { flex-direction: row !important; align-items: center; gap: 8px !important; }
.checkbox-label input[type="checkbox"] { width: auto; }
hr { border: none; border-top: 1px solid var(--border); margin: 8px 0; }

/* ── Buttons ─────────────────────────── */

.btn {
  padding: 8px 16px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  font-family: inherit;
  transition: all .15s;
  display: inline-flex; align-items: center; gap: 4px;
}
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn-outline { background: transparent; border-color: var(--border); color: var(--text); }
.btn-outline:hover:not(:disabled) { background: var(--bg); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover:not(:disabled) { background: var(--danger-hover); }
.btn-warn { background: var(--warn); color: #fff; }
.btn-warn:hover:not(:disabled) { background: var(--warn-hover); }
.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }

/* ── JSON View ───────────────────────── */

.json-view {
  background: #1e1e2e;
  color: #cdd6f4;
  padding: 16px;
  border-radius: var(--radius);
  font-family: "SF Mono", "Fira Code", "Cascadia Code", monospace;
  font-size: 13px;
  line-height: 1.5;
  overflow-x: auto;
  white-space: pre-wrap;
  word-break: break-all;
  max-height: 400px;
  overflow-y: auto;
}
.json-view.loading { color: #f9e2af; }
.json-view.error { color: #f38ba8; }

/* ── Result Inline ───────────────────── */

.result-inline {
  font-size: 13px;
  padding: 8px;
  border-radius: var(--radius);
  background: var(--bg);
  min-height: 20px;
  max-height: 200px;
  overflow-y: auto;
  white-space: pre-wrap;
  font-family: "SF Mono", "Fira Code", monospace;
}

/* ── Alert ───────────────────────────── */

.alert { padding: 10px 14px; border-radius: var(--radius); font-size: 13px; }
.alert-danger { background: #fef2f2; color: var(--danger); border: 1px solid #fecaca; }

/* ── List Container ──────────────────── */

.list-container {
  max-height: 300px;
  overflow-y: auto;
  font-size: 13px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px;
}
.keyword-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 8px;
  border-bottom: 1px solid var(--border);
}
.keyword-row:last-child { border-bottom: none; }
.keyword-row:hover { background: var(--bg); }

/* ── Quick Links ─────────────────────── */

.quick-links { display: flex; gap: 10px; flex-wrap: wrap; }

/* ── Modal ───────────────────────────── */

.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.4);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000;
}
.modal-overlay.hidden { display: none; }
.modal {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  width: 440px;
  max-width: 90vw;
}
.modal-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.modal-header h2 { font-size: 16px; }
.btn-close {
  border: none; background: none; font-size: 20px;
  color: var(--text-secondary); cursor: pointer; padding: 0 4px;
}
.btn-close:hover { color: var(--text); }
.modal-body { padding: 20px; }
.hint { font-size: 12px; color: var(--text-secondary); }

/* ── Wizard ───────────────────────────── */

.wizard {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
}
.wizard-title { font-size: 18px; margin-bottom: 20px; }
.wizard-steps { display: flex; flex-direction: column; gap: 0; }
.wiz-step {
  display: flex; gap: 16px; padding: 16px;
  border-left: 3px solid var(--border);
  transition: border-color .3s, background .3s;
  opacity: 0.55;
}
.wiz-step.active { opacity: 1; border-left-color: var(--primary); background: rgba(79,70,229,.03); }
.wiz-step.done { opacity: 1; border-left-color: var(--success); }

.wiz-num {
  width: 32px; height: 32px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 14px; flex-shrink: 0;
  background: var(--border); color: var(--text-secondary);
}
.wiz-step.active .wiz-num { background: var(--primary); color: #fff; }
.wiz-step.done .wiz-num { background: var(--success); color: #fff; }

.wiz-body { flex: 1; }
.wiz-body strong { font-size: 14px; }
.wiz-body p { font-size: 13px; color: var(--text-secondary); margin: 4px 0 10px; }
.wiz-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.wiz-status { font-size: 12px; font-weight: 500; }
.wiz-status.ok { color: var(--success); }
.wiz-status.err { color: var(--danger); }
.wiz-input { padding: 8px 10px; border: 1px solid var(--border); border-radius: var(--radius); font-size: 14px; width: 200px; }

/* ── View Toggle ──────────────────────── */

.panel-header-actions { display: flex; align-items: center; gap: 12px; }
.view-toggle { display: flex; border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.vt-btn {
  padding: 5px 12px; border: none; background: transparent;
  font-size: 12px; cursor: pointer; color: var(--text-secondary);
  font-family: inherit;
}
.vt-btn.active { background: var(--primary); color: #fff; }
.vt-btn:not(.active):hover { background: var(--bg); }

/* ── Notes Card Grid ──────────────────── */

.notes-card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
  color: var(--text-secondary);
  font-size: 14px;
  min-height: 60px;
}
.note-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  transition: box-shadow .2s;
  cursor: pointer;
}
.note-card:hover { box-shadow: var(--shadow-md); }
.note-card-cover {
  width: 100%; height: 180px; object-fit: cover;
  background: var(--bg); display: block;
}
.note-card-cover-fallback {
  width: 100%; height: 180px; background: linear-gradient(135deg, #e2e5ee, #f5f6fa);
  display: flex; align-items: center; justify-content: center;
  font-size: 40px; color: #c0c5d0;
}
.note-card-cover.img-broken { display: none; }
.note-card-body { padding: 12px; }
.note-card-title {
  font-size: 14px; font-weight: 600; color: var(--text);
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden; margin-bottom: 8px; line-height: 1.4;
}
.note-card-meta {
  display: flex; justify-content: space-between; align-items: center;
  font-size: 12px;
}
.note-card-author { display: flex; align-items: center; gap: 4px; }
.note-card-avatar {
  width: 18px; height: 18px; border-radius: 50%;
  background: var(--primary); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 10px; font-weight: 600;
}
.note-card-stats { display: flex; gap: 10px; align-items: center; }
.note-card-badge {
  font-size: 11px; padding: 2px 6px; border-radius: 4px;
  background: #fef3c7; color: #b45309;
}
.note-card-badge.video { background: #dbeafe; color: #1d4ed8; }
.note-card-time { color: var(--text-secondary); }

/* ── Images Preview ───────────────────── */

.images-preview { }
.images-header {
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 10px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}
.images-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 10px;
}
.img-cell {
  position: relative;
  aspect-ratio: 1;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  overflow: hidden;
  background: var(--bg);
}
.img-cell img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: transform .15s;
}
.img-cell:hover img { transform: scale(1.05); }
.img-cell.img-broken {
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  font-size: 12px;
}
.img-cell.img-broken::before { content: '加载失败'; }
.img-cell.img-broken img { display: none; }

/* ── Empty State ──────────────────────── */

.empty-state {
  grid-column: 1 / -1;
  text-align: center; padding: 40px 20px; color: var(--text-secondary);
}
.empty-state-icon { font-size: 48px; margin-bottom: 12px; }
.empty-state p { font-size: 14px; }

/* ── Toast ───────────────────────────── */

.toast-container {
  position: fixed; bottom: 20px; right: 20px;
  display: flex; flex-direction: column; gap: 8px;
  z-index: 2000;
}
.toast {
  padding: 10px 18px;
  border-radius: var(--radius);
  font-size: 13px;
  color: #fff;
  box-shadow: var(--shadow-md);
  animation: slideIn .25s ease;
  max-width: 360px;
}
.toast.success { background: var(--success); }
.toast.error { background: var(--danger); }
.toast.info { background: var(--primary); }
@keyframes slideIn {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

/* ── Pagination Bar ─────────────────────── */

.pagination-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 0;
  margin-top: 8px;
  border-top: 1px solid var(--border);
  gap: 12px;
  flex-wrap: wrap;
}
.pagination-bar.hidden { display: none; }
.pagination-info {
  font-size: 13px;
  color: var(--text-secondary);
}
.pagination-btns {
  display: flex;
  align-items: center;
  gap: 6px;
}
.pagination-current {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: var(--radius);
  background: var(--primary);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
}

/* ── Responsive ──────────────────────── */

@media (max-width: 768px) {
  .card-grid, .panel-grid { grid-template-columns: 1fr; }
  .tab-bar { overflow-x: auto; }
  .header { flex-direction: column; gap: 8px; }
}
