/* === Design Tokens === */
:root {
  --bg-primary: #0f1117;
  --bg-card: #1a1d27;
  --bg-card-hover: #1f2231;
  --border: #2a2e3d;
  --text-primary: #e1e4ed;
  --text-secondary: #8b8fa3;
  --text-muted: #555a6e;
  --accent-blue: #4a9eff;
  --accent-green: #34d399;
  --accent-amber: #fbbf24;
  --accent-red: #f87171;
  --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  --font-mono: 'SF Mono', 'Fira Code', 'Cascadia Code', monospace;
  --radius: 10px;
  --shadow: 0 2px 8px rgba(0,0,0,0.3);
}

[data-theme="light"] {
  --bg-primary: #f0f2f5;
  --bg-card: #ffffff;
  --bg-card-hover: #f7f8fa;
  --border: #d4d8e0;
  --text-primary: #1a1d27;
  --text-secondary: #555a6e;
  --text-muted: #8b8fa3;
  --shadow: 0 2px 8px rgba(0,0,0,0.08);
}

/* === Reset & Base === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: var(--font-sans);
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
}

/* === Header === */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-card);
}
.header-left {
  display: flex;
  align-items: center;
  gap: 12px;
}
.header-title {
  font-size: 1.1em;
  font-weight: 600;
}
.theme-toggle {
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 4px 10px;
  font-size: 1.1em;
  transition: border-color 0.2s;
}
.theme-toggle:hover { border-color: var(--accent-blue); }
[data-theme="light"] .theme-icon::after { content: '☀'; }

/* === Connection Status === */
.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: inline-block;
  flex-shrink: 0;
}
.status-dot.connected { background: var(--accent-green); box-shadow: 0 0 6px var(--accent-green); }
.status-dot.disconnected { background: var(--accent-red); }

/* === Dashboard Grid === */
.dashboard {
  max-width: 1400px;
  margin: 0 auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.row {
  display: grid;
  gap: 16px;
}
.row-top, .row-bottom {
  grid-template-columns: 1fr 1fr;
}
.row-middle {
  grid-template-columns: 1fr;
}

/* === Cards === */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.card-title {
  font-size: 0.8em;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-secondary);
  padding: 14px 18px 0;
}
.card-body {
  padding: 14px 18px 18px;
}

/* === Empty State === */
.empty-state {
  color: var(--text-muted);
  font-size: 0.9em;
  text-align: center;
  padding: 24px 0;
}

/* === Utilities === */
.hidden { display: none !important; }
.mono { font-family: var(--font-mono); }
.accent { color: var(--accent-blue); }

/* === Session Progress === */
.progress-layout {
  display: flex;
  align-items: center;
  gap: 24px;
}
.doughnut-wrap {
  flex-shrink: 0;
}
.progress-info {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.stat-block {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.stat-label {
  font-size: 0.75em;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-secondary);
}
.stat-value {
  font-size: 1.15em;
  font-weight: 600;
}

/* === Badges === */
.badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 12px;
  font-size: 0.8em;
  font-weight: 600;
}
.badge-active { background: #134e2a; color: var(--accent-green); }
.badge-waiting { background: #3b2f0a; color: var(--accent-amber); }
.badge-complete { background: #1e3a5f; color: var(--accent-blue); }
.badge-muted { background: #2a2e3d; color: var(--text-muted); }

[data-theme="light"] .badge-active { background: #d1fae5; color: #065f46; }
[data-theme="light"] .badge-waiting { background: #fef3c7; color: #92400e; }
[data-theme="light"] .badge-complete { background: #dbeafe; color: #1e40af; }
[data-theme="light"] .badge-muted { background: #e5e7eb; color: #6b7280; }

/* === Current Participant === */
.participant-content { display: flex; flex-direction: column; gap: 12px; }
.participant-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.participant-code { font-weight: 700; font-size: 1.1em; }
.phase-timer { font-size: 1.2em; color: var(--accent-blue); }
.phase-info { display: flex; flex-direction: column; gap: 2px; }
.phase-name { font-weight: 600; font-size: 1em; }

/* === Phase Timeline === */
.phase-timeline {
  display: flex;
  gap: 3px;
  height: 8px;
  border-radius: 4px;
  overflow: hidden;
}
.phase-seg {
  flex: 1;
  border-radius: 2px;
  transition: background 0.3s;
}
.phase-seg.completed { background: var(--accent-green); }
.phase-seg.current { background: var(--accent-blue); animation: pulse 1.5s ease-in-out infinite; }
.phase-seg.future { background: var(--border); }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

.comprehension-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

/* === Timing Chart === */
.chart-wrap {
  position: relative;
  width: 100%;
  min-height: 200px;
}
#timing-chart {
  width: 100% !important;
}

/* === Session Results === */
.vickrey-results {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
}
.divider {
  height: 1px;
  background: var(--border);
  margin: 12px 0;
}
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88em;
}
.data-table th {
  text-align: left;
  font-size: 0.75em;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-secondary);
  padding: 6px 8px;
  border-bottom: 1px solid var(--border);
}
.data-table td {
  padding: 6px 8px;
  border-bottom: 1px solid var(--border);
}
.data-table .num { text-align: right; font-family: var(--font-mono); }
.data-table tr.winner { background: rgba(74, 158, 255, 0.1); }
.data-table tr.winner td:first-child::before { content: '★ '; color: var(--accent-blue); }
.bid-stats {
  display: flex;
  gap: 16px;
  margin-top: 10px;
}
.stat-micro {
  font-size: 0.78em;
  color: var(--text-secondary);
}

/* === Aggregate Stats === */
.aggregate-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 14px;
}
#bid-histogram {
  width: 100% !important;
  min-height: 220px;
  max-height: 260px;
}

/* === Session History === */
.history-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: 400px;
  overflow-y: auto;
}
.history-date-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.history-date-header {
  font-size: 0.78em;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-secondary);
  padding: 6px 2px 2px;
  border-bottom: 1px dashed var(--border);
  margin-bottom: 4px;
}
.history-date-count {
  color: var(--text-muted);
  font-weight: 400;
  text-transform: none;
  letter-spacing: 0;
}
.history-item {
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.15s;
}
.history-item:hover { background: var(--bg-card-hover); }
.history-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  gap: 8px;
}
.history-id {
  font-weight: 600;
  font-size: 0.9em;
  font-family: var(--font-mono);
}
.history-meta {
  display: flex;
  gap: 12px;
  align-items: center;
  font-size: 0.8em;
  color: var(--text-secondary);
}
.history-detail {
  padding: 0 12px 12px;
  display: none;
}
.history-item.expanded .history-detail { display: block; }
.history-detail .data-table td,
.history-detail .data-table th { font-size: 0.82em; }

/* === Responsive === */
@media (max-width: 900px) {
  .row-top, .row-bottom {
    grid-template-columns: 1fr;
  }
  .vickrey-results {
    grid-template-columns: repeat(2, 1fr);
  }
  .dashboard { padding: 12px; }
}
