/* ==========================================================================
   Muted Support — UI Kit
   Дизайн-токены в духе shadcn/ui: все цвета — HSL-каналы в CSS-переменных,
   компоненты ссылаются только на токены. Иконки — Lucide (inline-спрайт).
   ========================================================================== */

/* ==========================================================================
   1. АКЦЕНТНЫЙ ЦВЕТ — меняется ТОЛЬКО здесь.
      Формат: HSL-каналы «тон насыщенность% светлота%» (без hsl()).
      Пример смены на фиолетовый: --primary: 262 83% 58%;
      Всё остальное (кнопки, бейджи, пузыри, фокус-кольца, подсветка
      активного чата) подтянется автоматически через color-mix().
   ========================================================================== */
:root {
    --primary: 221 83% 53%;              /* blue-600 */
    --primary-foreground: 210 40% 98%;   /* текст на акцентном фоне */
    --ring: 221 83% 53%;                 /* фокус-кольцо */
}

[data-theme="dark"] {
    --primary: 217 91% 60%;              /* blue-500 — ярче для тёмного фона */
    --primary-foreground: 0 0% 100%;     /* белый текст на акценте в обеих темах */
    --ring: 217 91% 60%;
}

/* --------------------------------------------------------------------------
   2. Нейтральные токены (light / dark) — чистый серый (zinc), без подмеса
      акцентного тона: сменишь акцент — нейтраль не «поплывёт»
   -------------------------------------------------------------------------- */
:root {
    --background: 0 0% 98%;
    --foreground: 240 6% 10%;

    --card: 0 0% 100%;
    --card-foreground: 240 6% 10%;

    --muted: 240 5% 96%;
    --muted-foreground: 240 4% 46%;

    --accent: 240 5% 94%;
    --accent-foreground: 240 6% 10%;

    --destructive: 0 84% 60%;
    --destructive-foreground: 0 0% 98%;

    --success: 142 71% 45%;

    --border: 240 6% 90%;
    --input: 240 6% 90%;

    --radius: 0.625rem;

    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 12px -2px rgb(0 0 0 / 0.08);
    --shadow-lg: 0 16px 40px -12px rgb(0 0 0 / 0.18);

    color-scheme: light;
}

[data-theme="dark"] {
    --background: 240 6% 5%;
    --foreground: 0 0% 96%;

    --card: 240 5% 8%;
    --card-foreground: 0 0% 96%;

    --muted: 240 4% 14%;
    --muted-foreground: 240 4% 64%;

    --accent: 240 4% 16%;
    --accent-foreground: 0 0% 96%;

    --destructive: 0 72% 55%;
    --destructive-foreground: 0 0% 98%;

    --success: 142 69% 50%;

    --border: 240 4% 15%;
    --input: 240 4% 18%;

    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.35);
    --shadow-md: 0 4px 12px -2px rgb(0 0 0 / 0.45);
    --shadow-lg: 0 16px 40px -12px rgb(0 0 0 / 0.6);

    color-scheme: dark;
}

/* Производные от акцента (автоматически следуют за --primary) */
:root, [data-theme="dark"] {
    --primary-hover: color-mix(in srgb, hsl(var(--primary)) 88%, hsl(var(--foreground)) 12%);
    --primary-soft: color-mix(in srgb, hsl(var(--primary)) 11%, transparent);
    --primary-soft-strong: color-mix(in srgb, hsl(var(--primary)) 18%, transparent);
}

/* --------------------------------------------------------------------------
   3. Reset и база
   -------------------------------------------------------------------------- */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html, body {
    height: 100%;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-size: 0.9375rem;
    line-height: 1.5;
    background: hsl(var(--background));
    color: hsl(var(--foreground));
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
}

button, input, textarea {
    font: inherit;
    color: inherit;
}

img {
    max-width: 100%;
    display: block;
}

::selection {
    background: var(--primary-soft-strong);
}

