:root {
  --bg: #0f1115;
  --surface: #181c23;
  --surface-2: #222833;
  --border: #2e3645;
  --text: #eef1f6;
  --muted: #9aa4b5;
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --danger: #dc2626;
  --danger-hover: #b91c1c;
  --ok: #16a34a;
  --warn: #d97706;
  --radius: 12px;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.5;
}

.app {
  min-height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.app.in-call {
  padding: 0;
  display: block;
  height: 100%;
}

.card {
  width: 100%;
  max-width: 560px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
}

.status-card {
  max-width: 440px;
  text-align: center;
}

.status-card h1 {
  margin: 0 0 8px;
  font-size: 1.35rem;
}

.muted {
  color: var(--muted);
  margin: 0;
}

.actions {
  margin-top: 20px;
  display: flex;
  justify-content: center;
  gap: 8px;
}

.prejoin-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.eyebrow {
  margin: 0;
  font-size: 0.78rem;
  color: var(--muted);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.prejoin-header h1 {
  margin: 2px 0 0;
  font-size: 1.3rem;
  word-break: break-word;
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 600;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  white-space: nowrap;
}

.badge-ok {
  border-color: var(--ok);
  color: #86efac;
}

.badge-warn {
  border-color: var(--warn);
  color: #fde68a;
}

.preview-box {
  position: relative;
  aspect-ratio: 16 / 9;
  width: 100%;
  background: #080a0d;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--border);
  margin-bottom: 16px;
}

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

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

.preview-controls {
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: 12px;
  display: flex;
  justify-content: center;
  gap: 8px;
}

.prejoin-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

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

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.85rem;
  color: var(--muted);
}

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

.field input:focus,
.field select:focus {
  outline: 2px solid var(--primary);
  outline-offset: 1px;
}

.error-text {
  margin: 0;
  color: #fca5a5;
  font-size: 0.88rem;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 14px;
  border-radius: 8px;
  border: 1px solid transparent;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  color: var(--text);
  background: var(--surface-2);
  transition: background 0.12s ease;
}

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

.btn-primary {
  background: var(--primary);
}

.btn-primary:hover:not(:disabled) {
  background: var(--primary-hover);
}

.btn-secondary {
  background: var(--surface-2);
  border-color: var(--border);
}

.btn-secondary:hover:not(:disabled) {
  background: #2c3442;
}

.btn-secondary.is-off {
  background: #3a1f24;
  border-color: #7f1d1d;
  color: #fecaca;
}

.btn-secondary.is-active {
  background: #1e3a5f;
  border-color: var(--primary);
  color: #bfdbfe;
}

.btn-danger {
  background: var(--danger);
}

.btn-danger:hover:not(:disabled) {
  background: var(--danger-hover);
}

.btn-warn {
  background: var(--warn);
  color: #111;
}

.btn-full {
  width: 100%;
  padding: 11px 16px;
}

.btn-icon {
  background: transparent;
  border: none;
  color: var(--muted);
  font-size: 1rem;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
}

.btn-icon:hover {
  background: var(--surface-2);
  color: var(--text);
}

.call-layout {
  height: 100dvh;
  display: flex;
  flex-direction: column;
}

.call-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.call-header-left {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  flex-wrap: wrap;
}

.call-header h1 {
  margin: 0;
  font-size: 1rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.call-body {
  flex: 1;
  min-height: 0;
  display: flex;
  overflow: hidden;
}

.stage {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 12px;
  overflow: auto;
}

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

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

.tile {
  position: relative;
  aspect-ratio: 16 / 9;
  background: #141820;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

.tile.is-speaking {
  border-color: var(--primary);
}

.tile.is-screen {
  aspect-ratio: 16 / 9;
  max-height: 62vh;
  background: #050608;
}

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

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

.tile.is-screen video {
  object-fit: contain;
}

.tile-avatar {
  width: 68px;
  height: 68px;
  border-radius: 50%;
  background: var(--surface-2);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text);
}

.tile-label {
  position: absolute;
  left: 10px;
  bottom: 10px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 9px;
  border-radius: 6px;
  background: rgba(10, 12, 16, 0.78);
  font-size: 0.82rem;
  max-width: calc(100% - 20px);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tile-muted {
  color: #fca5a5;
  font-weight: 700;
}

.side-panel {
  width: 320px;
  max-width: 100%;
  background: var(--surface);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

.side-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
}

.side-panel-header h2 {
  margin: 0;
  font-size: 0.95rem;
}

.devices-panel-body {
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

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

.chat-item {
  background: var(--surface-2);
  border-radius: 8px;
  padding: 8px 10px;
}

.chat-meta {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-size: 0.75rem;
  color: var(--muted);
  margin-bottom: 3px;
}

.chat-text {
  margin: 0;
  font-size: 0.9rem;
  white-space: pre-wrap;
  word-break: break-word;
}

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

.chat-form input {
  flex: 1;
  min-width: 0;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 0.9rem;
}

.control-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 8px;
  padding: 10px 14px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.unread-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--primary);
  color: #fff;
  font-size: 0.72rem;
}

@media (max-width: 720px) {
  .side-panel {
    position: fixed;
    inset: 48px 0 60px 0;
    width: auto;
    z-index: 20;
    border-left: none;
  }
}
