:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #eef1f5;
  --border: #dde1e8;
  --text: #1c2230;
  --muted: #6b7280;
  --accent: #c9781f;
  --accent-strong: #a8630f;
  --accent-soft: rgba(201, 120, 31, 0.12);
  --state-active: #2f6fed;
  --danger: #c62828;
  --radius: 14px;
  --font-display: 'Noto Sans', sans-serif;
  --font-body: 'Noto Sans', sans-serif;
}

* { box-sizing: border-box; }

/* [hidden] muss IMMER gewinnen, auch gegen Klassenregeln mit eigenem
   display-Wert (z.B. .screen, .preview-error) – sonst bleiben Elemente
   trotz hidden-Attribut sichtbar. */
[hidden] {
  display: none !important;
}

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

button, input, select { font-family: inherit; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 24px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.05rem;
  letter-spacing: 0.01em;
}

.prejoin-logo {
  display: block;
  height: 36px;
  width: auto;
  object-fit: contain;
  margin: 0 auto 16px;
}

/* Der Raum-Code wird wie ein Zutritts-Badge dargestellt — das
   wiederkehrende Signaturelement der Anwendung. */
.room-badge {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px 14px 6px 10px;
}

.room-badge-label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.room-badge-code {
  font-family: var(--font-display);
  font-weight: 600;
  letter-spacing: 0.03em;
  color: var(--accent-strong);
}

.screen {
  min-height: calc(100vh - 66px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

/* ---------- Prejoin ---------- */

.prejoin-card {
  width: 100%;
  max-width: 420px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 28px;
  box-shadow: 0 1px 2px rgba(20, 24, 33, 0.04), 0 12px 32px rgba(20, 24, 33, 0.06);
}

.prejoin-card h1 {
  font-family: var(--font-display);
  font-size: 1.5rem;
  margin: 0 0 4px;
  text-align: center;
}

.sub {
  color: var(--muted);
  margin: 0 0 20px;
  font-size: 0.92rem;
  text-align: center;
}

.preview-wrap {
  position: relative;
  aspect-ratio: 4 / 3;
  background: var(--surface-2);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 18px;
  border: 1px solid var(--border);
}

.preview-video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scaleX(-1);
  background: var(--surface-2);
}

.preview-off {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-size: 0.85rem;
}

.preview-error {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 16px;
  color: var(--danger);
  font-size: 0.85rem;
  background: rgba(255, 255, 255, 0.95);
}

.field {
  margin-bottom: 14px;
}

.field label {
  display: block;
  font-size: 0.78rem;
  color: var(--muted);
  margin-bottom: 6px;
}

.field input,
.field select {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 0.92rem;
}

.field input:focus,
.field select:focus {
  border-color: var(--accent);
}

.device-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.preview-controls {
  position: absolute;
  left: 50%;
  bottom: 12px;
  transform: translateX(-50%);
  z-index: 2;
  display: flex;
  gap: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px;
  box-shadow: 0 8px 24px rgba(20, 24, 33, 0.12);
}

.join-btn {
  width: 100%;
  background: var(--accent);
  color: #241505;
  font-weight: 600;
  border: none;
  border-radius: 12px;
  padding: 13px;
  font-size: 0.95rem;
  cursor: pointer;
  transition: background 0.15s ease, opacity 0.15s ease;
}

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

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

.status-line {
  min-height: 18px;
  text-align: center;
  font-size: 0.8rem;
  color: var(--muted);
  margin: 10px 0 0;
}

.status-line.error { color: var(--danger); }

/* ---------- Call screen ---------- */

#callScreen {
  display: flex;
  flex-direction: column;
  padding: 16px 16px 100px;
  align-items: stretch;
}

.grid {
  flex: 1;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 12px;
  align-content: start;
}

.tile {
  position: relative;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  aspect-ratio: 4 / 3;
  overflow: hidden;
}

.tile.speaking {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-soft);
}

.tile video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.tile.local video { transform: scaleX(-1); }

.tile .avatar {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-display);
  font-size: 1.8rem;
  font-weight: 600;
  color: var(--muted);
  background: var(--surface-2);
}

.tile .name-tag {
  position: absolute;
  left: 10px;
  bottom: 10px;
  background: rgba(255, 255, 255, 0.9);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.78rem;
  display: flex;
  align-items: center;
  gap: 6px;
}

.tile .mic-off-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--danger);
}

.host-badge {
  background: var(--accent);
  color: #241505;
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 2px 6px;
  border-radius: 999px;
}

.tile.screen-tile {
  grid-column: 1 / -1;
  aspect-ratio: 16 / 9;
}

.tile.screen-tile video {
  object-fit: contain;
  background: #0d0f14;
}

