*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #f5f6f8;
  --card: #ffffff;
  --text: #1a1a2e;
  --muted: #6b7280;
  --accent: #2563eb;
  --border: #e2e4e9;
  --radius: 6px;
  --sidebar-w: 220px;
  --toolbar-h: 32px;
  --cursor-color: #e74c3c;
  --msg-row-h: 24px;
  --mono: 'SF Mono', 'Consolas', 'Monaco', 'Menlo', monospace;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.4;
  height: 100vh;
  overflow: hidden;
  font-size: 13px;
}

/* ── Landing view ── */
#landing header {
  text-align: center;
  padding: 2rem 1rem 1rem;
}
#landing header h1 { font-size: 1.6rem; }
.subtitle { color: var(--muted); font-size: 0.9rem; margin-top: 0.25rem; }
.privacy-note {
  font-size: 0.82rem; color: var(--muted); margin-top: 0.5rem;
  background: #f0f7f0; border: 1px solid #c6e6c6; border-radius: 6px;
  padding: 0.5rem 1rem; display: inline-block;
}
.privacy-note a { color: var(--accent); text-decoration: none; }
.privacy-note a:hover { text-decoration: underline; }
.landing-main { max-width: 700px; margin: 0 auto; padding: 0 1rem 3rem; }

/* Preview section */
.preview-section {
  margin-top: 2rem;
}
.preview-heading {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 0.75rem;
  text-align: center;
}
.preview-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}
.preview-figure {
  margin: 0;
}
.preview-img {
  width: 100%;
  max-width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  display: block;
}
.preview-caption {
  font-size: 0.78rem;
  color: var(--muted);
  text-align: center;
  margin-top: 0.3rem;
}

.preview-video-wrapper {
  margin-top: 1.25rem;
  position: relative;
  width: 100%;
  padding-bottom: 56.25%; /* 16:9 */
  height: 0;
}
.preview-video {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

/* Upload zone */
.upload-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 3rem 2rem;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
  margin-bottom: 1.5rem;
}
.upload-zone:hover, .upload-zone.dragover {
  border-color: var(--accent);
  background: rgba(37, 99, 235, 0.04);
}
.upload-content svg { color: var(--muted); margin-bottom: 0.75rem; }
.upload-content p { color: var(--muted); }

/* Loading */
.loading {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: rgba(0,0,0,0.45);
  z-index: 9999;
}
.spinner {
  width: 32px; height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto 0.75rem;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── App view ── */
.app-view {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* Left sidebar */
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--card);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  height: 100vh;
}
.sidebar-header {
  padding: 0.5rem 0.75rem 0.35rem;
  border-bottom: 1px solid var(--border);
}
.sidebar-header h2 { font-size: 0.9rem; margin-bottom: 0.1rem; }
.sidebar-build { font-size: 0.65rem; color: var(--muted); display: block; }
.sidebar-label { font-size: 0.7rem; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; margin-top: 0.3rem; }
.sidebar-files {
  flex-shrink: 0;
  overflow-y: auto;
  max-height: 150px;
  padding: 0.15rem 0;
}
.sidebar-minimap {
  flex: 1;
  min-height: 120px;
  border-top: 1px solid var(--border);
}
.sidebar-footer {
  padding: 0.4rem 0.5rem;
  border-top: 1px solid var(--border);
}

