/* Авито-чат — визуал по мотивам мессенджера Авито (светлая тема) */
:root {
  --blue: #0099f7;          /* фирменный синий Авито (действия, ссылки) */
  --blue-dark: #0086d9;
  --bg: #ffffff;
  --bg-grey: #f5f4f2;       /* фон поиска, карточек */
  --bubble-in: #f2f1f0;     /* входящий пузырь */
  --bubble-out: #d9efff;    /* исходящий пузырь (голубой как в Авито) */
  --text: #1a1a1a;
  --text-2: #8c8c8c;
  --divider: #ececec;
  --unread: #0099f7;
  --safe-b: env(safe-area-inset-bottom, 0px);
}
* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  font-size: 15px; color: var(--text); background: var(--bg);
  overscroll-behavior-y: none;
}
.hidden { display: none !important; }
.screen { position: fixed; inset: 0; display: flex; flex-direction: column; background: var(--bg); max-width: 760px; margin: 0 auto; }

/* ---------- Вход ---------- */
#scr-login { align-items: center; justify-content: center; }
.login-box { display: flex; flex-direction: column; align-items: center; gap: 12px; width: 260px; }
.login-logo { width: 76px; height: 76px; border-radius: 20px; }
.login-box h1 { font-size: 22px; }
.login-sub { color: var(--text-2); font-size: 13px; margin-top: -8px; }
.login-box input {
  width: 100%; padding: 13px 16px; font-size: 20px; letter-spacing: 6px; text-align: center;
  border: 1.5px solid var(--divider); border-radius: 14px; outline: none;
}
.login-box input:focus { border-color: var(--blue); }
.login-box button {
  width: 100%; padding: 13px; font-size: 16px; font-weight: 600; color: #fff;
  background: var(--blue); border: none; border-radius: 14px; cursor: pointer;
}
.login-box button:active { background: var(--blue-dark); }
.login-err { color: #e00000; font-size: 13px; min-height: 18px; }

/* ---------- Список диалогов ---------- */
.list-header { display: flex; align-items: center; gap: 10px; padding: 14px 16px 8px; }
.list-header h1 { font-size: 26px; font-weight: 700; }
.badge-total {
  background: var(--unread); color: #fff; font-size: 13px; font-weight: 600;
  border-radius: 12px; padding: 2px 9px;
}
.search-wrap { padding: 4px 16px 10px; }
.search-wrap input {
  width: 100%; padding: 10px 14px; font-size: 15px; border: none; outline: none;
  background: var(--bg-grey); border-radius: 12px;
}
.chatlist { flex: 1; overflow-y: auto; }
.chat-row {
  display: flex; gap: 12px; padding: 10px 16px; align-items: flex-start;
  cursor: pointer; position: relative;
}
.chat-row:active { background: var(--bg-grey); }
.row-main { flex: 1; min-width: 0; border-bottom: 1px solid var(--divider); padding-bottom: 10px; }
.chat-row:last-child .row-main { border-bottom: none; }
.row-top { display: flex; align-items: baseline; gap: 8px; }
.row-name { font-weight: 600; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-time { margin-left: auto; color: var(--text-2); font-size: 12px; flex: none; }
.row-item { color: var(--text-2); font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 1px; }
.row-snippet {
  color: var(--text-2); font-size: 13.5px; margin-top: 3px;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
  padding-right: 20px;
}
.row-snippet .me { color: var(--text); }
.row-dot {
  position: absolute; right: 16px; top: 50%; width: 10px; height: 10px;
  background: var(--unread); border-radius: 50%;
}
.btn-more {
  margin: 8px 16px calc(14px + var(--safe-b)); padding: 11px; font-size: 15px;
  background: var(--bg-grey); color: var(--text); border: none; border-radius: 12px; cursor: pointer;
}
.list-status { text-align: center; color: var(--text-2); font-size: 13px; padding: 6px 0 calc(8px + var(--safe-b)); }

/* ---------- Диалог ---------- */
.chat-header {
  display: flex; align-items: center; gap: 10px; padding: 8px 12px;
  border-bottom: 1px solid var(--divider); background: var(--bg); z-index: 2;
}
.btn-back {
  width: 36px; height: 36px; font-size: 30px; line-height: 30px; color: var(--blue);
  background: none; border: none; cursor: pointer; flex: none; padding-bottom: 6px;
}
.chat-title { min-width: 0; }
.chat-name { font-weight: 600; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-sub {
  display: block; color: var(--text-2); font-size: 12px; text-decoration: none;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.msgs { flex: 1; overflow-y: auto; padding: 12px 12px 4px; display: flex; flex-direction: column; gap: 6px; }
.day-sep {
  align-self: center; color: var(--text-2); font-size: 12px;
  background: var(--bg-grey); border-radius: 10px; padding: 3px 12px; margin: 8px 0 4px;
}
.bubble {
  max-width: 78%; padding: 9px 12px 6px; border-radius: 16px;
  font-size: 15px; line-height: 1.35; white-space: pre-wrap; word-break: break-word;
  position: relative;
}
.bubble.in  { align-self: flex-start; background: var(--bubble-in); border-bottom-left-radius: 6px; }
.bubble.out { align-self: flex-end; background: var(--bubble-out); border-bottom-right-radius: 6px; }
.bubble.failed { background: #ffe3e3; }
.bubble .meta {
  display: block; text-align: right; font-size: 11px; color: var(--text-2);
  margin-top: 3px; user-select: none;
}
.bubble img { max-width: 100%; border-radius: 10px; display: block; margin-bottom: 4px; }
.bubble.sys {
  align-self: center; background: none; color: var(--text-2); font-size: 12.5px;
  padding: 2px 8px; max-width: 90%;
}
.bubble a { color: var(--blue); }

/* Быстрые ответы */
.quick {
  display: flex; gap: 8px; overflow-x: auto; padding: 6px 12px;
  scrollbar-width: none;
}
.quick::-webkit-scrollbar { display: none; }
.quick-chip {
  flex: none; padding: 7px 14px; font-size: 13.5px; color: var(--blue);
  background: #eaf6ff; border: none; border-radius: 16px; cursor: pointer;
  white-space: nowrap; max-width: 260px; overflow: hidden; text-overflow: ellipsis;
}
.quick-chip:active { background: #d9efff; }

/* Поле ввода */
.inputbar {
  display: flex; align-items: flex-end; gap: 8px;
  padding: 8px 12px calc(8px + var(--safe-b)); border-top: 1px solid var(--divider);
  background: var(--bg);
}
.inputbar textarea {
  flex: 1; resize: none; border: none; outline: none; font: inherit;
  background: var(--bg-grey); border-radius: 18px; padding: 10px 14px;
  max-height: 120px;
}
.inputbar button {
  width: 40px; height: 40px; flex: none; border: none; border-radius: 50%;
  background: var(--blue); color: #fff; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.inputbar button:disabled { background: #c9c9c9; }
.inputbar button:active:not(:disabled) { background: var(--blue-dark); }

/* Тост */
.toast {
  position: fixed; left: 50%; bottom: calc(80px + var(--safe-b)); transform: translateX(-50%);
  background: rgba(30,30,30,.92); color: #fff; font-size: 14px;
  padding: 10px 18px; border-radius: 12px; z-index: 10; max-width: 84%;
}
