/* === Базовые стили === */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
}

:root {
  --primary-color: #1a73e8;
  --primary-dark: #0d47a1;
  --secondary-color: #34a853;
  --danger-color: #ea4335;
  --warning-color: #fbbc05;
  --bg-dark: #0a0a0a;
  --bg-card: #1a1a1a;
  --bg-hover: #2a2a2a;
  --text-primary: #ffffff;
  --text-secondary: #b0b0b0;
  --text-muted: #666666;
  --border-color: #333333;
  --shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  --radius: 12px;
  --radius-sm: 8px;
}

body {
  background: var(--bg-dark);
  color: var(--text-primary);
  height: 100vh;
  overflow: hidden;
  touch-action: manipulation;
  line-height: 1.5;
}

/* === Экран входа === */
.login-screen {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: linear-gradient(135deg, var(--bg-dark) 0%, #1a1a2e 50%, #16213e 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.login-container {
  background: var(--bg-card);
  padding: 2.5rem;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  width: 90%;
  max-width: 400px;
  text-align: center;
}

.login-header h1 {
  font-size: 2rem;
  font-weight: 700;
  margin-bottom: 0.5rem;
  background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.login-header p {
  color: var(--text-secondary);
  margin-bottom: 2rem;
}

.input-group {
  margin-bottom: 1rem;
}

.input-group input {
  width: 100%;
  padding: 1rem;
  border: 2px solid var(--border-color);
  border-radius: var(--radius-sm);
  background: var(--bg-dark);
  color: var(--text-primary);
  font-size: 1rem;
  transition: all 0.3s ease;
}

.input-group input:focus {
  outline: none;
  border-color: var(--primary-color);
  box-shadow: 0 0 0 3px rgba(26, 115, 232, 0.2);
}

.button-group {
  display: flex;
  gap: 1rem;
  margin-top: 1.5rem;
}

.btn {
  flex: 1;
  padding: 1rem;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
}

.btn-primary {
  background: var(--primary-color);
  color: white;
}

.btn-primary:hover {
  background: var(--primary-dark);
  transform: translateY(-2px);
}

.btn-secondary {
  background: transparent;
  color: var(--text-secondary);
  border: 2px solid var(--border-color);
}

.btn-secondary:hover {
  border-color: var(--primary-color);
  color: var(--primary-color);
}

.login-footer {
  margin-top: 2rem;
  color: var(--text-muted);
  font-size: 0.9rem;
}

/* === Основное приложение === */
.app-container {
  height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg-dark);
}

/* Хедеры */
.mobile-header {
  display: none;
  background: var(--bg-card);
  padding: 1rem;
  border-bottom: 1px solid var(--border-color);
  align-items: center;
  gap: 1rem;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 100;
  height: 60px;
}

.desktop-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 2rem;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border-color);
  height: 70px;
  flex-shrink: 0;
}

.header-btn {
  background: none;
  border: none;
  color: var(--text-primary);
  font-size: 1.5rem;
  cursor: pointer;
  padding: 0.5rem;
  border-radius: var(--radius-sm);
  transition: background 0.3s ease;
  display: flex;
  align-items: center;
  justify-content: center;
}

.header-btn:hover {
  background: var(--bg-hover);
}

.header-title {
  flex: 1;
  text-align: center;
  font-weight: 600;
  font-size: 1.1rem;
}

.app-title {
  font-size: 1.5rem;
  font-weight: 700;
  background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.user-info {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--text-secondary);
}

.user-label {
  font-size: 0.9rem;
}

.username {
  font-weight: 600;
  color: var(--text-primary);
}

.desktop-call-btn {
  background: var(--secondary-color);
  color: white;
  border: none;
  padding: 0.75rem 1.5rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 600;
  transition: all 0.3s ease;
}

.desktop-call-btn:hover {
  background: #2e8b57;
  transform: translateY(-2px);
}

.call-btn {
  background: var(--secondary-color);
  color: white;
  border: none;
  border-radius: 20px;
  padding: 8px 15px;
  cursor: pointer;
  font-size: 14px;
  margin-left: 10px;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  transition: all 0.3s ease;
}

.call-btn:hover {
  background: #2e8b57;
  transform: translateY(-2px);
}

/* Основной контент */
.main-content {
  flex: 1;
  display: flex;
  overflow: hidden;
  height: calc(100vh - 70px);
}

/* Панель контактов */
.contacts-panel {
  width: 320px;
  background: var(--bg-card);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

.contacts-header {
  padding: 1.5rem;
  border-bottom: 1px solid var(--border-color);
}

.contacts-header h2 {
  font-size: 1.25rem;
  margin-bottom: 0.5rem;
}

.online-indicator {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--text-secondary);
  font-size: 0.9rem;
}