/* Тонкие скроллбары */
* {
    scrollbar-width: thin;
    scrollbar-color: hsl(var(--border)) transparent;
}
*::-webkit-scrollbar { width: 8px; height: 8px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb {
    background: hsl(var(--border));
    border-radius: 999px;
}
*::-webkit-scrollbar-thumb:hover {
    background: hsl(var(--muted-foreground) / 0.5);
}

/* --------------------------------------------------------------------------
   4. Утилиты
   -------------------------------------------------------------------------- */
.is-hidden { display: none !important; }

.text-muted { color: hsl(var(--muted-foreground)); }

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* --------------------------------------------------------------------------
   5. Иконки (Lucide)
   -------------------------------------------------------------------------- */
.icon {
    width: 1.25rem;
    height: 1.25rem;
    flex-shrink: 0;
    pointer-events: none;
}
.icon-sm { width: 1rem; height: 1rem; }
.icon-xl { width: 2.75rem; height: 2.75rem; }

.spin {
    animation: spin 0.9s linear infinite;
}
@keyframes spin {
    to { transform: rotate(360deg); }
}

/* --------------------------------------------------------------------------
   6. Кнопки
   -------------------------------------------------------------------------- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    height: 2.5rem;
    padding: 0 1rem;
    border: 1px solid transparent;
    border-radius: calc(var(--radius) - 2px);
    font-size: 0.875rem;
    font-weight: 500;
    white-space: nowrap;
    cursor: pointer;
    user-select: none;
    background: transparent;
    transition: background-color 0.15s ease, border-color 0.15s ease,
                color 0.15s ease, box-shadow 0.15s ease, transform 0.1s ease;
}

.btn:focus-visible {
    outline: none;
    box-shadow: 0 0 0 2px hsl(var(--background)), 0 0 0 4px hsl(var(--ring));
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn:active:not(:disabled) {
    transform: scale(0.97);
}

.btn-primary {
    background: hsl(var(--primary));
    color: hsl(var(--primary-foreground));
    box-shadow: var(--shadow-sm);
}
.btn-primary:hover:not(:disabled) {
    background: var(--primary-hover);
}

.btn-outline {
    border-color: hsl(var(--input));
    background: hsl(var(--card));
}
.btn-outline:hover:not(:disabled) {
    background: hsl(var(--accent));
}

.btn-ghost {
    color: hsl(var(--muted-foreground));
}
.btn-ghost:hover:not(:disabled) {
    background: hsl(var(--accent));
    color: hsl(var(--accent-foreground));
}

.btn-icon {
    width: 2.5rem;
    padding: 0;
    flex-shrink: 0;
}

/* --------------------------------------------------------------------------
   7. Поля ввода
   -------------------------------------------------------------------------- */
.input {
    width: 100%;
    height: 2.5rem;
    padding: 0 0.75rem;
    border: 1px solid hsl(var(--input));
    border-radius: calc(var(--radius) - 2px);
    background: hsl(var(--card));
    color: hsl(var(--foreground));
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.input::placeholder {
    color: hsl(var(--muted-foreground));
}

.input:focus-visible {
    outline: none;
    border-color: hsl(var(--ring));
    box-shadow: 0 0 0 3px var(--primary-soft-strong);
}

.input-with-icon {
    position: relative;
}
.input-with-icon .input {
    padding-left: 2.25rem;
}
.input-with-icon .input-icon {
    position: absolute;
    left: 0.75rem;
    top: 50%;
    transform: translateY(-50%);
    color: hsl(var(--muted-foreground));
}

.label {
    display: block;
    margin-bottom: 0.5rem;
    font-size: 0.875rem;
    font-weight: 500;
}

/* --------------------------------------------------------------------------
   8. Карточки, аватары, бейджи
   -------------------------------------------------------------------------- */
.card {
    background: hsl(var(--card));
    color: hsl(var(--card-foreground));
    border: 1px solid hsl(var(--border));
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
}

.avatar {
    position: relative;
    width: 2.75rem;
    height: 2.75rem;
    border-radius: 50%;
    flex-shrink: 0;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--primary-soft-strong);
    color: hsl(var(--primary));
    font-weight: 600;
    font-size: 1rem;
    user-select: none;
}

.avatar img {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.avatar-sm {
    width: 2.25rem;
    height: 2.25rem;
    font-size: 0.875rem;
}

.unread-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 1.375rem;
    height: 1.375rem;
    padding: 0 0.375rem;
    border-radius: 999px;
    background: hsl(var(--primary));
    color: hsl(var(--primary-foreground));
    font-size: 0.75rem;
    font-weight: 600;
    flex-shrink: 0;
}

/* --------------------------------------------------------------------------
   9. Каркас приложения
   -------------------------------------------------------------------------- */
.app {
    display: flex;
    height: 100dvh;
}

/* --------------------------------------------------------------------------
   10. Сайдбар
   -------------------------------------------------------------------------- */
.sidebar {
    display: flex;
    flex-direction: column;
    width: 21.25rem;
    flex-shrink: 0;
    background: hsl(var(--card));
    border-right: 1px solid hsl(var(--border));
}

.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    padding: 1rem 1rem 0.75rem;
}

