:root {
  --bg: #0b0f17;
  --bg-elev: #131a26;
  --bg-elev2: #1a2333;
  --border: #232e42;
  --text: #e6ecf5;
  --text-dim: #8b98af;
  --muted: #5c6a83;
  --accent: #4c9aff;
  --ok: #21c07a;
  --warn: #f5b342;
  --bad: #ef4a5b;
  --purple: #a879ff;
  --pink: #ff6ba8;
  --cyan: #33d3d3;
  --shadow: 0 1px 3px rgba(0,0,0,0.4), 0 4px 20px rgba(0,0,0,0.25);
  --radius: 12px;
  --radius-sm: 6px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, "Helvetica Neue", Arial, "Apple Color Emoji", "Segoe UI Emoji", sans-serif;
  font-size: 14px;
  background: linear-gradient(180deg, var(--bg) 0%, #070a10 100%);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ==== TOP BAR ==== */
.topbar {
  padding: 14px 26px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  background: rgba(10, 14, 22, 0.9);
  backdrop-filter: blur(8px);
  position: sticky;
  top: 0;
  z-index: 10;
}
.brand { display: flex; align-items: center; gap: 14px; min-width: 0; }
.brand-info { min-width: 0; }
.brand h1 { font-size: 18px; font-weight: 700; letter-spacing: -0.01em; }
.brand-sub { font-size: 11px; color: var(--muted); font-weight: 500; margin-left: 4px; }
.target-row { display: flex; align-items: center; gap: 6px; margin-top: 3px; min-width: 0; }
.target-label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; flex-shrink: 0; }
.brand .target {
  font-family: "SF Mono", "JetBrains Mono", Consolas, monospace;
  font-size: 12px;
  color: var(--accent);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-decoration: none;
  transition: color 0.15s;
}
.brand .target:hover { color: var(--cyan); text-decoration: underline; }

.header-right { display: flex; align-items: center; gap: 14px; flex-shrink: 0; }
.active-file {
  font-family: "SF Mono", monospace;
  font-size: 11px;
  color: var(--text-dim);
  padding: 4px 10px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 100px;
}

.pulse {
  width: 10px; height: 10px; border-radius: 100%; background: var(--muted);
  transition: background 0.25s;
  flex-shrink: 0;
}
.pulse.active { background: var(--ok); box-shadow: 0 0 8px var(--ok); animation: pulse 1.6s infinite; }
@keyframes pulse { 0%,100% { opacity: 1;} 50% { opacity: 0.4;} }

.conn { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--text-dim); }
.conn .dot { width: 8px; height: 8px; border-radius: 100%; background: var(--muted); }
.conn.on .dot { background: var(--ok); box-shadow: 0 0 6px var(--ok); }
.conn.off .dot { background: var(--bad); }

/* ==== GRID ==== */
.grid {
  display: grid;
  gap: 16px;
  padding: 20px 26px 24px;
  grid-template-columns: repeat(12, 1fr);
  flex: 1;
}

.card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  box-shadow: var(--shadow);
  min-width: 0;
}
.card.hidden { display: none; }
.card-title {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
  margin-bottom: 14px;
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ==== KPI ==== */
.kpi {
  grid-column: span 12;
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 24px;
  padding: 22px 24px;
}
.kpi-item { min-width: 0; }
.kpi-label {
  font-size: 11px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 6px;
}
.kpi-value {
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.1;
}
.kpi-value .unit { font-size: 14px; color: var(--text-dim); font-weight: 500; margin-left: 3px; }
.kpi-value .muted { font-weight: 400; color: var(--muted); font-size: 18px; }
.kpi-sub { font-size: 12px; color: var(--text-dim); margin-top: 6px; line-height: 1.4; }
.kpi-sub .good { color: var(--ok); font-weight: 600; }
.kpi-sub .bad { color: var(--bad); font-weight: 600; }
.kpi-sub .warn { color: var(--warn); font-weight: 600; }

.progress {
  height: 5px;
  background: var(--bg-elev2);
  border-radius: 3px;
  overflow: hidden;
  margin-top: 8px;
}
.progress-bar {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--cyan));
  transition: width 0.6s ease;
  width: 0%;
}

/* ==== TIMELINE + FEED (side by side) ==== */
.timeline-card { grid-column: span 8; }
.timeline-card canvas { width: 100%; display: block; }
.legend { display: flex; gap: 18px; margin-top: 8px; font-size: 12px; color: var(--text-dim); }
.legend .sw { display: inline-block; width: 12px; height: 12px; border-radius: 2px; vertical-align: middle; margin-right: 4px; }
.legend .ok { background: var(--ok); }
.legend .fail { background: var(--bad); }
.legend .start { background: var(--accent); opacity: 0.5; }

