*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  min-height: 100vh;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: #0d0d0d;
  color: #e5e5e5;
  position: relative;
  zoom: 1.33;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  background: url("/static/img/wall.jpg") center / cover no-repeat;
  opacity: 0.1;
  z-index: -1;
  pointer-events: none;
}

/* auth pages */
.auth-nav {
  display: flex;
  align-items: center;
  padding: 14px 24px;
  border-bottom: 1px solid #222;
  background: rgba(0,0,0,0.85);
}

.auth-nav a {
  color: #e5e5e5;
  font-size: 18px;
  font-weight: 600;
  text-decoration: none;
}

.auth-form {
  max-width: 380px;
  margin: 48px auto 0;
  padding: 24px;
  background: rgba(0,0,0,0.7);
  border-radius: 12px;
}

.auth-form h1 {
  font-size: 24px;
  font-weight: 600;
  text-align: center;
  margin-bottom: 32px;
}

.auth-input {
  width: 100%;
  padding: 14px 16px;
  background: #1a1a1a;
  border: 1px solid #2a2a2a;
  border-radius: 12px;
  color: #e5e5e5;
  font-size: 15px;
  outline: none;
  transition: border-color 0.15s;
  margin-bottom: 12px;
}

.auth-input:focus {
  border-color: #e5e5e5;
}

.auth-input::placeholder {
  color: #555;
}

.auth-btn {
  width: 100%;
  padding: 14px;
  background: #e5e5e5;
  color: #0d0d0d;
  border: none;
  border-radius: 12px;
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s;
  margin-top: 4px;
}

.auth-btn:hover:not(:disabled) {
  background: #d4d4d4;
}

.auth-btn:disabled {
  opacity: 0.6;
  cursor: default;
}

.auth-error {
  display: none;
  text-align: center;
  margin-top: 16px;
  padding: 12px;
  background: #1a0a0a;
  color: #cc4444;
  border-radius: 12px;
  font-size: 14px;
  line-height: 1.5;
}

.auth-switch {
  text-align: center;
  margin-top: 24px;
  color: #555;
  font-size: 14px;
}

.auth-switch a {
  color: #888;
  text-decoration: none;
  transition: color 0.15s;
}

.auth-switch a:hover {
  color: #e5e5e5;
}

/* navigation (app pages) */
.nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px;
  border-bottom: 1px solid #222;
  background: rgba(0,0,0,0.85);
}

.nav-left {
  display: flex;
  align-items: center;
  gap: 24px;
}

.nav-logo {
  color: #e5e5e5;
  font-size: 18px;
  font-weight: 600;
  text-decoration: none;
}

.nav-link {
  color: #888;
  font-size: 14px;
  text-decoration: none;
  transition: color 0.15s;
}

.nav-link:hover {
  color: #e5e5e5;
}

.nav-link.active {
  color: #e5e5e5;
}

.nav-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.nav-username {
  color: #666;
  font-size: 14px;
}

/* page layout */
.page {
  max-width: 700px;
  margin: 16px auto;
  padding: 32px 24px;
  background: rgba(0,0,0,0.7);
  border-radius: 12px;
}

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
}

.page-title {
  font-size: 22px;
  font-weight: 600;
}

/* buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 10px 20px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  border: none;
  text-decoration: none;
  transition: background 0.15s;
  white-space: nowrap;
}

.btn-primary {
  background: #e5e5e5;
  color: #0d0d0d;
}

.btn-primary:hover:not(:disabled) {
  background: #d4d4d4;
}

.btn-secondary {
  background: #1a1a1a;
  color: #e5e5e5;
  border: 1px solid #2a2a2a;
}

.btn-secondary:hover:not(:disabled) {
  background: #222;
}

.btn-danger {
  background: #2a0a0a;
  color: #cc4444;
  border: 1px solid #3a1a1a;
}

.btn-danger:hover:not(:disabled) {
  background: #3a0a0a;
}

.btn-sm {
  padding: 6px 14px;
  font-size: 13px;
}

.btn:disabled {
  opacity: 0.5;
  cursor: default;
}

/* room list */
.room-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px;
  background: #1a1a1a;
  border: 1px solid #2a2a2a;
  border-radius: 12px;
  margin-bottom: 8px;
  gap: 16px;
}

.room-info {
  min-width: 0;
}

.room-info h3 {
  font-size: 16px;
  font-weight: 500;
  margin-bottom: 4px;
}

.room-meta {
  font-size: 13px;
  color: #888;
}