.dot {
  width: 8px;
  height: 8px;
  background: var(--secondary-color);
  border-radius: 50%;
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

.contacts-list-container {
  flex: 1;
  overflow-y: auto;
}

.contacts-list {
  list-style: none;
  padding: 0.5rem;
}

.contact-item {
  padding: 1rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.3s ease;
  margin-bottom: 0.25rem;
  display: flex;
  align-items: center;
  gap: 1rem;
}

.contact-item:hover {
  background: var(--bg-hover);
}

.contact-item.active {
  background: var(--primary-color);
  color: white;
}

.contact-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 1.1rem;
}

.contact-info {
  flex: 1;
}

.contact-name {
  font-weight: 600;
  margin-bottom: 0.25rem;
}

.contact-status {
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.contact-item.active .contact-status {
  color: rgba(255, 255, 255, 0.8);
}

.no-contacts {
  text-align: center;
  padding: 2rem;
  color: var(--text-muted);
}

/* Панель чата */
.chat-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--bg-dark);
}

.chat-header {
  padding: 1.5rem 2rem;
  border-bottom: 1px solid var(--border-color);
  background: var(--bg-card);
}

.chat-contact-info {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

#chat-contact-name {
  font-size: 1.25rem;
  font-weight: 600;
}

.chat-status {
  color: var(--text-secondary);
  font-size: 0.9rem;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.welcome-message {
  text-align: center;
  padding: 3rem 2rem;
  color: var(--text-secondary);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
}

.welcome-icon {
  font-size: 4rem;
  margin-bottom: 1rem;
}

.welcome-message h3 {
  font-size: 1.5rem;
  margin-bottom: 1rem;
  color: var(--text-primary);
}

.message {
  max-width: 70%;
  padding: 1rem 1.25rem;
  border-radius: var(--radius);
  position: relative;
  animation: messageSlide 0.3s ease;
}

@keyframes messageSlide {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.message.received {
  background: var(--bg-card);
  align-self: flex-start;
  border-bottom-left-radius: var(--radius-sm);
}

.message.sent {
  background: var(--primary-color);
  align-self: flex-end;
  border-bottom-right-radius: var(--radius-sm);
}

.message-time {
  font-size: 0.75rem;
  opacity: 0.7;
  margin-top: 0.5rem;
  text-align: right;
}

.chat-input-container {
  padding: 1rem 2rem;
  background: var(--bg-card);
  border-top: 1px solid var(--border-color);
  flex-shrink: 0;
}

.chat-input {
  display: flex;
  gap: 1rem;
  align-items: flex-end;
}

.chat-input input {
  flex: 1;
  padding: 1rem 1.25rem;
  border: 2px solid var(--border-color);
  border-radius: 2rem;
  background: var(--bg-dark);
  color: var(--text-primary);
  font-size: 1rem;
  transition: all 0.3s ease;
  resize: none;
  min-height: 50px;
  max-height: 120px;
}

.chat-input input:focus {
  outline: none;
  border-color: var(--primary-color);
}

.chat-input input:not(:disabled) {
  border-color: var(--primary-color);
}

.send-btn {
  background: var(--primary-color);
  color: white;
  border: none;
  border-radius: 50%;
  width: 50px;
  height: 50px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.3s ease;
  flex-shrink: 0;
}

.send-btn:not(:disabled):hover {
  background: var(--primary-dark);
  transform: scale(1.05);
}

.send-btn:disabled {
  background: var(--text-muted);
  cursor: not-allowed;
  transform: none;
}

/* === Модальные окна и звонки === */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.8);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
  backdrop-filter: blur(10px);
}

.call-modal {
  background: var(--bg-card);
  padding: 2.5rem;
  border-radius: var(--radius);
  text-align: center;
  max-width: 400px;
  width: 90%;
  box-shadow: var(--shadow);
}

.call-modal-header {
  margin-bottom: 1.5rem;
}

.call-icon-large {
  font-size: 4rem;
  margin-bottom: 1rem;
}

.caller-name {
  font-size: 1.5rem;
  font-weight: 600;
  margin-bottom: 0.5rem;
  color: var(--text-primary);
}

.call-subtitle {
  color: var(--text-secondary);
  margin-bottom: 2rem;
}

.call-modal-actions {
  display: flex;
  gap: 1rem;
  justify-content: center;
}

.btn-reject {
  background: var(--danger-color);
  color: white;
}

.btn-reject:hover {
  background: #d32f2f;
}

.btn-accept {
  background: var(--secondary-color);
  color: white;
}