.feed-card { grid-column: span 4; display: flex; flex-direction: column; }
.feed {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
  overflow-y: auto;
  max-height: 220px;
  padding-right: 4px;
  font-family: "SF Mono", "JetBrains Mono", Consolas, monospace;
  font-size: 12px;
}
.feed-row {
  display: grid;
  grid-template-columns: auto auto 1fr;
  gap: 8px;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  align-items: baseline;
  animation: rowIn 1.2s ease-out;
  background: rgba(255,255,255,0.01);
}
.feed-t { color: var(--muted); font-size: 11px; }
.feed-ico { font-size: 13px; text-align: center; width: 18px; }
.feed-msg { color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.feed-ok    { background: rgba(33, 192, 122, 0.06); }
.feed-fail  { background: rgba(239, 74, 91, 0.10); }
.feed-fail .feed-msg { color: var(--bad); }
.feed-start { background: rgba(76, 154, 255, 0.05); }
.feed-cb    { background: rgba(245, 179, 66, 0.15); }
.feed-cb .feed-msg { color: var(--warn); font-weight: 600; }
.feed-switch { background: rgba(168, 121, 255, 0.10); color: var(--purple); }
.feed-done  { background: rgba(51, 211, 211, 0.10); font-weight: 600; }
.feed-empty { color: var(--muted); text-align: center; padding: 40px 10px; font-size: 12px; }

/* ==== BREAKDOWN ==== */
.breakdown { grid-column: span 12; }
.breakdown-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 18px;
}
.mini { min-width: 0; }
.mini-title { font-size: 11px; color: var(--text-dim); text-transform: uppercase; margin-bottom: 8px; letter-spacing: 0.04em; }
.bars { display: flex; flex-direction: column; gap: 6px; }
.bar-row { display: flex; flex-direction: column; gap: 3px; }
.bar-row .lbl { display: flex; justify-content: space-between; font-size: 12px; align-items: baseline; }
.bar-row .lbl .name { color: var(--text); display: flex; align-items: center; gap: 5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-row .lbl .name .ico { font-size: 13px; flex-shrink: 0; }
.bar-row .lbl .num { color: var(--text-dim); font-family: "SF Mono", monospace; flex-shrink: 0; padding-left: 8px; }
.bar-row .lbl .num .pct { color: var(--muted); font-size: 11px; }
.bar-row .track {
  height: 4px;
  background: var(--bg-elev2);
  border-radius: 2px;
  overflow: hidden;
}
.bar-row .fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--purple));
  transition: width 0.4s;
}

/* ==== ERRORS ==== */
.errors-card { grid-column: span 12; }
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 100px;
  font-size: 11px;
  font-weight: 700;
  margin-left: 6px;
}
.badge.bad { background: rgba(239, 74, 91, 0.18); color: var(--bad); }
.errors { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 12px; }
.err-group {
  background: var(--bg-elev2);
  border: 1px solid rgba(239, 74, 91, 0.2);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
}
.err-head { display: flex; align-items: center; gap: 10px; margin-bottom: 6px; }
.err-class { font-family: "SF Mono", monospace; font-size: 12px; color: var(--bad); font-weight: 600; }
.err-count { font-size: 11px; color: var(--warn); font-weight: 700; padding: 2px 6px; background: rgba(245,179,66,0.15); border-radius: 4px; }
.err-time  { font-size: 10px; color: var(--muted); margin-left: auto; }
.err-detail { font-size: 11px; color: var(--text-dim); font-family: "SF Mono", monospace; line-height: 1.4; word-break: break-word; }

/* ==== VISITS TABLE ==== */
.visits-card { grid-column: span 12; }
.filter-chips { display: inline-flex; gap: 6px; margin-left: auto; }
.chip {
  background: var(--bg-elev2);
  border: 1px solid var(--border);
  color: var(--text-dim);
  padding: 4px 10px;
  border-radius: 100px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  cursor: pointer;
  transition: all 0.15s;
  font-family: inherit;
  letter-spacing: 0.03em;
}
.chip:hover { border-color: var(--accent); color: var(--text); }
.chip.active { background: rgba(76, 154, 255, 0.15); border-color: var(--accent); color: var(--accent); }

.table-wrap { overflow-x: auto; max-height: 520px; overflow-y: auto; border-radius: var(--radius-sm); border: 1px solid var(--border); }
.visits { width: 100%; border-collapse: collapse; font-size: 13px; }
.visits th, .visits td {
  text-align: left;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.visits thead th {
  position: sticky;
  top: 0;
  background: var(--bg-elev2);
  font-size: 11px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  z-index: 1;
}
.visits tbody tr { transition: background 0.15s; }
.visits tbody tr:hover { background: var(--bg-elev2); }
.visits tbody tr[title]:hover { cursor: help; }
.visits tbody tr.new { animation: rowIn 1.6s ease-out; }
@keyframes rowIn {
  0% { background: rgba(76, 154, 255, 0.18); }
  100% { background: transparent; }
}

.status-pill {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 100px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.status-pill.in-progress { background: rgba(76, 154, 255, 0.15); color: var(--accent); }
.status-pill.ok { background: rgba(33, 192, 122, 0.15); color: var(--ok); }
.status-pill.fail { background: rgba(239, 74, 91, 0.15); color: var(--bad); }

.ip { font-family: "SF Mono", monospace; font-size: 12px; color: var(--cyan); }
.persona { font-family: "SF Mono", monospace; font-size: 11px; color: var(--text-dim); }
.bounce-yes { color: var(--warn); font-weight: 600; }
.bounce-no { color: var(--ok); font-weight: 600; }

.muted { color: var(--muted); }
.small { font-size: 12px; }

footer { padding: 14px 26px 20px; text-align: center; border-top: 1px solid var(--border); font-size: 12px; }
footer a { color: var(--accent); text-decoration: none; }
footer a:hover { text-decoration: underline; }

/* ==== RESPONSIVE ==== */
@media (max-width: 1200px) {
  .kpi { grid-template-columns: repeat(3, 1fr); }
  .timeline-card { grid-column: span 12; }
  .feed-card { grid-column: span 12; }
  .breakdown-grid { grid-template-columns: repeat(4, 1fr); }
}
@media (max-width: 900px) {
  .breakdown-grid { grid-template-columns: repeat(2, 1fr); }
  .header-right { gap: 8px; }
  .active-file { display: none; }
}
@media (max-width: 720px) {
  .topbar { padding: 10px 14px; }
  .grid { padding: 14px; gap: 12px; }
  .kpi { grid-template-columns: 1fr 1fr; padding: 16px; gap: 16px; }
  .breakdown-grid { grid-template-columns: 1fr; }
  .kpi-value { font-size: 22px; }
  .filter-chips { display: none; }
}
