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

:root {
  --bg: #0f0f13;
  --surface: #1a1a24;
  --border: #2a2a3a;
  --text: #f0f0f8;
  --muted: #8888aa;
  --accent: #7c6af7;
  --accent-hover: #9d8fff;
  --success: #4ade80;
  --danger: #f87171;
  --warning: #fbbf24;
  --radius: 12px;
  --radius-sm: 8px;
}

body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
}

h1, h2, h3 {
  font-weight: 700;
  letter-spacing: -0.02em;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 20px;
  border-radius: var(--radius-sm);
  border: none;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
}

.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
}
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }

.btn-success {
  background: #166534;
  color: var(--success);
  border: 1px solid #166534;
}
.btn-success:hover:not(:disabled) { background: #15803d; }

.btn-danger {
  background: #7f1d1d;
  color: var(--danger);
  border: 1px solid #7f1d1d;
}
.btn-danger:hover:not(:disabled) { background: #991b1b; }

.btn-ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
}
.btn-ghost:hover:not(:disabled) {
  background: var(--surface);
  color: var(--text);
}

.btn-warning {
  background: #78350f;
  color: var(--warning);
  border: 1px solid #78350f;
}
.btn-warning:hover:not(:disabled) { background: #92400e; }

/* Inputs */
input[type="text"],
input[type="password"] {
  width: 100%;
  padding: 12px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 16px;
  outline: none;
  transition: border-color 0.15s;
}
input:focus {
  border-color: var(--accent);
}
input::placeholder { color: var(--muted); }

/* Cards */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
}

/* Status dot */
.status-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--muted);
}
.status-dot.connected { background: var(--success); }
.status-dot.disconnected { background: var(--danger); }