/* Quicklook table */
.quicklook-table { width: 100%; border-collapse: collapse; font-size: 0.75rem; }
.quicklook-table th {
  text-align: left; color: var(--muted); font-weight: 500;
  padding: 0.2rem 0.4rem; border-bottom: 1px solid var(--border);
}
.quicklook-table td { padding: 0.25rem 0.4rem; }
.quicklook-table tbody tr { cursor: pointer; transition: background 0.15s; }
.quicklook-table tbody tr:hover { background: rgba(37,99,235,0.06); }
.quicklook-table tbody tr.active { background: rgba(37,99,235,0.12); font-weight: 600; }
.quicklook-swatch { display: inline-block; width: 8px; height: 8px; border-radius: 2px; }
.quicklook-close {
  border: none; background: transparent; color: var(--muted); cursor: pointer;
  font-size: 0.85rem; padding: 0 0.1rem; opacity: 0.4; line-height: 1;
}
.quicklook-close:hover { opacity: 1; color: #c0392b; }

.add-file-btn {
  width: 100%;
  padding: 0.3rem 0.5rem;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  background: transparent;
  font-size: 0.78rem;
  color: var(--muted);
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s;
}
.add-file-btn:hover { border-color: var(--accent); color: var(--accent); }
.sidebar-drop-hint {
  font-size: 0.68rem;
  color: var(--muted);
  text-align: center;
  margin-top: 0.3rem;
  opacity: 0.7;
}

/* Right pane */
.right-pane {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
}

/* ── Toolbar ── */
.toolbar {
  height: var(--toolbar-h);
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0 0.75rem;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  font-size: 0.78rem;
  flex-shrink: 0;
}
.toolbar-file { font-weight: 600; color: var(--text); max-width: 200px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.toolbar-sep { color: var(--border); }
.toolbar-cursor { color: var(--muted); font-family: var(--mono); font-size: 0.72rem; }
.toolbar-zoom { color: var(--muted); font-size: 0.72rem; }
.toolbar-btn {
  border: 1px solid var(--border); border-radius: 3px; background: var(--card);
  padding: 1px 6px; font-size: 0.72rem; cursor: pointer; color: var(--muted);
}
.toolbar-btn:hover { border-color: var(--accent); color: var(--accent); }
.toolbar-spacer { flex: 1; }
.toolbar-keys { color: var(--muted); cursor: pointer; font-size: 0.7rem; }
.toolbar-keys:hover { color: var(--accent); }

/* ── Tab bar ── */
.tab-bar {
  display: flex;
  gap: 0;
  border-bottom: 1px solid var(--border);
  background: var(--card);
  flex-shrink: 0;
}
.tab-btn {
  padding: 0.45rem 1.25rem;
  border: none;
  background: transparent;
  font-size: 0.82rem;
  color: var(--muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: color 0.15s, border-color 0.15s;
}
.tab-btn:hover { color: var(--text); }
.tab-btn.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }

/* ── Tab content ── */
.tab-content {
  flex: 1;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.tab-content.hidden { display: none !important; }

/* ── Summary bar (sticky at top of plots) ── */
.summary-bar {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.3rem 0.75rem;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  font-size: 0.78rem;
  flex-shrink: 0;
}
.summary-bar-title { font-weight: 600; white-space: nowrap; }
.summary-bar-items {
  display: flex;
  flex-wrap: wrap;
  gap: 0 0.5rem;
  align-items: center;
}
.summary-item { white-space: nowrap; }
.summary-item .label { color: var(--muted); }
.summary-item .value { font-weight: 600; }
.summary-item + .summary-item::before { content: '\00b7'; color: var(--border); margin-right: 0.5rem; }

/* ── Plots tab ── */
.plots-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 0.75rem;
}
.plot-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}
.plot-grid.secondary {
  grid-template-columns: 1fr 1fr;
}
.plot-box {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  min-height: 260px;
}

@media (max-width: 1100px) {
  .plot-grid, .plot-grid.secondary { grid-template-columns: 1fr; }
}

/* ── Messages tab ── */
.filter-bar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.35rem 0.75rem;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.msg-search {
  width: 200px;
  padding: 3px 8px;
  border: 1px solid var(--border);
  border-radius: 3px;
  font-size: 0.78rem;
  font-family: var(--mono);
  outline: none;
}
.msg-search:focus { border-color: var(--accent); }
.link-zoom-label {
  font-size: 0.75rem;
  color: var(--muted);
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
}
.link-zoom-label input { margin-right: 3px; vertical-align: middle; }
.msg-status { font-size: 0.75rem; color: var(--muted); margin-left: auto; white-space: nowrap; }

/* Type chips */
.type-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  padding: 0.25rem 0.75rem;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.type-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 0.72rem;
  cursor: pointer;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--muted);
  transition: all 0.15s;
  user-select: none;
  white-space: nowrap;
}
.type-chip .chip-dot {
  width: 7px; height: 7px; border-radius: 50%;
}
.type-chip.on {
  border-color: currentColor;
  font-weight: 600;
}
.type-chip:hover { border-color: var(--accent); }

/* Message list + detail split */
.msg-split {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 0;
}

