/* bots — telegram-inspired shell, own teal accent. Light + dark. */

:root {
  --accent: #2f9e8f;
  --accent-hover: #268576;
  --accent-soft: #d9f2ee;
  --bg-panel: #ffffff;
  --bg-chat: #eef2f5;
  --bg-hover: #f2f5f7;
  --bubble-in: #ffffff;
  --bubble-out: #d9f2ee;
  --text: #1a2026;
  --text-2: #7a858f;
  --border: #e3e8ec;
  --error: #d64545;
  --plate-bg: rgba(255, 255, 255, .85);
  --plate-text: #7a858f;
  --shadow: 0 1px 2px rgba(16, 35, 47, .08);
  --pattern:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180' viewBox='0 0 180 180'%3E%3Cg fill='none' stroke='%23c8d2da' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round' opacity='.55'%3E%3Cpath d='M20 30h26v16l-7-5H20z'/%3E%3Cpath d='M120 20l-14 8 24 2z'/%3E%3Crect x='140' y='60' width='24' height='16' rx='2'/%3E%3Cpath d='M140 62l12 8 12-8'/%3E%3Cpath d='M40 120c0-6 5-10 11-10s11 4 11 10-5 10-11 10h-11z'/%3E%3Cpath d='M100 140l10-10a5 5 0 0 1 7 7l-12 12a8 8 0 0 1-11-11l12-12'/%3E%3Ccircle cx='160' cy='140' r='3'/%3E%3Ccircle cx='30' cy='80' r='3'/%3E%3Cpath d='M70 55l4 4 7-8'/%3E%3C/g%3E%3C/svg%3E");
}

html[data-theme="dark"] {
  --accent: #3ba99c;
  --accent-hover: #46b8aa;
  --accent-soft: #1f4a44;
  --bg-panel: #1e242b;
  --bg-chat: #12161b;
  --bg-hover: #252d35;
  --bubble-in: #252d35;
  --bubble-out: #1f4a44;
  --text: #e8ecef;
  --text-2: #8b959e;
  --border: #2a323a;
  --error: #e06c6c;
  --plate-bg: rgba(0, 0, 0, .35);
  --plate-text: #aab4bd;
  --shadow: 0 1px 3px rgba(0, 0, 0, .3);
  --pattern:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180' viewBox='0 0 180 180'%3E%3Cg fill='none' stroke='%23222b33' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M20 30h26v16l-7-5H20z'/%3E%3Cpath d='M120 20l-14 8 24 2z'/%3E%3Crect x='140' y='60' width='24' height='16' rx='2'/%3E%3Cpath d='M140 62l12 8 12-8'/%3E%3Cpath d='M40 120c0-6 5-10 11-10s11 4 11 10-5 10-11 10h-11z'/%3E%3Cpath d='M100 140l10-10a5 5 0 0 1 7 7l-12 12a8 8 0 0 1-11-11l12-12'/%3E%3Ccircle cx='160' cy='140' r='3'/%3E%3Ccircle cx='30' cy='80' r='3'/%3E%3Cpath d='M70 55l4 4 7-8'/%3E%3C/g%3E%3C/svg%3E");
}

* { margin: 0; padding: 0; box-sizing: border-box; }

[hidden] { display: none !important; }

html, body { height: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  font-size: 14px;
  color: var(--text);
  background: var(--bg-chat);
  overflow: hidden;
}

button { font: inherit; color: inherit; background: none; border: none; cursor: pointer; }

.app {
  display: flex;
  height: 100dvh;
  --list-width: 320px;
}

/* ---------- icons ---------- */

.icon-btn {
  width: 38px; height: 38px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 50%;
  color: var(--text-2);
  flex: none;
}
.icon-btn svg { width: 22px; height: 22px; }
.icon-btn:hover { background: var(--bg-hover); }

/* ---------- sidebar ---------- */

.sidebar {
  width: var(--list-width);
  min-width: 260px;
  flex: none;
  display: flex;
  flex-direction: column;
  background: var(--bg-panel);
  border-right: 1px solid var(--border);
}

.sidebar-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
}

.menu-wrap { position: relative; }
.menu {
  position: absolute;
  top: 44px; left: 0;
  min-width: 180px;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow);
  padding: 4px;
  z-index: 30;
}
.menu-item {
  display: block;
  width: 100%;
  text-align: left;
  padding: 9px 12px;
  border-radius: 7px;
}
.menu-item:hover { background: var(--bg-hover); }

.tabs {
  display: flex;
  gap: 4px;
  background: var(--bg-hover);
  border-radius: 9px;
  padding: 3px;
  flex: 1;
}
.tab {
  flex: 1;
  padding: 6px 0;
  border-radius: 7px;
  color: var(--text-2);
  font-weight: 500;
}
.tab.active { background: var(--bg-panel); color: var(--text); box-shadow: var(--shadow); }

.chat-list { flex: 1; overflow-y: auto; padding: 6px; }

