:root {
  --bg: #12151c;
  --panel: #1a1f29;
  --line: #2a3140;
  --text: #e8ecf3;
  --muted: #8d97a8;
  --accent: #4f8cff;
  --danger: #ff6b6b;
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

.screen { max-width: 680px; margin: 0 auto; padding: 12px 14px 24px; }

h1 { font-size: 26px; margin: 18px 0 4px; }
h2 { font-size: 17px; margin: 14px 0 8px; color: var(--muted); font-weight: 600; }

.hint { color: var(--muted); font-size: 13px; }
.error { color: var(--danger); font-size: 14px; }

label { display: block; margin: 12px 0; font-size: 13px; color: var(--muted); }

input:not([type="file"]) {
  display: block;
  width: 100%;
  margin-top: 4px;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  font-size: 16px;
}

button {
  padding: 10px 14px;
  border-radius: 10px;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #fff;
  font-size: 15px;
  cursor: pointer;
}

button.ghost { background: transparent; border-color: var(--line); color: var(--muted); }
button.small { padding: 4px 8px; font-size: 13px; }

header { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 6px; }
header > div:first-child { display: flex; flex-direction: column; min-width: 0; }
.head-actions { display: flex; gap: 6px; }

.chats { list-style: none; padding: 0; margin: 0 0 12px; }
.chats li { margin-bottom: 6px; }
.chat-item {
  width: 100%;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  text-align: left;
  background: var(--panel);
  border-color: var(--line);
  color: var(--text);
  padding: 12px 14px;
}
.chat-name { font-weight: 600; }
.chat-item.has-unread { border-color: var(--accent); }
.chat-item.has-unread .chat-name::after { content: " •"; color: var(--accent); }

.tabs { display: flex; gap: 4px; margin: 8px 0 10px; overflow-x: auto; }
.tab {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--muted);
  padding: 6px 12px;
  font-size: 14px;
  white-space: nowrap;
}
.tab.active { color: var(--text); border-color: var(--accent); }

.messages { list-style: none; padding: 0; margin: 0 0 8px; max-height: 62vh; overflow-y: auto; }
.messages li { padding: 3px 8px; margin-bottom: 3px; background: var(--panel); border-radius: 8px; }
.messages .meta { font-size: 10px; color: var(--muted); margin-bottom: 1px; line-height: 1.2; }
.messages .text { white-space: pre-wrap; word-break: break-word; font-size: 14px; line-height: 1.25; }
.messages audio { width: 100%; height: 32px; margin-top: 2px; }

.file-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.file-link { color: var(--accent); text-decoration: none; word-break: break-all; }

.composer { display: flex; gap: 6px; align-items: center; }
.composer input { margin: 0; padding: 4px 10px; height: 30px; font-size: 15px; border-radius: 8px; }
.composer button { padding: 0 12px; height: 30px; font-size: 15px; }

.voice-row { display: flex; align-items: center; gap: 8px; margin-top: 8px; flex-wrap: wrap; }
.voice-row button { padding: 6px 12px; font-size: 14px; }
#record.recording { background: var(--danger); border-color: var(--danger); }
.file-label {
  display: inline-flex;
  align-items: center;
  padding: 6px 10px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--panel);
  font-size: 16px;
  cursor: pointer;
  margin: 0;
}

.photos { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 6px; }
.photos .thumb { width: 100%; height: 96px; object-fit: cover; border-radius: 8px; }
.messages .thumb { width: auto; max-width: 100%; max-height: 220px; border-radius: 8px; }

.links, .docs { list-style: none; padding: 0; margin: 0; }
.links li, .docs li { padding: 10px 12px; margin-bottom: 6px; background: var(--panel); border-radius: 10px; }
.links a { color: var(--accent); word-break: break-all; }
.docs .file-link { display: inline-block; margin-bottom: 4px; }

.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .7);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 20;
}
.modal[hidden] { display: none !important; }
.modal-card { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 18px; width: 100%; max-width: 440px; }
.modal-card input { margin: 8px 0; font-size: 14px; }
.modal-actions { display: flex; gap: 8px; margin-top: 10px; }

.lightbox-card { max-width: 100%; max-height: 100%; display: flex; flex-direction: column; gap: 10px; align-items: center; }
.lightbox-card img { max-width: 100%; max-height: 80vh; border-radius: 10px; }

.link { background: none; border: none; color: var(--accent); padding: 0; font-size: 14px; text-decoration: underline; cursor: pointer; }

/* всплывающие плашки о новых сообщениях */
.toasts { position: fixed; left: 12px; right: 12px; top: calc(env(safe-area-inset-top) + 8px); z-index: 30; display: flex; flex-direction: column; gap: 6px; pointer-events: none; }
.toast {
  pointer-events: auto;
  background: var(--panel);
  border: 1px solid var(--accent);
  border-left-width: 4px;
  border-radius: 10px;
  padding: 8px 12px;
  box-shadow: 0 6px 18px rgba(0, 0, 0, .45);
  font-size: 14px;
  display: flex;
  align-items: center;
  gap: 8px;
  animation: toast-in .18s ease-out;
}
.toast .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); flex: 0 0 auto; }
.toast .body { min-width: 0; }
.toast .who { font-weight: 600; }
.toast .text { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
@keyframes toast-in { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: none; } }
.people { list-style: none; padding: 0; margin: 8px 0; max-height: 50vh; overflow-y: auto; }
.people li { padding: 10px 12px; margin-bottom: 6px; background: var(--bg); border: 1px solid var(--line); border-radius: 10px; display: flex; justify-content: space-between; gap: 8px; align-items: center; }
.people button { padding: 6px 10px; font-size: 14px; }
.ghost.wide { width: 100%; margin-bottom: 8px; }