/* ═══ Analytics Page ═══ */

/* ── Controls ── */
.an-controls {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 18px;
  flex-wrap: wrap;
}
.an-days-wrap {
  display: flex;
  align-items: center;
  gap: 6px;
}
.an-label {
  font-size: 12px;
  color: var(--muted);
  font-family: 'JetBrains Mono', monospace;
  margin-right: 4px;
}
.an-day-btn {
  padding: 5px 12px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 5px;
  color: var(--muted);
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  cursor: pointer;
  transition: all 0.18s;
}
.an-day-btn:hover { border-color: var(--cyan); color: var(--text); }
.an-day-btn.active {
  border-color: var(--cyan);
  color: var(--cyan);
  background: rgba(0,212,255,0.08);
}

/* ── Tabs ── */
.an-tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}
.an-tab {
  padding: 8px 22px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 7px;
  color: var(--muted);
  font-family: 'JetBrains Mono', monospace;
  font-size: 12px;
  cursor: pointer;
  transition: all 0.18s;
}
.an-tab:hover { border-color: var(--cyan); color: var(--text); }
.an-tab.active {
  border-color: var(--cyan);
  color: var(--cyan);
  background: rgba(0,212,255,0.08);
  box-shadow: 0 0 12px rgba(0,212,255,0.1);
}

/* ── Loading / states ── */
.an-spinner {
  text-align: center;
  padding: 60px;
  color: var(--muted);
  font-size: 14px;
  font-family: 'JetBrains Mono', monospace;
}
.an-spinner.hidden { display: none; }
.an-error {
  text-align: center;
  padding: 48px;
  color: var(--red);
  font-family: 'JetBrains Mono', monospace;
  font-size: 13px;
}
.an-empty {
  text-align: center;
  padding: 60px;
  color: var(--muted);
  font-size: 13px;
  font-family: 'JetBrains Mono', monospace;
}

/* ── Summary cards ── */
.an-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 10px;
  margin-bottom: 20px;
}
.an-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 12px;
  text-align: center;
  transition: border-color 0.18s;
}
.an-card:hover { border-color: var(--cyan); }
.an-card-val {
  font-family: 'Orbitron', monospace;
  font-size: 20px;
  font-weight: 700;
  line-height: 1;
}
.an-card-lbl {
  font-size: 10px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-top: 6px;
}

/* ── SVG chart wrapper ── */
.an-svg-wrap {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 20px 16px 8px;
  margin-bottom: 16px;
  overflow: hidden;
}
.an-svg {
  width: 100%;
  height: auto;
  display: block;
  overflow: visible;
}
.an-dot {
  cursor: pointer;
  transition: r 0.15s;
}
.an-dot:hover { r: 7; }

/* ── SVG tooltip (foreignObject) ── */
.an-svg-tooltip {
  background: var(--bg);
  border: 1px solid var(--cyan);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 11px;
  font-family: 'JetBrains Mono', monospace;
  white-space: nowrap;
  color: var(--text);
  line-height: 1.65;
  box-shadow: 0 4px 24px rgba(0,212,255,0.15), 0 0 40px rgba(0,0,0,0.6);
}

/* ── Legend ── */
.an-legend {
  display: flex;
  gap: 18px;
  justify-content: center;
  flex-wrap: wrap;
  margin-top: 10px;
  margin-bottom: 4px;
}
.an-leg-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: var(--muted);
  font-family: 'JetBrains Mono', monospace;
}
.an-leg-color {
  width: 18px;
  height: 10px;
  border-radius: 2px;
  flex-shrink: 0;
  display: inline-block;
}

/* ── Pattern table ── */
.an-table-wrap {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px;
  margin-bottom: 16px;
  overflow-x: auto;
}
.an-chart-title {
  font-family: 'Orbitron', monospace;
  font-size: 11px;
  color: var(--cyan);
  letter-spacing: 2px;
  margin-bottom: 14px;
  text-shadow: 0 0 8px rgba(0,212,255,0.3);
}
.an-table {
  width: 100%;
  border-collapse: collapse;
  font-family: 'JetBrains Mono', monospace;
  font-size: 12px;
}
.an-table thead th {
  text-align: center;
  padding: 8px 8px;
  font-size: 10px;
  color: var(--muted);
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  text-transform: uppercase;
  letter-spacing: 1px;
  position: sticky;
  top: 0;
  z-index: 2;
}
.an-table tbody tr {
  border-bottom: 1px solid rgba(26,58,74,0.2);
  transition: background 0.15s;
}
.an-table tbody tr:hover { background: rgba(0,212,255,0.04); }
.an-cell-center { text-align: center; padding: 6px 8px; }
.an-cell-mono {
  text-align: center;
  padding: 6px 8px;
  font-family: 'JetBrains Mono', monospace;
}

