/* ================================================================
   KITTI TopoPointPWC — Sci-Fi Autonomous Driving Theme
   Dual-mode: Light / Dark / System
   ================================================================ */
/* No external font CDN — use system fonts for fast loading everywhere */

:root {
  --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Microsoft YaHei', 'Helvetica Neue', Arial, sans-serif;
  --font-mono: 'SF Mono', 'Cascadia Code', 'Menlo', 'Consolas', 'Microsoft YaHei Mono', monospace;
  --font-display: var(--font-sans);
  --radius-sm: 6px; --radius-md: 10px; --radius-lg: 14px;
  --transition: 0.25s ease;
}

/* ============ LIGHT THEME ============ */
[data-theme="light"] {
  --bg-deep: #f0f4f8;
  --bg-panel: #ffffff;
  --bg-card: #ffffff;
  --bg-card-hover: #f7faff;
  --border-subtle: #d4dce6;
  --border-glow: #a0b8d0;
  --accent-primary: #0066cc;
  --accent-secondary: #0099ff;
  --accent-tertiary: #7c3aed;
  --accent-warn: #cc6600;
  --accent-success: #008844;
  --accent-danger: #cc2244;
  --text-primary: #1a2332;
  --text-secondary: #556678;
  --text-dim: #8899aa;
  --grid-line: rgba(0, 102, 204, 0.04);
  --shadow-card: 0 1px 4px rgba(0,0,0,0.06);
  --shadow-glow: 0 0 24px rgba(0,102,204,0.12);
  --btn-bg: #e8eef4;
  --btn-hover: #dce4ec;
}

/* ============ DARK THEME (default) ============ */
[data-theme="dark"] {
  --bg-deep: #06080d;
  --bg-panel: #0c1018;
  --bg-card: #111620;
  --bg-card-hover: #161e2c;
  --border-subtle: #1a2340;
  --border-glow: #0a3050;
  --accent-primary: #00e5ff;
  --accent-secondary: #0077ff;
  --accent-tertiary: #7c3aed;
  --accent-warn: #ff8c00;
  --accent-success: #00e676;
  --accent-danger: #ff3366;
  --text-primary: #e0e8f0;
  --text-secondary: #8899b4;
  --text-dim: #556678;
  --grid-line: rgba(0, 229, 255, 0.04);
  --shadow-card: 0 1px 4px rgba(0,0,0,0.3);
  --shadow-glow: 0 0 24px rgba(0,229,255,0.12);
  --btn-bg: #1a2540;
  --btn-hover: #243058;
}

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

