/* ── Variables ───────────────────────────────────────────────────────────── */
:root {
  --bg: #0d1117;
  --bg2: #161b22;
  --bg3: #1c2128;
  --accent: #2563eb;
  --accent-h: #1d4ed8;
  --text: #e6edf3;
  --text2: #8b949e;
  --border: #30363d;
  --speak: #22c55e;
  --danger: #ef4444;
  --radius: 12px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bot: env(safe-area-inset-bottom, 0px);
}

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

html, body {
  height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

body {
  padding-top: var(--safe-top);
  padding-bottom: var(--safe-bot);
}

#app { min-height: 100dvh; display: flex; flex-direction: column; }

.screen { display: flex; flex-direction: column; flex: 1 1 auto; }
.screen.d-none { display: none !important; }

/* ── Typography ─────────────────────────────────────────────────────────── */
a { color: var(--accent); }
.text-secondary { color: var(--text2) !important; }

/* ── Screen header ──────────────────────────────────────────────────────── */
.screen-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 0 4px;
}
.screen-title {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 600;
}
.btn-back {
  background: none;
  border: none;
  color: var(--text);
  font-size: 1.25rem;
  cursor: pointer;
  padding: 4px;
  line-height: 1;
  display: flex;
  align-items: center;
  opacity: .75;
}
.btn-back:hover { opacity: 1; }

/* ── Logo / Home ────────────────────────────────────────────────────────── */
.logo-wrap { text-align: center; }

.logo-icon {
  font-size: 4rem;
  color: var(--accent);
  display: block;
  line-height: 1;
}

