:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --surface-2: #eef0f7;
  --border: #d7dbea;
  --text: #1a1a2e;
  --text-dim: #6b7280;
  --accent: #7a5cff;
  --accent-hover: #6248e0;
  --green: #16a34a;
  --green-bg: #dcfce7;
  --yellow: #b45309;
  --yellow-bg: #fef9c3;
  --red: #dc2626;
  --red-bg: #fee2e2;
  --font-ui: 'Fira Code', monospace;
  --font-body: 'Roboto Mono', monospace;
}

html[data-theme="dark"] {
  --bg: #050505;
  --surface: #121216;
  --surface-2: #18181f;
  --border: rgba(122,92,255,0.18);
  --text: #e0e0e0;
  --text-dim: #858595;
  --green: #00ff41;
  --green-bg: rgba(0,255,65,0.08);
  --yellow: #fbbf24;
  --yellow-bg: rgba(251,191,36,0.08);
  --red: #ff4444;
  --red-bg: rgba(255,68,68,0.08);
}

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

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  transition: background-color 0.3s ease, color 0.3s ease;
}

/* Base Layout */
.pulse-wrap {
  max-width: 880px;
  margin: 0 auto;
  padding: 2rem 1.25rem;
}

/* Glassmorphism Cards */
.pulse-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.04);
  padding: 2rem;
  margin-bottom: 2rem;
  transition: transform 0.2s ease, box-shadow 0.2s ease, background-color 0.3s ease, border-color 0.3s ease;
}

.pulse-card:hover {
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.08);
}

/* Typography & Headers */
.pulse-title {
  font-family: var(--font-ui);
  font-size: 1.8rem;
  font-weight: 700;
  margin: 0 0 0.5rem 0;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--text);
}

.pulse-subtitle {
  font-size: 0.9rem;
  color: var(--text-dim);
  margin: 0 0 2rem 0;
  line-height: 1.5;
}

.pulse-section-title {
  font-family: var(--font-ui);
  font-size: 1.1rem;
  font-weight: 600;
  margin-top: 0;
  margin-bottom: 1rem;
  color: var(--text);
}

/* Form Controls */
.pulse-form-group {
  margin-bottom: 1.25rem;
}

.pulse-label {
  display: block;
  font-family: var(--font-ui);
  font-size: 0.8rem;
  font-weight: 600;
  margin-bottom: 0.4rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-dim);
}

.pulse-input {
  width: 100%;
  padding: 0.75rem 1rem;
  font-family: var(--font-body);
  font-size: 0.9rem;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  outline: none;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.pulse-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(122, 92, 255, 0.15);
}

.pulse-setup-actions {
  display: flex;
  justify-content: flex-end;
  margin: -1rem 0 1.25rem;
}

.pulse-checkbox-label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-family: var(--font-body);
  font-size: 0.9rem;
  cursor: pointer;
  user-select: none;
}

.pulse-checkbox {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
  cursor: pointer;
}

/* Buttons */
.pulse-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.75rem 1.5rem;
  font-family: var(--font-ui);
  font-size: 0.9rem;
  font-weight: 600;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s ease;
  text-decoration: none;
  gap: 0.5rem;
}

.pulse-btn-primary {
  background: var(--accent);
  color: #ffffff;
}

.pulse-btn-primary:hover {
  background: var(--accent-hover);
  transform: translateY(-1px);
}

.pulse-btn-primary:active {
  transform: translateY(0);
}

.pulse-btn-secondary {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
}

.pulse-btn-secondary:hover {
  background: var(--border);
  color: var(--text);
}

.pulse-btn-danger {
  background: var(--red);
  color: #ffffff;
}

.pulse-btn-danger:hover {
  opacity: 0.9;
  transform: translateY(-1px);
}

/* Large Student Response Buttons */
.pulse-response-options {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.pulse-response-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 85px;
  font-family: var(--font-ui);
  font-size: 1.1rem;
  font-weight: 600;
  border: 2px solid transparent;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s ease;
  user-select: none;
  color: var(--text);
  background: var(--surface-2);
  outline: none;
}

.pulse-response-btn.pulse-green {
  border-color: rgba(22, 163, 74, 0.2);
}
.pulse-response-btn.pulse-green:hover,
.pulse-response-btn.pulse-green:focus-visible {
  background: var(--green-bg);
  border-color: var(--green);
}
.pulse-response-btn.pulse-green.selected {
  background: var(--green-bg);
  border-color: var(--green);
  box-shadow: 0 0 12px rgba(22, 163, 74, 0.4);
}

