:root {
  --bg: #0f1115;
  --panel: #171a21;
  --panel-alt: #1d2129;
  --border: #2a2e38;
  --text: #e8eaf0;
  --text-muted: #8b93a7;
  --accent: #2dd4bf;
  --accent-hover: #25b8a5;
  --accent-text: #06201c;
  --danger: #ef4444;
  --header-height: 56px;
}

* {
  box-sizing: border-box;
}

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

/* --- App header --- */
.app-header {
  height: var(--header-height);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.25rem;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 700;
  font-size: 1.05rem;
  letter-spacing: -0.01em;
}

.brand-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 10px var(--accent);
}

.header-actions {
  display: flex;
  gap: 0.5rem;
}

.header-btn {
  background: var(--panel-alt);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 10px;
  padding: 0.4rem 0.6rem;
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
}

.header-btn.active {
  border-color: var(--accent);
  background: rgba(45, 212, 191, 0.12);
}

.screen {
  height: calc(100vh - var(--header-height));
}

.screen[hidden] {
  display: none;
}

/* --- Entry screen --- */
#entry-screen:not([hidden]) {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.entry-form {
  background: var(--panel);
  border: 1px solid var(--border);
  padding: 2.25rem;
  border-radius: 16px;
  width: 100%;
  max-width: 380px;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.35);
}

.entry-form h1 {
  margin: 0 0 0.25rem;
  font-size: 1.5rem;
  letter-spacing: -0.01em;
}

.subtitle {
  margin: 0 0 1.25rem;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.entry-form label {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-top: 0.6rem;
}

.entry-form input[type="text"],
.entry-form input[type="number"],
.entry-form select {
  padding: 0.65rem 0.75rem;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--panel-alt);
  color: var(--text);
  font-size: 1rem;
}

.entry-form input:focus,
.entry-form select:focus,
.message-form input:focus {
  outline: none;
  border-color: var(--accent);
}

.checkbox-label {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 0.9rem;
  line-height: 1.35;
}

.checkbox-label input {
  margin-top: 0.2rem;
  accent-color: var(--accent);
}

.error-text {
  color: var(--danger);
  font-size: 0.85rem;
  margin: 0.3rem 0 0;
}

.entry-form button[type="submit"] {
  margin-top: 1.4rem;
  padding: 0.75rem;
  border: none;
  border-radius: 10px;
  background: var(--accent);
  color: var(--accent-text);
  font-weight: 600;
  font-size: 1rem;
  cursor: pointer;
  transition: background 0.15s ease;
}

.entry-form button[type="submit"]:hover:not(:disabled) {
  background: var(--accent-hover);
}

.entry-form button[type="submit"]:disabled {
  background: var(--border);
  color: var(--text-muted);
  cursor: not-allowed;
}

/* --- Chat screen --- */
#chat-screen:not([hidden]) {
  display: flex;
}

.sidebar {
  width: 240px;
  background: var(--panel);
  border-right: 1px solid var(--border);
  padding: 1.1rem;
  overflow-y: auto;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.sidebar-section h2 {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  margin: 0 0 0.6rem;
}

.room-list,
.user-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.room-item {
  background: var(--panel-alt);
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 0.5rem 0.65rem;
  font-size: 0.88rem;
  cursor: pointer;
  transition: border-color 0.15s ease;
}

.room-item:hover {
  border-color: var(--border);
}

.room-item.active {
  border-color: var(--accent);
  color: var(--accent);
  font-weight: 600;
}

.user-item {
  background: var(--panel-alt);
  border-radius: 10px;
  padding: 0.55rem;
  font-size: 0.85rem;
}

.user-name {
  display: block;
  font-weight: 600;
  margin-bottom: 0.35rem;
  word-break: break-word;
}

.user-actions {
  display: flex;
  gap: 0.3rem;
  flex-wrap: wrap;
}

.user-actions button {
  font-size: 0.7rem;
  padding: 0.25rem 0.45rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text-muted);
  cursor: pointer;
}

.user-actions button:hover {
  color: var(--text);
  border-color: var(--accent);
}

.chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.tab-bar {
  display: flex;
  gap: 0.25rem;
  padding: 0.5rem 1.1rem 0;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.tab-button {
  background: none;
  border: none;
  color: var(--text-muted);
  padding: 0.55rem 0.8rem;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  font-size: 0.9rem;
}

.tab-button.active {
  color: var(--text);
  border-bottom-color: var(--accent);
}

.panels {
  flex: 1;
  overflow: hidden;
  position: relative;
}

.panel {
  display: none;
  height: 100%;
  overflow-y: auto;
  padding: 1.1rem;
}

.panel.active {
  display: block;
}

/* --- Video call bar (inside cam-eligible DM panels) --- */
.call-bar {
  padding: 0.7rem 0.85rem;
  margin-bottom: 0.9rem;
  background: var(--panel-alt);
  border: 1px solid var(--border);
  border-radius: 12px;
}

.call-bar-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.6rem;
}

