/* Чат (chat.js). Цвета — токены из style.css, светлая и тёмная тема берутся оттуда. */
.chat {
  display: grid; grid-template-columns: minmax(240px, 320px) minmax(0, 1fr); min-width: 0;
  height: calc(100vh - 76px); min-height: 440px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden;
}
.chat-side { border-right: 1px solid var(--border); display: flex; flex-direction: column; min-height: 0; min-width: 0; }
.chat-side-head { padding: 14px 16px 8px; font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); font-weight: 600; }
.chat-list { overflow-y: auto; padding: 0 8px 8px; flex: 1 1 auto; overscroll-behavior: contain; }
.chat-item {
  display: flex; align-items: center; gap: 10px; padding: 9px 8px; border-radius: var(--radius-sm); color: var(--text);
  text-decoration: none !important; min-width: 0;
}
.chat-item:hover { background: var(--surface2); }
.chat-item.active { background: var(--accent-soft); }
.chat-item.off { opacity: .6; }
.chat-item .ava, .chat-head .ava { width: 40px; height: 40px; font-size: 14px; }
.chat-ava-all { background: var(--accent-soft) !important; color: var(--accent) !important; }
.chat-ava-all .ico { width: 20px; height: 20px; }
.chat-item-main { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.chat-item-top, .chat-item-bottom { display: flex; align-items: center; gap: 8px; min-width: 0; }
.chat-item-name { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.chat-item-time { font-size: 12px; color: var(--muted); flex: 0 0 auto; }
.chat-item-last { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; color: var(--muted); }
.chat-item-bottom .count { margin-left: 0; flex: 0 0 auto; }

.chat-pane { display: flex; flex-direction: column; min-height: 0; min-width: 0; }
.chat-blank { margin: auto; padding: 24px; max-width: 360px; text-align: center; }
.chat-head { display: flex; align-items: center; gap: 10px; padding: 10px 16px; border-bottom: 1px solid var(--border); min-width: 0; }
.chat-title { font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-sub { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-back { display: none; }

.chat-msgs { flex: 1 1 auto; overflow-y: auto; overflow-x: hidden; padding: 12px 16px; background: var(--surface2); overscroll-behavior: contain; }
.chat-older { display: flex; margin: 0 auto 10px; }
.chat-empty { text-align: center; padding: 30px 10px; }
.chat-day { text-align: center; margin: 12px 0 8px; }
.chat-day span { display: inline-block; padding: 2px 10px; border-radius: 999px; background: var(--surface3); color: var(--muted); font-size: 12px; }
.msg { display: flex; margin-top: 8px; min-width: 0; }
.msg.cont { margin-top: 2px; }
.msg.mine { justify-content: flex-end; }
.msg-bubble {
  max-width: min(78%, 560px); min-width: 0; padding: 7px 11px 5px; border-radius: 14px; border-top-left-radius: 6px;
  background: var(--surface); border: 1px solid var(--border); overflow-wrap: anywhere;
}
.msg.mine .msg-bubble { background: var(--accent-soft); border-color: transparent; border-top-left-radius: 14px; border-top-right-radius: 6px; }
.msg-author { font-size: 12px; font-weight: 650; color: var(--accent); margin-bottom: 1px; }
.msg.cont .msg-author { display: none; }
.msg-text { white-space: pre-wrap; line-height: 1.4; }
.msg-gone { color: var(--muted); font-style: italic; }
.msg-meta { display: flex; align-items: center; justify-content: flex-end; gap: 6px; font-size: 11px; color: var(--muted); margin-top: 2px; font-variant-numeric: tabular-nums; }
.msg-del { display: inline-grid; place-items: center; border: 0; background: none; color: var(--muted); padding: 2px; cursor: pointer; border-radius: 6px; }
.msg-del:hover { color: var(--neg); background: var(--neg-soft); }
.msg-del .ico { width: 14px; height: 14px; }
.msg-img { display: block; margin: 2px 0 6px; }
.msg-img img { display: block; max-width: 100%; max-height: 280px; border-radius: 10px; background: var(--surface3); }
.msg-file {
  display: flex; align-items: center; gap: 8px; padding: 7px 9px; margin: 2px 0 4px; border-radius: 10px; min-width: 0;
  background: color-mix(in srgb, var(--surface3) 70%, transparent); color: var(--text); text-decoration: none !important;
}
.msg-file .ico { color: var(--accent); }
.msg-file-name { display: block; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg-file-size { display: block; font-size: 12px; color: var(--muted); }

.chat-progress { padding: 6px 16px; border-top: 1px solid var(--border); font-size: 12px; color: var(--muted); }
.chat-progress-text { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-progress-bar { display: block; height: 4px; border-radius: 2px; background: var(--surface3); margin-top: 4px; overflow: hidden; }
.chat-progress-bar i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .2s; }
.chat-compose { display: flex; align-items: flex-end; gap: 6px; padding: 8px 10px; border-top: 1px solid var(--border); background: var(--surface); }
.chat-input {
  flex: 1 1 auto; min-width: 0; resize: none; min-height: 40px; max-height: 140px; padding: 9px 12px; line-height: 1.4;
  border: 1px solid var(--border-strong); border-radius: 20px; background: var(--surface2); color: var(--text);
}
.chat-input:focus { outline: 2px solid color-mix(in srgb, var(--accent) 40%, transparent); outline-offset: 0; border-color: var(--accent); }
.chat-btn {
  display: inline-grid; place-items: center; width: 40px; height: 40px; flex: 0 0 auto; padding: 0; border: 0; border-radius: 50%;
  background: none; color: var(--muted); cursor: pointer;
}
.chat-btn:hover { background: var(--surface2); color: var(--text); }
.chat-send { background: var(--accent); color: var(--accent-text); }
.chat-send:hover { background: var(--accent); color: var(--accent-text); filter: brightness(1.08); }
.chat-btn[disabled] { opacity: .45; cursor: default; }

/* значок чата в шапке телефона */
.top-chat { display: none; }

@media (max-width: 899px) {
  .chat {
    display: block; height: auto; min-height: 0; border-radius: 16px;
  }
  .chat-side { border-right: 0; }
  .chat-side-head { display: none; }
  .chat-list { padding: 6px; }
  .chat.has-conv .chat-side { display: none; }
  .chat:not(.has-conv) .chat-pane { display: none; }
  .chat.has-conv { margin: -14px -14px 0; border: 0; border-radius: 0; box-shadow: none; }
  .main:has(> div > .chat.has-conv) { padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom)); }
  .chat-pane {
    height: calc(100vh - 52px - var(--nav-h));
    height: calc(100dvh - 52px - var(--nav-h) - env(safe-area-inset-top) - env(safe-area-inset-bottom));
  }
  .chat-head { padding: 8px 10px; }
  .chat-back { display: inline-grid; place-items: center; width: 34px; height: 40px; margin-right: -4px; color: var(--text); }
  .chat-back .ico { width: 22px; height: 22px; }
  .chat-msgs { padding: 10px; }
  .msg-bubble { max-width: 86%; }
  .chat-input { font-size: 16px; }
  .top-chat {
    display: inline-grid; place-items: center; position: relative; width: 36px; height: 36px; flex: 0 0 auto;
    border: 1px solid var(--border); border-radius: 999px; background: var(--surface2); color: var(--text); text-decoration: none !important;
  }
  .top-chat .ico { width: 19px; height: 19px; }
  .top-chat .count { position: absolute; top: -5px; right: -6px; margin: 0; min-width: 18px; line-height: 18px; font-size: 11px; padding: 0 5px; }
}