.brand {
    display: flex;
    align-items: center;
    gap: 0.625rem;
    min-width: 0;
}

.brand-mark {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 2.5rem;
    height: 2.5rem;
    border-radius: calc(var(--radius) - 2px);
    background: hsl(var(--primary));
    color: hsl(var(--primary-foreground));
    flex-shrink: 0;
}

.brand-text {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.brand-title {
    font-size: 0.9375rem;
    font-weight: 700;
    letter-spacing: -0.01em;
    white-space: nowrap;
}

.brand-subtitle {
    font-size: 0.75rem;
    color: hsl(var(--muted-foreground));
    white-space: nowrap;
}

.sidebar-actions {
    display: flex;
    gap: 0.125rem;
}

/* Иконка темы: показываем только актуальную */
.theme-icon-light { display: none; }
.theme-icon-dark { display: block; }
[data-theme="dark"] .theme-icon-light { display: block; }
[data-theme="dark"] .theme-icon-dark { display: none; }

/* Переключатель уведомлений: колокольчик по состоянию */
.notify-on-icon { display: none; }
.notify-off-icon { display: block; }
#notify-toggle.is-on .notify-on-icon { display: block; }
#notify-toggle.is-on .notify-off-icon { display: none; }
#notify-toggle.is-on { color: hsl(var(--primary)); }

.sidebar-search {
    padding: 0 1rem 0.75rem;
}

.dialogs {
    flex: 1;
    overflow-y: auto;
    padding: 0.25rem 0.5rem 0.75rem;
    display: flex;
    flex-direction: column;
    gap: 0.125rem;
    overscroll-behavior: contain;
}

.dialog-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.625rem 0.75rem;
    border-radius: calc(var(--radius) - 2px);
    cursor: pointer;
    transition: background-color 0.15s ease;
    -webkit-tap-highlight-color: transparent;
}

.dialog-item:hover {
    background: hsl(var(--accent));
}

.dialog-item.active {
    background: var(--primary-soft);
}

.dialog-item.active .dialog-name {
    color: hsl(var(--primary));
}

.dialog-body {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 0.125rem;
}

.dialog-top {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 0.5rem;
}

.dialog-name {
    font-weight: 600;
    font-size: 0.875rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.dialog-time {
    font-size: 0.6875rem;
    color: hsl(var(--muted-foreground));
    flex-shrink: 0;
    font-variant-numeric: tabular-nums;
}

.dialog-bottom {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
}

.dialog-meta {
    font-size: 0.75rem;
    color: hsl(var(--muted-foreground));
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.dialogs-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.75rem;
    padding: 3rem 1rem;
    color: hsl(var(--muted-foreground));
    text-align: center;
    font-size: 0.875rem;
}

.sidebar-backdrop {
    display: none;
}

/* --------------------------------------------------------------------------
   11. Окно чата
   -------------------------------------------------------------------------- */
.chat {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    position: relative;
}

.chat-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    min-height: 4rem;
    background: hsl(var(--card));
    border-bottom: 1px solid hsl(var(--border));
}

.chat-menu-btn {
    display: none;
}

.chat-peer {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    min-width: 0;
    flex: 1;
}

.chat-peer-info {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.chat-peer-name {
    font-size: 0.9375rem;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-peer-meta {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-size: 0.75rem;
    white-space: nowrap;
    overflow: hidden;
}

.chat-peer-id {
    opacity: 0.75;
    font-variant-numeric: tabular-nums;
}

.chat-placeholder-title {
    flex: 1;
    font-size: 1rem;
    font-weight: 600;
    color: hsl(var(--muted-foreground));
}

.chat-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-left: auto;
}

.chat-loader {
    display: flex;
    align-items: center;
    color: hsl(var(--primary));
}

/* --------------------------------------------------------------------------
   12. Сообщения
   -------------------------------------------------------------------------- */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 1.25rem 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 0.375rem;
    overscroll-behavior: contain;
    /* scroll-behavior: smooth здесь нельзя — плавная прокрутка проезжает
       через верх контейнера и ложно триггерит подгрузку истории;
       поведение задаётся в JS для каждого вызова scrollTo */
}

.chat-empty {
    position: absolute;
    inset: 4rem 0 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    color: hsl(var(--muted-foreground));
    text-align: center;
    pointer-events: none;
}

.chat-empty .icon-xl {
    opacity: 0.4;
}

.date-divider {
    align-self: center;
    margin: 0.75rem 0 0.375rem;
    padding: 0.25rem 0.75rem;
    border-radius: 999px;
    background: hsl(var(--muted));
    color: hsl(var(--muted-foreground));
    font-size: 0.75rem;
    font-weight: 500;
}