.room-code {
  display: inline-block;
  padding: 1px 8px;
  background: #0d0d0d;
  border: 1px dashed #333;
  border-radius: 4px;
  font-family: monospace;
  font-size: 12px;
  color: #888;
  cursor: pointer;
  transition: border-color 0.15s;
  vertical-align: middle;
}

.room-code:hover {
  border-color: #e5e5e5;
  color: #e5e5e5;
}

.room-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

/* source list */
.source-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px;
  background: #1a1a1a;
  border: 1px solid #2a2a2a;
  border-radius: 12px;
  margin-bottom: 8px;
  gap: 16px;
}

.source-item-info {
  min-width: 0;
  flex: 1;
}

.source-item-name {
  font-size: 16px;
  font-weight: 500;
  margin-bottom: 4px;
}

.source-item-url {
  font-size: 13px;
  color: #555;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 40%;
}

.source-item-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

.source-item-active .source-item-name::after {
  content: " (активен)";
  color: #4a8;
  font-size: 12px;
  font-weight: 400;
}

.source-btn-link {
  display: inline-flex;
  align-items: center;
  padding: 8px 16px;
  background: #e5e5e5;
  color: #0d0d0d;
  border: none;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.15s;
  white-space: nowrap;
}

.source-btn-link:hover {
  background: #d4d4d4;
}

/* join row */
.join-row {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}

.join-row input {
  flex: 1;
  padding: 12px 14px;
  background: #1a1a1a;
  border: 1px solid #2a2a2a;
  border-radius: 10px;
  color: #e5e5e5;
  font-size: 14px;
  outline: none;
  transition: border-color 0.15s;
}

.join-row input:focus {
  border-color: #e5e5e5;
}

.join-row input::placeholder {
  color: #555;
}

/* modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.modal {
  background: #1a1a1a;
  border: 1px solid #2a2a2a;
  border-radius: 16px;
  padding: 24px;
  width: 90%;
  max-width: 400px;
}

.modal h2 {
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 20px;
  text-align: center;
}

.modal-input {
  width: 100%;
  padding: 12px 14px;
  background: #0d0d0d;
  border: 1px solid #2a2a2a;
  border-radius: 10px;
  color: #e5e5e5;
  font-size: 14px;
  outline: none;
  transition: border-color 0.15s;
  margin-bottom: 12px;
}

.modal-input:focus {
  border-color: #e5e5e5;
}

.modal-input::placeholder {
  color: #555;
}

.modal-btns {
  display: flex;
  gap: 8px;
}

.modal-btns .btn {
  flex: 1;
}

/* empty state */
.empty {
  text-align: center;
  padding: 48px 24px;
  color: #555;
  font-size: 14px;
}

/* toast */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: #1a1a1a;
  border: 1px solid #2a2a2a;
  color: #e5e5e5;
  padding: 12px 24px;
  border-radius: 12px;
  font-size: 14px;
  z-index: 200;
  transition: opacity 0.3s;
  pointer-events: none;
}

/* room page */
.room-body {
  height: 100dvh;
  overflow: hidden;
  display: flex;
  zoom: 1;
}

.room-video {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  background: rgba(0,0,0,0.65);
}

.room-video-inner {
  flex: 1;
  background: #000;
  position: relative;
  margin: 8px;
  border-radius: 12px;
  overflow: hidden;
}

.room-video-inner iframe {
  width: 100%;
  height: 100%;
  border: 0;
}

.room-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  color: #555;
  font-size: 14px;
  text-align: center;
  padding: 24px;
}

.room-placeholder a {
  color: #888;
  text-decoration: none;
  transition: color 0.15s;
}

.room-placeholder a:hover {
  color: #e5e5e5;
}

.room-chat {
  width: 320px;
  display: flex;
  flex-direction: column;
  border-left: 1px solid #222;
  flex-shrink: 0;
  background: rgba(0,0,0,0.1);
}

.room-chat-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  border-bottom: 1px solid #222;
  font-size: 13px;
  color: #888;
  flex-shrink: 0;
  position: relative;
}

.room-chat-header-right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 4px;
}

.room-status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  flex-shrink: 0;
}

.room-status-dot.online {
  background: #4a8;
}

.room-status-dot.offline {
  background: #c44;
}

.room-msg-count {
  color: #555;
  font-size: 12px;
}

.room-chat-header-btn {
  background: none;
  border: none;
  color: #555;
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
  font-size: 16px;
  line-height: 1;
  transition: color 0.15s;
}

.room-chat-header-btn:hover {
  color: #e5e5e5;
}

.room-source-name {
  color: #555;
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 140px;
  min-width: 0;
}

