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

html, body { height: 100%; }

body {
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  background: #0f1420;
  color: #e8ecf3;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-text-size-adjust: 100%;
}

button { touch-action: manipulation; }

input, textarea {
  user-select: text;
  -webkit-user-select: text;
  font-family: inherit;
}

.hidden { display: none !important; }

/* ---------- экраны входа ---------- */

.screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.card {
  background: #1a2233;
  border: 1px solid #232d44;
  border-radius: 16px;
  padding: 28px;
  width: min(92vw, 380px);
  display: flex;
  flex-direction: column;
  gap: 14px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
}

.card h1 { font-size: 20px; font-weight: 600; }

.field {
  width: 100%;
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid #2a3550;
  background: #0f1420;
  color: inherit;
  font-size: 15px;
  outline: none;
}

.field:focus { border-color: #4f8cff; }

.field.code {
  text-transform: uppercase;
  letter-spacing: 6px;
  font-family: Consolas, monospace;
  font-size: 18px;
  text-align: center;
}

.btn {
  padding: 12px 16px;
  border-radius: 10px;
  border: none;
  background: #4f8cff;
  color: #fff;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}

.btn:hover { background: #649bff; }

.btn.secondary { background: #2a3550; }
.btn.secondary:hover { background: #35436a; }

.btn.ghost { background: transparent; color: #a8b3c7; padding: 8px 14px; }
.btn.ghost:hover { color: #e8ecf3; }

.divider { text-align: center; color: #66738f; font-size: 13px; }

/* список комнат в админке */
.sort-bar { display: flex; gap: 6px; flex-wrap: wrap; }

.sort-btn {
  padding: 5px 12px;
  border-radius: 999px;
  border: 1px solid #2a3550;
  background: #0f1420;
  color: #8fa0bd;
  font-size: 12px;
  cursor: pointer;
}

.sort-btn:hover { color: #e8ecf3; }
.sort-btn.active { border-color: #4f8cff; color: #cfe0ff; }

.rooms-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 42vh;
  overflow-y: auto;
}

.room-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-radius: 10px;
  border: 1px solid #2a3550;
  background: #0f1420;
  color: #e8ecf3;
  cursor: pointer;
  text-align: left;
  font-size: 13px;
}

.room-row:hover { background: #1c2740; }
.room-row.live { border-color: #2f5fd0; }

.room-code {
  font-family: Consolas, monospace;
  letter-spacing: 3px;
  font-size: 15px;
  flex: none;
}

.room-meta { display: flex; gap: 12px; align-items: center; color: #8fa0bd; }
.room-meta .online { color: #7fd88f; }
.room-row:not(.live) .online { color: #5f6c86; }
.room-meta .room-when { color: #5f6c86; font-size: 11px; }

.error { color: #ff7b72; font-size: 13px; min-height: 17px; word-break: break-word; }

.hint { color: #66738f; font-size: 12px; line-height: 1.5; }

/* ---------- чат ---------- */

/* 100dvh учитывает мобильную адресную строку (в т.ч. нижнюю) и клавиатуру */
.chat {
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
}

/* центрирующая колонка: на широких экранах чат не растягивается на весь монитор */
.shell {
  width: 100%;
  max-width: 960px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

#messages {
  width: 100%;
  max-width: 960px;
  margin: 0 auto;
}

.chat-header {
  display: flex;
  align-items: center;
  padding: 10px max(14px, env(safe-area-inset-left, 0px));
  padding-top: calc(10px + env(safe-area-inset-top, 0px));
  background: #131a29;
  border-bottom: 1px solid #232d44;
}

#code-chip {
  font-family: Consolas, monospace;
  font-size: 15px;
  letter-spacing: 4px;
  padding: 8px 14px 8px 18px;
  border: none;
  border-radius: 10px;
  background: #2a3550;
  color: #cfe0ff;
  cursor: pointer;
  flex: none;
}

#code-chip:hover { background: #35436a; }

.badge {
  background: #3a2b16;
  color: #e8b45a;
  padding: 8px 14px;
  border-radius: 999px;
  font-size: 13px;
}

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

.msg {
  max-width: 76%;
  display: flex;
  flex-direction: column;
  gap: 3px;
  align-self: flex-start;
}

.msg.own { align-self: flex-end; align-items: flex-end; }

.msg .name { font-size: 12px; color: #8fa0bd; padding: 0 4px; }

.msg .bubble {
  background: #1c2740;
  padding: 9px 13px;
  border-radius: 4px 14px 14px 14px;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 15px;
  line-height: 1.45;
}

.msg.own .bubble {
  background: #2f5fd0;
  color: #fff;
  border-radius: 14px 4px 14px 14px;
}

.msg .time { font-size: 10px; color: #5f6c86; padding: 0 4px; }

.system {
  align-self: center;
  color: #7786a3;
  font-size: 13px;
  font-style: italic;
  text-align: center;
}

.locked {
  align-self: center;
  color: #5f6c86;
  font-size: 12px;
  background: #131a29;
  border: 1px dashed #2a3550;
  border-radius: 999px;
  padding: 4px 12px;
}

.media-slot.failed {
  border: 1px solid #ff7b72;
}

.media-slot {
  position: relative;
  min-width: 180px;
  min-height: 100px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #101828;
  border-radius: 12px;
  overflow: hidden;
}

.media-slot .meta {
  display: flex;
  flex-direction: column;
  gap: 4px;
  align-items: center;
  padding: 12px 16px;
  text-align: center;
  width: 100%;
}

.media-slot .dl-name {
  font-size: 12px;
  color: #8fa0bd;
  word-break: break-all;
  max-width: 100%;
}

.media-slot .dl-label { font-size: 11px; color: #5f6c86; }

.media-slot .dl-bar {
  position: absolute;
  left: 0;
  bottom: 0;
  height: 3px;
  width: 0%;
  background: #4f8cff;
  transition: width 0.15s linear;
}

.media-slot.filled { min-height: 0; min-width: 0; background: transparent; }

img.media, video.media {
  display: block;
  max-width: min(76vw, 420px);
  max-height: 300px;
  border-radius: 12px;
  cursor: pointer;
}

/* ---------- композер ---------- */

.composer {
  position: relative;
  display: flex;
  padding: 10px max(10px, env(safe-area-inset-left, 0px));
  /* нижний отступ учитывает адресную строку/индикатор iPhone */
  padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px));
  background: #131a29;
  border-top: 1px solid #232d44;
}

.composer .shell {
  align-items: flex-end;
  position: relative;
}

#msg-input {
  flex: 1;
  resize: none;
  max-height: 132px;
  padding: 11px 13px;
  border-radius: 12px;
  border: 1px solid #2a3550;
  background: #0f1420;
  color: inherit;
  font-size: 16px; /* <16px вызывает автозум на iOS при фокусе */
  line-height: 1.4;
  outline: none;
}

#msg-input:focus { border-color: #4f8cff; }

/* прокрутка многострочного ввода работает, но полоса прокрутки не рисуется */
#msg-input { scrollbar-width: none; -ms-overflow-style: none; }
#msg-input::-webkit-scrollbar { display: none; width: 0; }

.icon-btn {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  border: none;
  background: #2a3550;
  color: #cfe0ff;
  font-size: 18px;
  cursor: pointer;
  flex: none;
}

.icon-btn:hover { background: #35436a; }
.icon-btn:disabled { opacity: 0.45; cursor: default; }
.icon-btn.send { background: #4f8cff; }
.icon-btn.send:hover { background: #649bff; }

#upload-progress {
  position: absolute;
  top: -3px;
  left: 10px;
  right: 10px;
  height: 3px;
  border-radius: 2px;
  background: #2a3550;
  overflow: hidden;
}

#upload-bar { height: 100%; width: 0%; background: #4f8cff; transition: width 0.15s linear; }

.readonly-note {
  padding: 12px;
  padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  text-align: center;
  color: #66738f;
  font-size: 13px;
  background: #131a29;
  border-top: 1px solid #232d44;
}

/* ---------- лайтбокс ---------- */

#lightbox {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.96);
  z-index: 10000;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: zoom-out;
}

#lightbox img, #lightbox video { max-width: 96vw; max-height: 96vh; border-radius: 4px; }

#lightbox-fullscreen {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 44px;
  height: 44px;
  border-radius: 12px;
  border: none;
  background: #2a3550;
  color: #cfe0ff;
  font-size: 18px;
  cursor: pointer;
}

#lightbox-fullscreen:hover { background: #35436a; }

/* ---------- blackout, toast ---------- */

#blackout {
  position: fixed;
  inset: 0;
  background: #000;
  z-index: 2147483647;
  display: none;
}

#blackout.visible { display: block; }

#toast {
  position: fixed;
  bottom: 88px;
  left: 50%;
  transform: translateX(-50%);
  background: #26324d;
  color: #e8ecf3;
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 14px;
  z-index: 10001;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
  max-width: 90vw;
  text-align: center;
}

.privacy-banner {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 8px 14px;
  background: #3a2b16;
  border-bottom: 1px solid #6b4f1e;
  color: #e8b45a;
  font-size: 12.5px;
  line-height: 1.45;
}

.privacy-banner .banner-close {
  position: absolute;
  right: 8px;
  top: 6px;
  border: none;
  background: transparent;
  color: #e8b45a;
  font-size: 14px;
  cursor: pointer;
  padding: 2px 6px;
}

/* ---------- мобильные ---------- */

@media (max-width: 640px) {
  #messages { padding: 10px; }
  .msg { max-width: 88%; }
  img.media, video.media { max-width: 86vw; }
  .card { padding: 20px; }
  .chat-header { padding-left: 8px; padding-right: 8px; }
  .composer { padding-left: 8px; padding-right: 8px; }
  #code-chip { font-size: 14px; letter-spacing: 3px; padding: 8px 10px 8px 13px; }
  #msg-input { padding: 10px 12px; }
}

/* Печать/сохранение в PDF — пустая страница */
@media print {
  body { display: none !important; }
}