.call-notice {
  margin: 0.5rem 0 0;
  font-size: 0.75rem;
  color: var(--text-muted);
  line-height: 1.4;
}

.call-start-btn,
.call-cancel-btn,
.call-hangup-btn {
  padding: 0.5rem 0.85rem;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  cursor: pointer;
  font-size: 0.85rem;
}

.call-start-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.call-hangup-btn {
  border-color: var(--danger);
  color: var(--danger);
}

.call-status {
  color: var(--text-muted);
  font-size: 0.85rem;
}

.call-videos {
  display: flex;
  gap: 0.6rem;
  width: 100%;
  margin-top: 0.4rem;
}

.call-videos[hidden] {
  display: none;
}

.remote-video {
  width: 100%;
  max-width: 420px;
  border-radius: 10px;
  background: #000;
}

.local-video {
  width: 120px;
  border-radius: 10px;
  background: #000;
  align-self: flex-end;
}

.call-accept-btn {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
}

.room-hint {
  margin: 0 0 0.9rem;
  padding: 0.7rem 0.85rem;
  background: rgba(45, 212, 191, 0.1);
  border: 1px solid var(--accent);
  border-radius: 10px;
  color: var(--text);
  font-size: 0.85rem;
  line-height: 1.4;
}

.room-hint[hidden] {
  display: none;
}

.messages {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.message {
  font-size: 0.9rem;
  line-height: 1.45;
}

.message .msg-author {
  font-weight: 600;
  margin-right: 0.4rem;
  color: var(--accent);
}

.message.system {
  color: var(--text-muted);
  font-style: italic;
}

.message .msg-time {
  margin-left: 0.4rem;
  color: var(--text-muted);
  font-size: 0.75rem;
}

.message-form {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.85rem 1.1rem;
  border-top: 1px solid var(--border);
}

.message-form input {
  flex: 1;
  padding: 0.65rem 0.8rem;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--panel-alt);
  color: var(--text);
}

.message-form button[type="submit"] {
  padding: 0.65rem 1.1rem;
  border: none;
  border-radius: 10px;
  background: var(--accent);
  color: var(--accent-text);
  font-weight: 600;
  cursor: pointer;
}

.message-form button[type="submit"]:hover {
  background: var(--accent-hover);
}

/* --- Emoji picker --- */
.emoji-picker-wrapper {
  position: relative;
}

.emoji-btn {
  background: var(--panel-alt);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.55rem 0.65rem;
  font-size: 1.1rem;
  cursor: pointer;
  line-height: 1;
}

.emoji-picker {
  position: absolute;
  bottom: calc(100% + 0.5rem);
  left: 0;
  width: 260px;
  max-height: 220px;
  overflow-y: auto;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.6rem;
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 0.15rem;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
  z-index: 20;
}

.emoji-picker[hidden] {
  display: none;
}

.emoji-option {
  background: none;
  border: none;
  font-size: 1.25rem;
  padding: 0.3rem;
  cursor: pointer;
  border-radius: 6px;
  line-height: 1;
}

.emoji-option:hover {
  background: var(--panel-alt);
}

/* --- Modal --- */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.modal[hidden] {
  display: none;
}

.modal-content {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 1.5rem;
  width: 100%;
  max-width: 360px;
}

.call-modal-hint {
  margin: 0.5rem 0 0;
  font-size: 0.8rem;
  color: var(--text-muted);
  line-height: 1.4;
}

.modal-content textarea {
  width: 100%;
  min-height: 80px;
  margin-top: 0.5rem;
  padding: 0.6rem;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--panel-alt);
  color: var(--text);
  resize: vertical;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: 1rem;
}

.modal-actions button {
  padding: 0.55rem 0.95rem;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--panel-alt);
  color: var(--text);
  cursor: pointer;
}

#report-submit {
  background: var(--danger);
  border-color: var(--danger);
  color: white;
}

/* --- Responsive --- */
@media (max-width: 640px) {
  #chat-screen:not([hidden]) {
    flex-direction: column;
  }
  .sidebar {
    width: 100%;
    max-height: 160px;
    flex-direction: row;
    gap: 1rem;
  }
  .sidebar-section {
    flex: 1;
    min-width: 0;
  }
}