.room-source-name:not(:empty)::before {
  content: "| ";
  color: #333;
}

.room-header-menu {
  display: none;
  position: absolute;
  top: 100%;
  right: 8px;
  background: #1a1a1a;
  border: 1px solid #2a2a2a;
  border-radius: 8px;
  padding: 4px;
  z-index: 20;
  min-width: 180px;
}

.room-header-menu.open {
  display: block;
}

.room-header-menu-item {
  display: block;
  width: 100%;
  padding: 8px 12px;
  background: none;
  border: none;
  color: #ccc;
  font-size: 13px;
  text-align: left;
  cursor: pointer;
  border-radius: 4px;
  transition: background 0.15s;
}

.room-header-menu-item:hover {
  background: #2a2a2a;
  color: #e5e5e5;
}

.room-header-menu-item.danger {
  color: #c44;
}

.room-header-menu-item.danger:hover {
  background: #2a0a0a;
}

.modal-source-list {
  max-height: 280px;
  overflow-y: auto;
  margin-bottom: 12px;
}

.modal-source-item {
  display: block;
  width: 100%;
  padding: 10px 14px;
  background: #0d0d0d;
  border: 1px solid #2a2a2a;
  border-radius: 8px;
  color: #ccc;
  font-size: 14px;
  text-align: left;
  cursor: pointer;
  margin-bottom: 4px;
  transition: border-color 0.15s, color 0.15s;
}

.modal-source-item:hover {
  border-color: #e5e5e5;
  color: #e5e5e5;
}

.room-messages {
  flex: 1;
  overflow-y: auto;
  padding: 8px 16px;
  min-height: 0;
}

.room-msg {
  display: flex;
  gap: 6px;
  padding: 2px 0 2px 8px;
  font-size: 14px;
  line-height: 1.5;
  word-break: break-word;
  border-left: 3px solid transparent;
}

.room-msg.system {
  justify-content: center;
  color: #555;
  font-style: italic;
  font-size: 12px;
  padding: 4px 0;
}

.room-msg-username {
  font-weight: 600;
  white-space: nowrap;
  flex-shrink: 0;
}

.room-msg-text {
  color: #ccc;
  min-width: 0;
}

.room-chat-form {
  display: flex;
  border-top: 1px solid #222;
  flex-shrink: 0;
}

.room-chat-input {
  flex: 1;
  padding: 12px 16px;
  background: #0d0d0d;
  border: none;
  color: #e5e5e5;
  font-size: 14px;
  outline: none;
  min-width: 0;
}

.room-chat-input::placeholder {
  color: #555;
}

.room-chat-send {
  padding: 12px 16px;
  background: none;
  border: none;
  border-left: 1px solid #222;
  color: #555;
  cursor: pointer;
  font-size: 16px;
  transition: color 0.15s;
}

.room-chat-send:hover {
  color: #e5e5e5;
}

.room-chat-send:disabled {
  opacity: 0.3;
  cursor: default;
}

.room-top-left {
  position: fixed;
  top: 12px;
  left: 12px;
  z-index: 10;
}

.room-top-left a {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  background: rgba(0,0,0,0.5);
  color: #888;
  border-radius: 8px;
  text-decoration: none;
  font-size: 16px;
  transition: background 0.15s, color 0.15s;
  backdrop-filter: blur(4px);
}

.room-top-left a:hover {
  background: rgba(0,0,0,0.7);
  color: #e5e5e5;
}

@media (max-width: 1023px) {
  body {
    zoom: 1;
  }

  .nav {
    position: relative;
    justify-content: center;
    padding: 10px 12px;
  }

  .nav-left {
    gap: 12px;
    min-width: 0;
  }

  .nav-logo {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 16px;
  }

  .nav-link {
    font-size: 13px;
    white-space: nowrap;
  }

  .nav-right {
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    gap: 6px;
  }

  .nav-username {
    display: none;
  }

  .room-body {
    flex-direction: column;
  }

  .room-video {
    flex: 0 0 35dvh;
  }

  .room-video-inner {
    margin: 4px;
  }

  .room-chat {
    width: 100%;
    flex: 1;
    border-left: none;
    border-top: 1px solid #222;
    min-height: 0;
  }
}

/* scrollbar */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: #0d0d0d;
}

::-webkit-scrollbar-thumb {
  background: #2a2a2a;
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: #3a3a3a;
}

@media (pointer: fine) {
  * {
    scrollbar-width: thin;
    scrollbar-color: #2a2a2a #0d0d0d;
  }
}
