:root {
  --bg: #0e1621;
  --panel: #17212b;
  --panel-alt: #1e2b38;
  --accent: #2b8cf0;
  --text: #e6edf3;
  --text-dim: #8a96a3;
  --bubble-me: #2b5278;
  --bubble-other: #182533;
  --border: #263340;
}

* {
  box-sizing: border-box;
}

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

.hidden {
  display: none !important;
}

/* Высота экрана — это высота видимой части окна (--app-height ставит JS по
   visualViewport). На телефоне при открытии клавиатуры окно не «уезжает»
   вверх вместе с шапкой чата, а сжимается: шапка и поле ввода остаются на
   месте, прокручивается только лента сообщений. */
.screen {
  height: var(--app-height, 100%);
}

/* Login */
#login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.login-card {
  background: var(--panel);
  padding: 32px;
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: min(340px, 100%);
}

.login-card h1 {
  margin: 0 0 8px;
  font-size: 20px;
  text-align: center;
}

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

.brand-logo {
  width: 32px;
  height: 32px;
  object-fit: contain;
  flex-shrink: 0;
}

.brand-name {
  font-weight: 700;
  font-size: 18px;
}

.login-card .brand {
  justify-content: center;
  margin-bottom: 4px;
}

.login-card .brand-logo {
  width: 48px;
  height: 48px;
}

.login-card .brand-name {
  font-size: 22px;
}

.login-card input {
  padding: 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--panel-alt);
  color: var(--text);
  font-size: 16px;
}

.login-card button {
  padding: 12px;
  border-radius: 8px;
  border: none;
  background: var(--accent);
  color: white;
  font-size: 16px;
  cursor: pointer;
}

.error {
  color: #e5484d;
  font-size: 14px;
  margin: 0;
}

/* App layout */
/* Высоту сюда не дублируем: её задаёт .screen через --app-height. Селектор по
   id перебил бы её своей специфичностью, и приложение снова растянулось бы на
   всю высоту окна — под экранную клавиатуру вместе с полем ввода. */
#app-screen {
  display: flex;
  position: relative;
  overflow: hidden;
}

#sidebar {
  width: 320px;
  flex-shrink: 0;
  background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
}

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

.sidebar-header button {
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 14px;
}

/* Колокольчик уведомлений: серый, когда звук и уведомления выключены. */
.notify-btn {
  font-size: 16px;
  line-height: 1;
  padding: 0;
  opacity: 0.45;
  filter: grayscale(1);
}

.notify-btn.enabled {
  opacity: 1;
  filter: none;
}

.notify-btn:disabled {
  cursor: default;
}

#chat-list {
  overflow-y: auto;
  flex: 1;
}

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

.chat-item:hover,
.chat-item.active {
  background: var(--panel-alt);
}

.chat-item .title {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 6px;
  font-weight: 600;
}

/* Обрезается длинное имя, а не строка целиком: точка «в сети» стоит сразу за
   именем и должна остаться видимой. */
.chat-item .title .name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.online-dot {
  flex-shrink: 0;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #3fbf5f;
}

.chat-item .unread-badge {
  flex-shrink: 0;
  min-width: 20px;
  padding: 0 6px;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  line-height: 20px;
  text-align: center;
}

.chat-section-label {
  padding: 10px 16px;
  color: var(--text-dim);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

#chat-view {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

/* Шапка закреплена сверху: не сжимается и не уезжает при прокрутке ленты. */
.chat-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 16px;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  min-height: 24px;
  flex-shrink: 0;
}

/* Заголовок чата в две строки: имя собеседника и его статус в сети. */
.chat-header-info {
  display: flex;
  flex-direction: column;
  min-width: 0;
  line-height: 1.25;
}

#chat-title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#chat-subtitle {
  font-size: 12px;
  font-weight: 400;
  color: var(--text-dim);
}

#chat-subtitle.online,
#chat-subtitle.typing {
  color: var(--accent);
}

.back-btn {
  display: none;
  background: none;
  border: none;
  color: var(--text);
  font-size: 20px;
  cursor: pointer;
  padding: 0;
}

#messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.message {
  max-width: 70%;
  padding: 8px 12px;
  border-radius: 12px;
  background: var(--bubble-other);
  align-self: flex-start;
}

.message.mine {
  background: var(--bubble-me);
  align-self: flex-end;
}

.message .sender {
  font-size: 12px;
  color: var(--text-dim);
  margin-bottom: 2px;
}

.message .text {
  white-space: pre-wrap;
  word-break: break-word;
}

.message img {
  max-width: 100%;
  border-radius: 8px;
  display: block;
  margin-top: 4px;
}

.message .time {
  font-size: 11px;
  color: var(--text-dim);
  text-align: right;
  margin-top: 2px;
}

.ticks {
  font-size: 12px;
  letter-spacing: -1px;
}

.ticks.sent,
.ticks.delivered {
  color: var(--text-dim);
}

.ticks.read {
  color: #34b7f1;
}

.message-form {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.attach-btn {
  cursor: pointer;
  font-size: 20px;
}

.message-form input[type="text"] {
  flex: 1;
  padding: 10px 14px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: var(--panel-alt);
  color: var(--text);
  font-size: 16px;
}

.message-form button[type="submit"] {
  background: var(--accent);
  border: none;
  color: white;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 16px;
  flex-shrink: 0;
}

.message-form button[type="submit"]:disabled {
  opacity: 0.5;
  cursor: default;
}

/* Сообщение, которое ещё отправляется. */
.message.pending {
  opacity: 0.75;
}

.message .uploading {
  position: relative;
  margin-top: 4px;
}

.message .uploading img {
  margin-top: 0;
  max-height: 240px;
}

.upload-progress {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(14, 22, 33, 0.45);
  border-radius: 8px;
}

.upload-progress svg {
  width: 48px;
  height: 48px;
  /* Прогресс отсчитывается от 12 часов, а не от 3. */
  transform: rotate(-90deg);
}

.upload-progress circle {
  fill: none;
  stroke-width: 4;
}

.upload-track {
  stroke: rgba(255, 255, 255, 0.25);
}

.upload-bar {
  stroke: white;
  stroke-linecap: round;
  transition: stroke-dashoffset 0.15s linear;
}

#photo-preview {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

#photo-preview img {
  height: 56px;
  border-radius: 6px;
}

#photo-preview button {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 16px;
  cursor: pointer;
}

/* Просмотр фото во весь экран */
#lightbox {
  position: fixed;
  inset: 0;
  z-index: 10;
  background: rgba(0, 0, 0, 0.9);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  cursor: zoom-out;
}

#lightbox img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border-radius: 4px;
}

.message img {
  cursor: zoom-in;
}

.message.pending img {
  cursor: default;
}

@media (max-width: 768px) {
  #sidebar {
    width: 100%;
    position: absolute;
    inset: 0;
    z-index: 1;
  }

  #chat-view {
    position: absolute;
    inset: 0;
    transform: translateX(100%);
    transition: transform 0.2s ease;
    z-index: 2;
    background: var(--bg);
  }

  #app-screen.chat-open #sidebar {
    display: none;
  }

  #app-screen.chat-open #chat-view {
    transform: translateX(0);
  }

  .back-btn {
    display: block;
  }
}