.chat-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 8px 10px;
  border-radius: 10px;
  text-align: left;
}
.chat-item:hover { background: var(--bg-hover); }
.chat-item.active { background: var(--accent); color: #fff; }
.chat-item.active .chat-item-preview,
.chat-item.active .chat-item-time { color: rgba(255, 255, 255, .8); }

.chat-item-body { flex: 1; min-width: 0; }
.chat-item-top { display: flex; align-items: baseline; gap: 6px; }
.chat-item-name {
  flex: 1;
  font-weight: 600;
  font-size: 14px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.chat-item-time { font-size: 12px; color: var(--text-2); font-variant-numeric: tabular-nums; }
.chat-item-bottom { display: flex; align-items: center; gap: 6px; margin-top: 2px; }
.chat-item-preview {
  flex: 1;
  color: var(--text-2);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.badge {
  flex: none;
  min-width: 20px; height: 20px;
  padding: 0 6px;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  font-size: 12px;
  font-weight: 600;
  display: flex; align-items: center; justify-content: center;
}
.chat-item.active .badge { background: #fff; color: var(--accent); }
.muted-mark { flex: none; color: var(--text-2); }
.muted-mark svg { width: 14px; height: 14px; display: block; }

.chat-list-empty { padding: 40px 16px; text-align: center; color: var(--text-2); }

/* ---------- avatars ---------- */

.avatar {
  position: relative;
  width: 46px; height: 46px;
  flex: none;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: #fff;
  font-weight: 600;
  font-size: 17px;
  user-select: none;
}
.avatar.small { width: 38px; height: 38px; font-size: 14px; }
.avatar.big { width: 84px; height: 84px; font-size: 30px; }
.avatar .ch-badge {
  position: absolute;
  right: -2px; bottom: -2px;
  width: 18px; height: 18px;
  border-radius: 50%;
  /* the MAX logo is a rounded square; clip it to the round badge shape */
  overflow: hidden;
  border: 2px solid var(--bg-panel);
  display: flex; align-items: center; justify-content: center;
}
.avatar.big .ch-badge { width: 24px; height: 24px; }
.ch-badge svg { width: 100%; height: 100%; display: block; }
/* the VK logo is a rounded square with margins; scale it up so the
   round badge is filled edge to edge instead of showing cut corners */
.ch-badge svg[viewBox="0 0 101 100"] { transform: scale(1.18); }

/* ---------- resizer ---------- */

.resizer {
  width: 5px;
  margin-left: -3px;
  flex: none;
  cursor: col-resize;
  z-index: 5;
}
.resizer:hover, .resizer.dragging { background: var(--accent); opacity: .35; }

/* ---------- chat ---------- */

.chat {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  position: relative;
  background: var(--bg-chat);
}
.chat::before {
  content: "";
  position: absolute; inset: 0;
  background-image: var(--pattern);
  pointer-events: none;
}

.chat-empty {
  margin: auto;
  z-index: 1;
  background: var(--plate-bg);
  color: var(--plate-text);
  padding: 8px 16px;
  border-radius: 16px;
}

.chat-view {
  position: absolute; inset: 0;
  display: flex;
  flex-direction: column;
}

.chat-head {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 6px 12px;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border);
  z-index: 2;
}
.back-btn { display: none; }
.chat-head-info {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 8px;
  border-radius: 10px;
  min-width: 0;
}
.chat-head-info:hover { background: var(--bg-hover); }
.chat-head-info .avatar { width: 40px; height: 40px; font-size: 15px; }
.chat-head-text { display: flex; flex-direction: column; align-items: flex-start; min-width: 0; }
.chat-head-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-head-sub { font-size: 12px; color: var(--text-2); }

/* ---------- messages ---------- */

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 12px 14px 8px;
  display: flex;
  flex-direction: column;
  z-index: 1;
}

.day-sep, .unread-sep {
  align-self: center;
  margin: 10px 0;
  padding: 4px 12px;
  border-radius: 13px;
  background: var(--plate-bg);
  color: var(--plate-text);
  font-size: 13px;
  font-weight: 500;
}
.unread-sep { align-self: stretch; text-align: center; border-radius: 0; background: none; }

.author-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--accent);
  align-self: flex-end;
  margin: 6px 4px 2px 0;
}

.msg {
  max-width: min(72%, 560px);
  margin-top: 3px;
  padding: 7px 10px 6px;
  border-radius: 14px;
  position: relative;
  word-wrap: break-word;
  white-space: pre-wrap;
  box-shadow: var(--shadow);
  line-height: 1.35;
}
.msg.in { align-self: flex-start; background: var(--bubble-in); border-bottom-left-radius: 5px; }
.msg.out { align-self: flex-end; background: var(--bubble-out); border-bottom-right-radius: 5px; }