.app-title {
  font-size: 2rem;
  font-weight: 700;
  letter-spacing: -0.5px;
  margin: 8px 0 4px;
  background: linear-gradient(135deg, #60a5fa, #818cf8);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

/* ── Forms ───────────────────────────────────────────────────────────────── */
.form-wrap { max-width: 480px; width: 100%; }

.form-control, .form-select {
  background: var(--bg3) !important;
  border: 1px solid var(--border) !important;
  color: var(--text) !important;
  border-radius: 8px !important;
}
.form-control:focus, .form-select:focus {
  border-color: var(--accent) !important;
  box-shadow: 0 0 0 3px rgba(37,99,235,.25) !important;
  outline: none !important;
}
.form-control::placeholder { color: var(--text2) !important; }
.form-label { color: var(--text2); font-size: .875rem; margin-bottom: 6px; }
.form-check-input { background-color: var(--bg3) !important; border-color: var(--border) !important; }
.form-check-input:checked { background-color: var(--accent) !important; border-color: var(--accent) !important; }
.form-check-label { color: var(--text); }

/* ── Buttons ─────────────────────────────────────────────────────────────── */
.btn-primary {
  background: var(--accent) !important;
  border-color: var(--accent) !important;
  border-radius: 10px !important;
  font-weight: 600;
  transition: background .15s, transform .1s;
}
.btn-primary:hover { background: var(--accent-h) !important; }
.btn-primary:active { transform: scale(.97); }

.btn-outline-secondary {
  border-color: var(--border) !important;
  color: var(--text2) !important;
  border-radius: 10px !important;
}
.btn-outline-secondary:hover { background: var(--bg3) !important; color: var(--text) !important; }

.btn-outline-danger { border-radius: 10px !important; }

/* Loading state */
.btn-loading .btn-text { display: none; }
.btn-loading .spinner-border { display: inline-block !important; }

/* ── Info cards (Invite screen) ──────────────────────────────────────────── */
.info-card {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
}
.info-label { font-size: .75rem; text-transform: uppercase; letter-spacing: .05em; color: var(--text2); }
.pin-display {
  font-size: 2rem;
  font-weight: 700;
  letter-spacing: .3em;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

/* ── Room title (Join screen) ────────────────────────────────────────────── */
.room-title {
  font-size: 1rem;
  color: var(--text2);
  padding: 10px 14px;
  background: var(--bg3);
  border-radius: 8px;
  border-left: 3px solid var(--accent);
}

/* ── Conference layout ───────────────────────────────────────────────────── */
.conference-screen {
  height: 100dvh;
  overflow: hidden;
}

.conference-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  padding-top: calc(12px + var(--safe-top));
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.conf-title {
  font-size: .9rem;
  font-weight: 600;
  color: var(--text);
  max-width: 60%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.conf-timer {
  font-size: .875rem;
  font-variant-numeric: tabular-nums;
  color: var(--text2);
  background: var(--bg3);
  padding: 3px 10px;
  border-radius: 20px;
  border: 1px solid var(--border);
}

/* ── Participants grid ───────────────────────────────────────────────────── */
.participants-grid {
  display: flex;
  flex-wrap: wrap;
  align-content: flex-start;
  gap: 12px;
  padding: 16px;
  overflow-y: auto;
  flex: 1 1 auto;
}

.participant-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  width: calc(33.333% - 8px);
  min-width: 80px;
  max-width: 120px;
  position: relative;
}

@media (min-width: 480px) {
  .participant-card { width: calc(20% - 10px); }
}
@media (min-width: 768px) {
  .participant-card { width: calc(16.6% - 10px); }
}

.avatar {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: var(--bg3);
  border: 2px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text);
  transition: border-color .2s, box-shadow .2s;
  position: relative;
  user-select: none;
}

/* Speaking indicator */
.participant-card.speaking .avatar {
  border-color: var(--speak);
  box-shadow: 0 0 0 3px rgba(34,197,94,.35), 0 0 12px rgba(34,197,94,.2);
}

/* Muted indicator */
.participant-card.muted .avatar::after {
  content: '';
  position: absolute;
  bottom: 0;
  right: 0;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--danger);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='white'%3E%3Cpath d='M13 8s0 .6-.1.9L12 8l1-.9zm-5 4.8A4 4 0 0 1 4 9H3a5 5 0 0 0 4.5 4.9v1.1h-2v1h5v-1h-2v-1.2zM8 1a3 3 0 0 0-3 3v4a3 3 0 0 0 .1.7l6-5.4A3 3 0 0 0 8 1z'/%3E%3Cpath d='M1.5 1.5L14 14.5l-.7.7L.8 2.2z'/%3E%3C/svg%3E");
  background-size: 11px;
  background-repeat: no-repeat;
  background-position: center;
  border: 2px solid var(--bg);
}

.participant-name {
  font-size: .7rem;
  color: var(--text2);
  text-align: center;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.participant-name .you-badge {
  color: var(--accent);
  font-size: .65rem;
}

/* ── Conference footer ───────────────────────────────────────────────────── */
.conference-footer {
  display: flex;
  justify-content: space-around;
  align-items: flex-start;
  padding: 12px 8px;
  padding-bottom: calc(12px + var(--safe-bot));
  background: var(--bg2);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.action-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 12px;
  color: var(--text);
  cursor: pointer;
  padding: 10px 16px;
  min-width: 60px;
  transition: background .15s, opacity .15s;
  font-size: .75rem;
  line-height: 1;
}
.action-btn i { font-size: 1.25rem; }
.action-btn:hover { background: var(--border); }
.action-btn:disabled { opacity: .4; cursor: default; }
.action-btn:disabled:hover { background: var(--bg3); }

.action-btn.muted {
  background: rgba(239,68,68,.15);
  border-color: var(--danger);
  color: var(--danger);
}

.action-btn-danger {
  background: rgba(239,68,68,.15) !important;
  border-color: var(--danger) !important;
  color: var(--danger) !important;
}
.action-btn-danger:hover { background: rgba(239,68,68,.3) !important; }

/* ── Waiting screen ──────────────────────────────────────────────────────── */
.waiting-dots {
  display: flex;
  gap: 8px;
  justify-content: center;
}
.waiting-dots span {
  width: 10px; height: 10px;
  border-radius: 50%;
  background: var(--accent);
  animation: bounce 1.2s infinite ease-in-out;
}
.waiting-dots span:nth-child(2) { animation-delay: .2s; }
.waiting-dots span:nth-child(3) { animation-delay: .4s; }

@keyframes bounce {
  0%, 80%, 100% { transform: scale(0.7); opacity: .5; }
  40% { transform: scale(1); opacity: 1; }
}

/* ── Modal (join by link) ────────────────────────────────────────────────── */
.modal-content {
  background: var(--bg2) !important;
  border: 1px solid var(--border) !important;
  border-radius: var(--radius) !important;
}
.modal-header, .modal-footer { border-color: var(--border) !important; }

/* ── Offcanvas (participants) ────────────────────────────────────────────── */
.offcanvas {
  background: var(--bg2) !important;
  border-left: 1px solid var(--border) !important;
}
.offcanvas-title { color: var(--text) !important; }

.participant-list-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}
.participant-list-item:last-child { border-bottom: none; }

.mini-avatar {
  width: 36px; height: 36px;
  border-radius: 50%;
  background: var(--bg3);
  border: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  font-size: .85rem; font-weight: 700;
  flex-shrink: 0;
}
.mini-avatar.speaking { border-color: var(--speak); }

.participant-list-info { flex: 1; min-width: 0; }
.participant-list-name { font-size: .875rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.participant-list-role { font-size: .7rem; color: var(--text2); }

.pending-section { margin-top: 16px; }
.pending-section h6 { color: var(--text2); font-size: .75rem; text-transform: uppercase; letter-spacing: .05em; margin-bottom: 8px; }

.pending-item {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.pending-item-name { flex: 1; font-size: .875rem; }
.pending-actions { display: flex; gap: 6px; }

/* ── Toast ───────────────────────────────────────────────────────────────── */
.toast-container { z-index: 9999; }

/* ── Alerts ──────────────────────────────────────────────────────────────── */
.alert {
  border-radius: 8px !important;
  font-size: .875rem;
}
.alert-danger {
  background: rgba(239,68,68,.1) !important;
  border-color: rgba(239,68,68,.3) !important;
  color: #fca5a5 !important;
}

/* ── Raise hand ──────────────────────────────────────────────────────────── */
.participant-card.hand-raised .avatar {
  border-color: #f59e0b;
  box-shadow: 0 0 0 3px rgba(245,158,11,.3), 0 0 12px rgba(245,158,11,.15);
  animation: hand-pulse 2s ease-in-out infinite;
}

@keyframes hand-pulse {
  0%, 100% { box-shadow: 0 0 0 3px rgba(245,158,11,.3), 0 0 12px rgba(245,158,11,.15); }
  50%       { box-shadow: 0 0 0 5px rgba(245,158,11,.45), 0 0 20px rgba(245,158,11,.25); }
}

.hand-icon {
  position: absolute;
  top: -5px;
  right: -5px;
  font-size: 1.1rem;
  line-height: 1;
  animation: hand-wave 1.2s ease-in-out infinite;
  pointer-events: none;
}

@keyframes hand-wave {
  0%, 100% { transform: rotate(0deg); }
  25%       { transform: rotate(18deg); }
  75%       { transform: rotate(-12deg); }
}

#btn-hand.active {
  background: rgba(245,158,11,.15) !important;
  border-color: #f59e0b !important;
  color: #f59e0b !important;
}

/* ── Chat panel ──────────────────────────────────────────────────────────── */
#chat-panel {
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: var(--bg2);
  border-top: 1px solid var(--border);
  padding: 8px 12px;
  flex-shrink: 0;
  max-height: 260px;
}

#chat-messages {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 172px;
  overflow-y: auto;
  padding-right: 2px;
}