.message {
    max-width: min(72%, 34rem);
    padding: 0.5rem 0.75rem;
    border-radius: 1.125rem;
    animation: message-in 0.18s ease;
    word-break: break-word;
    overflow-wrap: anywhere;
}

@keyframes message-in {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: none; }
}

.message.user {
    align-self: flex-start;
    background: hsl(var(--card));
    border: 1px solid hsl(var(--border));
    border-bottom-left-radius: 0.375rem;
}

.message.support {
    align-self: flex-end;
    background: hsl(var(--primary));
    color: hsl(var(--primary-foreground));
    border-bottom-right-radius: 0.375rem;
}

.message-text {
    white-space: pre-wrap;
}

.message .timestamp {
    display: block;
    margin-top: 0.125rem;
    font-size: 0.6875rem;
    text-align: right;
    opacity: 0.65;
    font-variant-numeric: tabular-nums;
}

.message-media {
    border-radius: 0.75rem;
    max-height: 20rem;
    object-fit: contain;
    cursor: zoom-in;
    margin-bottom: 0.25rem;
    background: hsl(var(--muted));
}

.message.has-media {
    padding: 0.375rem;
}
.message.has-media .message-text,
.message.has-media .timestamp {
    padding: 0 0.5rem;
}
.message.has-media .timestamp {
    padding-bottom: 0.25rem;
}

.media-broken {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    width: 14rem;
    max-width: 100%;
    padding: 1.5rem 1rem;
    border-radius: 0.75rem;
    background: hsl(var(--muted));
    color: hsl(var(--muted-foreground));
    font-size: 0.8125rem;
    text-align: center;
}

/* --------------------------------------------------------------------------
   13. Композер (ввод сообщения)
   -------------------------------------------------------------------------- */
.composer {
    padding: 0.75rem 1rem calc(0.75rem + env(safe-area-inset-bottom, 0px));
    background: hsl(var(--card));
    border-top: 1px solid hsl(var(--border));
}

.composer-row {
    display: flex;
    align-items: flex-end;
    gap: 0.5rem;
}

.composer-input {
    flex: 1;
    min-height: 2.5rem;
    max-height: 10rem;
    padding: 0.5rem 0.875rem;
    border: 1px solid hsl(var(--input));
    border-radius: 1.25rem;
    background: hsl(var(--background));
    resize: none;
    overflow-y: hidden;
    line-height: 1.5;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.composer-input.is-scrollable {
    overflow-y: auto;
}

.composer-input::placeholder {
    color: hsl(var(--muted-foreground));
}

.composer-input:focus-visible {
    outline: none;
    border-color: hsl(var(--ring));
    box-shadow: 0 0 0 3px var(--primary-soft-strong);
}

.composer #send-button,
.composer #attach-btn {
    border-radius: 50%;
}

.composer.drag-over {
    outline: 2px dashed hsl(var(--primary));
    outline-offset: -6px;
    background: var(--primary-soft);
}

.image-preview-container {
    position: relative;
    display: inline-block;
    margin-bottom: 0.625rem;
}

.image-preview {
    max-height: 7.5rem;
    border-radius: calc(var(--radius) - 2px);
    border: 1px solid hsl(var(--border));
}

.image-preview-remove {
    position: absolute;
    top: -0.5rem;
    right: -0.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 1.5rem;
    height: 1.5rem;
    border: none;
    border-radius: 50%;
    background: hsl(var(--destructive));
    color: hsl(var(--destructive-foreground));
    cursor: pointer;
    box-shadow: var(--shadow-sm);
}

/* --------------------------------------------------------------------------
   14. Модальные окна
   -------------------------------------------------------------------------- */
.modal-overlay {
    position: fixed;
    inset: 0;
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    background: rgb(0 0 0 / 0.5);
    backdrop-filter: blur(4px);
    animation: fade-in 0.15s ease;
}

@keyframes fade-in {
    from { opacity: 0; }
    to { opacity: 1; }
}

.modal-card {
    width: 100%;
    max-width: 24rem;
    box-shadow: var(--shadow-lg);
    animation: modal-in 0.18s ease;
}

@keyframes modal-in {
    from { opacity: 0; transform: translateY(10px) scale(0.98); }
    to { opacity: 1; transform: none; }
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    padding: 1rem 1rem 0.75rem 1.25rem;
}

.modal-header h3 {
    font-size: 1rem;
    font-weight: 600;
}

