*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:        #0f1117;
  --surface:   #1a1d27;
  --surface2:  #242736;
  --border:    #2e3248;
  --text:      #e2e8f0;
  --muted:     #8892a4;
  --accent:    #6366f1;
  --accent2:   #818cf8;
  --green:     #22c55e;
  --red:       #ef4444;
  --blue:      #3b82f6;
  --yellow:    #f59e0b;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 14px;
  line-height: 1.5;
  padding: 24px;
  max-width: 1600px;
  margin: 0 auto;
}

header {
  margin-bottom: 24px;
}

.header-main {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.header-user {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}

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

.btn-logout {
  padding: 5px 14px;
  font-size: 12px;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
  border-radius: 6px;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s;
}
.btn-logout:hover {
  border-color: var(--red);
  color: var(--red);
}

header h1 {
  font-size: 24px;
  font-weight: 700;
  color: var(--text);
}

.subtitle {
  color: var(--muted);
  font-size: 13px;
  margin-top: 4px;
}

/* ─── Filters ─── */
.filters {
  display: flex;
  align-items: flex-end;
  gap: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px 20px;
  margin-bottom: 24px;
  flex-wrap: wrap;
}

.filter-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.filter-group label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  font-weight: 600;
}

.filter-group input,
.filter-group select {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  padding: 8px 12px;
  font-size: 13px;
  outline: none;
  min-width: 140px;
  transition: border-color 0.15s;
}

.filter-group input:focus,
.filter-group select:focus {
  border-color: var(--accent);
}

button {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 9px 20px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s;
  align-self: flex-end;
}

button:hover { opacity: 0.85; }

button.secondary {
  background: var(--surface2);
  color: var(--muted);
  border: 1px solid var(--border);
}

/* ─── KPI ─── */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 16px;
  margin-bottom: 24px;
}

.kpi-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
}

.kpi-label {
  font-size: 12px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 600;
  margin-bottom: 8px;
}

.kpi-value {
  font-size: 32px;
  font-weight: 700;
  color: var(--text);
  line-height: 1;
}

.kpi-sub {
  font-size: 12px;
  color: var(--accent2);
  margin-top: 6px;
}

#kpi-used .kpi-value { color: var(--green); }
#kpi-active .kpi-value { color: var(--blue); }
#kpi-expired .kpi-value { color: var(--red); }

/* ─── Chart rows ─── */
.charts-row {
  display: flex;
  gap: 16px;
  margin-bottom: 24px;
  flex-wrap: wrap;
}

.chart-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
}

.chart-card h2 {
  font-size: 14px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 16px;
}

.chart-card.wide   { flex: 2; min-width: 460px; }
.chart-card.narrow { flex: 1; min-width: 260px; }
.chart-card.medium { flex: 1; min-width: 360px; }
.chart-card.full   { flex: 1 1 100%; }

.chart-wrap { position: relative; height: 280px; }

/* ─── Funnel ─── */
.funnel-wrap {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding-top: 8px;
}