.chat-input-row {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-shrink: 0;
}
.chat-input-row .form-control { flex: 1; }
.chat-input-row .btn { flex-shrink: 0; }

.chat-msg {
  align-self: flex-start;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 5px 10px;
  max-width: 85%;
  font-size: .8rem;
  line-height: 1.35;
  word-break: break-word;
}
.chat-msg .chat-author {
  font-size: .68rem;
  font-weight: 600;
  color: var(--accent);
  margin-bottom: 2px;
}
.chat-msg.self {
  align-self: flex-end;
  background: rgba(37,99,235,.18);
  border-color: rgba(37,99,235,.35);
}
.chat-msg.self .chat-author { color: #93c5fd; }

/* ── Scrollbar ───────────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

/* ── Clickable card (admin grants voice by tapping avatar) ───────────────── */
.participant-card.clickable-card { cursor: pointer; }
.participant-card.clickable-card:hover .avatar,
.participant-card.clickable-card:active .avatar {
  border-color: #22c55e;
  box-shadow: 0 0 0 3px rgba(34,197,94,.3);
}

/* ── Recording ───────────────────────────────────────────────────────────── */
#btn-record.recording {
  background: rgba(239,68,68,.15) !important;
  border-color: #ef4444 !important;
  color: #ef4444 !important;
}

.rec-indicator {
  animation: rec-pulse 1.5s ease-in-out infinite;
}

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