:root {
  --bg: #0b0c10;
  --surface: #16171d;
  --surface-2: #1e1f27;
  --accent: #5b6dfa;
  --accent-hover: #6f80ff;
  --danger: #e5484d;
  --text: #f2f2f5;
  --muted: #9698a6;
  --border: #2a2b34;
}

* {
  box-sizing: border-box;
}

html, body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

/* Login */
.auth-box {
  max-width: 340px;
  margin: 12vh auto;
  padding: 32px 28px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.35);
}

.auth-box h1 {
  margin: 0 0 4px;
  font-size: 1.7rem;
  background: linear-gradient(135deg, var(--accent), #9b8bff);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.auth-box .subtitle {
  margin: 0 0 24px;
  color: var(--muted);
  font-size: 0.85rem;
}

.auth-box input {
  display: block;
  width: 100%;
  margin: 10px 0;
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 0.95rem;
  outline: none;
  transition: border-color 0.15s;
}

.auth-box input:focus {
  border-color: var(--accent);
}

.auth-box button {
  width: 100%;
  margin-top: 6px;
  padding: 12px;
  border-radius: 10px;
  border: none;
  background: var(--accent);
  color: white;
  font-weight: 600;
  font-size: 0.95rem;
  cursor: pointer;
  transition: background 0.15s;
}

.auth-box button:hover {
  background: var(--accent-hover);
}

.error {
  color: var(--danger);
  min-height: 1.2em;
  font-size: 0.85rem;
  margin-top: 10px;
}

.error.success {
  color: #4cd97b;
}

/* Call page layout */
body.call-page {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  overflow: hidden;
}

header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

header .brand {
  font-weight: 700;
  letter-spacing: 0.3px;
}

header .header-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

header .header-right {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.85rem;
  color: var(--muted);
}

.icon-btn {
  border: none;
  background: var(--surface-2);
  color: var(--text);
  width: 32px;
  height: 32px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 1rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
}

.link-btn {
  font-size: 1.1rem;
}

.muted {
  color: var(--muted);
  font-weight: 400;
}

.room-share {
  display: flex;
  gap: 8px;
  padding: 10px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.room-share input {
  flex: 1;
  min-width: 0;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 0.85rem;
}

.room-share button {
  padding: 8px 14px;
  border-radius: 8px;
  border: none;
  background: var(--accent);
  color: white;
  font-size: 0.85rem;
  cursor: pointer;
  white-space: nowrap;
}

.stage {
  position: relative;
  flex: 1;
  min-height: 0;
  background: radial-gradient(circle at 50% 30%, #1a1b23, #08080b 70%);
  overflow: hidden;
}

.stage #remote-video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: #000;
}

.placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  pointer-events: none;
}

.avatar {
  width: 84px;
  height: 84px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), #9b8bff);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2rem;
  font-weight: 700;
}

#status {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
  text-align: center;
  padding: 0 20px;
}

.pip {
  position: absolute;
  bottom: 16px;
  right: 16px;
  width: 110px;
  aspect-ratio: 3 / 4;
  object-fit: cover;
  border-radius: 12px;
  border: 2px solid var(--border);
  background: #000;
  transform: scaleX(-1);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
}

