/* ── Variables ─────────────────────────────────────── */
:root {
  --bg:          #080e1a;
  --bg-card:     #111827;
  --bg-card-2:   #1a2235;
  --border:      #1f2d42;
  --text-primary:#e8edf5;
  --text-sec:    #8da0b8;
  --text-muted:  #4f6078;
  --accent:      #3b82f6;
  --accent-dim:  rgba(59,130,246,0.15);
  --good:        #22c55e;
  --good-bg:     rgba(34,197,94,0.12);
  --medium:      #eab308;
  --medium-bg:   rgba(234,179,8,0.12);
  --bad:         #ef4444;
  --bad-bg:      rgba(239,68,68,0.12);
  --radius:      10px;
  --shadow:      0 4px 24px rgba(0,0,0,0.4);
}

/* ── Reset ─────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 15px; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text-primary);
  min-height: 100vh;
  line-height: 1.5;
}

/* ── Header ────────────────────────────────────────── */
.header {
  background: linear-gradient(135deg, #0d1629 0%, #111827 100%);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}
.header-inner {
  max-width: 1400px;
  margin: 0 auto;
  padding: 12px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.header-brand {
  display: flex;
  align-items: center;
  gap: 12px;
}
.header-icon { font-size: 1.8rem; }
.header-title {
  font-size: 1.2rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text-primary);
}
.header-sub {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.btn-refresh {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--accent-dim);
  color: var(--accent);
  border: 1px solid rgba(59,130,246,0.3);
  border-radius: 8px;
  padding: 8px 14px;
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s;
  white-space: nowrap;
}
.btn-refresh:hover {
  background: rgba(59,130,246,0.25);
  border-color: var(--accent);
}
.refresh-icon { font-size: 1rem; display: inline-block; }
.refresh-icon.spinning { animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Main layout ───────────────────────────────────── */
.main {
  max-width: 1400px;
  margin: 0 auto;
  padding: 20px;
}

/* ── Controls bar ──────────────────────────────────── */
.controls-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  margin-bottom: 8px;
}

/* ── Tabs ──────────────────────────────────────────── */
.tabs {
  display: flex;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 4px;
  gap: 2px;
}
.tab-btn {
  background: transparent;
  border: none;
  color: var(--text-sec);
  padding: 8px 18px;
  border-radius: 7px;
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 500;
  transition: background 0.15s, color 0.15s;
}
.tab-btn:hover { background: var(--bg-card-2); color: var(--text-primary); }
.tab-btn.active { background: var(--accent); color: #fff; }

/* ── Period selector ───────────────────────────────── */
.period-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.period-control {
  display: flex;
  align-items: center;
  gap: 8px;
}
.period-control.hidden { display: none; }
.period-label {
  font-size: 0.8rem;
  color: var(--text-sec);
  white-space: nowrap;
}
.period-select {
  background: var(--bg-card);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 0.85rem;
  cursor: pointer;
  outline: none;
  transition: border-color 0.15s;
  max-width: 220px;
}
.period-select:focus { border-color: var(--accent); }

/* ── Period label display ──────────────────────────── */
.period-label-display {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-bottom: 16px;
  min-height: 18px;
}

/* ── State cards (loading/error/empty) ─────────────── */
.state-card {
  grid-column: 1 / -1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 60px 20px;
  color: var(--text-sec);
  font-size: 0.95rem;
}
.state-card.error { color: var(--bad); }

.spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

/* ── Stats grid ────────────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 16px;
}

/* ── Manager card ──────────────────────────────────── */
.manager-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  transition: border-color 0.2s, transform 0.15s;
}
.manager-card:hover {
  border-color: rgba(59,130,246,0.4);
  transform: translateY(-2px);
}

.card-header {
  background: var(--bg-card-2);
  border-bottom: 1px solid var(--border);
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.manager-name {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-primary);
}
.manager-total {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--accent);
}
.manager-total-label {
  font-size: 0.68rem;
  color: var(--text-muted);
  text-align: right;
  line-height: 1.2;
}

.card-body { padding: 14px 16px; display: flex; flex-direction: column; gap: 12px; }

/* ── Answer rate progress bar ──────────────────────── */
.rate-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.rate-label { font-size: 0.78rem; color: var(--text-sec); white-space: nowrap; }
.rate-value {
  font-size: 0.85rem;
  font-weight: 700;
  white-space: nowrap;
}
.progress-track {
  flex: 1;
  height: 6px;
  background: var(--border);
  border-radius: 99px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  border-radius: 99px;
  transition: width 0.5s ease;
}
.progress-fill.good  { background: var(--good); }
.progress-fill.medium { background: var(--medium); }
.progress-fill.bad   { background: var(--bad); }

/* ── Stat grid inside card ─────────────────────────── */
.stat-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.stat-block {
  background: rgba(255,255,255,0.025);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 8px 10px;
}
.stat-block-label {
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-bottom: 3px;
}
.stat-block-value {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-primary);
}

/* ── Color classes ─────────────────────────────────── */
.val-good   { color: var(--good); }
.val-medium { color: var(--medium); }
.val-bad    { color: var(--bad); }

.badge {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 99px;
}
.badge-good   { background: var(--good-bg);   color: var(--good); }
.badge-medium { background: var(--medium-bg); color: var(--medium); }
.badge-bad    { background: var(--bad-bg);    color: var(--bad); }

/* ── Divider ───────────────────────────────────────── */
.card-divider {
  height: 1px;
  background: var(--border);
  margin: 0 -16px;
}

/* ── Hourly chart ──────────────────────────────────── */
.chart-section { display: flex; flex-direction: column; gap: 6px; }
.chart-title {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}
.chart {
  display: flex;
  align-items: flex-end;
  gap: 4px;
  height: 72px;
}
.bar-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  height: 100%;
  gap: 2px;
}
.bar-inner {
  flex: 1;
  width: 100%;
  display: flex;
  align-items: flex-end;
}
.bar {
  width: 100%;
  background: linear-gradient(180deg, #3b82f6 0%, #1d4ed8 100%);
  border-radius: 3px 3px 0 0;
  min-height: 3px;
  transition: height 0.4s ease;
}
.bar-val {
  font-size: 0.62rem;
  color: var(--text-sec);
  line-height: 1;
}
.bar-lbl {
  font-size: 0.6rem;
  color: var(--text-muted);
  line-height: 1;
  white-space: nowrap;
}

/* ── Responsive ────────────────────────────────────── */
@media (max-width: 640px) {
  .main { padding: 12px; }
  .controls-bar { flex-direction: column; align-items: flex-start; }
  .stats-grid { grid-template-columns: 1fr; }
  .header-title { font-size: 1rem; }
  .tab-btn { padding: 7px 12px; font-size: 0.82rem; }
  .period-select { max-width: 160px; }
}

@media (max-width: 480px) {
  .stat-grid { grid-template-columns: 1fr 1fr; }
  .bar-lbl { font-size: 0.55rem; }
}
