/* ============================================================
   max-ui.css — дизайн-слой «MAX» для ВЫШКА-мессенджера
   Слой визуальной полировки поверх существующих стилей.
   Логика и разметка не меняются. Цветовой закон ВЫШКИ:
   синий #1a56db (основной), зелёный #0ea86a (онлайн/успех).
   v=2 (2026-09-02) — +E4: разделители дат, pull-to-refresh
   ============================================================ */

:root {
  --accent: #1a56db;
  --accent-strong: #123fa8;
  --accent-2: #0ea86a;
  --grad-accent: linear-gradient(135deg, #3b82f6 0%, #1a56db 55%, #123fa8 100%);
  --grad-header: linear-gradient(160deg, #2352c9 0%, #16337f 100%);
  --grad-bubble-out: linear-gradient(135deg, #3b82f6 0%, #1a56db 100%);
  --radius: 16px;
  --radius-bubble: 18px;
  --shadow: 0 1px 2px rgba(15, 23, 42, 0.07), 0 4px 14px rgba(15, 23, 42, 0.05);
  --shadow-lift: 0 6px 22px rgba(26, 86, 219, 0.22);
  --accent-soft: rgba(26, 86, 219, 0.09);
  --accent-soft-strong: rgba(26, 86, 219, 0.16);
  --motion-fast: 0.16s cubic-bezier(0.2, 0.7, 0.3, 1);
  --motion-base: 0.26s cubic-bezier(0.2, 0.7, 0.3, 1);
  --motion-spring: 0.34s cubic-bezier(0.34, 1.45, 0.5, 1);
}

html[data-theme="dark"] {
  --accent: #4f82f7;
  --grad-header: linear-gradient(160deg, #17304f 0%, #0e1b33 100%);
  --grad-bubble-out: linear-gradient(135deg, #2f6bff 0%, #1d4ed8 100%);
  --accent-soft: rgba(79, 130, 247, 0.14);
  --accent-soft-strong: rgba(79, 130, 247, 0.22);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.35), 0 4px 14px rgba(0, 0, 0, 0.25);
}

/* ---------- 1. Шапки: градиент MAX ---------- */

.list-header,
.thread-header,
.view-header {
  background: var(--grad-header);
  border-bottom: none;
  color: #fff;
  position: relative;
}

.list-header::after,
.thread-header::after,
.view-header::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 1px;
  background: rgba(255, 255, 255, 0.14);
}

.list-header__title,
.view-header h1 {
  color: #fff;
  letter-spacing: -0.02em;
}

.thread-header__name {
  color: #fff;
}

.thread-header__status {
  color: rgba(255, 255, 255, 0.78);
}

.thread-header__status.is-online {
  color: #7dedc0;
}

.list-header .btn-icon,
.thread-header .btn-icon,
.view-header .btn-icon,
.list-header .btn-text,
.view-header .btn-text,
.thread-header .btn-back {
  color: #fff;
}

.list-header .btn-icon:hover,
.thread-header .btn-icon:hover,
.view-header .btn-icon:hover {
  background: rgba(255, 255, 255, 0.14);
}

/* Онлайн-точка рядом со статусом собеседника */
.thread-header__status::before {
  content: "";
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent-2);
  margin-right: 6px;
  vertical-align: 1px;
  box-shadow: 0 0 0 3px rgba(14, 168, 106, 0.22);
}

.thread-header__status:empty::before {
  display: none;
}

/* Поиск в стиле MAX: мягкая пилюля */
.search__input {
  border-radius: 22px;
  background: var(--surface-2);
  transition: box-shadow var(--motion-base), background var(--motion-base);
}

.search__input:focus {
  box-shadow: 0 0 0 2px var(--accent), background var(--surface);
}

/* ---------- 2. Список чатов ---------- */

.chat-row {
  border-radius: 14px;
  margin: 2px 8px;
  padding: 10px 10px;
  width: calc(100% - 16px);
  transition: background var(--motion-fast), transform var(--motion-fast);
}

.chat-row:hover {
  background: var(--surface-2);
  transform: translateY(-1px);
}

.chat-row:active {
  transform: scale(0.985);
}

.chat-row.is-active {
  background: var(--accent-soft);
}

.chat-row__avatar {
  box-shadow: 0 2px 8px rgba(26, 86, 219, 0.18);
}

.chat-row__badge {
  background: var(--grad-accent);
  box-shadow: 0 2px 6px rgba(26, 86, 219, 0.35);
}

/* Появление списка: каскадное затухание (stagger fade) */
@keyframes maxi-fade-up {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.chatlist .chat-row,
.chatlist .chat-row.maxi-anim {
  animation: maxi-fade-up 0.32s var(--motion-base) both;
}

.chatlist .chat-row:nth-child(1) { animation-delay: 0.02s; }
.chatlist .chat-row:nth-child(2) { animation-delay: 0.05s; }
.chatlist .chat-row:nth-child(3) { animation-delay: 0.08s; }
.chatlist .chat-row:nth-child(4) { animation-delay: 0.11s; }
.chatlist .chat-row:nth-child(5) { animation-delay: 0.14s; }
.chatlist .chat-row:nth-child(6) { animation-delay: 0.17s; }
.chatlist .chat-row:nth-child(7) { animation-delay: 0.2s; }
.chatlist .chat-row:nth-child(n + 8) { animation-delay: 0.23s; }

/* ---------- 3. Бабблы сообщений ---------- */

.msg {
  max-width: min(76%, 520px);
}

.msg--out .bubble {
  background: var(--grad-bubble-out);
  color: #fff;
  border-bottom-right-radius: 6px;
  box-shadow: 0 2px 10px rgba(26, 86, 219, 0.28);
}

.msg--in .bubble {
  background: var(--bubble-in);
  border-bottom-left-radius: 6px;
  box-shadow: var(--shadow);
}

html[data-theme="dark"] .msg--in .bubble {
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
}

/* Группировка: средние сообщения группы — ровные углы стыковки */
.msg--out:has(+ .msg--out) .bubble {
  border-bottom-right-radius: var(--radius-bubble);
}

.msg--out + .msg--out .bubble {
  border-top-right-radius: 8px;
}

.msg--in:has(+ .msg--in) .bubble {
  border-bottom-left-radius: var(--radius-bubble);
}

.msg--in + .msg--in .bubble {
  border-top-left-radius: 8px;
}

/* Текст и мета на градиенте */
.msg--out .bubble__text {
  color: #fff;
}

.msg--out .bubble__meta {
  color: rgba(255, 255, 255, 0.78);
}

.msg--out .bubble__meta .ticks {
  color: rgba(255, 255, 255, 0.9);
}

/* Цитата-ответ внутри градиентной бабблы */
.msg--out .bubble__reply {
  background: rgba(255, 255, 255, 0.16);
  border-left-color: rgba(255, 255, 255, 0.7);
  color: rgba(255, 255, 255, 0.92);
  border-radius: 10px;
}

/* Реакции: стеклянные чипы */
.bubble__reacts {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  margin-top: 4px;
  position: relative;
  z-index: 1;
}

.bubble-react {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 2px 8px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.22);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  border: 1px solid rgba(255, 255, 255, 0.25);
  font-size: 12px;
  color: #fff;
  transition: transform var(--motion-fast), background var(--motion-fast);
}

.bubble-react.is-mine {
  background: rgba(255, 255, 255, 0.34);
  border-color: rgba(255, 255, 255, 0.5);
}

.msg--in .bubble-react {
  background: var(--accent-soft);
  border-color: rgba(26, 86, 219, 0.18);
  color: var(--text);
}

.msg--in .bubble-react.is-mine {
  background: var(--accent-soft-strong);
  border-color: var(--accent);
}

.bubble-react:active {
  transform: scale(0.92);
}

.bubble-react__n {
  font-weight: 700;
}

/* Панель эмодзи-реакций: пружинное появление */
@keyframes maxi-pop-in {
  0% {
    opacity: 0;
    transform: scale(0.7) translateY(6px);
  }
  70% {
    transform: scale(1.04) translateY(0);
  }
  100% {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

.msg-act__picker.react-picker,
.msg-act__menu {
  animation: maxi-pop-in 0.22s var(--motion-spring) both;
  border-radius: 16px;
  box-shadow: 0 10px 34px rgba(15, 23, 42, 0.24);
  border: 1px solid var(--border);
}

.react-picker__btn {
  border-radius: 12px;
  transition: transform var(--motion-fast), background var(--motion-fast);
}

.react-picker__btn:hover {
  background: var(--accent-soft);
  transform: scale(1.18);
}

/* Реакция «прилипает»: мини-подпрыгивание чипа */
@keyframes maxi-react-bounce {
  0% { transform: scale(0.4); }
  60% { transform: scale(1.15); }
  100% { transform: scale(1); }
}

.bubble-react.maxi-new {
  animation: maxi-react-bounce 0.32s var(--motion-spring) both;
}

/* Анимация отправки / получения сообщения */
@keyframes maxi-msg-out {
  0% {
    opacity: 0;
    transform: translateY(10px) scale(0.92);
  }
  65% {
    transform: translateY(-1px) scale(1.01);
  }
  100% {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes maxi-msg-in {
  0% {
    opacity: 0;
    transform: translateY(8px) scale(0.96);
  }
  100% {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.msg.maxi-new.msg--out .bubble {
  animation: maxi-msg-out 0.3s var(--motion-spring) both;
}

.msg.maxi-new.msg--in .bubble {
  animation: maxi-msg-in 0.26s ease-out both;
}

/* ---------- 4. Композер ---------- */

.composer-wrap {
  background: var(--surface);
  border-top: none;
  box-shadow: 0 -4px 18px rgba(15, 23, 42, 0.06);
}

.composer__field {
  border-radius: 24px;
  box-shadow: inset 0 0 0 1px var(--border);
  transition: box-shadow var(--motion-base);
}

.composer__field:focus-within {
  box-shadow: inset 0 0 0 2px var(--accent);
}

.btn-send {
  background: var(--grad-accent);
  box-shadow: 0 3px 12px rgba(26, 86, 219, 0.4);
  transition: transform var(--motion-spring), box-shadow var(--motion-base), opacity var(--motion-fast);
}

.btn-send:not(:disabled):hover {
  transform: scale(1.07);
  box-shadow: 0 5px 18px rgba(26, 86, 219, 0.5);
}

@keyframes maxi-send-show {
  0% {
    opacity: 0;
    transform: scale(0.5) rotate(-30deg);
  }
  70% {
    transform: scale(1.1) rotate(4deg);
  }
  100% {
    opacity: 1;
    transform: scale(1) rotate(0);
  }
}

.btn-send:not(.hidden) {
  animation: maxi-send-show 0.28s var(--motion-spring) both;
}

/* Микро-анимация всех кнопок и навигации */
.btn-icon:active,
.btn-text:active,
.bottomnav__btn:active,
.sidenav__btn:active {
  transform: scale(0.9);
}

@keyframes maxi-nav-bounce {
  0% { transform: translateY(0) scale(1); }
  40% { transform: translateY(-4px) scale(1.12); }
  100% { transform: translateY(0) scale(1); }
}

.maxi-bounce {
  animation: maxi-nav-bounce 0.34s var(--motion-spring) both;
}

/* ---------- 5. Переходы экранов ---------- */

@keyframes maxi-view-in {
  from {
    opacity: 0;
    transform: translateX(14px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

.view:not(.hidden) {
  animation: maxi-view-in 0.26s var(--motion-base) both;
}

/* ---------- 6. Скелетон-загрузка ---------- */

@keyframes maxi-shimmer {
  0% { background-position: -300px 0; }
  100% { background-position: 300px 0; }
}

.maxi-skel {
  background: linear-gradient(
    90deg,
    var(--surface-2) 25%,
    color-mix(in srgb, var(--surface-2) 55%, var(--surface)) 45%,
    var(--surface-2) 65%
  );
  background-size: 600px 100%;
  animation: maxi-shimmer 1.3s infinite linear;
  border-radius: 10px;
}

.maxi-skel-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
}

.maxi-skel-row .maxi-skel--ava {
  width: 50px;
  height: 50px;
  border-radius: 50%;
  flex-shrink: 0;
}

.maxi-skel-row .maxi-skel--lines {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.maxi-skel-row .maxi-skel--line {
  height: 12px;
  border-radius: 6px;
}

.maxi-skel-row .maxi-skel--line:last-child {
  width: 60%;
}

/* ---------- 7. Настройки ---------- */

.settings-card--profile {
  background: var(--grad-header);
  color: #fff;
  border-radius: 18px;
  box-shadow: var(--shadow-lift);
}

.settings-card--profile .settings-profile__name,
.settings-profile strong {
  color: #fff;
}

.settings-profile__name,
.settings-card--profile .settings-profile [class*="__"] {
  color: #fff;
}

.settings-card--profile .settings-profile__hint,
.settings-card--profile span {
  color: rgba(255, 255, 255, 0.78);
}

.settings-toggle__track {
  border-radius: 16px;
}

.settings-toggle input:checked + .settings-toggle__track {
  background: var(--accent);
  box-shadow: 0 2px 8px rgba(26, 86, 219, 0.35);
}

.settings-group__title {
  letter-spacing: 0.04em;
  text-transform: uppercase;
  font-size: 12px;
}

.seg__btn.is-active {
  background: var(--grad-accent);
  color: #fff;
  box-shadow: 0 2px 8px rgba(26, 86, 219, 0.3);
}

/* ---------- 8. Прочее ---------- */

.btn-primary {
  background: var(--grad-accent);
  box-shadow: 0 3px 12px rgba(26, 86, 219, 0.32);
  border-radius: 14px;
  transition: transform var(--motion-fast), box-shadow var(--motion-base);
}

.btn-primary:not(:disabled):hover {
  box-shadow: 0 5px 18px rgba(26, 86, 219, 0.42);
}

.btn-primary:active {
  transform: scale(0.97);
}

.sheet {
  border-radius: 22px 22px 0 0;
}

.toast {
  border-radius: 14px;
  box-shadow: 0 8px 28px rgba(15, 23, 42, 0.25);
  animation: maxi-fade-up 0.26s var(--motion-base) both;
}

/* Онлайн-статус зелёным по цветовому закону */
.is-online,
.status-online {
  color: var(--accent-2);
}

/* Пульс звонка-плашки «В эфире» */
@keyframes maxi-live-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.45; }
}

.calls-live-dot,
[data-live] .live-dot {
  animation: maxi-live-pulse 1.6s ease-in-out infinite;
  background: var(--accent-2);
}

/* Ripple */
.maxi-ripple {
  position: absolute;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.22;
  transform: scale(0);
  animation: maxi-ripple 0.5s ease-out forwards;
  pointer-events: none;
}

@keyframes maxi-ripple {
  to {
    transform: scale(2.4);
    opacity: 0;
  }
}

.bottomnav__btn,
.sidenav__btn,
.chat-row,
.btn-send {
  position: relative;
  overflow: hidden;
}

/* Скелетон только при включённой анимации */
@media (prefers-reduced-motion: reduce) {
  .maxi-skel,
  .chatlist .chat-row,
  .view:not(.hidden),
  .msg.maxi-new .bubble,
  .btn-send:not(.hidden),
  .maxi-bounce,
  .bubble-react.maxi-new {
    animation: none !important;
  }
}

/* ---------- 9. E4: разделители дат в ленте ---------- */

.maxi-daysep {
  align-self: stretch;
  display: flex;
  justify-content: center;
  margin: 10px 0 6px;
  pointer-events: none;
  user-select: none;
}

.maxi-daysep span {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.01em;
  color: var(--muted, #64748b);
  background: var(--accent-soft, rgba(26, 86, 219, 0.09));
  border: 1px solid var(--border, rgba(15, 23, 42, 0.08));
  border-radius: 999px;
  padding: 3px 12px;
}

/* ---------- 10. E4: pull-to-refresh чип ---------- */

.maxi-ptr {
  position: fixed;
  z-index: 90;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 14px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted, #64748b);
  background: var(--surface, #fff);
  border: 1px solid var(--border, rgba(15, 23, 42, 0.08));
  box-shadow: var(--shadow-lift);
  opacity: 0;
  transform: translate(-50%, -10px) scale(0.85);
  transition: opacity 0.2s ease, transform 0.3s var(--motion-spring);
  pointer-events: none;
}

.maxi-ptr.is-pulling {
  /* во время тяги transform следует за пальцем без перехода */
  transition: opacity 0.15s ease;
}

.maxi-ptr__spin {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 2px solid var(--accent, #1a56db);
  border-top-color: transparent;
  animation: maxi-ptr-spin 0.7s linear infinite;
}

@keyframes maxi-ptr-spin {
  to {
    transform: rotate(360deg);
  }
}

@media (prefers-reduced-motion: reduce) {
  .maxi-ptr__spin {
    animation: none;
  }
}
