/* Мессенджер «Моей Ведической Карты» — по утверждённому макету (member.html в Codex). */
.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
.icon { width: 21px; height: 21px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; vertical-align: middle; }
body[data-view="messages"] .blog-page { max-width: 1280px; }

.icon-action {
  display: inline-flex; align-items: center; justify-content: center; flex: none;
  width: 44px; min-height: 44px; padding: 8px; border: 1px solid transparent; border-radius: 50%;
  background: transparent; color: inherit; list-style: none; cursor: pointer;
}
.icon-action::-webkit-details-marker { display: none; }
.icon-action:hover { background: hsl(var(--secondary)); }

.m-avatar {
  display: inline-grid; place-items: center; overflow: hidden; flex-shrink: 0;
  width: 44px; height: 44px; border-radius: 12px; color: var(--focus); background: #eee5d4;
  font: 700 20px/1 var(--display);
}
.m-avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }

.message-shell {
  display: grid; grid-template-columns: minmax(260px, 320px) minmax(0, 1fr); min-height: 486px;
  background: hsl(var(--card)); border: 1px solid hsl(var(--border)); border-radius: 16px; overflow: hidden;
}
.message-list { border-right: 1px solid hsl(var(--border)); padding: 16px; min-width: 0; }
.list-tabs { border-bottom: 1px solid hsl(var(--border)); margin-bottom: 12px; }
.tabs { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.tabs button {
  position: relative; min-width: 0; min-height: 44px; padding: 8px 2px; border: 0; border-bottom: 2px solid transparent;
  background: transparent; font-size: 13px; line-height: 18px; overflow-wrap: anywhere;
}
.tabs [aria-selected="true"] { border-color: hsl(var(--accent)); font-weight: 600; }
.tab-badge { display: inline-grid; place-items: center; min-width: 18px; height: 18px; margin-left: 4px; padding: 0 5px; border-radius: 9px; background: var(--action); color: var(--action-text); font: 600 10px/1 Inter, sans-serif; vertical-align: 1px; }
.contact-tools { display: flex; align-items: center; gap: 8px; }
.m-search { flex: 1; display: flex; align-items: center; min-width: 0; padding-inline: 12px; gap: 8px; border: 1px solid hsl(var(--border)); background: hsl(var(--card)); border-radius: 999px; }
.m-search:focus-within { outline: 2px solid var(--focus); outline-offset: 2px; }
.m-search .icon { width: 18px; height: 18px; color: hsl(var(--muted-foreground)); }
.m-search input { width: 100%; min-width: 0; min-height: 44px; border: 0; background: transparent; padding: 8px 0; outline: none; font-size: 14px; }
.contacts { display: grid; gap: 2px; margin-top: 12px; max-height: 560px; overflow-y: auto; }
.contact { display: flex; align-items: center; gap: 10px; width: 100%; text-align: left; border: 0; border-radius: 10px; min-width: 0; padding: 8px; background: transparent; }
.contact:hover, .contact[aria-pressed="true"] { background: hsl(var(--secondary)); }
.contact-copy { display: grid; min-width: 0; flex: 1; }
.contact-copy strong { font-weight: 600; font-size: 15px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.contact small { color: hsl(var(--muted-foreground)); font-size: 13px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.contact.unread small { color: hsl(var(--foreground)); font-weight: 500; }
.m-empty { padding: 16px 8px; color: hsl(var(--muted-foreground)); font-size: 14px; }

.support-panel { width: min(100%, 640px); min-width: 0; padding: 24px; }
.support-panel h2 { font: 700 24px/32px var(--display); }
.support-form { display: grid; gap: 16px; margin-top: 16px; }
.support-form .btn { justify-self: start; }
.m-field { display: grid; gap: 8px; font-size: 13px; font-weight: 500; }
.m-field textarea, .chat-form textarea {
  width: 100%; min-height: 48px; border: 1px solid hsl(var(--border)); border-radius: 10px; padding: 10px 12px;
  background: #fff; font: 400 16px/24px Inter, sans-serif;
}
.m-field textarea { min-height: 144px; resize: vertical; }
.m-field textarea:focus, .chat-form textarea:focus { outline: none; border-color: hsl(var(--accent)); }
.form-status { color: var(--focus); font-size: 13px; }

.welcome { align-self: center; justify-self: center; margin: 24px; text-align: center; }
.welcome h2 { font: 700 24px/32px var(--display); }
.welcome p { margin-top: 6px; font-size: 13px; color: hsl(var(--muted-foreground)); }

.conversation { min-width: 0; display: flex; flex-direction: column; }
.chat-head { display: flex; align-items: center; gap: 10px; padding: 12px 20px; border-bottom: 1px solid hsl(var(--border)); }
.chat-back { display: none; }
.peer-copy { display: grid; min-width: 0; flex: 1; }
.peer-copy a { font-weight: 600; text-decoration: none; overflow-wrap: anywhere; }
.peer-copy a[href]:hover { color: var(--gold); }
.peer-copy small { font-size: 12px; color: hsl(var(--muted-foreground)); }
.peer-copy small:empty { display: none; }

.chat-log { flex: 1; display: flex; flex-direction: column; align-items: flex-start; gap: 8px; overflow: auto; height: 420px; padding: 20px; }
.bubble { position: relative; max-width: min(85%, 54ch); padding: 8px 12px; font-size: 14px; line-height: 20px; border-radius: 10px; background: hsl(var(--secondary)); white-space: pre-wrap; overflow-wrap: anywhere; }
.bubble.mine { align-self: flex-end; background: #eee5d4; }
.bubble.deleted { font-style: italic; color: hsl(var(--muted-foreground)); }
.bubble.pending { opacity: .6; }
.bubble-author { display: block; margin-bottom: 2px; font-size: 12px; font-weight: 600; color: var(--focus); }
.bubble a { color: var(--focus); }
.bubble time { display: block; text-align: right; margin-top: 4px; color: hsl(var(--muted-foreground)); font-size: 11px; }
.bubble-quote { margin-bottom: 6px; padding: 4px 8px; border-left: 2px solid hsl(var(--accent)); font-size: 12px; color: hsl(var(--muted-foreground)); white-space: normal; }
.bubble:hover .bubble-actions, .bubble:focus-within .bubble-actions { display: flex; }
.bubble-media { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; font-weight: 500; white-space: normal; }
.bubble-media small { color: hsl(var(--muted-foreground)); font-weight: 400; }
.bubble audio { display: block; width: min(260px, 100%); height: 40px; margin-top: 4px; }
.bubble-image { display: block; max-width: min(260px, 100%); border-radius: 12px; margin-top: 4px; }
.bubble-file { display: inline-flex; align-items: center; gap: 8px; margin-top: 4px; font-weight: 500; text-decoration: none; }
.bubble.has-video { padding: 6px; background: transparent; }
.bubble.has-video time { padding-right: 6px; }
/* Видеосообщение — квадрат с мягкими углами, как в исходном проекте */
.video-message { width: 260px; max-width: 100%; }
.video-message video { display: block; width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 18px; background: #171412; }

.chat-blocked { margin: 0 16px 12px; padding: 10px 12px; border-radius: 10px; background: hsl(var(--secondary)); font-size: 13px; }
.chat-form { display: grid; gap: 8px; border-top: 1px solid hsl(var(--border)); padding: 12px 16px; }
.chat-form textarea { max-height: 144px; resize: vertical; }
.chat-toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.chat-toolbar [aria-expanded="true"] { background: hsl(var(--secondary)); }
.chat-send { margin-inline-start: auto; }
/* Ошибка отправки — как статус формы в макете. */
.chat-error { color: var(--focus); font-size: 13px; }
.emoji-picker { display: grid; grid-template-columns: repeat(auto-fit, minmax(44px, 1fr)); gap: 8px; padding: 8px; border: 1px solid hsl(var(--border)); border-radius: 10px; background: hsl(var(--background)); }
.emoji-picker button { min-width: 0; min-height: 44px; padding: 4px; border: 0; border-radius: 8px; background: transparent; font-size: 24px; }
.emoji-picker button:hover { background: hsl(var(--secondary)); }
.media-preview { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; padding: 8px 12px; background: hsl(var(--secondary)); border-radius: 10px; font-size: 14px; }
.media-preview .icon-action { margin-inline-start: auto; }

/* Запись */
.capture-stage { min-height: 120px; display: grid; place-items: center; align-content: center; gap: 8px; padding: 12px; border-radius: 12px; background: hsl(var(--secondary)); text-align: center; }
.capture-icon { width: 32px; height: 32px; color: var(--focus); }
.capture-video { width: min(100%, 260px); aspect-ratio: 1; object-fit: cover; border-radius: 18px; background: #171412; transform: scaleX(-1); }
.capture-timer { font-size: 24px; font-variant-numeric: tabular-nums; }
.call-state { color: hsl(var(--muted-foreground)); font-size: 13px; }
.call-state:empty { display: none; }

/* Беседа */
.group-people { margin: 0; padding: 0; border: 0; min-width: 0; }
.group-people legend { margin-bottom: 8px; font-size: 13px; font-weight: 500; }
#groupPeople { display: grid; gap: 2px; max-height: 240px; overflow: auto; }
#groupPeople label { display: flex; align-items: center; gap: 10px; min-height: 48px; padding: 4px 8px; border-radius: 10px; cursor: pointer; }
#groupPeople label:hover { background: hsl(var(--secondary)); }
#groupPeople input { width: 18px; height: 18px; accent-color: hsl(var(--accent)); }

/* Звонок */
.call-dialog { width: min(100%, 720px); }
.call-body { display: grid; gap: 16px; padding-bottom: 28px; }
.call-stage { position: relative; display: grid; place-items: center; aspect-ratio: 16 / 9; max-height: 56dvh; overflow: clip; border-radius: 16px; background: radial-gradient(ellipse at 45% 20%, #645651, hsl(var(--foreground)) 72%); color: hsl(var(--background)); }
.call-remote { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.call-peer { position: relative; display: grid; justify-items: center; padding: 12px; gap: 8px; text-align: center; overflow-wrap: anywhere; }
.call-peer .m-avatar { width: 64px; height: 64px; font-size: 28px; }
.call-self { position: absolute; inset: auto 12px 12px auto; display: grid; place-items: center; width: 120px; aspect-ratio: 4 / 3; overflow: hidden; border: 1px solid hsl(38 44% 97% / .25); border-radius: 10px; background: var(--action); font-size: 11px; line-height: 14px; text-align: center; }
.call-self video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; transform: scaleX(-1); }
.call-self span { display: grid; justify-items: center; gap: 4px; }
.call-self svg { width: 18px; height: 18px; }
.call-tools { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; }
.call-tools .icon-action { background: hsl(var(--secondary)); }
.call-tools .icon-action:hover, .call-tools [aria-pressed="true"] { background: #e3d6bc; }
.call-tools [aria-pressed="false"]:is(#callMic, #callCamera) { background: #973f35; color: #fff; }
.call-tools #callAccept { min-height: 48px; padding-inline: 24px; font-size: 14px; }
.call-tools #callAccept:focus-visible { background: var(--action); color: var(--action-text); outline: 2px solid hsl(var(--accent)); outline-offset: 3px; }
.call-tools #callAccept:hover { background: hsl(var(--secondary)); color: var(--action); }
.call-tools .end-call { background: #973f35; border-color: #973f35; color: #fff; }
.call-tools .end-call:hover { background: #783329; color: #fff; }

@media (max-width: 767px) {
  .message-shell { grid-template-columns: minmax(0, 1fr); }
  .message-list { border-right: 0; }
  .message-shell .welcome { display: none; }
  .message-shell:has(.support-panel:not([hidden])) .message-list { border-bottom: 1px solid hsl(var(--border)); }
  .support-panel { padding: 20px 16px; }
  .support-form .btn { width: 100%; }
  .chat-form { padding-inline: 10px; }
  .chat-send { width: 48px; padding: 8px; }
  .chat-send span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
  .call-stage { aspect-ratio: 3 / 4; }
  .call-self { width: 88px; inset: auto 8px 8px auto; }
  .video-message { width: 230px; }
}
@media (max-width: 767px), (any-pointer: coarse) {
  .tabs button, .contact-tools .icon-action, :is(.chat-head, .chat-toolbar, .call-tools, .media-preview) .icon-action, .chat-send { min-width: 48px; min-height: 48px; }
  .emoji-picker { grid-template-columns: repeat(auto-fit, minmax(48px, 1fr)); }
  .emoji-picker button { min-height: 48px; }
  .call-tools #callScreen { display: none; }
}

/* Открытая переписка на телефоне занимает экран целиком: шапка, меню и подвал уступают место вводу. */
@media (max-width: 767px), (max-height: 480px) and (any-pointer: coarse) {
  body.thread-screen { padding: 0; overflow: hidden; }
  body.thread-screen :is(.preview-header, footer.shared-shell, .platform-bottom-nav, .blog-intro, .blog-banner) { display: none !important; }
  body.thread-screen .message-list, body.thread-screen .welcome { display: none; }
  body.thread-screen .blog-page { padding: 0; }
  body.thread-screen .message-shell {
    position: fixed; inset-inline: 0; top: var(--thread-top, 0px); height: var(--thread-height, 100vh);
    display: block; min-height: 0; margin: 0; border: 0; border-radius: 0; overflow: hidden; z-index: 60;
  }
  @supports (height: 100dvh) { body.thread-screen .message-shell { height: var(--thread-height, 100dvh); } }
  body.thread-screen .conversation { display: flex; flex-direction: column; height: 100%; min-height: 0; }
  body.thread-screen .chat-log { flex: 1 1 auto; }
  body.thread-screen .chat-head { padding: calc(8px + env(safe-area-inset-top, 0px)) max(12px, env(safe-area-inset-right, 0px)) 8px max(12px, env(safe-area-inset-left, 0px)); }
  body.thread-screen .chat-back { display: inline-flex; }
  body.thread-screen .chat-log { height: auto; min-height: 0; padding: 12px max(16px, env(safe-area-inset-right, 0px)); overscroll-behavior-y: contain; background: var(--page); }
  body.thread-screen .chat-form { padding: 8px max(12px, env(safe-area-inset-right, 0px)) calc(8px + env(safe-area-inset-bottom, 0px)) max(12px, env(safe-area-inset-left, 0px)); background: hsl(var(--card)); }
  body.thread-screen .emoji-picker { max-height: min(120px, 22dvh); overflow-y: auto; }
}

/* Аудиозвонок: только собеседник и микрофон, без окна своей камеры. */
.audio-call .call-self { display: none; }
.audio-call .call-stage { aspect-ratio: auto; min-height: 220px; }

/* Видео в звонке: каждый поток в своём окне — экран или камера собеседника крупно, его камера миниатюрой при показе экрана, своя камера в углу. */
.call-remote.is-screen { object-fit: contain; background: #171412; }
.call-remote-cam { position: absolute; top: 12px; right: 12px; z-index: 2; width: 160px; aspect-ratio: 4 / 3; object-fit: cover; border-radius: 10px; border: 1px solid hsl(38 44% 97% / .25); background: #171412; }
.call-self { z-index: 2; }
.call-record-state { position: absolute; top: 12px; left: 12px; z-index: 3; background: #973f35; color: #fff; border-radius: 999px; padding: 3px 10px; font-size: 12px; }
.call-sharing { position: absolute; bottom: 12px; left: 12px; z-index: 3; background: rgb(0 0 0 / .55); color: #fff; border-radius: 999px; padding: 3px 10px; font-size: 12px; }
.call-tools #callRecord[aria-pressed="true"] { background: #973f35; color: #fff; }
.call-tools #callEnd.decline { background: #973f35; }
.bubble-recording { display: grid; gap: 4px; margin-top: 4px; padding: 10px 12px; border-radius: 12px; background: hsl(var(--card)); border: 1px solid hsl(var(--border)); white-space: normal; }
.bubble-recording strong { font-weight: 600; }
.bubble-recording small { color: hsl(var(--muted-foreground)); }
.bubble-recording a { justify-self: start; font-weight: 500; }
@media (max-width: 767px) { .call-remote-cam { width: 96px; top: 8px; right: 8px; } }
