/* ============================================================
   Говорить Семья — Styles
   ============================================================ */

/* -----------------------------------------------------------
   RESET & BASE
   ----------------------------------------------------------- */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --primary: #4a90d9;
  --primary-dark: #3a7bc8;
  --danger: #e74c3c;
  --danger-dark: #c0392b;
  --bg: #0f1923;
  --bg-card: #1a2737;
  --bg-surface: #243447;
  --text: #ecf0f1;
  --text-muted: #8899a6;
  --border: #2c3e50;
  --success: #27ae60;
  --radius: 12px;
  --radius-sm: 8px;
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
}

/* -----------------------------------------------------------
   LANDING PAGE
   ----------------------------------------------------------- */
.landing {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  min-height: 100dvh;
  padding: 20px;
  background: linear-gradient(135deg, #0f1923 0%, #1a2737 50%, #0f1923 100%);
}

.landing-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 48px 40px;
  max-width: 460px;
  width: 100%;
  text-align: center;
}

.logo {
  color: var(--primary);
  margin-bottom: 16px;
}

.landing-card h1 {
  font-size: 32px;
  font-weight: 700;
  margin-bottom: 8px;
  letter-spacing: -0.5px;
}

.subtitle {
  color: var(--text-muted);
  font-size: 16px;
  margin-bottom: 32px;
}

.divider {
  display: flex;
  align-items: center;
  margin: 28px 0;
  color: var(--text-muted);
  font-size: 14px;
}

.divider::before,
.divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

.divider span {
  padding: 0 16px;
}

.join-section {
  display: flex;
  gap: 10px;
}

.room-info {
  margin-top: 24px;
  padding: 20px;
  background: var(--bg-surface);
  border-radius: var(--radius);
}

.room-info p {
  margin-bottom: 12px;
  font-size: 15px;
}

.link-box {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}

.input-link {
  flex: 1;
  font-size: 13px !important;
}

.btn-go {
  width: 100%;
  margin-top: 8px;
}

.landing-footer {
  margin-top: 32px;
  color: var(--text-muted);
  font-size: 14px;
}

/* -----------------------------------------------------------
   BUTTONS & INPUTS
   ----------------------------------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 14px 28px;
  border: none;
  border-radius: var(--radius);
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
}

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

.btn-primary:hover {
  background: var(--primary-dark);
  transform: translateY(-1px);
}

.btn-secondary {
  background: var(--bg-surface);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-secondary:hover {
  background: var(--border);
}

.btn-copy {
  padding: 10px 14px;
  background: var(--bg-surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.btn-copy.copied {
  background: var(--success);
  border-color: var(--success);
}

.btn-icon {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 6px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  transition: all 0.15s;
}

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

.input {
  padding: 14px 16px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 16px;
  width: 100%;
  outline: none;
  transition: border-color 0.2s;
}

.input:focus {
  border-color: var(--primary);
}

.input.error {
  border-color: var(--danger);
  animation: shake 0.3s ease;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-6px); }
  75% { transform: translateX(6px); }
}

/* -----------------------------------------------------------
   MODAL (Name Entry)
   ----------------------------------------------------------- */
.modal {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.8);
  z-index: 100;
  padding: 20px;
}

.modal-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 40px;
  max-width: 400px;
  width: 100%;
  text-align: center;
}

.modal-card h2 {
  font-size: 24px;
  margin-bottom: 8px;
}

.modal-card p {
  color: var(--text-muted);
  margin-bottom: 24px;
  font-size: 15px;
}

.modal-card .input {
  margin-bottom: 16px;
}

.modal-card .btn {
  width: 100%;
}

/* -----------------------------------------------------------
   CALL UI
   ----------------------------------------------------------- */
.call-ui {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh; /* dynamic viewport height — shrinks when mobile URL bar shows */
  background: var(--bg);
}

/* -----------------------------------------------------------
   VIDEO GRID
   ----------------------------------------------------------- */
.video-grid {
  flex: 1;
  display: grid;
  gap: 6px;
  padding: 6px;
  overflow: hidden;
}

/* Grid layouts based on participant count */
.video-grid[data-count="1"] {
  grid-template-columns: 1fr;
}

.video-grid[data-count="2"] {
  grid-template-columns: 1fr 1fr;
}

.video-grid[data-count="3"] {
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr 1fr;
}

.video-grid[data-count="3"] .video-wrap:first-child {
  grid-column: span 2;
}

.video-grid[data-count="4"] {
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr 1fr;
}

.video-grid[data-count="5"],
.video-grid[data-count="6"] {
  grid-template-columns: 1fr 1fr 1fr;
  grid-template-rows: 1fr 1fr;
}

.video-wrap {
  position: relative;
  background: var(--bg-card);
  border-radius: var(--radius);
  overflow: hidden;
}

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

.video-wrap.video-off video {
  opacity: 0;
}

.video-wrap.video-off::after {
  content: '';
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-card);
}

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

/* When rear camera is active, don't mirror */
.local-video-wrap.rear-camera video {
  transform: scaleX(1);
}

.video-label {
  position: absolute;
  bottom: 8px;
  left: 8px;
  padding: 4px 10px;
  background: rgba(0, 0, 0, 0.6);
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  pointer-events: none;
}

.mute-indicator {
  position: absolute;
  top: 8px;
  right: 8px;
  padding: 4px;
  background: rgba(0, 0, 0, 0.6);
  border-radius: 6px;
  display: flex;
  align-items: center;
}

/* -----------------------------------------------------------
   STATUS BAR
   ----------------------------------------------------------- */
