:root {
  --bg: #0f1419;
  --surface: #1a2332;
  --text: #e7ecf3;
  --muted: #8b9cb3;
  --accent: #3d8bfd;
  --error: #f87171;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

.login-page {
  display: grid;
  place-items: center;
}

.login-card {
  background: var(--surface);
  padding: 2rem;
  border-radius: 12px;
  width: min(100%, 360px);
}

.login-card h1 { margin: 0 0 0.25rem; }
.subtitle { color: var(--muted); margin: 0 0 1.5rem; }

label { display: block; margin-bottom: 0.5rem; font-size: 0.9rem; }

input {
  width: 100%;
  padding: 0.75rem;
  border: 1px solid #2d3a4f;
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  margin-bottom: 1rem;
}

button {
  width: 100%;
  padding: 0.75rem;
  border: none;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  cursor: pointer;
}

.error { color: var(--error); font-size: 0.9rem; margin-top: 0.75rem; }

.chat-page { display: flex; flex-direction: column; min-height: 100vh; }

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.5rem;
  background: var(--surface);
  border-bottom: 1px solid #2d3a4f;
}

.chat-header h1 { margin: 0; font-size: 1.25rem; }

.btn-secondary {
  width: auto;
  padding: 0.5rem 1rem;
  background: transparent;
  border: 1px solid #2d3a4f;
  color: var(--text);
}

.chat-header-left { display: flex; flex-direction: column; gap: 0.15rem; }
.chat-header-right { display: flex; align-items: center; gap: 0.75rem; }

.online-status {
  margin: 0;
  font-size: 0.85rem;
  color: var(--muted);
}

.user-name {
  font-size: 0.9rem;
  color: var(--muted);
}

.chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  max-width: 800px;
  width: 100%;
  margin: 0 auto;
  padding: 0 1rem 1rem;
}

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 1rem 0;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  min-height: 200px;
}

.message {
  background: var(--surface);
  border-radius: 10px;
  padding: 0.75rem 1rem;
  max-width: 85%;
}

.message-meta {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.35rem;
  font-size: 0.8rem;
}

.message-sender { color: var(--accent); }
.message-time { color: var(--muted); }
.message-body { margin: 0; white-space: pre-wrap; word-break: break-word; }

.load-more {
  width: auto;
  align-self: center;
  margin-bottom: 0.5rem;
  padding: 0.4rem 0.9rem;
  font-size: 0.85rem;
  background: transparent;
  border: 1px solid #2d3a4f;
  color: var(--muted);
}

.chat-form {
  display: flex;
  gap: 0.5rem;
  align-items: flex-end;
  padding-top: 0.5rem;
  border-top: 1px solid #2d3a4f;
}

.chat-form textarea {
  flex: 1;
  resize: vertical;
  min-height: 2.75rem;
  max-height: 8rem;
  margin-bottom: 0;
  font-family: inherit;
}

.chat-form button {
  width: auto;
  min-width: 5rem;
  flex-shrink: 0;
}

.chat-form button:disabled,
.chat-form textarea:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

#name-dialog {
  border: none;
  border-radius: 12px;
  padding: 0;
  background: var(--surface);
  color: var(--text);
  max-width: 360px;
}

#name-dialog::backdrop {
  background: rgba(0, 0, 0, 0.6);
}

.name-dialog-form {
  padding: 1.5rem;
}

.name-dialog-form h2 { margin: 0 0 0.25rem; }
.name-dialog-form .subtitle { margin-bottom: 1rem; }

.call-status {
  margin: 0;
  font-size: 0.85rem;
  color: var(--accent);
}

.btn-call {
  width: auto;
  padding: 0.5rem 1rem;
  background: #22a06b;
}

.btn-danger {
  width: auto;
  padding: 0.5rem 1rem;
  background: #c9372c;
}

.call-panel {
  background: #000;
  border-bottom: 1px solid #2d3a4f;
}

.video-grid {
  position: relative;
  max-width: 900px;
  margin: 0 auto;
  aspect-ratio: 16 / 9;
  max-height: 50vh;
  background: #000;
}

.video-remote {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.video-local {
  position: absolute;
  right: 1rem;
  bottom: 1rem;
  width: min(28%, 200px);
  aspect-ratio: 4 / 3;
  object-fit: cover;
  border-radius: 8px;
  border: 2px solid var(--surface);
  background: #111;
}

.mobile-call-note {
  margin: 0.75rem 0 0;
  font-size: 0.85rem;
  color: var(--muted);
  text-align: center;
}

.incoming-dialog {
  border: none;
  border-radius: 12px;
  padding: 1.5rem;
  background: var(--surface);
  color: var(--text);
  max-width: 360px;
}

.incoming-dialog::backdrop {
  background: rgba(0, 0, 0, 0.6);
}

.incoming-actions {
  display: flex;
  gap: 0.75rem;
  margin-top: 1.25rem;
}

.incoming-actions button {
  flex: 1;
}

@media (max-width: 600px) {
  .chat-header { flex-wrap: wrap; gap: 0.75rem; }
  .message { max-width: 100%; }
  #call-btn, #end-call-btn { display: none !important; }
}