.msg-scroll {
  position: relative;
  overflow-y: auto;
  flex: 1;
  min-height: 0;
  background: var(--card);
}
.msg-header, .msg-row {
  display: flex;
  font-size: 0.75rem;
  font-family: var(--mono);
}
.msg-header {
  position: sticky;
  top: 0;
  background: var(--card);
  z-index: 1;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  color: var(--muted);
  font-size: 0.72rem;
}
.msg-header > span, .msg-row > span {
  padding: 3px 6px;
  white-space: nowrap;
}
.msg-row > span {
  overflow: hidden;
  text-overflow: ellipsis;
}
.msg-row {
  position: absolute;
  left: 0; right: 0;
  height: var(--msg-row-h);
  cursor: pointer;
  border-left: 3px solid transparent;
}
.msg-row:hover { background: rgba(37,99,235,0.04); }
.msg-row.selected { background: rgba(37,99,235,0.10); }
.msg-row.cursor-highlight { background: rgba(231,76,60,0.08); }
.msg-col-time { width: 76px; flex-shrink: 0; }
.msg-col-utc { width: 90px; flex-shrink: 0; }
.msg-col-type { width: 140px; flex-shrink: 0; }
.msg-col-fields { flex: 1; min-width: 0; }

/* ── Detail panel ── */
.detail-panel {
  flex-shrink: 0;
  max-height: 45%;
  border-top: 2px solid var(--accent);
  background: var(--card);
  overflow-y: auto;
  font-size: 0.8rem;
}
.detail-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.35rem 0.75rem;
  background: #f0f2f5;
  border-bottom: 1px solid var(--border);
  font-family: var(--mono);
  font-size: 0.72rem;
  color: var(--muted);
  position: sticky;
  top: 0;
  z-index: 1;
}
.detail-close {
  border: none; background: none; cursor: pointer; font-size: 1.1rem; color: var(--muted); line-height: 1;
}
.detail-close:hover { color: #c0392b; }
.detail-body {
  display: flex;
  gap: 1rem;
  padding: 0.5rem 0.75rem;
}
.detail-fields {
  flex: 1;
  font-family: var(--mono);
  font-size: 0.78rem;
  line-height: 1.7;
}
.detail-fields .field-row { display: flex; gap: 0.75rem; }
.detail-fields .field-key { color: var(--muted); min-width: 120px; text-align: right; }
.detail-fields .field-val { font-weight: 600; }
.detail-context {
  flex: 1;
  border-left: 1px solid var(--border);
  padding-left: 0.75rem;
}
.detail-context-title {
  font-size: 0.72rem;
  color: var(--muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  margin-bottom: 0.3rem;
}
.detail-context-row {
  font-family: var(--mono);
  font-size: 0.72rem;
  padding: 2px 4px;
  border-radius: 2px;
  cursor: pointer;
  display: flex;
  gap: 0.5rem;
}
.detail-context-row:hover { background: rgba(37,99,235,0.06); }
.detail-context-row.current { background: rgba(37,99,235,0.12); font-weight: 600; }
.detail-context-row .ctx-dot { width: 6px; height: 6px; border-radius: 50%; margin-top: 4px; flex-shrink: 0; }
.detail-hex {
  padding: 0.35rem 0.75rem;
  border-top: 1px solid var(--border);
  font-size: 0.72rem;
}
.detail-hex summary { cursor: pointer; color: var(--muted); font-size: 0.75rem; }
.detail-hex pre {
  font-family: var(--mono);
  font-size: 0.72rem;
  line-height: 1.5;
  margin-top: 0.25rem;
  max-height: 120px;
  overflow-y: auto;
  white-space: pre;
  color: var(--text);
}

/* ── Modal ── */
.modal-overlay {
  position: fixed; top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.3);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000;
}
.modal-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 1.25rem;
  min-width: 320px;
  max-width: 450px;
}
.modal-card h3 { margin-bottom: 0.75rem; font-size: 0.95rem; }
.keys-table { width: 100%; font-size: 0.82rem; border-collapse: collapse; }
.keys-table td { padding: 0.25rem 0.5rem; }
.keys-table td:first-child { white-space: nowrap; text-align: right; width: 100px; }
kbd {
  background: #f0f2f5; border: 1px solid var(--border); border-radius: 3px;
  padding: 0 4px; font-family: var(--mono); font-size: 0.78rem;
}
.modal-close {
  margin-top: 0.75rem;
  padding: 0.3rem 1rem;
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--card); cursor: pointer; font-size: 0.82rem;
}
.modal-close:hover { border-color: var(--accent); color: var(--accent); }

.hidden { display: none !important; }
