:root {
  --bg: #f0f2f5;
  --bg-panel: #ffffff;
  --bg-hover: #f5f6f8;
  --text: #0f1419;
  --text-secondary: #6b7280;
  --accent: #3b82f6;
  --bubble-out: #3b82f6;
  --bubble-out-text: #ffffff;
  --bubble-in: #ffffff;
  --bubble-in-text: #0f1419;
  --border: #e5e7eb;
}

[data-theme="dark"] {
  --bg: #17212b;
  --bg-panel: #1e2a35;
  --bg-hover: #232f3b;
  --text: #e8edf1;
  --text-secondary: #8b98a5;
  --accent: #4ea4f6;
  --bubble-out: #2b5278;
  --bubble-out-text: #e8edf1;
  --bubble-in: #232f3b;
  --bubble-in-text: #e8edf1;
  --border: #2b3944;
}

[data-theme="amoled"] {
  --bg: #000000;
  --bg-panel: #000000;
  --bg-hover: #0d0d0d;
  --text: #e8edf1;
  --text-secondary: #808080;
  --accent: #4ea4f6;
  --bubble-out: #1a3a52;
  --bubble-out-text: #e8edf1;
  --bubble-in: #111111;
  --bubble-in-text: #e8edf1;
  --border: #1a1a1a;
}

* { box-sizing: border-box; }

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

.auth-wrapper {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100vh;
  background: var(--bg);
}

.auth-card {
  background: var(--bg-panel);
  padding: 32px;
  border-radius: 16px;
  width: 100%;
  max-width: 380px;
  box-shadow: 0 4px 24px rgba(0,0,0,0.08);
}

.auth-card h1 {
  font-size: 22px;
  margin-bottom: 4px;
}
.auth-card p.subtitle {
  color: var(--text-secondary);
  margin-top: 0;
  margin-bottom: 20px;
  font-size: 14px;
}

.field {
  margin-bottom: 14px;
}
.field label {
  display: block;
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 6px;
}
.field input {
  width: 100%;
  padding: 11px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}
.field input:focus { outline: 2px solid var(--accent); }

.captcha-row {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg);
  padding: 10px 12px;
  border-radius: 10px;
  margin-bottom: 14px;
  font-size: 14px;
}
.captcha-row .refresh {
  cursor: pointer;
  color: var(--accent);
  font-size: 18px;
  user-select: none;
}

button.primary {
  width: 100%;
  padding: 12px;
  border: none;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}
button.primary:hover { opacity: 0.9; }
button.primary:disabled { opacity: 0.5; cursor: not-allowed; }

.auth-footer {
  text-align: center;
  margin-top: 16px;
  font-size: 13px;
  color: var(--text-secondary);
}
.auth-footer a { color: var(--accent); text-decoration: none; cursor: pointer; }

.error-msg {
  color: #ef4444;
  font-size: 13px;
  margin-bottom: 12px;
  min-height: 16px;
}

/* ==== Основной экран ==== */
.app {
  display: flex;
  height: 100vh;
}

.sidebar {
  width: 320px;
  min-width: 280px;
  background: var(--bg-panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
}
.sidebar-header {
  padding: 14px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border);
}
.sidebar-header .title { font-weight: 700; font-size: 18px; }
.sidebar-header .icons { display: flex; gap: 14px; color: var(--text-secondary); cursor: pointer; }

.search-box {
  padding: 10px 14px;
}
.search-box input {
  width: 100%;
  padding: 9px 12px;
  border-radius: 20px;
  border: none;
  background: var(--bg);
  color: var(--text);
}

