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

:root {
  --bg: #0a0a0f;
  --bg-surface: #14141f;
  --bg-hover: #1e1e2e;
  --text: #e8e8f0;
  --text-dim: #888899;
  --accent: #6c8cff;
  --green: #22c55e;
  --amber: #f59e0b;
  --red: #ef4444;
  --border: #2a2a3a;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

/* ===== BUTTONS ===== */
.btn {
  border: 1px solid var(--border);
  background: var(--bg-surface);
  color: var(--text);
  padding: 8px 16px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
  transition: background 0.15s, opacity 0.15s;
}
.btn:hover { background: var(--bg-hover); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-sm { padding: 4px 12px; font-size: 13px; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: #5a7aee; }
.btn-go { background: #166534; border-color: var(--green); color: var(--green); }
.btn-go:hover { background: #15803d; }
.btn-warn { background: #713f12; border-color: var(--amber); color: var(--amber); }
.btn-warn:hover { background: #854d0e; }
.btn-danger { background: #7f1d1d; border-color: var(--red); color: var(--red); }
.btn-danger:hover { background: #991b1b; }

/* ===== CONTROL PANEL ===== */
#control-panel {
  max-width: 900px;
  margin: 0 auto;
  padding: 20px;
}

.cp-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
  gap: 12px;
}
.cp-header h1 { font-size: 22px; font-weight: 600; }
.cp-header-actions { display: flex; align-items: center; gap: 8px; }

.total-time {
  font-size: 13px;
  padding: 4px 10px;
  border-radius: 4px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
}
.total-time.over { color: var(--red); border-color: var(--red); }
.total-time.under { color: var(--green); border-color: var(--green); }

/* State Summary */
.state-summary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 12px;
  margin: 16px 0;
}
.summary-reactions { font-size: 14px; letter-spacing: 1px; white-space: nowrap; }
.summary-reactions .reaction-warn {
  color: var(--amber);
  animation: pulse 1.5s ease-in-out infinite;
}
.summary-item {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  text-align: center;
}
.summary-label { display: block; font-size: 11px; text-transform: uppercase; color: var(--text-dim); letter-spacing: 0.5px; }
.summary-value { display: block; font-size: 18px; font-weight: 600; margin-top: 4px; }

/* Session Bar */
.session-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 16px 0 0;
  padding: 12px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  flex-wrap: wrap;
}
.session-bar label {
  color: var(--text-dim);
  font-size: 13px;
  font-weight: 600;
}
.session-bar select {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 6px 10px;
  border-radius: 6px;
  font-size: 14px;
  font-family: inherit;
  min-width: 180px;
}
.session-bar select:focus {
  outline: none;
  border-color: var(--accent);
}
.session-save-flash {
  font-size: 13px;
  color: var(--green);
  transition: opacity 0.3s;
}

/* Current Speaker Notes */
.current-notes-panel {
  margin: 12px 0 0;
  padding: 12px 16px;
  background: var(--bg-surface);
  border: 1px solid var(--accent);
  border-radius: 8px;
}
.current-notes-panel[hidden] { display: none; }
.current-notes-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}
.current-notes-speaker {
  font-size: 15px;
  font-weight: 700;
}
.current-notes-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--accent);
  font-weight: 600;
}
.current-notes-text {
  font-size: 15px;
  line-height: 1.6;
  color: var(--text);
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px 12px;
  font-family: inherit;
  resize: vertical;
  min-height: 60px;
}
.current-notes-text:focus {
  outline: none;
  border-color: var(--accent);
}

/* Event Time Window */
.time-window {
  margin: 16px 0 0;
  padding: 12px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 8px;
}
.time-window-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  font-size: 14px;
}
.time-window-row label {
  color: var(--text-dim);
  font-size: 13px;
}
.time-window-row input[type="time"] {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 6px 10px;
  border-radius: 6px;
  font-size: 14px;
  font-family: inherit;
}
.time-window-row input[type="time"]:focus {
  outline: none;
  border-color: var(--accent);
}
.time-window-info {
  font-size: 13px;
  color: var(--text-dim);
  margin-left: auto;
}
.time-window-info.over { color: var(--red); }
.time-window-info.ok { color: var(--green); }

/* Transport Controls */
.transport-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 16px 0;
  padding: 12px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  flex-wrap: wrap;
}
.btn-transport { padding: 10px 20px; font-size: 15px; font-weight: 600; }
.btn-adjust { font-weight: 600; font-size: 14px; }

/* Slide controls */
.slide-controls {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-left: 8px;
  padding-left: 8px;
  border-left: 1px solid var(--border);
}
.slide-controls[hidden] { display: none; }
.slide-indicator {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
  min-width: 50px;
  text-align: center;
}

