* { box-sizing: border-box; }
:root {
  --bg-body: #111318;
  --bg-panel: #1a1e27;
  --bg-panel-alt: #20252f;
  --bg-input: #14171d;
  --border: #2c3340;
  --border-light: #3a4352;
  --text: #e8ecf4;
  --text-muted: #8892a4;
  --text-dim: #6b7385;
  --accent: #4f8af7;
  --accent-light: #6fa0ff;
  --accent-dim: #2d4f8e;
  --green: #34d399;
  --green-dim: #1a6b4d;
  --orange: #f59e0b;
  --orange-dim: #7a4f06;
  --red: #ef4444;
  --red-dim: #7f1d1d;
  --purple: #a78bfa;
  --purple-dim: #4a3a7a;
  --teal: #2dd4bf;
  --pink: #f472b6;
  --radius: 10px;
  --radius-lg: 14px;
}
body {
  margin: 0;
  font-family: "Inter", "Segoe UI", Arial, sans-serif;
  background: var(--bg-body);
  color: var(--text);
  line-height: 1.5;
}
.wrap {
  max-width: 1420px;
  margin: 0 auto;
  padding: 20px 18px 40px;
}

/* ── Topbar ── */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 6px;
}
.title {
  font-size: 22px;
  font-weight: 800;
  letter-spacing: -0.3px;
  background: linear-gradient(135deg, var(--accent-light), var(--purple));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.subtitle {
  color: var(--text-dim);
  font-size: 12px;
  margin-top: 2px;
}

/* ── Buttons ── */
.btn {
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  padding: 7px 14px;
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.15s, opacity 0.15s;
}
.btn:hover { background: var(--accent-light); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn.secondary { background: #2e3542; }
.btn.secondary:hover { background: #3b4454; }

/* ── Panels ── */
.panel {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 14px 16px;
  margin-top: 12px;
}
.panel h3 {
  margin: 0 0 10px;
  font-size: 14px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.6px;
}
.panel h4 {
  margin: 12px 0 6px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
}

/* ── Filters ── */
.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: end;
}
.field {
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.field label {
  font-size: 11px;
  color: var(--text-dim);
  font-weight: 500;
}
.field input, .field select {
  min-width: 110px;
  border: 1px solid var(--border);
  background: var(--bg-input);
  color: var(--text);
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 13px;
}
.field input:focus, .field select:focus {
  outline: none;
  border-color: var(--accent);
}

/* ── KPI Cards ── */
.kpis {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(155px, 1fr));
  gap: 10px;
}
.kpi {
  background: var(--bg-panel-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  position: relative;
  overflow: hidden;
}
.kpi::before {
  content: "";
  position: absolute;
  top: 0; left: 0;
  width: 4px; height: 100%;
  border-radius: 4px 0 0 4px;
}
.kpi:nth-child(1)::before { background: var(--accent); }
.kpi:nth-child(2)::before { background: var(--green); }
.kpi:nth-child(3)::before { background: var(--purple); }
.kpi:nth-child(4)::before { background: var(--teal); }
.kpi:nth-child(5)::before { background: var(--orange); }
.kpi:nth-child(6)::before { background: var(--pink); }
.kpi:nth-child(7)::before { background: var(--red); }
.kpi:nth-child(8)::before { background: var(--text-dim); }
.kpi .label {
  color: var(--text-dim);
  font-size: 11px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.kpi .value {
  margin-top: 4px;
  font-size: 26px;
  font-weight: 800;
  letter-spacing: -0.5px;
  color: var(--text);
}

/* ── Grid ── */
.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; }

/* ── Bar Chart (horizontal bars) ── */
.bar-chart { display: flex; flex-direction: column; gap: 6px; }
.bar-row {
  display: flex;
  align-items: center;
  gap: 8px;
}
.bar-label {
  flex: 0 0 120px;
  font-size: 12px;
  color: var(--text-muted);
  text-align: right;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.bar-track {
  flex: 1;
  height: 22px;
  background: var(--bg-input);
  border-radius: 6px;
  overflow: hidden;
  position: relative;
}
.bar-fill {
  height: 100%;
  border-radius: 6px;
  transition: width 0.5s ease;
  min-width: 2px;
}
.bar-fill.c-blue { background: linear-gradient(90deg, var(--accent-dim), var(--accent)); }
.bar-fill.c-green { background: linear-gradient(90deg, var(--green-dim), var(--green)); }
.bar-fill.c-purple { background: linear-gradient(90deg, var(--purple-dim), var(--purple)); }
.bar-fill.c-orange { background: linear-gradient(90deg, var(--orange-dim), var(--orange)); }
.bar-fill.c-pink { background: linear-gradient(90deg, #7a2050, var(--pink)); }
.bar-fill.c-teal { background: linear-gradient(90deg, #155c50, var(--teal)); }
.bar-count {
  flex: 0 0 44px;
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
  text-align: right;
}

/* ── Activity Chart (SVG container) ── */
.activity-chart-wrap {
  width: 100%;
  height: 130px;
  position: relative;
}
.activity-chart-wrap svg {
  width: 100%;
  height: 100%;
  display: block;
}

/* ── Hourly Heatmap ── */
.hourly-grid {
  display: grid;
  grid-template-columns: repeat(24, 1fr);
  gap: 2px;
  margin-top: 6px;
}
.hourly-cell {
  aspect-ratio: 1;
  border-radius: 3px;
  min-height: 18px;
  position: relative;
}
.hourly-cell::after {
  content: attr(data-label);
  position: absolute;
  bottom: -15px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 9px;
  color: var(--text-dim);
  white-space: nowrap;
}
.hourly-labels {
  display: grid;
  grid-template-columns: repeat(24, 1fr);
  gap: 2px;
  margin-top: 4px;
}
.hourly-labels span {
  text-align: center;
  font-size: 9px;
  color: var(--text-dim);
}

/* ── Duration Buckets ── */
.dur-buckets {
  display: flex;
  gap: 6px;
  align-items: flex-end;
  height: 90px;
  padding-top: 4px;
}
.dur-col {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
}
.dur-bar-outer {
  width: 100%;
  height: 60px;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.dur-bar {
  width: 70%;
  border-radius: 4px 4px 0 0;
  transition: height 0.5s ease;
  min-height: 2px;
}
.dur-count {
  font-size: 12px;
  font-weight: 700;
  color: var(--text);
}
.dur-label {
  font-size: 10px;
  color: var(--text-dim);
  text-align: center;
}

/* ── Tables ── */
.list {
  width: 100%;
  border-collapse: collapse;
}
.list th, .list td {
  border-bottom: 1px solid var(--border);
  padding: 7px 8px;
  text-align: left;
  font-size: 12px;
}
.list th {
  color: var(--text-dim);
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}
.session-row { cursor: pointer; transition: background 0.12s; }
.session-row:hover { background: rgba(79,138,247,0.08); }
.session-row.active { background: rgba(79,138,247,0.15); }
.badge {
  display: inline-block;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
}
.badge-admin { background: var(--orange-dim); color: var(--orange); }
.badge-user { background: var(--green-dim); color: var(--green); }

/* Session duration mini bar */
.dur-mini-bar {
  display: inline-block;
  height: 6px;
  border-radius: 3px;
  background: var(--accent);
  vertical-align: middle;
  margin-right: 6px;
  transition: width 0.4s ease;
}

/* ── Timeline Visual ── */
.timeline-visual {
  position: relative;
  padding: 8px 0 8px 32px;
  max-height: 500px;
  overflow-y: auto;
}
.timeline-visual::before {
  content: "";
  position: absolute;
  left: 14px;
  top: 0;
  bottom: 0;
  width: 2px;
  background: var(--border);
}
.tl-event {
  position: relative;
  padding: 4px 0 4px 16px;
  font-size: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.tl-dot {
  position: absolute;
  left: -24px;
  top: 50%;
  transform: translateY(-50%);
  width: 10px;
  height: 10px;
  border-radius: 50%;
  border: 2px solid var(--bg-panel);
}
.tl-dot.type-tab_changed { background: var(--accent); }
.tl-dot.type-button_click { background: var(--green); }
.tl-dot.type-session_start { background: var(--teal); }
.tl-dot.type-session_heartbeat { background: var(--text-dim); }
.tl-dot.type-project_save_success { background: var(--orange); }
.tl-dot.type-layout_export_success { background: var(--pink); }
.tl-dot.type-viewport_click { background: var(--purple); }
.tl-dot.type-viewport_right_click { background: var(--red); }
.tl-dot.type-default { background: var(--text-muted); }
.tl-time {
  flex: 0 0 60px;
  font-size: 11px;
  color: var(--text-dim);
  font-family: "Cascadia Mono", "Consolas", monospace;
}
.tl-type {
  font-weight: 600;
  color: var(--text);
}
.tl-tab {
  font-size: 11px;
  color: var(--text-dim);
  padding: 1px 6px;
  background: var(--bg-input);
  border-radius: 4px;
}

/* ── Section Header Row ── */
.section-header-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}

/* ── Session Detail Visual Dashboard ── */
.detail-block {
  margin-top: 16px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}
.detail-block:first-of-type { border-top: none; margin-top: 8px; }
.detail-block h4 {
  margin: 0 0 10px;
  font-size: 13px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* Info Cards (top row in session detail) */
.detail-info-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 8px;
  margin-top: 8px;
}
.info-card {
  background: var(--bg-panel-alt);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  text-align: center;
}
.info-card .ic-label {
  font-size: 10px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.4px;
}
.info-card .ic-value {
  margin-top: 3px;
  font-size: 18px;
  font-weight: 800;
  color: var(--text);
}
.info-card .ic-sub {
  margin-top: 2px;
  font-size: 10px;
  color: var(--text-dim);
}

/* Tab Visual Grid (big bars with labels) */
.tab-visual-grid {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.tab-visual-row {
  display: flex;
  align-items: center;
  gap: 10px;
}
.tab-visual-name {
  flex: 0 0 110px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  text-align: right;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.tab-visual-bar-wrap {
  flex: 1;
  position: relative;
}
.tab-visual-track {
  height: 28px;
  background: var(--bg-input);
  border-radius: 6px;
  overflow: hidden;
  position: relative;
}
.tab-visual-fill {
  height: 100%;
  border-radius: 6px;
  transition: width 0.5s ease;
  min-width: 3px;
  display: flex;
  align-items: center;
  padding-left: 8px;
}
.tab-visual-fill-label {
  font-size: 11px;
  font-weight: 600;
  color: #fff;
  text-shadow: 0 1px 2px rgba(0,0,0,0.5);
  white-space: nowrap;
}
.tab-visual-dur {
  flex: 0 0 70px;
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
  text-align: right;
}
.tab-visual-pct {
  flex: 0 0 40px;
  font-size: 11px;
  color: var(--text-dim);
  text-align: right;
}

/* Tab Actions Grid */
.tab-actions-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 10px;
}
.tab-action-card {
  background: var(--bg-panel-alt);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px 16px;
  min-height: 120px;
}
.tab-action-card .tac-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}
.tab-action-card .tac-name {
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
}
.tab-action-card .tac-count {
  font-size: 18px;
  font-weight: 800;
  color: var(--accent-light);
}
.tab-action-card .tac-breakdown {
  font-size: 13px;
  color: var(--text-dim);
  line-height: 1.7;
}
.product-detail-toggle summary { margin-bottom: 4px; }
.product-detail-toggle[open] summary { margin-bottom: 6px; }
.product-detail-toggle div { padding-left: 6px; border-left: 2px solid var(--border); margin-left: 4px;
}

/* Export Previews */
.export-gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 10px;
}
.export-card {
  background: var(--bg-panel-alt);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}
.export-card-img {
  width: 100%;
  max-height: 180px;
  object-fit: cover;
  display: block;
  background: var(--bg-input);
}
.export-card-info {
  padding: 8px 10px;
}
.export-card-type {
  font-size: 10px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.4px;
}
.export-card-name {
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
  margin-top: 2px;
  word-break: break-all;
}
.export-card-meta {
  font-size: 11px;
  color: var(--text-dim);
  margin-top: 2px;
}

/* Project Saves */
.save-list { display: flex; flex-direction: column; gap: 6px; }
.save-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  background: var(--bg-panel-alt);
  border: 1px solid var(--border);
  border-radius: 8px;
}
.save-icon {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  background: var(--orange-dim);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  flex-shrink: 0;
}
.save-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}
.save-time {
  font-size: 11px;
  color: var(--text-dim);
}

/* Toggle Raw Button */
.btn-toggle-raw {
  font-size: 12px;
  padding: 5px 12px;
}

/* Collapsible */
.collapsible-section { overflow: hidden; }

.pre {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 300px;
  overflow: auto;
  font-size: 11px;
  font-family: "Cascadia Mono", "Consolas", monospace;
}
a.link { color: var(--accent-light); text-decoration: none; }
a.link:hover { text-decoration: underline; }
.muted { color: var(--text-muted); }
.error { color: var(--red); }

/* ── Returning visitor badge ── */
.badge-returning {
  background: var(--purple-dim);
  color: var(--purple);
  font-size: 10px;
  padding: 1px 5px;
  border-radius: 4px;
  margin-left: 4px;
}

/* ── Tab action card footer ── */
.tac-footer {
  margin-top: 10px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-dim);
}

/* ── No data ── */
.no-data {
  padding: 20px;
  text-align: center;
  color: var(--text-dim);
  font-size: 13px;
}

/* ── Heatmap Grid ── */
.heatmap-container { overflow-x: auto; }
.heatmap-grid { min-width: 400px; }
.hm-corner { background: transparent; }
.hm-day-hdr {
  text-align: center;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-dim);
  padding: 4px 0;
}
.hm-time-label {
  font-size: 10px;
  color: var(--text-dim);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding-right: 6px;
}
.hm-cell {
  border-radius: 3px;
  min-height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.1s;
  cursor: default;
}
.hm-cell:hover { transform: scale(1.1); z-index: 1; }
.hm-val {
  font-size: 9px;
  color: rgba(255,255,255,0.7);
  font-weight: 600;
}

/* ── Responsive ── */
@media (max-width: 1100px) {
  .grid, .grid-3, .detail-layout { grid-template-columns: 1fr; }
}
@media (max-width: 700px) {
  .kpis { grid-template-columns: repeat(2, 1fr); }
  .bar-label { flex: 0 0 80px; font-size: 11px; }
}