.status-bar {
  text-align: center;
  padding: 6px;
  font-size: 13px;
  color: var(--text-muted);
}

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

/* -----------------------------------------------------------
   TOOLBAR
   ----------------------------------------------------------- */
.toolbar {
  display: flex;
  justify-content: center;
  gap: 12px;
  padding: 12px 16px 20px;
  background: var(--bg-card);
  border-top: 1px solid var(--border);
}

.toolbar-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 12px 18px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.15s;
  position: relative;
}

.toolbar-btn:hover {
  background: var(--border);
  color: var(--text);
}

.toolbar-btn.active {
  background: var(--primary);
  border-color: var(--primary);
  color: white;
}

.toolbar-btn.active .icon-off { display: none; }
.toolbar-btn.active .icon-on { display: block; }
.toolbar-btn:not(.active) .icon-on { display: none; }
.toolbar-btn:not(.active) .icon-off { display: block; }

/* For buttons with only one icon (no on/off states) */
.toolbar-btn:not(.active) svg:only-of-type { display: block; }

.toolbar-btn.hangup {
  background: var(--danger);
  border-color: var(--danger);
  color: white;
}

.toolbar-btn.hangup:hover {
  background: var(--danger-dark);
}

.toolbar-label {
  font-size: 11px;
  font-weight: 500;
}

.chat-badge {
  position: absolute;
  top: 4px;
  right: 4px;
  background: var(--danger);
  color: white;
  font-size: 11px;
  font-weight: 700;
  min-width: 18px;
  height: 18px;
  border-radius: 9px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 4px;
}

/* -----------------------------------------------------------
   CHAT PANEL
   ----------------------------------------------------------- */
.chat-panel {
  position: fixed;
  top: 0;
  right: 0;
  width: 340px;
  height: 100vh;
  height: 100dvh;
  background: var(--bg-card);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  z-index: 50;
  animation: slideIn 0.2s ease;
}

@keyframes slideIn {
  from { transform: translateX(100%); }
  to { transform: translateX(0); }
}

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

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

.chat-msg {
  max-width: 85%;
}

.chat-msg-self {
  align-self: flex-end;
}

.chat-msg-other {
  align-self: flex-start;
}

.chat-msg-header {
  display: flex;
  gap: 8px;
  align-items: baseline;
  margin-bottom: 4px;
}

.chat-msg-name {
  font-size: 12px;
  font-weight: 600;
  color: var(--primary);
}

.chat-msg-self .chat-msg-name {
  color: var(--success);
}

.chat-msg-time {
  font-size: 11px;
  color: var(--text-muted);
}

.chat-msg-body {
  padding: 10px 14px;
  background: var(--bg-surface);
  border-radius: 12px 12px 12px 4px;
  font-size: 14px;
  line-height: 1.4;
  word-break: break-word;
}

.chat-msg-self .chat-msg-body {
  background: var(--primary);
  color: white;
  border-radius: 12px 12px 4px 12px;
}

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

.chat-input-wrap .input {
  flex: 1;
  padding: 10px 14px;
  font-size: 14px;
}

/* -----------------------------------------------------------
   SHARE LINK OVERLAY
   ----------------------------------------------------------- */
.share-overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: 60px;
  background: rgba(0, 0, 0, 0.5);
  z-index: 80;
}

.share-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  max-width: 500px;
  width: 90%;
  text-align: center;
}

.share-card p {
  margin-bottom: 12px;
  font-size: 15px;
}

.share-card .link-box {
  margin-bottom: 16px;
}

/* -----------------------------------------------------------
   UTILITIES
   ----------------------------------------------------------- */
.hidden {
  display: none !important;
}

/* -----------------------------------------------------------
   RESPONSIVE — MOBILE
   ----------------------------------------------------------- */
@media (max-width: 768px) {
  .landing-card {
    padding: 32px 24px;
    border-radius: 16px;
  }

  .landing-card h1 {
    font-size: 26px;
  }

  .join-section {
    flex-direction: column;
  }

  /* Video grid on mobile */
  .video-grid[data-count="2"] {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr 1fr;
  }

  .video-grid[data-count="3"] .video-wrap:first-child {
    grid-column: span 1;
  }

  .video-grid[data-count="3"],
  .video-grid[data-count="4"] {
    grid-template-columns: 1fr 1fr;
    grid-template-rows: 1fr 1fr;
  }

  .video-grid[data-count="5"],
  .video-grid[data-count="6"] {
    grid-template-columns: 1fr 1fr;
    grid-template-rows: 1fr 1fr 1fr;
  }

  /* Toolbar compact */
  .toolbar {
    gap: 6px;
    padding: 6px 6px 10px;
  }

  .toolbar-btn {
    padding: 8px 10px;
    gap: 2px;
  }

  .toolbar-label {
    font-size: 9px;
  }

  /* Status bar tighter */
  .status-bar {
    padding: 3px;
    font-size: 12px;
  }

  /* Video grid tighter */
  .video-grid {
    gap: 3px;
    padding: 3px;
  }

  /* Chat panel full width on mobile */
  .chat-panel {
    width: 100%;
  }
}

@media (max-width: 400px) {
  .toolbar-label {
    display: none;
  }

  .toolbar-btn {
    padding: 10px;
    border-radius: var(--radius-sm);
  }

  .toolbar {
    padding: 5px 5px 8px;
    gap: 5px;
  }
}

/* -----------------------------------------------------------
   SCROLLBAR
   ----------------------------------------------------------- */
::-webkit-scrollbar {
  width: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}