.modal-body {
    padding: 0 1.25rem 1rem;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 0.5rem;
    padding: 0.75rem 1.25rem 1.25rem;
}

/* --------------------------------------------------------------------------
   15. Тосты
   -------------------------------------------------------------------------- */
.toast-container {
    position: fixed;
    top: 1rem;
    right: 1rem;
    z-index: 300;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    max-width: min(22rem, calc(100vw - 2rem));
}

.toast {
    display: flex;
    align-items: flex-start;
    gap: 0.625rem;
    padding: 0.75rem 0.875rem;
    background: hsl(var(--card));
    color: hsl(var(--card-foreground));
    border: 1px solid hsl(var(--border));
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
    font-size: 0.875rem;
    animation: toast-in 0.2s ease;
}

@keyframes toast-in {
    from { opacity: 0; transform: translateX(12px); }
    to { opacity: 1; transform: none; }
}

.toast.toast-hide {
    opacity: 0;
    transform: translateX(12px);
    transition: opacity 0.25s ease, transform 0.25s ease;
}

.toast-icon { margin-top: 0.0625rem; }
.toast-info .toast-icon { color: hsl(var(--primary)); }
.toast-success .toast-icon { color: hsl(var(--success)); }
.toast-error .toast-icon { color: hsl(var(--destructive)); }

.toast-message {
    flex: 1;
    min-width: 0;
}

.toast-close {
    display: flex;
    border: none;
    background: transparent;
    color: hsl(var(--muted-foreground));
    cursor: pointer;
    padding: 0.125rem;
    border-radius: 0.25rem;
}
.toast-close:hover {
    color: hsl(var(--foreground));
}

/* --------------------------------------------------------------------------
   16. Экран авторизации
   -------------------------------------------------------------------------- */
.auth-overlay {
    position: fixed;
    inset: 0;
    z-index: 400;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    background: hsl(var(--background));
}

.auth-card {
    width: 100%;
    max-width: 24rem;
    padding: 2rem 1.75rem;
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.625rem;
    box-shadow: var(--shadow-lg);
}

.auth-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 4rem;
    height: 4rem;
    border-radius: 50%;
    background: var(--primary-soft);
    color: hsl(var(--primary));
    margin-bottom: 0.375rem;
}

.auth-card h2 {
    font-size: 1.25rem;
    font-weight: 700;
    letter-spacing: -0.01em;
}

.auth-widget {
    margin: 0.875rem 0;
    min-height: 2.5rem;
}

.auth-note {
    font-size: 0.8125rem;
}

/* --------------------------------------------------------------------------
   17. Адаптив (мобильные устройства)
   -------------------------------------------------------------------------- */
@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        inset: 0 auto 0 0;
        z-index: 150;
        width: min(21.25rem, 86vw);
        transform: translateX(-100%);
        transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
        box-shadow: none;
        padding-top: env(safe-area-inset-top, 0px);
    }

    .sidebar.is-open {
        transform: translateX(0);
        box-shadow: var(--shadow-lg);
    }

    .sidebar-backdrop {
        display: block;
        position: fixed;
        inset: 0;
        z-index: 140;
        background: rgb(0 0 0 / 0.45);
        backdrop-filter: blur(2px);
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.25s ease;
    }

    .sidebar-backdrop.is-visible {
        opacity: 1;
        pointer-events: auto;
    }

    .chat-menu-btn {
        display: inline-flex;
    }

    .chat-header {
        padding: 0.5rem 0.75rem;
        padding-top: calc(0.5rem + env(safe-area-inset-top, 0px));
        min-height: 3.5rem;
        gap: 0.5rem;
    }

    .chat-messages {
        padding: 1rem 0.875rem;
    }

    .message {
        max-width: 86%;
    }

    .chat-empty {
        inset: 3.5rem 0 0;
        padding: 0 1.5rem;
    }

    .composer {
        padding: 0.5rem 0.625rem calc(0.5rem + env(safe-area-inset-bottom, 0px));
    }

    .refund-btn-label {
        display: none;
    }

    #refund-btn {
        width: 2.5rem;
        padding: 0;
    }

    .toast-container {
        top: auto;
        bottom: calc(4.5rem + env(safe-area-inset-bottom, 0px));
        left: 1rem;
        right: 1rem;
        max-width: none;
    }
}

/* Крупные экраны: чуть больше воздуха */
@media (min-width: 1600px) {
    .sidebar { width: 24rem; }
    .chat-messages { padding: 1.5rem 3rem; }
}

/* Уважение к reduce-motion */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}
