@font-face {
  font-family: "PerfCatRTSS";
  src: url("assets/rtss_afterburner.ttf") format("truetype");
  font-display: swap;
}

:root {
  --bg: #0a0b0f;
  --card: #16181f;
  --card-border: #252936;
  --pill-bg: #1f2330;
  --grid: #2a2f3d;
  --text: #f3f4f6;
  --muted: #9ca3af;
  --sky: #38bdf8;
  --primary: #2563eb;
  --green: #22c55e;
  --amber: #eab308;
  --orange: #f97316;
  --temp-orange: #ea580c;
  --red: #ef4444;
  --radius: 18px;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.mono {
  font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, "Liberation Mono", monospace;
}

.bold { font-weight: 600; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.hidden { display: none !important; }

code {
  background: var(--pill-bg);
  color: var(--sky);
  padding: 2px 6px;
  border-radius: 6px;
  font-size: 12px;
  font-family: ui-monospace, Menlo, Consolas, monospace;
}

/* Top Navigation Bar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: rgba(10, 11, 15, 0.92);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--card-border);
}

.topbar-inner {
  max-width: 1120px;
  margin: 0 auto;
  padding: 10px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-logo {
  display: block;
  border-radius: 8px;
}

.brand-text {
  display: flex;
  align-items: center;
  gap: 8px;
}

.brand-title {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.badge-pill {
  font-size: 11px;
  font-weight: 600;
  color: var(--sky);
  background: rgba(56, 189, 248, 0.14);
  padding: 3px 8px;
  border-radius: 999px;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

/* Pill Buttons (matches PerfCat PillButton) */
.pill-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: 12px;
  border: 1px solid transparent;
  background: rgba(243, 244, 246, 0.08);
  color: var(--text);
  font-size: 12.5px;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  transition: background 0.15s ease, opacity 0.15s ease;
  user-select: none;
}

.pill-btn:hover:not(:disabled) {
  background: rgba(243, 244, 246, 0.14);
}

.pill-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.pill-primary {
  background: var(--primary);
  color: #fff;
}

.pill-primary:hover:not(:disabled) {
  background: #1d4ed8;
}

.small-btn {
  padding: 6px 11px;
  font-size: 12px;
  border-radius: 10px;
}

.danger-btn {
  color: #fca5a5;
  background: rgba(239, 68, 68, 0.15);
}

.danger-btn:hover:not(:disabled) {
  background: rgba(239, 68, 68, 0.28);
}

/* Layout */
.container {
  max-width: 1120px;
  margin: 0 auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

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

/* Dropzone */
.dropzone {
  border: 1.5px dashed #32384a;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.dropzone.drag-over {
  border-color: var(--sky);
  background: rgba(56, 189, 248, 0.06);
}

.dropzone-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 26px 14px;
  gap: 10px;
}

.dropzone.compact .dropzone-inner {
  flex-direction: row;
  justify-content: space-between;
  text-align: left;
  padding: 8px 10px;
}

.dropzone.compact .drop-icon,
.dropzone.compact p {
  display: none;
}

.dropzone.compact h1 {
  font-size: 13.5px;
  color: var(--muted);
  font-weight: 500;
}

.dropzone h1 {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
}

.dropzone p {
  margin: 0;
  max-width: 640px;
  font-size: 13px;
  line-height: 1.55;
}

.drop-actions {
  display: flex;
  gap: 8px;
  margin-top: 4px;
  flex-wrap: wrap;
  justify-content: center;
}

/* Session Switcher Bar */
.session-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.session-tabs {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.session-tab {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 7px 11px;
  border-radius: 10px;
  background: var(--card);
  border: 1px solid var(--card-border);
  color: var(--text);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
}

.session-tab.active {
  background: rgba(37, 99, 235, 0.2);
  border-color: var(--primary);
  color: #fff;
  font-weight: 600;
}

.session-tab .tab-close {
  color: var(--muted);
  font-weight: 700;
  padding: 0 2px;
}

.session-tab .tab-close:hover {
  color: var(--red);
}

.session-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.compare-wrap {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.select-input {
  background: var(--pill-bg);
  color: var(--text);
  border: 1px solid var(--card-border);
  border-radius: 10px;
  padding: 6px 10px;
  font-size: 12px;
}

/* Report Root */
.report-root {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* Meta Card */
.meta-top {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
}

.app-icon-box {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: var(--pill-bg);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.meta-titles {
  min-width: 0;
  flex: 1;
}

.meta-app-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.meta-titles h2 {
  margin: 0;
  font-size: 17px;
  font-weight: 700;
}

.tag-chip {
  font-size: 10.5px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 6px;
  background: rgba(56, 189, 248, 0.14);
  color: var(--sky);
}

.meta-grid-4 {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-bottom: 12px;
}

.meta-kv {
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.kv-label {
  font-size: 11px;
  color: var(--muted);
}

.kv-val {
  font-size: 13px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.meta-pill-bar {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  background: var(--pill-bg);
  border-radius: 12px;
  padding: 10px 8px;
  gap: 8px;
}

.pill-col {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
}

.pill-val {
  font-size: 13.5px;
  font-weight: 700;
}

.note-box {
  margin-top: 10px;
  padding: 9px 12px;
  border-radius: 10px;
  background: rgba(243, 244, 246, 0.04);
  font-size: 12.5px;
  color: var(--text);
}

/* KPI Grid (3x3 exact PerfCat layout) */
.kpi-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.kpi-cell {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 8px 4px;
  border-radius: 12px;
  background: rgba(243, 244, 246, 0.025);
}

.kpi-top {
  font-size: 10.5px;
  color: var(--muted);
  letter-spacing: 0.03em;
}

.kpi-big {
  font-size: 22px;
  font-weight: 700;
  color: var(--sky);
  line-height: 1.25;
}

.kpi-bot {
  font-size: 10.5px;
  color: var(--muted);
}

/* Comparison Grid */
.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}

.card-head h3 {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
}

.compare-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 8px;
}

.cmp-cell {
  background: var(--pill-bg);
  border-radius: 12px;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.cmp-delta {
  font-size: 15px;
  font-weight: 700;
}

.delta-good { color: var(--green); }
.delta-bad { color: var(--red); }
.delta-neutral { color: var(--muted); }

/* Synchronized Scrub Strip */
.scrub-strip {
  position: sticky;
  top: 64px;
  z-index: 15;
  padding: 10px 14px;
  background: rgba(22, 24, 31, 0.96);
  backdrop-filter: blur(10px);
}

.scrub-header {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.scrub-dot {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: var(--sky);
}

.scrub-values {
  margin-top: 6px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px 14px;
  font-size: 11.5px;
  color: #d1d5db;
}

/* 8-Chart Grid */
.charts-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.chart-card {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.chart-head-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.chart-title {
  margin: 0;
  font-size: 14.5px;
  font-weight: 600;
}

.chart-reset-btn {
  background: transparent;
  border: none;
  color: var(--sky);
  font-size: 11.5px;
  font-weight: 600;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 6px;
}

.chart-reset-btn:hover {
  background: rgba(56, 189, 248, 0.12);
}

.chart-legend-chips {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.legend-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 9px;
  border-radius: 8px;
  background: rgba(243, 244, 246, 0.06);
  border: 1px solid rgba(243, 244, 246, 0.12);
  color: rgba(243, 244, 246, 0.88);
  font-size: 11.5px;
  font-weight: 500;
  cursor: pointer;
  transition: opacity 0.14s ease, background 0.14s ease, border-color 0.14s ease;
  user-select: none;
}

.legend-chip:hover {
  background: rgba(243, 244, 246, 0.12);
}

.legend-chip.active {
  color: #ffffff;
  font-weight: 700;
}

.legend-chip.dimmed {
  opacity: 0.35;
}

.legend-swatch {
  width: 9px;
  height: 9px;
  border-radius: 2px;
  flex-shrink: 0;
}

.chart-canvas-wrap {
  position: relative;
  width: 100%;
  height: 210px;
}

.chart-canvas {
  width: 100%;
  height: 100%;
  display: block;
  touch-action: pan-y;
  cursor: crosshair;
}

.chart-legend {
  font-size: 11.5px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Summary-only Details Grid */
.summary-details-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(175px, 1fr));
  gap: 8px;
}

.sum-item {
  background: var(--pill-bg);
  border-radius: 10px;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.sum-item .val {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}

/* Sample Table */
.table-scroll {
  max-height: 360px;
  overflow: auto;
  border-radius: 10px;
  border: 1px solid var(--card-border);
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 11.5px;
  font-family: ui-monospace, Menlo, Consolas, monospace;
}

.data-table th,
.data-table td {
  padding: 6px 9px;
  text-align: right;
  border-bottom: 1px solid var(--card-border);
  white-space: nowrap;
}

.data-table th {
  position: sticky;
  top: 0;
  background: var(--pill-bg);
  color: var(--muted);
  font-weight: 600;
}

.footer {
  text-align: center;
  padding: 16px 12px 28px;
  font-size: 11.5px;
  color: var(--muted);
}

@media (max-width: 820px) {
  .charts-grid {
    grid-template-columns: 1fr;
  }
  .meta-grid-4 {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* Thread Statistics Section (matches PerfCat v7.2.0 ThreadStatsScreen) */
.thread-head-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

.thread-icon-badge {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: #38bdf8;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.thread-stats-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.thread-item-card {
  background: var(--pill-bg);
  border: 1px solid var(--card-border);
  border-radius: 14px;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.thread-item-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.thread-item-title {
  display: flex;
  align-items: baseline;
  gap: 7px;
  min-width: 0;
}

.thread-name {
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.thread-tid {
  font-size: 11.5px;
  color: var(--muted);
}

.thread-metrics {
  font-size: 11.5px;
  font-weight: 600;
  color: rgba(243, 244, 246, 0.85);
  white-space: nowrap;
}

.thread-spark-wrap {
  width: 100%;
  height: 68px;
}

.thread-spark-canvas {
  width: 100%;
  height: 100%;
  display: block;
}

@media (max-width: 820px) {
  .thread-stats-grid {
    grid-template-columns: 1fr;
  }
}