.pulse-response-btn.pulse-yellow {
  border-color: rgba(180, 83, 9, 0.2);
}
.pulse-response-btn.pulse-yellow:hover,
.pulse-response-btn.pulse-yellow:focus-visible {
  background: var(--yellow-bg);
  border-color: var(--yellow);
}
.pulse-response-btn.pulse-yellow.selected {
  background: var(--yellow-bg);
  border-color: var(--yellow);
  box-shadow: 0 0 12px rgba(180, 83, 9, 0.4);
}

.pulse-response-btn.pulse-red {
  border-color: rgba(220, 38, 38, 0.2);
}
.pulse-response-btn.pulse-red:hover,
.pulse-response-btn.pulse-red:focus-visible {
  background: var(--red-bg);
  border-color: var(--red);
}
.pulse-response-btn.pulse-red.selected {
  background: var(--red-bg);
  border-color: var(--red);
  box-shadow: 0 0 12px rgba(220, 38, 38, 0.4);
}

/* Confirmation message */
.pulse-confirm-box {
  background: var(--green-bg);
  color: var(--green);
  border: 1px solid var(--green);
  border-radius: 6px;
  padding: 0.75rem 1rem;
  font-size: 0.9rem;
  font-weight: 600;
  margin-top: 1rem;
  text-align: center;
  display: none;
  animation: fadeIn 0.2s ease;
}

/* QR Code Placeholder */
.pulse-qr-placeholder {
  border: 2px dashed var(--border);
  border-radius: 8px;
  padding: 1.5rem;
  text-align: center;
  font-family: var(--font-ui);
  font-size: 0.8rem;
  color: var(--text-dim);
  opacity: 0.4;
  margin: 1.5rem 0;
  background: var(--surface-2);
}

/* Teacher Controls Area */
.pulse-teacher-controls {
  border-top: 1px dashed var(--border);
  margin-top: 2rem;
  padding-top: 1.5rem;
}

.pulse-simulation-area {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1.25rem;
  margin-top: 1.5rem;
}

.pulse-sim-row {
  display: flex;
  gap: 0.75rem;
  margin-top: 0.75rem;
  flex-wrap: wrap;
}

