/* Reset & base styles */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html,
body {
  width: 100%;
  min-height: 100%;
}

body {
  font-family: Arial, sans-serif;
  background: #eef2f5;
  color: #333;
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

button,
input {
  font: inherit;
}

#container {
  width: 100%;
  max-width: none;
  margin: 0 auto;
  padding: clamp(8px, 1vw, 16px);
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

/* Header */
header {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px 16px;
  align-items: center;
  margin-bottom: 10px;
  background-color: #2c3e50;
  color: white;
  padding: 12px 14px;
  border-radius: 4px;
  flex: 0 0 auto;
}

.header-info {
  display: flex;
  align-items: center;
  gap: 16px;
  min-width: 0;
}

.header-info p {
  font-weight: bold;
  white-space: nowrap;
}

.header-controls {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}

.header-controls button {
  min-height: 38px;
  padding: 8px 16px;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-weight: bold;
  transition: background-color 0.2s, opacity 0.2s;
}

.header-controls button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

#main-btn {
  background-color: #27ae60;
  color: white;
  min-width: 100px;
}

#main-btn.searching {
  background-color: #e74c3c;
}

#report-btn {
  background-color: #f39c12;
  color: white;
}

header p span {
  font-weight: normal;
  color: #ecf0f1;
}

#status {
  grid-column: 1 / -1;
  min-width: 0;
  font-weight: bold;
  color: #ecf0f1;
}

/* Main layout */
#main {
  display: grid;
  grid-template-columns: minmax(0, 1fr) clamp(320px, 26vw, 440px);
  gap: 10px;
  flex: 1 1 auto;
  min-height: 0;
}

#videos {
  position: relative;
  min-width: 0;
  min-height: 0;
  background: #000;
  border-radius: 4px;
  overflow: hidden;
}

#remoteVideo {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: contain;
  background: #000;
}

#localVideo {
  position: absolute;
  right: clamp(8px, 1.5vw, 20px);
  bottom: clamp(8px, 1.5vw, 20px);
  width: clamp(112px, 18%, 220px);
  aspect-ratio: 4 / 3;
  object-fit: contain;
  background: #000;
  border: 2px solid white;
  border-radius: 8px;
  z-index: 10;
}

#chat {
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: #fff;
  border-radius: 4px;
  border: 1px solid #ccc;
  overflow: hidden;
}

/* Chat scrollabile */
#messages-container {
  flex: 1 1 auto;
  overflow-y: auto;
  min-height: 0;
  padding: 14px;
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
}

#messages {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: min-content;
}

.message {
  padding: 8px 12px;
  border-radius: 18px;
  max-width: 82%;
  overflow-wrap: anywhere;
  animation: fadeIn 0.3s ease-out;
}

.message.sent {
  background: #007bff;
  color: white;
  margin-left: auto;
  border-bottom-right-radius: 4px;
}

.message.received {
  background: #e9ecef;
  color: #333;
  margin-right: auto;
  border-bottom-left-radius: 4px;
}

#input-area {
  display: flex;
  gap: 8px;
  border-top: 1px solid #ddd;
  padding: 8px;
  flex: 0 0 auto;
}

#message-input {
  flex: 1 1 auto;
  min-width: 0;
  border: 1px solid #ddd;
  border-radius: 20px;
  padding: 10px 15px;
  outline: none;
}

#send-btn {
  flex: 0 0 auto;
  border: none;
  background: #007bff;
  color: #fff;
  padding: 0 16px;
  min-height: 40px;
  border-radius: 20px;
  cursor: pointer;
}

/* Footer */
footer {
  flex: 0 0 auto;
  background-color: #2c3e50;
  color: white;
  padding: 8px 10px;
  text-align: center;
  font-size: 0.8rem;
  line-height: 1.35;
}

footer a {
  color: #3498db;
  text-decoration: none;
}

footer p {
  margin-top: 3px;
}

/* Tablet and mobile */
@media (max-width: 900px) {
  body {
    overflow: hidden;
  }

  #container {
    padding: 8px;
  }

  header {
    grid-template-columns: 1fr;
    gap: 8px;
    padding: 10px;
    margin-bottom: 8px;
  }

  .header-info {
    justify-content: space-between;
    gap: 10px;
  }

  .header-controls {
    width: 100%;
  }

  .header-controls button {
    flex: 1 1 0;
    min-width: 0;
    padding: 8px 10px;
  }

  #status {
    font-size: 0.92rem;
  }

  #main {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(0, 3fr) minmax(0, 2fr);
    gap: 8px;
  }

  #localVideo {
    top: 8px;
    right: 8px;
    bottom: auto;
    width: clamp(96px, 30%, 150px);
    border-radius: 6px;
  }

  #chat {
    width: 100%;
  }

  #messages-container {
    padding: 10px;
  }
}

@media (max-width: 520px) {
  .header-info {
    align-items: flex-start;
    flex-direction: column;
    gap: 4px;
  }

  .header-info p,
  #status {
    font-size: 0.82rem;
  }

  .header-controls button {
    min-height: 36px;
    font-size: 0.9rem;
  }

  #main {
    grid-template-rows: minmax(0, 58%) minmax(0, 42%);
  }

  #input-area {
    padding: 7px;
  }

  #message-input {
    padding: 9px 12px;
  }

  #send-btn {
    min-height: 38px;
    padding: 0 12px;
  }

  footer {
    padding: 6px 8px;
    font-size: 0.72rem;
  }

  footer p {
    display: none;
  }
}

@media (min-width: 1400px) {
  #main {
    grid-template-columns: minmax(0, 1fr) 420px;
  }
}

/* Animations */
@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}
