/* ===== CSS Variables ===== */
:root {
  --primary: #274546;
  --primary-light: #3a6364;
  --accent: #00BFA6;
  --danger: #EB4B5A;
  --bg-dark: #1a1a2e;
  --bg-card: #ffffff;
  --text-primary: #1a1a2e;
  --text-secondary: #687799;
  --text-white: #ffffff;
  --border: #e2e8f0;
  --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
  --radius: 12px;
}

/* ===== Reset & Base ===== */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html, body {
  height: 100%;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg-dark);
  color: var(--text-primary);
  overflow: hidden;
}

/* ===== Screen System ===== */
.screen {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  justify-content: center;
  align-items: center;
}

.screen.active {
  display: flex;
}

/* ===== Loading Screen ===== */
.loading-container {
  text-align: center;
  color: var(--text-white);
}

.logo {
  margin-bottom: 16px;
}

.loading-container h1 {
  font-size: 28px;
  font-weight: 700;
  margin-bottom: 8px;
}

.subtitle {
  font-size: 16px;
  color: rgba(255, 255, 255, 0.7);
  margin-bottom: 24px;
}

.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid rgba(255, 255, 255, 0.2);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ===== Error Screen ===== */
.error-container {
  text-align: center;
  background: var(--bg-card);
  padding: 48px 40px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  max-width: 420px;
  width: 90%;
}

.error-icon {
  font-size: 48px;
  margin-bottom: 16px;
}

.error-container h2 {
  font-size: 22px;
  margin-bottom: 8px;
  color: var(--danger);
}

.error-container p {
  color: var(--text-secondary);
  margin-bottom: 24px;
  line-height: 1.5;
}

/* ===== Pre-Call Screen ===== */
.precall-container {
  background: var(--bg-card);
  padding: 32px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  max-width: 480px;
  width: 90%;
  text-align: center;
}

.logo-small {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-bottom: 24px;
  font-size: 18px;
  font-weight: 600;
  color: var(--primary);
}

.precall-container h2 {
  font-size: 24px;
  font-weight: 700;
  margin-bottom: 8px;
}

.session-info {
  color: var(--text-secondary);
  margin-bottom: 20px;
  line-height: 1.6;
}

.preview-container {
  position: relative;
  width: 100%;
  height: 240px;
  background: #000;
  border-radius: 8px;
  overflow: hidden;
  margin-bottom: 16px;
}

.preview-container video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scaleX(-1);
}

.preview-placeholder {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  background: #2a2a3e;
  color: rgba(255, 255, 255, 0.6);
}

.preview-placeholder.hidden {
  display: none;
}

.avatar {
  font-size: 48px;
  margin-bottom: 8px;
}

.device-controls {
  display: flex;
  justify-content: center;
  gap: 16px;
  margin-bottom: 20px;
}