.chat-list { flex: 1; overflow-y: auto; }
.chat-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  cursor: pointer;
  border-bottom: 1px solid transparent;
}
.chat-item:hover { background: var(--bg-hover); }
.chat-item.active { background: var(--bg-hover); }
.avatar {
  width: 46px; height: 46px;
  border-radius: 50%;
  background: linear-gradient(135deg,#4ea4f6,#3b82f6);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700;
  flex-shrink: 0;
  position: relative;
  overflow: hidden;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.online-dot {
  position: absolute; bottom: 0; right: 0;
  width: 11px; height: 11px; border-radius: 50%;
  background: #22c55e; border: 2px solid var(--bg-panel);
}
.chat-item-body { flex: 1; min-width: 0; }
.chat-item-title { font-weight: 600; font-size: 14.5px; }
.chat-item-preview {
  font-size: 13px; color: var(--text-secondary);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.chat-item-meta { text-align: right; font-size: 11.5px; color: var(--text-secondary); }
.unread-badge {
  display: inline-block;
  background: var(--accent);
  color: #fff;
  border-radius: 10px;
  padding: 1px 7px;
  font-size: 11px;
  margin-top: 4px;
}

.chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--bg);
}
.chat-topbar {
  padding: 12px 20px;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 12px;
}
.chat-topbar .name { font-weight: 700; }
.chat-topbar .status { font-size: 12.5px; color: var(--text-secondary); }

.messages-area {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.msg-row { display: flex; margin-bottom: 2px; }
.msg-row.out { justify-content: flex-end; }

.bubble {
  max-width: 60%;
  padding: 9px 13px;
  border-radius: 14px;
  font-size: 14.5px;
  line-height: 1.4;
  position: relative;
  word-wrap: break-word;
}
.msg-row.in .bubble {
  background: var(--bubble-in);
  color: var(--bubble-in-text);
  border-bottom-left-radius: 4px;
}
.msg-row.out .bubble {
  background: var(--bubble-out);
  color: var(--bubble-out-text);
  border-bottom-right-radius: 4px;
}
.bubble .meta {
  font-size: 10.5px;
  opacity: 0.7;
  margin-top: 3px;
  text-align: right;
}
.bubble .edited-label { font-style: italic; opacity: 0.7; }
.bubble img.attachment, .bubble video.attachment {
  max-width: 260px; border-radius: 10px; display: block; margin-bottom: 4px;
}
.bubble .reply-quote {
  border-left: 3px solid var(--accent);
  padding-left: 8px;
  font-size: 12.5px;
  opacity: 0.8;
  margin-bottom: 5px;
}
.bubble .reactions { margin-top: 4px; display: flex; gap: 4px; flex-wrap: wrap; }
.bubble .reaction-pill {
  background: rgba(0,0,0,0.08);
  border-radius: 10px;
  padding: 1px 6px;
  font-size: 12px;
  cursor: pointer;
}

.msg-actions {
  display: none;
  gap: 6px;
  font-size: 12px;
  color: var(--text-secondary);
  margin: 0 8px;
  align-self: center;
}
.msg-row:hover .msg-actions { display: flex; }
.msg-actions span { cursor: pointer; }
.msg-actions span:hover { color: var(--accent); }

.composer {
  padding: 12px 16px;
  background: var(--bg-panel);
  border-top: 1px solid var(--border);
  display: flex;
  gap: 10px;
  align-items: flex-end;
}
.composer textarea {
  flex: 1;
  resize: none;
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 10px 16px;
  font-size: 14.5px;
  max-height: 120px;
  background: var(--bg);
  color: var(--text);
  font-family: inherit;
}
.composer button.send {
  background: var(--accent);
  border: none;
  color: #fff;
  width: 42px; height: 42px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 18px;
}
.composer label.attach {
  width: 42px; height: 42px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  color: var(--text-secondary);
  font-size: 20px;
}
.composer label.attach:hover { background: var(--bg-hover); }

.empty-state {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  flex-direction: column;
  gap: 10px;
}

.reply-preview {
  padding: 8px 16px;
  background: var(--bg-hover);
  border-top: 1px solid var(--border);
  display: none;
  justify-content: space-between;
  align-items: center;
  font-size: 13px;
}
.reply-preview .close { cursor: pointer; color: var(--text-secondary); }

::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
