/* Оформление LuxorMessenger: mobile-first, безопасные зоны iOS, светлая/тёмная тема от системы. */
:root {
  --bg: #f3f5f9;
  --surface: #ffffff;
  --surface-2: #e9edf5;
  --text: #0f172a;
  --muted: #64748b;
  --border: #d9dfeb;
  --primary: #1e66f5;
  --primary-text: #ffffff;
  --mine: #1e66f5;
  --mine-text: #ffffff;
  --theirs: #ffffff;
  --theirs-text: #0f172a;
  --danger: #dc2626;
  --ok: #16a34a;
  --shadow: 0 1px 2px rgba(15, 23, 42, 0.08);
  --radius: 14px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f172a;
    --surface: #1e293b;
    --surface-2: #273449;
    --text: #e2e8f0;
    --muted: #94a3b8;
    --border: #334155;
    --theirs: #1e293b;
    --theirs-text: #e2e8f0;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}
button, input, textarea { font: inherit; color: inherit; }
h1 { font-size: 20px; margin: 0; font-weight: 600; }
[hidden] { display: none !important; }

#app { position: fixed; inset: 0; display: flex; justify-content: center; }
.screen {
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 760px;
  min-height: 0;
  background: var(--bg);
}
@media (min-width: 800px) {
  .screen { border-left: 1px solid var(--border); border-right: 1px solid var(--border); }
}

/* Шапка */
.bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: calc(10px + env(safe-area-inset-top)) 14px 10px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex: none;
}
.bar h1 { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-right { display: flex; align-items: center; gap: 8px; }
.me { color: var(--muted); font-size: 14px; max-width: 40vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.net-status { font-size: 12px; color: var(--muted); }

/* Кнопки и поля */
.btn {
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 10px;
  padding: 10px 14px;
  cursor: pointer;
  white-space: nowrap;
  min-height: 44px;
}
.btn:active { opacity: 0.8; }
.btn.primary { background: var(--primary); color: var(--primary-text); border-color: var(--primary); }
.btn.small { padding: 6px 10px; min-height: 36px; font-size: 14px; }
.btn.icon { padding: 8px 12px; font-size: 20px; line-height: 1; }
.btn:disabled { opacity: 0.5; cursor: default; }
.link { background: none; border: none; padding: 4px 0; cursor: pointer; text-decoration: underline; font-size: 13px; }
.link.danger { color: var(--danger); }
.mine .link.danger { color: #ffd4d4; }
input, textarea {
  width: 100%;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 16px; /* меньше 16px — iOS увеличивает страницу при фокусе */
  min-height: 44px;
}
input:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: -1px; }
.row { display: flex; gap: 10px; }
.row .btn { flex: 1; }
.error { color: var(--danger); font-size: 14px; min-height: 1.4em; }
.hint { font-size: 14px; }
.muted { color: var(--muted); }
.ok { color: var(--ok); }
.warn { color: var(--danger); }

/* Экран входа */
#screen-auth { justify-content: center; padding: 16px; padding-top: calc(16px + env(safe-area-inset-top)); }
.auth-card {
  display: flex;
  flex-direction: column;
  gap: 14px;
  background: var(--surface);
  border-radius: var(--radius);
  padding: 22px;
  box-shadow: var(--shadow);
  max-width: 420px;
  width: 100%;
  margin: 0 auto;
}
.field { display: flex; flex-direction: column; gap: 6px; font-size: 14px; color: var(--muted); }

/* Список чатов */
.push-box { padding: 10px 14px 0; display: flex; flex-direction: column; gap: 8px; }
.push-box:empty { display: none; }
.push-box .btn { align-self: flex-start; }
.search { display: flex; gap: 8px; padding: 12px 14px; }
.search-result { padding: 0 14px; }
.search-result:empty { display: none; }
.user-card {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--surface);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-bottom: 8px;
  box-shadow: var(--shadow);
}
.user-card .login { flex: 1; font-weight: 600; overflow: hidden; text-overflow: ellipsis; }
.chat-list { flex: 1; overflow-y: auto; padding: 4px 14px calc(14px + env(safe-area-inset-bottom)); }
.chat-item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  text-align: left;
  background: var(--surface);
  border: none;
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-bottom: 8px;
  box-shadow: var(--shadow);
  cursor: pointer;
}
.chat-item:active { background: var(--surface-2); }
.avatar {
  flex: none;
  width: 44px; height: 44px;
  border-radius: 50%;
  background: var(--primary);
  color: var(--primary-text);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 18px; text-transform: uppercase;
}
.chat-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.chat-row { display: flex; align-items: center; gap: 8px; }
.chat-peer { flex: 1; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-time { color: var(--muted); font-size: 12px; flex: none; }
.chat-preview { flex: 1; color: var(--muted); font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.badge {
  flex: none;
  min-width: 22px; height: 22px;
  padding: 0 7px;
  border-radius: 11px;
  background: var(--primary);
  color: var(--primary-text);
  font-size: 12px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
}
.empty { color: var(--muted); text-align: center; padding: 40px 20px; }

/* Чат */
.messages {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 12px 12px 4px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.load-more { align-self: center; margin-bottom: 6px; }
.msg { display: flex; max-width: 82%; }
.msg.mine { align-self: flex-end; }
.msg.theirs { align-self: flex-start; }
.bubble {
  border-radius: 16px;
  padding: 8px 12px 6px;
  box-shadow: var(--shadow);
  min-width: 60px;
  max-width: 100%;
}
.mine .bubble { background: var(--mine); color: var(--mine-text); border-bottom-right-radius: 4px; }
.theirs .bubble { background: var(--theirs); color: var(--theirs-text); border-bottom-left-radius: 4px; }
.text { white-space: pre-wrap; overflow-wrap: anywhere; }
.meta { display: flex; align-items: center; justify-content: flex-end; gap: 4px; margin-top: 2px; }
.time { font-size: 11px; opacity: 0.7; }

/* Статус сообщения: кружок/галочка у времени. Свои: жёлтый — отправляется, красный — ошибка (нажать = повторить),
   зелёный кружок — отправлено, зелёная галочка — доставлено, белая галочка — прочитано. Чужие: синий кружок — ещё не видел. */
.status { display: inline-flex; width: 12px; height: 12px; padding: 0; border: none; background: none; color: inherit; flex: none; }
.status svg { width: 12px; height: 12px; display: block; }
.status-sending { color: #facc15; }
.status-error { color: #ef4444; cursor: pointer; }
.status-sent, .status-delivered { color: #22c55e; }
.status-read { color: #ffffff; }
.status-unread { color: #3b82f6; }
.status.fading { transition: opacity 0.6s ease; opacity: 0; }
.file { display: flex; flex-direction: column; gap: 6px; }
.file.deleted { font-style: italic; opacity: 0.8; }
.image-link img {
  display: block;
  max-width: min(70vw, 360px);
  max-height: 360px;
  border-radius: 10px;
  object-fit: contain;
  background: var(--surface-2);
}
.file-card {
  display: flex; align-items: center; gap: 8px;
  color: inherit; text-decoration: none;
  background: rgba(127, 127, 127, 0.15);
  border-radius: 10px; padding: 8px 10px;
  max-width: 100%;
}
.file-icon { font-size: 22px; flex: none; }
.file-name { flex: 1; min-width: 0; overflow-wrap: anywhere; text-decoration: underline; }
.file-size { flex: none; font-size: 12px; opacity: 0.8; }
.composer {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
  background: var(--surface);
  border-top: 1px solid var(--border);
  flex: none;
}
.composer textarea { flex: 1; resize: none; max-height: 140px; line-height: 1.35; }
.composer.uploading { opacity: 0.6; pointer-events: none; }

/* Всплывающее сообщение */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(80px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: var(--text);
  color: var(--bg);
  padding: 10px 16px;
  border-radius: 12px;
  max-width: 90vw;
  font-size: 14px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25);
  z-index: 10;
}