.device-btn {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: 2px solid var(--border);
  background: var(--bg-card);
  color: var(--primary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
}

.device-btn.active {
  background: var(--primary);
  color: var(--text-white);
  border-color: var(--primary);
}

.device-btn:hover {
  transform: scale(1.05);
}

.name-input-group {
  margin-bottom: 20px;
  text-align: left;
}

.name-input-group label {
  display: block;
  font-size: 14px;
  font-weight: 500;
  margin-bottom: 6px;
  color: var(--text-secondary);
}

.name-input-group input {
  width: 100%;
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 16px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.2s;
}

.name-input-group input:focus {
  border-color: var(--primary);
}

/* ===== Buttons ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 12px 24px;
  border: none;
  border-radius: 8px;
  font-size: 16px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.2s ease;
  text-decoration: none;
}

.btn-primary {
  background: var(--primary);
  color: var(--text-white);
}

.btn-primary:hover {
  background: var(--primary-light);
  transform: translateY(-1px);
}

.btn-large {
  width: 100%;
  padding: 14px;
  font-size: 17px;
}

/* ===== In-Call Screen ===== */
.call-container {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  background: #0f0f1a;
}

/* ===== In-call session-context header (web-join) ===== */
.call-header {
  padding: 10px 16px;
  background: #16161f;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  text-align: center;
  flex-shrink: 0;
}
.call-header-title {
  color: var(--text-white);
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.01em;
}
.call-header-sub {
  color: rgba(255, 255, 255, 0.6);
  font-size: 13px;
  margin-top: 2px;
}
.call-header-dot { margin: 0 6px; opacity: 0.6; }

/* Pre-call session-type badge */
.session-badge {
  display: inline-block;
  margin: 4px 0 8px;
  padding: 4px 12px;
  border-radius: 999px;
  background: rgba(0, 191, 166, 0.12);
  color: var(--accent);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.video-grid {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr;
  grid-template-rows: 1fr;
  position: relative;
  gap: 0;
}

.video-container {
  position: relative;
  overflow: hidden;
  background: #1a1a2e;
}

.video-container.remote {
  width: 100%;
  height: 100%;
}

.video-container.local {
  position: absolute;
  bottom: 80px;
  right: 16px;
  width: 160px;
  height: 120px;
  border-radius: 12px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  z-index: 10;
  overflow: hidden;
}

.video-player {
  width: 100%;
  height: 100%;
}

.video-player video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.video-placeholder {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  background: #1a1a2e;
  color: rgba(255, 255, 255, 0.6);
  z-index: 1;
}

.video-placeholder.hidden {
  display: none;
}

.avatar-large {
  font-size: 80px;
  margin-bottom: 16px;
}

.avatar-small {
  font-size: 32px;
}

.video-label {
  position: absolute;
  bottom: 8px;
  left: 8px;
  background: rgba(0, 0, 0, 0.6);
  color: white;
  padding: 4px 10px;
  border-radius: 4px;
  font-size: 13px;
  font-weight: 500;
  z-index: 5;
}

/* ===== Call Timer ===== */
.call-timer {
  position: absolute;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.6);
  color: white;
  padding: 6px 16px;
  border-radius: 20px;
  font-size: 14px;
  font-weight: 500;
  z-index: 20;
  font-variant-numeric: tabular-nums;
}

/* ===== Call Controls ===== */
.call-controls {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 20px;
  padding: 16px;
  background: rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(10px);
  z-index: 20;
}

.control-btn {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  color: white;
  background: rgba(255, 255, 255, 0.2);
}

.control-btn.active {
  background: rgba(255, 255, 255, 0.2);
}

.control-btn:not(.active):not(.end-call) {
  background: var(--danger);
}

.control-btn:hover {
  transform: scale(1.08);
}

.control-btn.end-call {
  background: var(--danger);
  width: 60px;
  height: 60px;
}

.control-btn.end-call:hover {
  background: #d63440;
}

/* ===== Call Ended Screen ===== */
.ended-container {
  text-align: center;
  background: var(--bg-card);
  padding: 48px 40px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  max-width: 420px;
  width: 90%;
}

.checkmark {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: var(--accent);
  color: white;
  font-size: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 16px;
}

.ended-container h2 {
  font-size: 22px;
  margin-bottom: 8px;
}

.ended-container p {
  color: var(--text-secondary);
  margin-bottom: 8px;
}

.ended-message {
  margin-bottom: 24px !important;
}

/* ===== Responsive ===== */
@media (max-width: 480px) {
  .precall-container {
    padding: 24px 20px;
    border-radius: 0;
    max-width: 100%;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: center;
  }

  .preview-container {
    height: 200px;
  }

  .video-container.local {
    width: 120px;
    height: 90px;
    bottom: 90px;
    right: 12px;
  }

  .call-controls {
    padding: 12px;
    gap: 16px;
  }

  .control-btn {
    width: 46px;
    height: 46px;
  }

  .control-btn.end-call {
    width: 54px;
    height: 54px;
  }
}

@media (min-width: 768px) {
  .video-container.local {
    width: 240px;
    height: 180px;
    bottom: 100px;
    right: 24px;
  }
}

/* Identity-bound login screen */
.login-error {
  color: #dc2626;
  font-size: 14px;
  margin: 4px 0 8px;
  text-align: center;
}

/* Small helper text under a login field */
.input-hint {
  font-size: 12px;
  color: #6b7280;
  margin: 6px 0 0;
  line-height: 1.4;
}

/* Ended-screen in-app review nudge */
.review-prompt {
  font-size: 14px;
  color: #274546;
  background: #eef6f2;
  border-radius: 12px;
  padding: 12px 16px;
  margin: 4px 0 20px;
  line-height: 1.45;
  max-width: 340px;
}