/* Spinner */
.spinner {
  width: 24px;
  height: 24px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Poll page */
.poll-container {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.poll-header {
  text-align: center;
  margin-bottom: 48px;
}

.poll-header h1 {
  font-size: clamp(24px, 5vw, 36px);
  background: linear-gradient(135deg, #7c6af7, #a78bfa);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.poll-card {
  width: 100%;
  max-width: 720px;
}

.question-text {
  font-size: clamp(20px, 4vw, 28px);
  font-weight: 700;
  text-align: center;
  margin-bottom: 32px;
  line-height: 1.3;
}

.answer-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.answer-form .btn {
  font-size: 16px;
  padding: 14px;
  justify-content: center;
}

.name-select-wrap {
  position: relative;
}

.name-search {
  width: 100%;
  padding: 14px 18px;
  font-size: 18px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  outline: none;
  transition: border-color 0.15s;
}
.name-search:focus {
  border-color: var(--accent);
}
.name-search::placeholder { color: var(--muted); }

.name-selected {
  padding: 14px 18px;
  font-size: 18px;
  font-weight: 600;
  background: rgba(124, 106, 247, 0.15);
  border: 1px solid var(--accent);
  border-radius: var(--radius-sm);
  color: #a78bfa;
  cursor: pointer;
  transition: background 0.15s;
}
.name-selected:hover {
  background: rgba(124, 106, 247, 0.22);
}

.name-dropdown {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  max-height: 260px;
  overflow-y: auto;
  z-index: 50;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
}

.name-dropdown-item {
  padding: 12px 18px;
  font-size: 16px;
  cursor: pointer;
  transition: background 0.1s;
  border-bottom: 1px solid var(--border);
}
.name-dropdown-item:last-child {
  border-bottom: none;
}
.name-dropdown-item:hover {
  background: rgba(124, 106, 247, 0.12);
  color: #a78bfa;
}

.waiting-state {
  text-align: center;
  padding: 48px 0;
}

.waiting-state .spinner {
  width: 40px;
  height: 40px;
  margin: 0 auto 16px;
}

.waiting-state p {
  color: var(--muted);
  font-size: 18px;
}

.submitted-state {
  text-align: center;
  padding: 24px 0;
}

.submitted-state .check {
  font-size: 48px;
  margin-bottom: 12px;
}

.submitted-state p {
  color: var(--muted);
}

/* Admin page */
.admin-layout {
  display: grid;
  grid-template-columns: 320px 1fr;
  min-height: 100vh;
}

.admin-sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  overflow-y: auto;
}

.admin-main {
  padding: 32px;
  overflow-y: auto;
}

.admin-logo {
  font-size: 20px;
  font-weight: 800;
  background: linear-gradient(135deg, #7c6af7, #a78bfa);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.section-title {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--muted);
  margin-bottom: 10px;
}

.question-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  border: 1px solid transparent;
  transition: all 0.15s;
  font-size: 14px;
}
.question-item:hover { background: rgba(124,106,247,0.08); }
.question-item.active {
  background: rgba(124,106,247,0.15);
  border-color: rgba(124,106,247,0.4);
  color: #a78bfa;
}

.question-item-text {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.q-type-badge {
  font-size: 10px;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 4px;
  flex-shrink: 0;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.q-type-professor {
  background: rgba(251, 191, 36, 0.15);
  color: var(--warning);
}
.q-type-open {
  background: rgba(124, 106, 247, 0.12);
  color: var(--accent);
}

.question-item-del {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  padding: 2px 4px;
  border-radius: 4px;
  font-size: 16px;
  line-height: 1;
  transition: color 0.15s;
  flex-shrink: 0;
}
.question-item-del:hover { color: var(--danger); }

.add-question-form {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.stat-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 16px 20px;
  text-align: center;
}

.stat-number {
  font-size: 48px;
  font-weight: 800;
  color: var(--accent);
  line-height: 1;
}

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

.control-grid {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.admin-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 28px;
}

.connection-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--muted);
}

.current-q-label {
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 8px;
}

.current-q-text {
  font-size: 22px;
  font-weight: 700;
  margin-bottom: 24px;
  padding: 16px 20px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  line-height: 1.3;
}

.no-question-msg {
  color: var(--muted);
  font-style: italic;
  font-size: 16px;
  text-align: center;
  padding: 40px;
}

.admin-links {
  margin-top: 16px;
  display: flex;
  gap: 10px;
}

.revealed-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 100px;
  font-size: 12px;
  font-weight: 600;
}
.revealed-badge.shown {
  background: rgba(74, 222, 128, 0.15);
  color: var(--success);
}
.revealed-badge.hidden {
  background: rgba(251, 191, 36, 0.15);
  color: var(--warning);
}

/* Auth overlay */
.auth-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.auth-box {
  width: 100%;
  max-width: 360px;
  padding: 40px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.auth-box h2 {
  margin-bottom: 8px;
}

.auth-box p {
  color: var(--muted);
  font-size: 14px;
  margin-bottom: 24px;
}

.auth-error {
  color: var(--danger);
  font-size: 13px;
  margin-top: 8px;
}

/* Brand */
.brand-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  margin-bottom: 16px;
}

.brand-logo {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  object-fit: contain;
  flex-shrink: 0;
  display: block;
}

.brand-logo-sm {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  object-fit: contain;
  flex-shrink: 0;
}

.brand-text {
  display: flex;
  flex-direction: column;
  text-align: left;
}

.brand-dept {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}

.brand-inst {
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-top: 2px;
}

.admin-brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.results-brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.results-subtitle {
  font-size: 11px;
  color: rgba(255,255,255,0.35);
  margin-top: 3px;
  letter-spacing: 0.04em;
}

/* Results page */
.results-page {
  width: 100vw;
  height: 100vh;
  overflow: hidden;
  background: #08080f;
  background-image: radial-gradient(circle, rgba(124,106,247,0.07) 1px, transparent 1px);
  background-size: 28px 28px;
  display: flex;
  flex-direction: column;
}

.results-header {
  padding: 20px 32px 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid rgba(255,255,255,0.05);
}

.results-header h1 {
  font-size: 18px;
  background: linear-gradient(135deg, #7c6af7, #a78bfa);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.results-question {
  font-size: clamp(18px, 3vw, 28px);
  font-weight: 700;
  text-align: center;
  padding: 20px 32px 0;
  line-height: 1.3;
  color: rgba(255,255,255,0.9);
}

#bubble-chart {
  flex: 1;
  width: 100%;
}

.waiting-screen {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  color: rgba(255,255,255,0.3);
}

.waiting-screen .spinner {
  width: 32px;
  height: 32px;
}

.waiting-screen p {
  font-size: 20px;
}

#qr-code {
  border-radius: 16px;
  overflow: hidden;
  box-shadow: 0 0 0 10px #0d0d18, 0 0 0 12px rgba(124,106,247,0.25);
}

#qr-code img,
#qr-code canvas {
  display: block;
}

.qr-label {
  font-size: 22px !important;
  font-weight: 700;
  color: rgba(255,255,255,0.85) !important;
  margin-top: 4px;
}

.qr-url {
  font-size: 13px;
  color: rgba(255,255,255,0.35);
  letter-spacing: 0.04em;
  margin-top: -8px;
}

.waiting-footer {
  display: flex;
  align-items: center;
  gap: 12px;
  color: rgba(255,255,255,0.25);
  font-size: 15px;
  margin-top: 12px;
}

@media (max-width: 768px) {
  .admin-layout {
    grid-template-columns: 1fr;
  }
  .admin-sidebar {
    border-right: none;
    border-bottom: 1px solid var(--border);
    max-height: 50vh;
  }
}