.controlbar {
  position: fixed;
  left: 50%;
  bottom: 22px;
  transform: translateX(-50%);
  display: flex;
  gap: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 8px;
  box-shadow: 0 12px 32px rgba(20, 24, 33, 0.1);
  z-index: 5;
}

.ctrl-btn {
  position: relative;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: none;
  background: var(--surface-2);
  color: var(--text);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
}

.ctrl-btn:not(.active):not(.off):not(.leave) { background: var(--surface-2); color: var(--text); }
.ctrl-btn.active { background: var(--state-active); color: #fff; }
.ctrl-btn.off { background: var(--danger); color: #fff; }
.ctrl-btn.leave { background: var(--danger); color: #fff; }

.ctrl-btn.has-unread::after {
  content: '';
  position: absolute;
  top: 4px;
  right: 4px;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--danger);
  border: 2px solid var(--surface);
}

.ctrl-btn-sm {
  width: 40px;
  height: 40px;
}

.ctrl-btn svg {
  width: 20px;
  height: 20px;
  display: block;
}

.ctrl-btn-sm svg {
  width: 18px;
  height: 18px;
}

/* ---------- Geräteauswahl im Call (Dropdown-Pfeile an Mikro/Kamera) ---------- */

.ctrl-combo {
  position: relative;
  display: flex;
  align-items: stretch;
}

.ctrl-combo .ctrl-btn {
  border-top-right-radius: 0;
  border-bottom-right-radius: 0;
}

.ctrl-caret {
  width: 18px;
  border: none;
  border-top-right-radius: 24px;
  border-bottom-right-radius: 24px;
  background: var(--surface-2);
  color: var(--text);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-left: 1px;
}

.ctrl-combo:has(.ctrl-btn.active) .ctrl-caret {
  background: var(--state-active);
  color: #fff;
}

.ctrl-combo:has(.ctrl-btn.off) .ctrl-caret {
  background: var(--danger);
  color: #fff;
}

.device-menu {
  position: absolute;
  bottom: 58px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 6px;
  min-width: 200px;
  max-width: 260px;
  box-shadow: 0 12px 32px rgba(20, 24, 33, 0.12);
  z-index: 15;
  display: none;
  flex-direction: column;
  gap: 2px;
}

.device-menu.open {
  display: flex;
}

.device-menu-item {
  text-align: left;
  background: none;
  border: none;
  padding: 8px 10px;
  border-radius: 8px;
  font-size: 0.85rem;
  color: var(--text);
  cursor: pointer;
}

.device-menu-item:hover {
  background: var(--surface-2);
}

.device-menu-item.selected {
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-weight: 600;
}

.device-menu-item.off-option {
  color: var(--danger);
}

/* ---------- Chat ---------- */

.chat-panel {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: 320px;
  max-width: 85vw;
  background: var(--surface);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform 0.2s ease;
  z-index: 20;
  box-shadow: -8px 0 24px rgba(20, 24, 33, 0.08);
}

.chat-panel.open {
  transform: translateX(0);
}

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  font-family: var(--font-display);
  font-weight: 600;
}

.chat-close {
  background: none;
  border: none;
  font-size: 1.3rem;
  line-height: 1;
  color: var(--muted);
  cursor: pointer;
  padding: 4px 8px;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.chat-msg {
  max-width: 88%;
  background: var(--surface-2);
  border-radius: 12px;
  padding: 8px 10px;
}

.chat-msg.local {
  align-self: flex-end;
  background: var(--accent-soft);
}

.chat-msg-meta {
  font-size: 0.7rem;
  color: var(--muted);
  margin-bottom: 2px;
}

.chat-msg-text {
  font-size: 0.88rem;
  white-space: pre-wrap;
  word-break: break-word;
}

.chat-form {
  display: flex;
  gap: 8px;
  padding: 12px;
  border-top: 1px solid var(--border);
}

.chat-form input {
  flex: 1;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 9px 12px;
  font-size: 0.88rem;
  color: var(--text);
}

.chat-form button {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  border: none;
  background: var(--accent);
  color: #241505;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
}

.chat-form button svg {
  width: 18px;
  height: 18px;
}

.copy-toast {
  position: fixed;
  left: 50%;
  bottom: 84px;
  transform: translateX(-50%);
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 6px 14px;
  border-radius: 999px;
  font-size: 0.8rem;
  color: var(--accent-strong);
  box-shadow: 0 4px 16px rgba(20, 24, 33, 0.08);
}

.tile .kick-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: none;
  background: rgba(198, 40, 40, 0.9);
  color: #fff;
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

@media (max-width: 480px) {
  .device-row { grid-template-columns: 1fr; }
  .topbar { padding: 14px 16px; }
  .controlbar { gap: 6px; padding: 6px; }
  .ctrl-btn { width: 42px; height: 42px; }
  .chat-panel { width: 100%; max-width: 100%; }
}