.btn-accept:hover {
  background: #2e8b57;
}

/* Экран звонка */
.call-screen {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: #000;
  z-index: 2000;
  display: none;
}

.call-container {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
}

.video-container {
  flex: 1;
  position: relative;
  background: #000;
}

.remote-video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.local-video {
  position: absolute;
  top: 20px;
  right: 20px;
  width: 120px;
  height: 160px;
  border-radius: var(--radius-sm);
  border: 2px solid white;
  object-fit: cover;
}

.call-controls {
  position: absolute;
  bottom: 2rem;
  left: 0;
  right: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
}

.call-info {
  text-align: center;
  color: white;
}

#call-timer {
  font-size: 1.5rem;
  font-weight: 600;
  display: block;
}

#call-status {
  font-size: 0.9rem;
  opacity: 0.8;
}

.btn-end-call {
  background: var(--danger-color);
  color: white;
  padding: 1rem 2rem;
  border-radius: 2rem;
  font-size: 1.1rem;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  transition: all 0.3s ease;
}

.btn-end-call:hover {
  background: #d32f2f;
  transform: scale(1.05);
}

/* === Адаптация для мобильных === */
@media (max-width: 768px) {
  .mobile-header {
    display: flex;
  }

  .desktop-header {
    display: none;
  }

  .contacts-panel {
    position: fixed;
    top: 60px;
    left: -100%;
    width: 100%;
    height: calc(100vh - 60px);
    z-index: 90;
    transition: left 0.3s ease;
    border-right: none;
  }

  .contacts-panel.visible {
    left: 0;
  }

  .chat-panel {
    margin-top: 60px;
    height: calc(100vh - 60px);
  }

  .chat-header {
    padding: 1rem;
  }

  .chat-input-container {
    padding: 1rem;
    padding-bottom: calc(1rem + env(safe-area-inset-bottom, 0px));
  }

  .message {
    max-width: 85%;
  }

  .local-video {
    width: 80px;
    height: 120px;
    top: 0.5rem;
    right: 0.5rem;
  }

  .call-controls {
    bottom: 1rem;
  }

  .call-modal {
    margin: 1rem;
    padding: 2rem 1.5rem;
  }

  .call-modal-actions {
    flex-direction: column;
  }

  .back-btn {
    display: flex !important;
  }

  .chat-panel.active ~ .mobile-header .menu-icon {
    display: none;
  }

  .chat-panel.active ~ .mobile-header .back-btn {
    display: flex !important;
  }

  .call-btn {
    background: transparent;
    font-size: 20px;
    padding: 5px;
  }
}

/* === Десктопная версия - ВАЖНЫЕ ИСПРАВЛЕНИЯ === */
@media (min-width: 769px) {
  .contacts-panel {
    display: flex !important;
    position: relative !important;
    left: auto !important;
    width: 320px;
    height: 100%;
  }

  .chat-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
  }

  .mobile-header {
    display: none !important;
  }

  .desktop-header {
    display: flex;
  }

  .back-btn {
    display: none !important;
  }

  .main-content {
    display: flex;
    height: calc(100vh - 70px);
  }

  /* Убедимся что контакты всегда видны на ПК */
  .contacts-panel.visible {
    display: flex !important;
    left: auto !important;
  }
}

/* === Утилиты === */
.hidden {
  display: none !important;
}

.notification {
  position: fixed;
  top: 20px;
  right: 20px;
  padding: 1rem 1.5rem;
  border-radius: 8px;
  z-index: 3000;
  box-shadow: var(--shadow);
  max-width: 300px;
  word-wrap: break-word;
}

.notification-error {
  background: var(--danger-color);
  color: white;
}

.notification-warning {
  background: var(--warning-color);
  color: black;
}

.notification-success {
  background: var(--secondary-color);
  color: white;
}

.notification-info {
  background: var(--primary-color);
  color: white;
}

/* Полоса прокрутки */
::-webkit-scrollbar {
  width: 6px;
}

::-webkit-scrollbar-track {
  background: var(--bg-dark);
}

::-webkit-scrollbar-thumb {
  background: var(--text-muted);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-secondary);
}

/* Selection */
::selection {
  background: var(--primary-color);
  color: white;
}

/* Focus styles */
button:focus-visible,
input:focus-visible {
  outline: 2px solid var(--primary-color);
  outline-offset: 2px;
}

/* Loading states */
.loading {
  opacity: 0.7;
  pointer-events: none;
}

/* Responsive images */
img {
  max-width: 100%;
  height: auto;
}

/* Print styles */
@media print {
  .login-screen,
  .mobile-header,
  .call-screen,
  .modal-overlay {
    display: none !important;
  }
}