body {
  background: var(--bg-deep);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-weight: 400;
  font-size: 15px;
  line-height: 1.6;
  min-height: 100vh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

/* Grid background (dark only) */
[data-theme="dark"] body::before {
  content: '';
  position: fixed; inset: 0;
  background-image: linear-gradient(var(--grid-line) 1px, transparent 1px),
                    linear-gradient(90deg, var(--grid-line) 1px, transparent 1px);
  background-size: 40px 40px;
  pointer-events: none; z-index: 0;
}

[data-theme="dark"] body::after {
  content: '';
  position: fixed; inset: 0;
  background: repeating-linear-gradient(0deg, transparent, transparent 2px, rgba(0,229,255,0.006) 2px, rgba(0,229,255,0.006) 4px);
  pointer-events: none; z-index: 0;
}

.app-container {
  position: relative; z-index: 1;
  max-width: 1600px; margin: 0 auto; padding: 0 20px;
}

/* ============ Header ============ */
.header {
  padding: 16px 0 12px;
  border-bottom: 1px solid var(--border-subtle);
  margin-bottom: 20px;
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px;
  flex-wrap: nowrap;
}

.header-left {
  display: flex; align-items: center; gap: 16px;
  flex-wrap: nowrap;
  min-width: 0;
  flex: 1;
}

.header-brand {
  display: flex; align-items: center; gap: 10px; text-decoration: none;
  flex-shrink: 0;
}

.header-logo {
  width: 32px; height: 32px;
  border: 2px solid var(--accent-primary);
  border-radius: 6px;
  display: flex; align-items: center; justify-content: center;
  background: color-mix(in srgb, var(--accent-primary) 8%, transparent);
  flex-shrink: 0;
}

.header-logo svg { width: 18px; height: 18px; fill: var(--accent-primary); }

.header-title {
  font-family: var(--font-sans); font-weight: 800; font-size: 16px;
  letter-spacing: 0.3px; color: var(--accent-primary);
  white-space: nowrap;
}

[data-theme="dark"] .header-title {
  text-shadow: 0 0 12px rgba(0,229,255,0.25);
}

.header-subtitle {
  font-family: var(--font-mono); font-size: 9px;
  color: var(--text-dim); letter-spacing: 1.5px; text-transform: uppercase;
}

.header-right {
  display: flex; align-items: center; gap: 8px;
  flex-wrap: nowrap;
  flex-shrink: 0;
}

/* ============ Model Selector ============ */
.model-selector {
  display: flex; background: var(--bg-card);
  border: 1px solid var(--border-subtle); border-radius: 6px; overflow: hidden;
  flex-shrink: 0;
}

.model-btn {
  font-family: var(--font-sans); font-weight: 600; font-size: 12px;
  padding: 7px 14px;
  border: none; background: transparent; color: var(--text-secondary);
  cursor: pointer; transition: all var(--transition);
  border-right: 1px solid var(--border-subtle);
  white-space: nowrap;
}
.model-btn:last-child { border-right: none; }
.model-btn:hover { color: var(--text-primary); background: color-mix(in srgb, var(--accent-primary) 4%, transparent); }
.model-btn.active {
  color: var(--accent-primary); background: color-mix(in srgb, var(--accent-primary) 10%, transparent);
  box-shadow: inset 0 -2px 0 var(--accent-primary);
}

/* ============ Theme & Lang Buttons ============ */
.icon-btn-group {
  display: flex; background: var(--bg-card);
  border: 1px solid var(--border-subtle); border-radius: 6px; overflow: hidden;
  flex-shrink: 0;
}

.icon-btn {
  font-family: var(--font-sans); font-size: 11px; font-weight: 500;
  padding: 7px 10px; border: none; background: transparent;
  color: var(--text-secondary); cursor: pointer;
  transition: all var(--transition);
  border-right: 1px solid var(--border-subtle);
  white-space: nowrap;
}
.icon-btn:last-child { border-right: none; }
.icon-btn:hover { color: var(--text-primary); background: var(--btn-hover); }
.icon-btn.active {
  color: var(--accent-primary); background: color-mix(in srgb, var(--accent-primary) 10%, transparent);
  font-weight: 600;
}

/* ============ Stats Bar ============ */
.stats-bar {
  display: flex; gap: 16px; margin-bottom: 22px; flex-wrap: wrap;
}

.stat-card {
  background: var(--bg-card); border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md); padding: 14px 20px; min-width: 130px;
  position: relative; overflow: hidden; box-shadow: var(--shadow-card);
}
.stat-card::before {
  content: ''; position: absolute; top: 0; left: 0;
  width: 3px; height: 100%; background: var(--accent-primary); opacity: 0.5;
}

.stat-label {
  font-family: var(--font-mono); font-size: 10px; color: var(--text-dim);
  letter-spacing: 1.5px; text-transform: uppercase; margin-bottom: 4px;
}

.stat-value {
  font-family: var(--font-sans); font-weight: 700; font-size: 20px;
  color: var(--accent-primary);
}

/* ============ Toolbar ============ */
.toolbar {
  display: flex; align-items: center; gap: 12px; margin-bottom: 18px; flex-wrap: wrap;
}

.search-box {
  background: var(--bg-card); border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm); padding: 10px 16px;
  color: var(--text-primary); font-family: var(--font-mono); font-size: 13px;
  width: 260px; outline: none; transition: border-color var(--transition);
}
.search-box:focus { border-color: var(--accent-primary); }
.search-box::placeholder { color: var(--text-dim); }

.sort-select {
  background: var(--bg-card); border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm); padding: 10px 12px;
  color: var(--text-secondary); font-family: var(--font-mono); font-size: 12px;
  outline: none; cursor: pointer;
}
.sort-select:focus { border-color: var(--accent-secondary); }
.sort-select option { background: var(--bg-card); color: var(--text-primary); }

/* ============ Sequence Grid ============ */
.seq-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(310px, 1fr));
  gap: 18px; margin-bottom: 32px;
}

.seq-card {
  background: var(--bg-card); border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg); padding: 22px 20px;
  cursor: pointer; transition: all var(--transition);
  text-decoration: none; display: flex; flex-direction: column; gap: 12px;
  box-shadow: var(--shadow-card);
  position: relative; overflow: hidden;
}
.seq-card::before {
  content: ''; position: absolute; top: 0; left: 0; right: 0;
  height: 3px; background: linear-gradient(90deg, var(--accent-primary), var(--accent-secondary));
  opacity: 0; transition: opacity var(--transition);
}
.seq-card:hover::before { opacity: 1; }
.seq-card:hover {
  background: var(--bg-card-hover); border-color: var(--accent-primary);
  box-shadow: var(--shadow-glow); transform: translateY(-3px);
}