/* Segment PDF controls */
.segment-pdf {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
}
.pdf-checkbox {
  display: flex;
  align-items: center;
  gap: 3px;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 12px;
  white-space: nowrap;
}
.pdf-checkbox input[type="checkbox"] { cursor: pointer; }
.pdf-checkbox input[type="checkbox"]:disabled { opacity: 0.3; cursor: not-allowed; }
.btn-pdf-upload {
  cursor: pointer;
  font-size: 14px;
  padding: 2px 4px;
  border-radius: 4px;
  color: var(--text-dim);
}
.btn-pdf-upload:hover { background: var(--bg-hover); color: var(--text); }
.btn-pdf-upload.content-set {
  color: var(--accent);
  background: rgba(108, 140, 255, 0.12);
}
.pdf-attached {
  font-size: 14px;
}
.btn-pdf-remove {
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 12px;
  padding: 2px 4px;
  border-radius: 4px;
}
.btn-pdf-remove:hover { color: var(--red); background: var(--bg-hover); }
.transport-spacer { flex: 1; }

/* Broadcast & notification tools */
.live-tools {
  margin: 16px 0;
  padding: 12px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.live-tools-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.live-tools-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-dim);
  white-space: nowrap;
}
.live-tools-row input[type="text"] {
  flex: 1;
  min-width: 160px;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 6px 10px;
  border-radius: 6px;
  font-size: 14px;
}
.live-tools-row input[type="text"]:focus { outline: none; border-color: var(--accent); }
.auto-email-label {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  color: var(--text-dim);
  cursor: pointer;
  white-space: nowrap;
}
.notify-status { font-size: 12px; color: var(--green); }
.notify-status.err { color: var(--red); }

/* Agenda Editor */
.agenda-editor { margin-top: 16px; }
.agenda-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.agenda-header h2 { font-size: 18px; }

.agenda-list { display: flex; flex-direction: column; gap: 2px; }

.segment-section-header {
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--accent);
  padding: 12px 8px 4px;
  margin-top: 8px;
}
.segment-section-header:first-child { margin-top: 0; }

.segment-row {
  display: grid;
  grid-template-columns: 36px 1fr 1fr 1fr 80px auto 120px;
  gap: 8px;
  align-items: center;
  padding: 8px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  transition: background 0.15s;
}
.segment-row:hover { background: var(--bg-hover); }
.segment-row.active {
  border-color: var(--green);
  background: rgba(34, 197, 94, 0.08);
}
.segment-row.completed { opacity: 0.5; }

.segment-index {
  font-size: 12px;
  color: var(--text-dim);
  text-align: center;
  font-weight: 600;
}

.segment-row input {
  background: transparent;
  border: 1px solid transparent;
  color: var(--text);
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 14px;
  width: 100%;
}
.segment-row input:focus {
  outline: none;
  border-color: var(--accent);
  background: var(--bg);
}
.segment-note-input {
  font-size: 12px !important;
  color: var(--text-dim) !important;
  font-style: italic;
}
.segment-row input[type="number"] {
  width: 70px;
  text-align: center;
  -moz-appearance: textfield;
}
.segment-row input[type="number"]::-webkit-inner-spin-button { -webkit-appearance: none; }

.segment-actions {
  display: flex;
  gap: 4px;
  justify-content: flex-end;
}
.segment-actions button {
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 16px;
  line-height: 1;
}
.segment-actions button:hover { background: var(--bg-hover); color: var(--text); }
.segment-actions button.delete-btn:hover { color: var(--red); }

.keyboard-hints {
  margin-top: 20px;
  font-size: 12px;
  color: var(--text-dim);
  text-align: center;
  padding: 10px;
  border-top: 1px solid var(--border);
}

/* ===== THEATRE DISPLAY ===== */
.theatre {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 1000;
}
.theatre[hidden] { display: none; }

.progress-bar-container {
  height: 6px;
  background: #1a1a2a;
  width: 100%;
  flex-shrink: 0;
}
.progress-bar {
  height: 100%;
  background: var(--accent);
  width: 0%;
  transition: width 0.5s linear;
}

.theatre-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  padding: 3vh 5vw;
  text-align: center;
}

.theatre-topic {
  font-size: clamp(24px, 4vw, 56px);
  font-weight: 400;
  color: var(--text-dim);
  letter-spacing: 1px;
  text-transform: uppercase;
  margin-bottom: 1vh;
}

.theatre-speaker {
  font-size: clamp(48px, 10vw, 140px);
  font-weight: 700;
  line-height: 1.1;
  margin-bottom: 2vh;
}

.theatre-timer {
  font-size: clamp(80px, 18vw, 260px);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
  line-height: 1;
  color: var(--green);
  transition: color 0.3s;
}

.theatre-timer.amber { color: var(--amber); }
.theatre-timer.red { color: var(--red); }
.theatre-timer.overtime {
  color: var(--red);
  animation: pulse 1s ease-in-out infinite;
}

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

.theatre-next {
  margin-top: 3vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}
.next-label {
  font-size: clamp(12px, 1.5vw, 18px);
  color: var(--text-dim);
  letter-spacing: 2px;
  font-weight: 600;
}
.next-info {
  font-size: clamp(16px, 2.5vw, 32px);
  color: var(--text);
  opacity: 0.7;
}