.pulse-btn-sim {
  padding: 0.5rem 1rem;
  font-size: 0.8rem;
  font-family: var(--font-ui);
  border: 1px solid var(--border);
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.pulse-btn-sim.sim-green {
  background: var(--green-bg);
  color: var(--green);
  border-color: var(--green);
}
.pulse-btn-sim.sim-green:hover {
  filter: brightness(0.95);
}

.pulse-btn-sim.sim-yellow {
  background: var(--yellow-bg);
  color: var(--yellow);
  border-color: var(--yellow);
}
.pulse-btn-sim.sim-yellow:hover {
  filter: brightness(0.95);
}

.pulse-btn-sim.sim-red {
  background: var(--red-bg);
  color: var(--red);
  border-color: var(--red);
}
.pulse-btn-sim.sim-red:hover {
  filter: brightness(0.95);
}

/* Dashboard Metrics */
.pulse-metrics-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.pulse-metric-card {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1rem;
  text-align: center;
  transition: background-color 0.3s ease, border-color 0.3s ease;
}

.pulse-metric-card.m-green {
  border-left: 4px solid var(--green);
}
.pulse-metric-card.m-yellow {
  border-left: 4px solid var(--yellow);
}
.pulse-metric-card.m-red {
  border-left: 4px solid var(--red);
}
.pulse-metric-card.m-gray {
  border-left: 4px solid var(--text-dim);
}

.pulse-metric-val {
  font-family: var(--font-ui);
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: 0.25rem;
}

.pulse-metric-lbl {
  font-size: 0.75rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* Dashboard Color Bar */
.pulse-color-bar {
  display: flex;
  height: 16px;
  border-radius: 8px;
  overflow: hidden;
  background: var(--border);
  margin-bottom: 2rem;
  border: 1px solid var(--border);
}

.bar-segment {
  height: 100%;
  transition: width 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

.bar-segment.bar-green {
  background: var(--green);
}
.bar-segment.bar-yellow {
  background: var(--yellow);
}
.bar-segment.bar-red {
  background: var(--red);
}
.bar-segment.bar-gray {
  background: var(--text-dim);
  opacity: 0.5;
}

/* Student Columns Grid */
.pulse-columns-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1rem;
  margin-bottom: 2rem;
}

.pulse-col {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1rem;
  min-height: 120px;
}

.pulse-col-header {
  font-family: var(--font-ui);
  font-size: 0.8rem;
  font-weight: 600;
  margin-bottom: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-bottom: 1px dashed var(--border);
  padding-bottom: 0.5rem;
}

.pulse-col-header.c-green { color: var(--green); }
.pulse-col-header.c-yellow { color: var(--yellow); }
.pulse-col-header.c-red { color: var(--red); }
.pulse-col-header.c-gray { color: var(--text-dim); }

.pulse-col-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.pulse-col-list li {
  font-size: 0.85rem;
  padding: 0.3rem 0;
  border-bottom: 1px solid rgba(0, 0, 0, 0.03);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

html[data-theme="dark"] .pulse-col-list li {
  border-bottom: 1px solid rgba(255, 255, 255, 0.03);
}

.pulse-col-list li:last-child {
  border-bottom: none;
}

/* Submitted Questions Section */
.pulse-questions-section {
  margin-top: 2rem;
  border-top: 1px dashed var(--border);
  padding-top: 1.5rem;
}

.pulse-questions-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin-top: 1rem;
}

.pulse-question-item {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 1rem;
  font-size: 0.9rem;
  line-height: 1.4;
  position: relative;
}

.pulse-question-item.q-green { border-left: 3px solid var(--green); }
.pulse-question-item.q-yellow { border-left: 3px solid var(--yellow); }
.pulse-question-item.q-red { border-left: 3px solid var(--red); }

.pulse-question-meta {
  font-size: 0.75rem;
  color: var(--text-dim);
  margin-bottom: 0.3rem;
  display: flex;
  justify-content: space-between;
}

.pulse-question-text {
  font-style: italic;
  color: var(--text);
}

/* Suggested Action Banner */
.pulse-action-banner {
  border-radius: 8px;
  padding: 1.25rem;
  margin: 2rem 0;
  font-size: 0.95rem;
  font-weight: 500;
  line-height: 1.5;
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  transition: all 0.3s ease;
}

.pulse-action-banner::before {
  content: "💡";
  font-size: 1.2rem;
}

.pulse-action-banner.status-green {
  background: var(--green-bg);
  color: var(--green);
  border: 1px solid var(--green);
}
.pulse-action-banner.status-green::before {
  content: "✅";
}

.pulse-action-banner.status-yellow {
  background: var(--yellow-bg);
  color: var(--yellow);
  border: 1px solid var(--yellow);
}
.pulse-action-banner.status-yellow::before {
  content: "⚠️";
}

.pulse-action-banner.status-red {
  background: var(--red-bg);
  color: var(--red);
  border: 1px solid var(--red);
}
.pulse-action-banner.status-red::before {
  content: "🚨";
}

/* Group Suggestions */
.pulse-groups-suggestion {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1.5rem;
  margin-bottom: 2rem;
}

.pulse-suggested-groups-list {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1rem;
  margin-top: 1rem;
}

.pulse-suggested-group-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 1rem;
}

.pulse-suggested-group-title {
  font-family: var(--font-ui);
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 0.5rem;
}

.pulse-suggested-group-members {
  font-size: 0.85rem;
  line-height: 1.45;
}

/* Action Buttons Row */
.pulse-actions-row {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
}

/* Header Session Badge */
.pulse-session-badge {
  display: inline-flex;
  align-items: center;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 0.25rem 0.75rem;
  font-size: 0.75rem;
  color: var(--text-dim);
  margin-bottom: 1.5rem;
  font-family: var(--font-ui);
}

/* Utility classes */
.pulse-flex {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.5rem;
}

.pulse-text-center {
  text-align: center;
}

.pulse-mt-0 { margin-top: 0; }
.pulse-mb-0 { margin-bottom: 0; }
.pulse-gap-1 { gap: 0.5rem; }

/* Demo notice */
.pulse-demo-notice {
  font-size: 0.8rem;
  color: var(--text-dim);
  margin-top: 1.5rem;
  text-align: center;
  border-top: 1px solid var(--border);
  padding-top: 1rem;
}

/* Empty state — shown when Pulse Check is opened without a Smart Lists roster */
.pulse-empty {
  text-align: center;
  padding: 1.5rem 1rem 0.5rem;
}
.pulse-empty-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
  margin: 0 0 0.4rem;
}
.pulse-empty-text {
  font-size: 0.85rem;
  color: var(--text-dim);
  line-height: 1.5;
  margin: 0 auto;
  max-width: 32ch;
}