.funnel-step {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.funnel-bar-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.funnel-bar-bg {
  flex: 1;
  height: 28px;
  background: var(--surface2);
  border-radius: 6px;
  overflow: hidden;
}

.funnel-bar-fill {
  height: 100%;
  border-radius: 6px;
  transition: width 0.4s ease;
}

.funnel-meta {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: var(--muted);
}

.funnel-label { font-weight: 600; color: var(--text); }
.funnel-count { font-size: 16px; font-weight: 700; min-width: 52px; text-align: right; }

/* ─── Heatmap ─── */
.heatmap-outer {
  overflow-x: auto;
}

.heatmap-grid {
  display: grid;
  gap: 3px;
}

.heatmap-cell {
  width: 100%;
  aspect-ratio: 1;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 600;
  cursor: default;
  transition: opacity 0.15s;
  position: relative;
}

.heatmap-cell:hover::after {
  content: attr(data-tooltip);
  position: absolute;
  bottom: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  background: #000;
  color: #fff;
  font-size: 11px;
  padding: 4px 8px;
  border-radius: 6px;
  white-space: nowrap;
  pointer-events: none;
  z-index: 10;
}

.heatmap-header {
  background: transparent;
  color: var(--muted);
  font-size: 10px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ─── Table ─── */
.table-wrap { overflow-x: auto; }

table {
  width: 100%;
  border-collapse: collapse;
}

th, td {
  padding: 10px 14px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

th {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  font-weight: 600;
}

td { font-size: 13px; }

tbody tr:hover { background: var(--surface2); }

tbody tr:last-child td { border-bottom: none; }

.badge-success {
  display: inline-block;
  background: rgba(34,197,94,0.15);
  color: var(--green);
  border-radius: 20px;
  padding: 2px 10px;
  font-size: 12px;
  font-weight: 600;
}

/* ─── Route cell ─── */
.route-cell { white-space: nowrap; }
.route-from, .route-to {
  font-size: 11px;
  font-weight: 600;
  padding: 2px 6px;
  border-radius: 4px;
  background: rgba(124,110,245,0.12);
  color: var(--accent, #7c6ef5);
}
.route-arrow {
  margin: 0 4px;
  color: var(--muted);
  font-size: 11px;
}

/* ─── Series block ─── */
.series-header {
  display: flex;
  align-items: baseline;
  gap: 12px;
  margin-bottom: 16px;
}

.series-hint {
  font-size: 11px;
  color: var(--muted);
  flex: 1;
}

.btn-show-all {
  margin-left: auto;
  padding: 4px 12px;
  font-size: 12px;
  background: transparent;
  border: 1px solid var(--accent, #7c6ef5);
  color: var(--accent, #7c6ef5);
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.btn-show-all:hover {
  background: var(--accent, #7c6ef5);
  color: #fff;
}

.series-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.series-item {
  display: grid;
  grid-template-columns: 32px 1fr auto auto;
  align-items: center;
  gap: 12px 20px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 18px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

.series-item:hover {
  border-color: var(--accent);
  background: #1e2133;
}

.series-rank {
  font-size: 18px;
  font-weight: 800;
  color: var(--muted);
  text-align: center;
}

.series-rank.gold   { color: #f59e0b; }
.series-rank.silver { color: #94a3b8; }
.series-rank.bronze { color: #b45309; }

.series-user {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
}

.series-meta {
  font-size: 12px;
  color: var(--muted);
  margin-top: 2px;
}

.series-count {
  display: flex;
  flex-direction: column;
  align-items: center;
  background: rgba(99,102,241,0.15);
  border-radius: 8px;
  padding: 6px 14px;
  min-width: 56px;
}

.series-count-num {
  font-size: 22px;
  font-weight: 800;
  color: var(--accent2);
  line-height: 1;
}

.series-count-label {
  font-size: 10px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-top: 2px;
}

.series-arrow {
  font-size: 16px;
  color: var(--muted);
  transition: transform 0.2s, color 0.15s;
}

.series-item:hover .series-arrow {
  transform: translateX(3px);
  color: var(--accent2);
}

/* ─── Modal ─── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.65);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
}

.modal-overlay[hidden] { display: none; }

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  width: 100%;
  max-width: 560px;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: modalIn 0.18s ease;
}

@keyframes modalIn {
  from { opacity: 0; transform: translateY(12px) scale(0.97); }
  to   { opacity: 1; transform: none; }
}

.modal-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  padding: 20px 24px 16px;
  border-bottom: 1px solid var(--border);
}

.modal-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
}

.modal-sub {
  font-size: 12px;
  color: var(--muted);
  margin-top: 4px;
}

.modal-close {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--muted);
  border-radius: 8px;
  padding: 4px 10px;
  font-size: 14px;
  cursor: pointer;
  line-height: 1.4;
  margin-top: -2px;
}

.modal-close:hover { color: var(--text); opacity: 1; }

.modal-body {
  overflow-y: auto;
  padding: 0 24px 20px;
}

/* ─── Loading state ─── */
.loading { opacity: 0.4; pointer-events: none; }

@media (max-width: 900px) {
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .chart-card.wide,
  .chart-card.narrow,
  .chart-card.medium { flex: 1 1 100%; min-width: unset; }
}