.theatre-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 20px;
  flex-shrink: 0;
}
.theatre-pace {
  text-align: center;
  font-size: clamp(14px, 2vw, 22px);
  color: var(--text-dim);
  flex: 1;
}
.theatre-pace.ahead { color: var(--green); }
.theatre-pace.behind { color: var(--red); }
.theatre-hard-end {
  font-size: clamp(12px, 1.5vw, 18px);
  color: var(--text-dim);
  text-align: right;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.theatre-hard-end.urgent { color: var(--red); }

/* Theatre QR Code */
.theatre-qr {
  position: fixed;
  bottom: 16px;
  right: 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  z-index: 20;
}
.theatre-qr[hidden] { display: none; }
.theatre-qr-label {
  font-size: clamp(10px, 1.2vw, 15px);
  color: rgba(255,255,255,0.6);
  text-align: center;
  letter-spacing: 0.5px;
  line-height: 1.3;
}
.theatre-qr-speaker {
  font-weight: 700;
  color: rgba(255,255,255,0.85);
}
.theatre-qr canvas {
  border-radius: 6px;
}

/* Event Complete */
.theatre-complete {
  position: absolute;
  inset: 0;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  z-index: 10;
}
.theatre-complete[hidden] { display: none; }
.complete-title {
  font-size: clamp(48px, 8vw, 120px);
  font-weight: 700;
  color: var(--green);
  margin-bottom: 3vh;
}
.complete-stats {
  font-size: clamp(20px, 3vw, 40px);
  color: var(--text-dim);
  line-height: 1.8;
  text-align: center;
}

/* ===== QUESTIONS PANEL ===== */
.questions-panel {
  margin-top: 24px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}
.questions-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}
.questions-header h2 { font-size: 18px; }
.questions-count-badge {
  display: inline-block;
  min-width: 22px;
  padding: 1px 7px;
  margin-left: 6px;
  background: var(--accent);
  color: #fff;
  border-radius: 11px;
  font-size: 12px;
  font-weight: 700;
  text-align: center;
  vertical-align: middle;
}
.questions-count-badge[hidden] { display: none; }
.q-votes {
  display: inline-block;
  font-size: 12px;
  font-weight: 700;
  color: var(--green);
  margin-right: 6px;
}
.questions-header-actions { display: flex; gap: 8px; }
.questions-filter {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
  font-size: 13px;
  color: var(--text-dim);
}
.questions-filter select {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 13px;
}
.questions-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 400px;
  overflow-y: auto;
}
.questions-empty {
  color: var(--text-dim);
  font-size: 14px;
  text-align: center;
  padding: 24px;
}
.question-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 6px;
}
.question-item.q-answered {
  opacity: 0.5;
  border-left: 3px solid var(--green);
}
.q-content { flex: 1; min-width: 0; }
.q-time {
  font-size: 11px;
  color: var(--text-dim);
  margin-right: 8px;
  font-variant-numeric: tabular-nums;
}
.q-topic {
  display: inline-block;
  font-size: 11px;
  color: var(--amber);
  margin-right: 6px;
  padding: 1px 6px;
  background: rgba(245, 158, 11, 0.1);
  border-radius: 3px;
  font-weight: 600;
}
.q-text { font-size: 14px; }
.q-assigned {
  display: inline-block;
  font-size: 11px;
  color: var(--accent);
  margin-left: 8px;
  padding: 1px 6px;
  background: rgba(108, 140, 255, 0.1);
  border-radius: 3px;
}
.q-actions {
  display: flex;
  gap: 4px;
  align-items: center;
  flex-shrink: 0;
}
.q-actions select {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 3px 6px;
  border-radius: 4px;
  font-size: 12px;
}

/* QR Overlay */
.qr-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.8);
  display: flex;
  justify-content: center;
  align-items: flex-start;
  overflow-y: auto;
  padding: 40px 20px;
  z-index: 500;
}
.qr-overlay[hidden] { display: none; }
.qr-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 32px;
  text-align: center;
  max-width: 400px;
  margin: auto;
}
.qr-card h3 {
  margin-bottom: 16px;
  font-size: 18px;
}
.qr-card canvas {
  display: block;
  margin: 0 auto 12px;
  border-radius: 8px;
}
.qr-url {
  font-size: 12px;
  color: var(--text-dim);
  word-break: break-all;
  margin-bottom: 8px;
}
.qr-note {
  font-size: 12px;
  color: var(--text-dim);
  margin-bottom: 16px;
  line-height: 1.5;
}

/* ===== RESPONSIVE ===== */
@media (max-width: 700px) {
  .state-summary { grid-template-columns: repeat(2, 1fr); }
  .segment-row { grid-template-columns: 28px 1fr 80px auto 90px; }
  .segment-note-input { display: none; }
  .segment-row input:nth-child(3) { display: none; } /* hide topic on small */
}