.msg-meta {
  float: right;
  margin: 6px -2px -2px 8px;
  font-size: 11px;
  color: var(--text-2);
  display: flex;
  align-items: center;
  gap: 3px;
  font-variant-numeric: tabular-nums;
}
.msg-meta svg { width: 15px; height: 15px; color: var(--accent); }
.msg-meta .st-error { color: var(--error); font-weight: 600; }

.msg img.msg-photo {
  display: block;
  max-width: 100%;
  max-height: 320px;
  border-radius: 9px;
  margin: 2px 0 4px;
  cursor: pointer;
}
.msg audio { display: block; max-width: 260px; margin: 4px 0; }
.msg-file {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 4px 0;
  color: inherit;
  text-decoration: none;
}
.msg-file-icon {
  width: 36px; height: 36px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  flex: none;
}
.msg-file-icon svg { width: 18px; height: 18px; }
.msg-file-name { font-weight: 500; word-break: break-all; }
.msg-file-size { font-size: 12px; color: var(--text-2); }

.scroll-down {
  position: absolute;
  right: 16px; bottom: 76px;
  width: 42px; height: 42px;
  border-radius: 50%;
  background: var(--bg-panel);
  color: var(--text-2);
  box-shadow: var(--shadow);
  display: flex; align-items: center; justify-content: center;
  z-index: 3;
}
.scroll-down svg { width: 22px; height: 22px; }

/* ---------- composer ---------- */

.composer {
  padding: 8px 12px calc(8px + env(safe-area-inset-bottom));
  background: var(--bg-panel);
  border-top: 1px solid var(--border);
  z-index: 2;
}
.pending-file {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 8px 8px;
  color: var(--text-2);
}
.pending-file-remove { color: var(--accent); }
.composer-row { display: flex; align-items: flex-end; gap: 6px; }
.input {
  flex: 1;
  resize: none;
  border: none;
  outline: none;
  background: none;
  color: var(--text);
  font: inherit;
  line-height: 1.4;
  max-height: 140px;
  padding: 9px 4px;
}
.input::placeholder { color: var(--text-2); }
.send-btn { color: var(--accent); }
.send-btn:hover { background: none; color: var(--accent-hover); }

/* ---------- info panel ---------- */

.info {
  width: 340px;
  flex: none;
  background: var(--bg-panel);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
}
.info-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 8px 10px 16px;
  font-weight: 600;
  border-bottom: 1px solid var(--border);
}
.info-body { flex: 1; overflow-y: auto; padding: 16px; }

.info-contact { display: flex; flex-direction: column; align-items: center; gap: 8px; margin-bottom: 8px; }
.info-name { font-size: 17px; font-weight: 600; }
.info-sub { color: var(--text-2); font-size: 13px; }
.info-id { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; color: var(--text-2); }

.info-section { margin-top: 18px; }
.info-section-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--accent);
  margin-bottom: 8px;
}
.info-row { display: flex; gap: 8px; }

select.group-select {
  flex: 1;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-panel);
  color: var(--text);
  font: inherit;
}

.text-btn {
  padding: 8px 12px;
  border-radius: 8px;
  background: var(--bg-hover);
  color: var(--accent);
  font-weight: 500;
}
.text-btn:hover { background: var(--border); }
.text-btn.danger { color: var(--error); }
.text-btn.full { width: 100%; margin-top: 8px; }

.note {
  border-left: 3px solid var(--accent);
  background: var(--bg-hover);
  border-radius: 6px;
  padding: 8px 10px;
  margin-bottom: 8px;
}
.note-text { white-space: pre-wrap; word-wrap: break-word; }
.note-meta {
  display: flex;
  justify-content: space-between;
  margin-top: 4px;
  font-size: 12px;
  color: var(--text-2);
}
.note-del { color: var(--text-2); font-size: 12px; }
.note-del:hover { color: var(--error); }

.note-add { display: flex; flex-direction: column; gap: 6px; margin-top: 8px; }
.note-add textarea {
  resize: vertical;
  min-height: 54px;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-panel);
  color: var(--text);
  font: inherit;
}

.new-group-row { display: flex; gap: 8px; margin-top: 8px; }
.new-group-row input {
  flex: 1;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-panel);
  color: var(--text);
  font: inherit;
}

/* ---------- boot / overlay ---------- */

.boot {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg-chat);
}
.boot-text { color: var(--text-2); }

.overlay {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, .35);
  z-index: 15;
}

/* ---------- responsive ---------- */

@media (max-width: 1100px) {
  .info {
    position: fixed;
    top: 0; right: 0; bottom: 0;
    z-index: 20;
    box-shadow: -4px 0 16px rgba(0, 0, 0, .15);
    border-left: none;
  }
}

@media (max-width: 760px) {
  .resizer { display: none; }
  .sidebar { width: 100%; min-width: 0; border-right: none; }
  .chat { display: none; }
  .app.mobile-chat .sidebar { display: none; }
  .app.mobile-chat .chat { display: flex; }
  .back-btn { display: flex; }
  .info { width: 100%; }
  .msg { max-width: 84%; }
}