.seq-card-top {
  display: flex; align-items: flex-start; justify-content: space-between;
}

.seq-frames-large {
  font-family: var(--font-sans); font-weight: 800; font-size: 22px;
  color: var(--accent-primary); line-height: 1.2;
}
.seq-frames-large .arrow {
  color: var(--accent-secondary); margin: 0 8px; font-weight: 400;
}
[data-theme="dark"] .seq-frames-large { text-shadow: 0 0 12px rgba(0,229,255,0.25); }

.seq-id-label {
  font-family: var(--font-mono); font-size: 11px; color: var(--text-dim);
  letter-spacing: 0.5px;
}

.seq-meta-row {
  display: flex; gap: 16px; flex-wrap: wrap;
}

.seq-meta-item {
  display: flex; align-items: center; gap: 5px;
  font-family: var(--font-mono); font-size: 11px; color: var(--text-dim);
}
.seq-meta-item .val { color: var(--text-secondary); font-weight: 600; }

.seq-badge {
  display: inline-block; padding: 3px 10px; border-radius: 4px;
  font-family: var(--font-mono); font-size: 10px; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.5px;
}
.badge-cached { background: color-mix(in srgb, var(--accent-success) 12%, transparent); color: var(--accent-success); border: 1px solid color-mix(in srgb, var(--accent-success) 20%, transparent); }
.badge-new { background: color-mix(in srgb, var(--accent-primary) 10%, transparent); color: var(--accent-primary); border: 1px solid color-mix(in srgb, var(--accent-primary) 18%, transparent); }

/* ============ Pagination ============ */
.pagination {
  display: flex; justify-content: center; align-items: center; gap: 6px;
  margin: 24px 0 36px; flex-wrap: wrap;
}

.page-btn {
  font-family: var(--font-mono); font-size: 13px; padding: 8px 14px;
  border: 1px solid var(--border-subtle); background: var(--bg-card);
  color: var(--text-secondary); border-radius: var(--radius-sm);
  cursor: pointer; transition: all var(--transition); text-decoration: none;
}
.page-btn:hover:not(:disabled) { border-color: var(--accent-primary); color: var(--accent-primary); }
.page-btn:disabled { opacity: 0.3; cursor: not-allowed; }
.page-btn.active {
  background: color-mix(in srgb, var(--accent-primary) 10%, transparent);
  border-color: var(--accent-primary); color: var(--accent-primary); font-weight: 700;
}
.page-info {
  font-family: var(--font-mono); font-size: 11px; color: var(--text-dim);
  margin-left: 8px;
}

/* ============ Detail Page ============ */
.detail-header {
  display: flex; align-items: center; gap: 14px; margin-bottom: 22px; flex-wrap: wrap;
}

.back-btn {
  font-family: var(--font-mono); font-size: 13px;
  padding: 9px 18px; border: 1px solid var(--border-subtle);
  background: var(--bg-card); color: var(--text-secondary);
  border-radius: var(--radius-sm); text-decoration: none;
  transition: all var(--transition);
}
.back-btn:hover { border-color: var(--accent-primary); color: var(--accent-primary); }

.detail-title {
  font-family: var(--font-sans); font-weight: 800; font-size: 19px;
  color: var(--accent-primary);
}

.detail-model-badge {
  font-family: var(--font-mono); font-size: 11px; padding: 5px 12px;
  border-radius: 4px; letter-spacing: 0.5px;
  background: color-mix(in srgb, var(--accent-tertiary) 15%, transparent);
  color: var(--accent-tertiary);
  border: 1px solid color-mix(in srgb, var(--accent-tertiary) 25%, transparent);
}

.detail-meta-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 10px; margin-bottom: 22px;
}

.detail-meta-card {
  background: var(--bg-card); border: 1px solid var(--border-subtle);
  border-radius: 8px; padding: 13px 16px; box-shadow: var(--shadow-card);
}

.detail-meta-label {
  font-family: var(--font-mono); font-size: 10px; color: var(--text-dim);
  letter-spacing: 1px; text-transform: uppercase; margin-bottom: 4px;
}

.detail-meta-value {
  font-family: var(--font-sans); font-weight: 700; font-size: 17px;
  color: var(--accent-secondary);
}

.detail-viz-container {
  background: var(--bg-panel); border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg); overflow: hidden; position: relative;
  display: flex; flex-direction: column;
}

.detail-viz-loading {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  flex-direction: column; gap: 14px; z-index: 10;
  background: var(--bg-panel);
}

