:root {
  --bg: #0e1621;
  --panel: #17212b;
  --panel-alt: #1c2733;
  --border: #0b131b;
  --text: #e4e6eb;
  --muted: #8a97a3;
  --accent: #4ea4f7;
  --bubble-out: #2b5278;
  --bubble-in: #1f2733;
}

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

.login-body { display: flex; align-items: center; justify-content: center; height: 100vh; }
.login-card { background: var(--panel); padding: 32px; border-radius: 12px; display: flex; flex-direction: column; gap: 12px; width: min(320px, 90vw); }
.login-card h1 { margin: 0 0 8px; font-size: 20px; text-align: center; }
.login-card input { background: var(--panel-alt); border: 1px solid var(--border); color: var(--text); padding: 10px 12px; border-radius: 8px; font-size: 15px; }
.login-card button { background: var(--accent); border: none; color: #fff; padding: 10px; border-radius: 8px; font-size: 15px; cursor: pointer; }
.login-card .error { color: #f36; margin: 0; font-size: 13px; }

.layout { display: grid; grid-template-columns: 260px 300px 1fr; height: 100vh; }
/* min-width:0 — у grid-элементов по умолчанию min-width:auto, и длинное
   название чата/папки без пробелов распирает колонку шире вьюпорта,
   из-за этого и была горизонтальная прокрутка. */
.pane { overflow-y: auto; overflow-x: hidden; border-right: 1px solid var(--border); min-width: 0; }
.folders { background: var(--panel); padding: 0; display: flex; flex-direction: column; }
.search-box { padding: 10px 12px; border-bottom: 1px solid var(--border); display: flex; gap: 8px; }
.search-box input { flex: 1; min-width: 0; background: var(--panel-alt); border: 1px solid var(--border); color: var(--text); padding: 8px 10px; border-radius: 16px; font-size: 14px; }
.notify-btn { flex: none; background: var(--panel-alt); border: 1px solid var(--border); border-radius: 50%; width: 36px; height: 36px; font-size: 16px; cursor: pointer; color: var(--text); }
.notify-btn.on { background: var(--accent); }
.search-results { overflow-y: auto; }
.search-section { padding: 8px 14px 4px; font-size: 12px; color: var(--muted); text-transform: uppercase; }
.search-status { padding: 14px; color: var(--muted); font-size: 13px; }
#folder-list { padding: 8px 0; }
.dialogs { background: var(--panel-alt); }
.chat { display: flex; flex-direction: column; border-right: none; }

.folder-item, .dialog-item { padding: 10px 14px; cursor: pointer; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.folder-item.active, .dialog-item.active { background: var(--accent); color: #fff; }
.dialog-item { display: flex; flex-direction: column; gap: 2px; border-bottom: 1px solid var(--border); white-space: normal; }
.dialog-item .title { font-weight: 600; display: flex; justify-content: space-between; gap: 8px; }
.dialog-item .title .title-text { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dialog-item .preview { color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.unread { flex: none; background: var(--accent); color: #fff; border-radius: 10px; font-size: 11px; padding: 1px 6px; }

.messages { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.msg { max-width: 70%; padding: 8px 12px; border-radius: 12px; background: var(--bubble-in); align-self: flex-start; overflow-wrap: anywhere; word-break: break-word; }
.msg.out { background: var(--bubble-out); align-self: flex-end; }
.msg .meta { font-size: 11px; color: var(--muted); margin-top: 4px; }
.msg img { max-width: 100%; border-radius: 8px; display: block; }
.msg .media-chip { display: inline-block; padding: 4px 8px; background: var(--panel); border-radius: 6px; font-size: 13px; cursor: pointer; }
.load-older { align-self: center; color: var(--accent); cursor: pointer; font-size: 13px; padding: 6px; }

.send-form { display: flex; gap: 8px; padding: 10px; border-top: 1px solid var(--border); background: var(--panel); }
.send-form input { flex: 1; background: var(--panel-alt); border: 1px solid var(--border); color: var(--text); padding: 10px 12px; border-radius: 20px; font-size: 15px; }
.send-form button { background: var(--accent); border: none; color: #fff; width: 40px; border-radius: 50%; font-size: 16px; cursor: pointer; }
.send-form button:disabled, .send-form input:disabled { opacity: .5; cursor: default; }

.back-btn { display: none; padding: 10px 14px; color: var(--accent); cursor: pointer; }

@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; }
  .pane { display: none; border-right: none; }
  .layout.view-folders .folders,
  .layout.view-dialogs .dialogs,
  .layout.view-chat .chat { display: flex; flex-direction: column; }
  .layout.view-folders .folders { display: block; }
  .layout.view-dialogs .dialogs { display: block; }
  /* По одной кнопке «назад» на экран, строго под текущий вид — иначе на
     экране чата одновременно видны обе кнопки (в папки и в диалоги) и
     непонятно, какая из них реально ведёт в список чатов. */
  .layout.view-dialogs .back-to-folders { display: block; }
  .layout.view-chat .back-to-dialogs { display: block; }
}