/* ── Inline bar in table ── */
.an-cell-bar {
  padding: 6px 10px;
  min-width: 140px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.an-bar-bg {
  flex: 1;
  height: 10px;
  background: rgba(255,255,255,0.05);
  border-radius: 3px;
  position: relative;
  overflow: hidden;
}
.an-bar-center {
  position: absolute;
  left: 50%;
  top: 0;
  bottom: 0;
  width: 1px;
  background: rgba(255,255,255,0.2);
}
.an-bar-fill {
  position: absolute;
  top: 0;
  height: 100%;
  border-radius: 2px;
  transition: width 0.4s ease;
}
.an-bar-val {
  font-size: 10px;
  color: var(--muted);
  white-space: nowrap;
  min-width: 38px;
  text-align: right;
}

/* ── Re-use reach styles ── */
.reach-chart-wrap {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 20px 16px 12px;
  margin-bottom: 16px;
  overflow-x: auto;
}
.reach-chart-title {
  font-family: 'Orbitron', monospace;
  font-size: 12px;
  color: var(--cyan);
  margin-bottom: 12px;
  letter-spacing: 2px;
  text-shadow: 0 0 8px rgba(0,212,255,0.3);
}
.reach-chart-legend {
  display: flex;
  gap: 14px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}
.reach-legend-item {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  color: var(--text);
  font-family: 'JetBrains Mono', monospace;
}
.reach-legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 2px;
  flex-shrink: 0;
}
.reach-chart {
  display: flex;
  align-items: flex-end;
  gap: 2px;
  height: 260px;
  min-width: max-content;
  padding-bottom: 20px;
}
.reach-bar-group {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 16px;
  position: relative;
  cursor: pointer;
}
.reach-bar-stack {
  width: 14px;
  height: 230px;
  position: relative;
}
.reach-bar {
  position: absolute;
  bottom: 0;
  left: 0;
  width: 100%;
  border-radius: 2px 2px 0 0;
  transition: height 0.5s cubic-bezier(0.22, 1, 0.36, 1);
}
.reach-bar-lbl {
  font-size: 8px;
  color: var(--muted);
  margin-top: 3px;
  font-family: 'JetBrains Mono', monospace;
  position: absolute;
  bottom: -18px;
  white-space: nowrap;
}
.reach-chart-axis {
  text-align: center;
  font-size: 10px;
  color: var(--muted);
  margin-top: 8px;
  font-family: 'JetBrains Mono', monospace;
}
.reach-bar-group:hover .reach-bar-tip { display: block; }
.reach-bar-tip {
  display: none;
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg);
  border: 1px solid var(--cyan);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 11px;
  font-family: 'JetBrains Mono', monospace;
  white-space: nowrap;
  z-index: 50;
  box-shadow: 0 4px 24px rgba(0,212,255,0.15), 0 0 40px rgba(0,0,0,0.5);
  margin-bottom: 8px;
  line-height: 1.6;
}
.reach-bar-tip::after {
  content: '';
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  border: 5px solid transparent;
  border-top-color: var(--cyan);
}
.reach-hm-scroll {
  overflow-x: auto;
  max-height: 70vh;
  overflow-y: auto;
}
.reach-hm {
  width: 100%;
  border-collapse: collapse;
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
}
.reach-hm thead { position: sticky; top: 0; z-index: 5; }
.reach-hm th {
  text-align: center;
  padding: 8px 4px;
  font-size: 10px;
  color: var(--muted);
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  text-transform: uppercase;
  letter-spacing: 1px;
}
.hm-th-cent { width: 42px; }
.hm-th-bar { width: 120px; min-width: 120px; }
.hm-cent {
  text-align: right;
  padding-right: 8px;
  font-weight: bold;
  color: var(--cyan);
  white-space: nowrap;
}
.hm-cell {
  text-align: center;
  padding: 4px 6px;
  border-bottom: 1px solid rgba(26,58,74,0.2);
  position: relative;
  min-width: 65px;
  transition: background 0.2s;
}
.hm-cell:hover { outline: 1px solid var(--cyan); z-index: 2; }
.hm-pct {
  display: block;
  font-weight: 600;
  font-size: 11px;
  color: rgba(255,255,255,0.9);
}
.hm-cnt {
  display: block;
  font-size: 9px;
  color: rgba(255,255,255,0.35);
  margin-top: 1px;
}
.hm-bar-cell {
  padding: 4px 8px;
  border-bottom: 1px solid rgba(26,58,74,0.2);
  position: relative;
}
.hm-bar-bg {
  width: 100%;
  height: 14px;
  background: rgba(255,255,255,0.04);
  border-radius: 3px;
  overflow: hidden;
}
.hm-bar-fill {
  height: 100%;
  border-radius: 3px;
  transition: width 0.4s ease;
}
.hm-bar-val {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 9px;
  color: var(--muted);
}
.reach-hm tbody tr:hover { background: rgba(0,212,255,0.04); }

/* ── Old aliases for reach (backward compat) ── */
.analytics-summary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
  margin-bottom: 24px;
}
.analytics-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px 14px;
  text-align: center;
  transition: border-color 0.2s;
}
.analytics-card:hover { border-color: var(--cyan); }
.analytics-card-val {
  font-family: 'Orbitron', monospace;
  font-size: 22px;
  font-weight: 700;
  line-height: 1;
}
.analytics-card-lbl {
  font-size: 10px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-top: 6px;
}

/* ── Responsive ── */
@media (max-width: 768px) {
  .an-cards { grid-template-columns: repeat(2, 1fr); }
  .an-card-val { font-size: 16px; }
  .an-tabs { flex-wrap: wrap; }
  .reach-chart { height: 200px; }
  .reach-bar-stack { height: 170px; }
  .an-table { font-size: 11px; }
}