.controls {
  display: flex;
  justify-content: center;
  gap: 14px;
  padding: 16px 16px calc(16px + env(safe-area-inset-bottom));
  background: var(--surface);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.ctrl-btn {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  border: none;
  background: var(--surface-2);
  color: var(--text);
  font-size: 1.3rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, transform 0.1s;
}

.ctrl-btn:active {
  transform: scale(0.94);
}

.ctrl-btn.off {
  background: var(--danger);
}

.hangup {
  background: var(--danger);
  width: 60px;
  height: 60px;
  font-size: 1.5rem;
}

.hangup:hover {
  background: #ff5c60;
}

/* Admin page */
body.admin-page {
  min-height: 100%;
}

.admin-main {
  max-width: 720px;
  margin: 0 auto;
  padding: 24px 16px 60px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.admin-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 20px;
}

.admin-card h2 {
  margin: 0 0 16px;
  font-size: 1.05rem;
}

.inline-form {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.inline-form input {
  flex: 1;
  min-width: 140px;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 0.9rem;
}

.inline-form button {
  padding: 10px 18px;
  border-radius: 8px;
  border: none;
  background: var(--accent);
  color: white;
  font-weight: 600;
  cursor: pointer;
}

.inline-form button:hover {
  background: var(--accent-hover);
}

.user-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.user-table th {
  text-align: left;
  color: var(--muted);
  font-weight: 500;
  padding: 8px;
  border-bottom: 1px solid var(--border);
}

.user-table td {
  padding: 10px 8px;
  border-bottom: 1px solid var(--border);
}

.status-active {
  color: #4cd97b;
}

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

.badge {
  margin-left: 8px;
  padding: 2px 8px;
  border-radius: 20px;
  background: var(--accent);
  color: white;
  font-size: 0.7rem;
}

.actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.small-btn {
  padding: 6px 10px;
  border-radius: 6px;
  border: none;
  background: var(--surface-2);
  color: var(--text);
  font-size: 0.8rem;
  cursor: pointer;
}

.small-btn.danger {
  background: rgba(229, 72, 77, 0.15);
  color: var(--danger);
}

.small-btn:hover {
  filter: brightness(1.15);
}

/* Chats page */
body.chats-page {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  overflow: hidden;
}

.chats-layout {
  flex: 1;
  min-height: 0;
  display: flex;
}

.contacts-panel {
  width: 100%;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.contacts-panel.hide-on-mobile {
  display: none;
}

.add-contact {
  display: flex;
  gap: 8px;
  padding: 12px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.add-contact input {
  flex: 1;
  min-width: 0;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 0.85rem;
}

.add-contact button {
  width: 40px;
  border-radius: 8px;
  border: none;
  background: var(--accent);
  color: white;
  font-size: 1.1rem;
  cursor: pointer;
}

.contact-list {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow-y: auto;
  flex: 1;
}

.contact-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
}

.contact-item:hover,
.contact-item.active {
  background: var(--surface-2);
}

.contact-meta {
  min-width: 0;
  flex: 1;
}

.contact-name {
  font-weight: 600;
  font-size: 0.92rem;
}

.contact-last {
  color: var(--muted);
  font-size: 0.8rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.avatar.small {
  width: 40px;
  height: 40px;
  flex-shrink: 0;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), #9b8bff);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  font-weight: 700;
}

.conversation-panel {
  display: none;
  flex: 1;
  min-width: 0;
  flex-direction: column;
  min-height: 0;
}

.conversation-panel.active {
  display: flex;
}

.conversation-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.conversation-header strong {
  flex: 1;
}

.call-icon-btn {
  background: #2f9e5c;
}

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

.bubble {
  max-width: 75%;
  padding: 8px 12px;
  border-radius: 14px;
  font-size: 0.9rem;
  line-height: 1.35;
}

.bubble.theirs {
  align-self: flex-start;
  background: var(--surface-2);
  border-bottom-left-radius: 4px;
}

.bubble.mine {
  align-self: flex-end;
  background: var(--accent);
  color: white;
  border-bottom-right-radius: 4px;
}

.bubble-time {
  margin-top: 4px;
  font-size: 0.7rem;
  opacity: 0.7;
  text-align: right;
}

.missed-call-row {
  align-self: center;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 14px;
  border-radius: 20px;
  background: rgba(229, 72, 77, 0.12);
  color: var(--danger);
  font-size: 0.8rem;
}

.message-form {
  display: none;
  gap: 8px;
  padding: 12px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  padding-bottom: calc(12px + env(safe-area-inset-bottom));
}

.message-form input {
  flex: 1;
  padding: 10px 14px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 0.9rem;
}

.message-form button {
  padding: 10px 18px;
  border-radius: 20px;
  border: none;
  background: var(--accent);
  color: white;
  font-weight: 600;
  cursor: pointer;
}

.empty-state {
  margin: auto;
  color: var(--muted);
  font-size: 0.9rem;
  text-align: center;
  padding: 20px;
}

@media (min-width: 720px) {
  .contacts-panel {
    width: 320px;
    flex-shrink: 0;
  }
  .contacts-panel.hide-on-mobile {
    display: flex;
  }
  .conversation-panel {
    display: flex;
  }
  .mobile-only {
    display: none;
  }
}