/* ── Teacher roster checklist (Response screen) ── */
.pulse-roster-instructions {
  font-size: 0.85rem;
  color: var(--text-dim);
  margin: 0 0 0.85rem;
  line-height: 1.5;
}
.pulse-roster-list {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  margin-bottom: 1.25rem;
}
.pulse-roster-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1.2fr);
  align-items: center;
  gap: 0.6rem;
  padding: 0.5rem 0.6rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
}
.pulse-roster-name {
  font-weight: 600;
  color: var(--text);
  font-size: 0.9rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.pulse-roster-status {
  display: inline-flex;
  gap: 0.3rem;
  flex-shrink: 0;
}
.pulse-status-btn {
  width: 42px;
  height: 42px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  font-size: 1.2rem;
  line-height: 1;
  cursor: pointer;
  opacity: 0.45;
  transition: opacity 0.15s, transform 0.1s, box-shadow 0.15s, border-color 0.15s;
}
.pulse-status-btn:hover { opacity: 0.8; }
.pulse-status-btn:active { transform: scale(0.94); }
.pulse-status-btn:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px rgba(122,92,255,0.35);
}
.pulse-status-btn.active { opacity: 1; }
.pulse-status-btn.status-green.active  { background: var(--green-bg);  border-color: var(--green); }
.pulse-status-btn.status-yellow.active { background: var(--yellow-bg); border-color: var(--yellow); }
.pulse-status-btn.status-red.active    { background: var(--red-bg);    border-color: var(--red); }
.pulse-roster-note {
  width: 100%;
  padding: 0.45rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  font-size: 0.82rem;
  font-family: inherit;
}
.pulse-roster-note:focus-visible {
  outline: none;
  border-color: var(--accent);
}

/* Session history */
.pulse-history-list {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}
.pulse-history-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: stretch;
  gap: 0.55rem;
}
.pulse-history-open {
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.85rem 1rem;
  text-align: left;
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  font-family: inherit;
  transition: border-color 0.15s, transform 0.15s, background-color 0.15s;
}
.pulse-history-open:hover {
  border-color: var(--accent);
  transform: translateY(-1px);
}
.pulse-history-open:focus-visible,
.pulse-history-delete:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px rgba(122,92,255,0.3);
}
.pulse-history-copy {
  min-width: 0;
}
.pulse-history-title {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 700;
  font-size: 0.9rem;
}
.pulse-history-meta {
  display: block;
  margin-top: 0.25rem;
  color: var(--text-dim);
  font-size: 0.75rem;
}
.pulse-history-result {
  flex-shrink: 0;
  display: inline-flex;
  gap: 0.45rem;
  padding: 0.35rem 0.55rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  font-family: var(--font-ui);
  font-size: 0.72rem;
  white-space: nowrap;
}
.pulse-history-green { color: var(--green); }
.pulse-history-yellow { color: var(--yellow); }
.pulse-history-red { color: var(--red); }
.pulse-history-delete {
  width: 44px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--red);
  cursor: pointer;
  font-size: 1rem;
}
.pulse-history-delete:hover {
  border-color: var(--red);
  background: var(--red-bg);
}
.pulse-history-empty {
  padding: 2rem 1rem;
  text-align: center;
  color: var(--text-dim);
  border: 1px dashed var(--border);
  border-radius: 8px;
}

/* History tabs (Sessions | Students) + per-student timeline */
.pulse-tabs {
  display: flex;
  gap: 0.4rem;
  margin-bottom: 1rem;
}
.pulse-tab {
  padding: 0.45rem 0.9rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text-dim);
  font-family: inherit;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s, background-color 0.15s;
}
.pulse-tab:hover {
  border-color: var(--accent);
  color: var(--text);
}
.pulse-tab.active {
  border-color: var(--accent);
  background: var(--surface);
  color: var(--accent);
}
.pulse-tab:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px rgba(122,92,255,0.3);
}
.pulse-student-detail-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
}
.pulse-student-detail-name {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 700;
}
.pulse-student-timeline-row {
  justify-content: flex-start;
}
.pulse-student-dot {
  flex-shrink: 0;
  font-size: 1rem;
}
.pulse-student-none {
  color: var(--text-dim);
}
.pulse-student-note {
  display: block;
  margin-top: 0.3rem;
  color: var(--text);
  font-size: 0.78rem;
  white-space: normal;
}

/* Keyframes */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(3px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Responsive Styles */
@media (max-width: 768px) {
  .pulse-response-options {
    grid-template-columns: 1fr;
    gap: 0.75rem;
  }

  /* Roster rows stack: name on top, status buttons + note below */
  .pulse-roster-row {
    grid-template-columns: 1fr;
    gap: 0.5rem;
  }
  .pulse-roster-status { justify-content: space-between; }
  .pulse-status-btn { flex: 1; }

  .pulse-response-btn {
    height: 70px;
    flex-direction: row;
    gap: 0.5rem;
  }
  
  .pulse-metrics-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  
  .pulse-columns-grid {
    grid-template-columns: 1fr;
  }
  
  .pulse-suggested-groups-list {
    grid-template-columns: 1fr;
  }
  
  .pulse-flex {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.75rem;
  }
  
  .pulse-actions-row {
    flex-direction: column;
    width: 100%;
  }
  
  .pulse-actions-row .pulse-btn {
    width: 100%;
  }

  .pulse-history-open {
    align-items: flex-start;
    flex-direction: column;
    gap: 0.6rem;
  }
}