.spinner {
  width: 40px; height: 40px;
  border: 3px solid var(--border-subtle);
  border-top: 3px solid var(--accent-primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.detail-viz-loading p {
  font-family: var(--font-mono); font-size: 12px; color: var(--text-dim);
}

.detail-viz-iframe {
  width: 100%; height: 85vh; min-height: 700px; border: none;
  display: block;
}

.no-viz-message {
  display: flex; align-items: center; justify-content: center;
  height: 350px; font-family: var(--font-sans); font-weight: 600;
  font-size: 16px; color: var(--text-dim);
}

/* ============ Footer ============ */
.footer {
  text-align: center; padding: 20px 0 28px;
  border-top: 1px solid var(--border-subtle); margin-top: 12px;
}
.footer p {
  font-family: var(--font-mono); font-size: 10px;
  color: var(--text-dim); letter-spacing: 1px;
}

/* ============ Empty State ============ */
.empty-state {
  text-align: center; padding: 50px 20px; color: var(--text-dim);
}
.empty-state svg { width: 56px; height: 56px; margin-bottom: 14px; opacity: 0.25; }
.empty-state h3 {
  font-family: var(--font-sans); font-weight: 700; font-size: 17px;
  margin-bottom: 6px; color: var(--text-secondary);
}
.empty-state p { font-family: var(--font-mono); font-size: 12px; }

/* ============ Error Pages ============ */
.error-page {
  text-align: center; padding: 80px 20px;
}
.error-code {
  font-family: var(--font-sans); font-weight: 900; font-size: 100px;
  color: color-mix(in srgb, var(--accent-primary) 8%, transparent);
  line-height: 1;
}
[data-theme="dark"] .error-code {
  text-shadow: 0 0 50px rgba(0,229,255,0.08);
}
.error-title {
  font-family: var(--font-sans); font-weight: 700; font-size: 22px;
  color: var(--text-secondary); margin: 12px 0;
}
.error-desc {
  font-family: var(--font-mono); color: var(--text-dim); margin-bottom: 20px;
}

/* ============ Responsive ============ */
@media (max-width: 768px) {
  .header { flex-direction: column; align-items: flex-start; }
  .header-right { flex-wrap: wrap; }
  .seq-grid { grid-template-columns: 1fr; }
  .detail-meta-grid { grid-template-columns: 1fr 1fr; }
  .detail-viz-iframe { height: 50vh; }
  .stats-bar { flex-direction: column; }
  .search-box { width: 100%; }
}

/* Dark-only flicker on title */
[data-theme="dark"] .header-title {
  animation: flicker 5s ease-in-out infinite;
}
@keyframes flicker {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.88; }
}

/* ============ Sidebar Navigation ============ */
.sidebar {
  position: fixed; top: 0; left: 0; bottom: 0; z-index: 100;
  width: 56px;
  background: var(--bg-panel);
  border-right: 1px solid var(--border-subtle);
  display: flex; flex-direction: column;
  transition: width var(--transition);
  overflow-x: hidden;
  overflow-y: auto;
  padding-top: 66px;
  scrollbar-width: none;
}
.sidebar::-webkit-scrollbar { display: none; }
.sidebar:hover, .sidebar.expanded { width: 220px; box-shadow: 4px 0 24px rgba(0,0,0,0.3); }

.sidebar-section {
  padding: 6px 0;
  border-bottom: 1px solid var(--border-subtle);
  flex-shrink: 0;
}
.sidebar-section:last-child { border-bottom: none; }

.sidebar-label {
  padding: 8px 18px 4px;
  font-family: var(--font-mono); font-size: 9px;
  color: var(--text-dim); text-transform: uppercase;
  letter-spacing: 2px;
  white-space: nowrap;
  opacity: 0;
  transition: opacity 0.15s;
}
.sidebar:hover .sidebar-label, .sidebar.expanded .sidebar-label { opacity: 1; }

.sidebar-nav { display: flex; flex-direction: column; }

.sidebar-item {
  display: flex; align-items: center; gap: 12px;
  padding: 11px 16px;
  color: var(--text-secondary);
  text-decoration: none;
  font-family: var(--font-sans); font-size: 13px; font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
  border: none; background: none;
  width: 100%; text-align: left;
  white-space: nowrap;
  position: relative;
  min-height: 42px;
}
.sidebar-item::before {
  content: ''; position: absolute; left: 0; top: 6px; bottom: 6px;
  width: 3px; background: var(--accent-primary);
  opacity: 0; border-radius: 0 2px 2px 0;
  transition: opacity var(--transition);
}
.sidebar-item:hover { color: var(--text-primary); background: color-mix(in srgb, var(--accent-primary) 5%, transparent); }
.sidebar-item.active { color: var(--accent-primary); font-weight: 600; background: color-mix(in srgb, var(--accent-primary) 8%, transparent); }
.sidebar-item.active::before { opacity: 1; }

.sidebar-icon {
  width: 24px; height: 24px;
  display: flex; align-items: center; justify-content: center;
  font-size: 17px; flex-shrink: 0;
  border-radius: 4px;
  background: color-mix(in srgb, var(--accent-primary) 6%, transparent);
  transition: all var(--transition);
}
.sidebar-item:hover .sidebar-icon, .sidebar-item.active .sidebar-icon {
  background: color-mix(in srgb, var(--accent-primary) 15%, transparent);
  color: var(--accent-primary);
}

.sidebar-text {
  opacity: 0; transition: opacity 0.15s; font-size: 12px;
}
.sidebar:hover .sidebar-text, .sidebar.expanded .sidebar-text { opacity: 1; }

/* Push main content for sidebar */
body.has-sidebar { padding-left: 56px; }
body.has-sidebar .app-container { margin-left: 0 !important; max-width: calc(1600px - 56px); }

/* Sidebar bottom toggle */
.sidebar-toggle {
  position: sticky; bottom: 0; margin-top: auto;
  padding: 10px 0; display: flex; justify-content: center;
  background: var(--bg-panel); border-top: 1px solid var(--border-subtle);
}
.sidebar-toggle-btn {
  background: var(--bg-card); border: 1px solid var(--border-subtle);
  border-radius: 6px; color: var(--text-secondary);
  padding: 6px 10px; cursor: pointer; font-size: 13px;
  transition: all var(--transition);
}
.sidebar-toggle-btn:hover { border-color: var(--accent-primary); color: var(--accent-primary); }

/* ============ Toast / Popup ============ */
.toast-overlay {
  position: fixed; inset: 0; z-index: 999;
  background: rgba(0,0,0,0.5);
  display: flex; align-items: center; justify-content: center;
  opacity: 0; pointer-events: none;
  transition: opacity 0.3s;
}
.toast-overlay.show { opacity: 1; pointer-events: auto; }

.toast-dialog {
  background: var(--bg-panel);
  border: 1px solid var(--accent-primary);
  border-radius: var(--radius-lg);
  padding: 32px 36px;
  text-align: center;
  max-width: 400px;
  box-shadow: var(--shadow-glow);
  transform: translateY(10px);
  transition: transform 0.3s;
}
.toast-overlay.show .toast-dialog { transform: translateY(0); }

.toast-icon {
  font-size: 40px; margin-bottom: 12px;
  filter: grayscale(0.3);
}
.toast-title {
  font-family: var(--font-sans); font-weight: 700; font-size: 18px;
  color: var(--accent-primary); margin-bottom: 8px;
}
.toast-msg {
  font-family: var(--font-mono); font-size: 13px;
  color: var(--text-secondary); margin-bottom: 20px; line-height: 1.6;
}
.toast-btn {
  font-family: var(--font-sans); font-weight: 600; font-size: 13px;
  padding: 10px 28px;
  border: 1px solid var(--accent-primary);
  background: color-mix(in srgb, var(--accent-primary) 8%, transparent);
  color: var(--accent-primary); border-radius: var(--radius-sm);
  cursor: pointer; transition: all var(--transition);
}
.toast-btn:hover { background: var(--accent-primary); color: var(--bg-deep); }

/* Stats Dashboard */
.stats-dashboard {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 20px; margin-bottom: 24px;
}
.stats-panel {
  background: var(--bg-card); border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md); padding: 20px;
  box-shadow: var(--shadow-card);
}
.stats-panel h3 {
  font-family: var(--font-sans); font-weight: 700; font-size: 15px;
  color: var(--accent-primary); margin-bottom: 14px;
}
.stats-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 0; border-bottom: 1px solid var(--border-subtle);
  font-family: var(--font-mono); font-size: 13px;
}
.stats-row:last-child { border-bottom: none; }
.stats-row .label { color: var(--text-secondary); }
.stats-row .value { color: var(--accent-secondary); font-weight: 600; }

.stats-bar-horiz {
  height: 8px; border-radius: 4px; background: var(--border-subtle);
  margin: 6px 0 14px; overflow: hidden;
}
.stats-bar-fill {
  height: 100%; border-radius: 4px;
  background: linear-gradient(90deg, var(--accent-primary), var(--accent-secondary));
  transition: width 0.6s ease;
}
