/* ============================================================================
 * Mystik Support Widget
 * Стили под основной CSS-стек germes.dev (CSS-переменные --gold/--bg2/--text)
 * Префикс: .ms-* (mystik-support)
 * ============================================================================ */

/* ───────────── FAB (floating action button) ───────────── */
@keyframes ms-fab-breathe {
    0% {
        transform: scale(1);
        box-shadow: 0 6px 20px rgba(0,0,0,0.4),
                    0 0 0 1px rgba(255,255,255,0.05) inset,
                    0 0 0 0 rgba(201,168,76,0.7);
    }
    35% {
        transform: scale(1.20);
        box-shadow: 0 14px 36px rgba(0,0,0,0.55),
                    0 0 0 1px rgba(255,255,255,0.1) inset,
                    0 0 0 22px rgba(201,168,76,0);
    }
    70%, 100% {
        transform: scale(1);
        box-shadow: 0 6px 20px rgba(0,0,0,0.4),
                    0 0 0 1px rgba(255,255,255,0.05) inset,
                    0 0 0 0 rgba(201,168,76,0);
    }
}

.ms-fab {
    position: fixed;
    right: 24px;
    bottom: 24px;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    border: none;
    background-color: var(--gold, #c9a84c);
    background-image: url('../assets/images/support-scroll.png');
    background-repeat: no-repeat;
    background-position: center;
    background-size: 60%;
    color: #080808;
    cursor: pointer;
    z-index: 9998;
    box-shadow: 0 6px 20px rgba(0,0,0,0.4), 0 0 0 1px rgba(255,255,255,0.05) inset;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    -webkit-tap-highlight-color: transparent;
    animation: ms-fab-breathe 1.8s ease-in-out infinite;
    will-change: transform, box-shadow;
}
.ms-fab:hover {
    transform: translateY(-2px) scale(1.04);
    box-shadow: 0 10px 28px rgba(0,0,0,0.5);
    animation-play-state: paused;
}
.ms-fab:active {
    transform: scale(0.96);
    animation-play-state: paused;
}
/* На время открытого окна анимация не нужна */
body.ms-window-open .ms-fab {
    animation: none;
}
/* prefers-reduced-motion НЕ отключаем — Риан явно хочет видеть pulse.
   Если в будущем нужно accessibility-friendly — заменить scale-transform на opacity-glow,
   который не вызывает motion sickness. */
/* старый SVG-icon скрыт — место занято background-image иконкой свитка */
.ms-fab-icon { display: none; }
.ms-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    min-width: 20px;
    height: 20px;
    border-radius: 10px;
    background: #c62828;
    color: #fff;
    font: 700 11px/20px var(--body-font, sans-serif);
    text-align: center;
    padding: 0 6px;
    border: 2px solid #080808;
    box-sizing: content-box;
}

/* ───────────── window — dark gold edition (v1) ───────────── */
:root {
    --ms-ink: #e0d9ce;          /* основной светлый текст */
    --ms-ink-soft: #8a7f72;     /* приглушённый */
    --ms-ink-mute: #6a6258;     /* выцветший — placeholder/время */
    --ms-paper-dark: rgba(201,168,76,0.2);  /* золотая полупрозрачная рамка */
}
.ms-window {
    position: fixed;
    right: 24px;
    bottom: 92px;
    width: 380px;
    max-width: calc(100vw - 32px);
    height: 560px;
    max-height: calc(100vh - 120px);
    background: var(--bg2, #0f0f0f);
    color: var(--text, #e0d9ce);
    font-family: var(--body-font, 'Proza Libre', sans-serif);
    font-size: 14px;
    line-height: 1.5;
    border: 1px solid var(--border, rgba(201,168,76,0.2));
    border-radius: 14px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.6);
    z-index: 9999;
    display: none;
    flex-direction: column;
    overflow: hidden;
}
.ms-window.is-open { display: flex; }

/* Mobile fullscreen */
@media (max-width: 639px) {
    .ms-window {
        right: 0; bottom: 0;
        width: 100%;
        max-width: 100%;
        height: 100%;
        max-height: 100%;
        border-radius: 0;
        border: none;
    }
    body.ms-window-open {
        overflow: hidden;
    }
    /* FAB прячем ТОЛЬКО когда окно открыто (а не всегда на mobile) */
    body.ms-window-open .ms-fab {
        display: none;
    }
    /* На mobile FAB чуть меньше + ниже к safe-area */
    .ms-fab {
        width: 52px;
        height: 52px;
        right: 16px;
        bottom: max(16px, env(safe-area-inset-bottom, 16px));
    }
    .ms-invite {
        right: 12px;
        left: 12px;
        width: auto;
        bottom: 82px;
    }
}

.ms-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    background: linear-gradient(180deg, rgba(201,168,76,0.08), transparent);
    border-bottom: 1px solid var(--border, rgba(201,168,76,0.15));
}
.ms-title {
    font-family: var(--heading-font, 'BluuNext', Georgia, serif);
    font-size: 18px;
    color: #fff;
    letter-spacing: 0.3px;
}
.ms-header-actions {
    display: flex;
    align-items: center;
    gap: 4px;
}
.ms-mute {
    background: transparent;
    border: none;
    color: var(--text-muted, #8a7f72);
    font-size: 18px;
    line-height: 1;
    cursor: pointer;
    padding: 6px;
    border-radius: 4px;
    transition: background 0.2s, transform 0.15s;
    -webkit-tap-highlight-color: transparent;
}
.ms-mute:hover { background: rgba(201,168,76,0.12); }
.ms-mute:active { transform: scale(0.92); }

.ms-close {
    background: transparent;
    border: none;
    color: var(--text-muted, #8a7f72);
    font-size: 28px;
    line-height: 1;
    cursor: pointer;
    padding: 0 4px;
    transition: color 0.2s;
}
.ms-close:hover { color: var(--gold, #c9a84c); }

.ms-status {
    padding: 8px 16px;
    font-size: 12px;
    letter-spacing: 0.4px;
    border-bottom: 1px solid var(--border, rgba(201,168,76,0.1));
    color: var(--text-muted, #8a7f72);
}
.ms-status--online::before {
    content: '';
    display: inline-block;
    width: 8px; height: 8px;
    background: #6abf6a; border-radius: 50%;
    margin-right: 8px; vertical-align: middle;
    box-shadow: 0 0 6px rgba(106,191,106,0.7);
}
.ms-status--offline::before {
    content: '';
    display: inline-block;
    width: 8px; height: 8px;
    background: #8a7f72; border-radius: 50%;
    margin-right: 8px; vertical-align: middle;
}

.ms-body {
    flex: 1;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

/* ───────────── error toast ───────────── */
.ms-error {
    background: #4a1b1b;
    color: #ffb4b4;
    padding: 10px 14px;
    margin: 10px 12px 0;
    border-radius: 6px;
    font-size: 13px;
    border-left: 3px solid #c62828;
}

/* ───────────── form (создание тикета) ───────────── */
.ms-form {
    padding: 14px 16px 16px;
    overflow-y: auto;
}
.ms-field {
    display: block;
    margin-bottom: 12px;
}
.ms-field > span,
.ms-field-label {
    display: block;
    font-size: 11px;
    letter-spacing: 1.5px;
    text-transform: uppercase;
    color: var(--text-muted, #8a7f72);
    margin-bottom: 6px;
    font-weight: 600;
}
.ms-form input[type="text"],
.ms-form input[type="email"],
.ms-form textarea,
.ms-composer textarea {
    width: 100%;
    background: #1a1a1a;
    color: var(--text, #e0d9ce);
    border: 1px solid var(--border, rgba(201,168,76,0.2));
    border-radius: 6px;
    padding: 10px 12px;
    font-family: var(--body-font, sans-serif);
    font-size: 14px;
    line-height: 1.4;
    outline: none;
    transition: border-color 0.2s, background 0.2s;
}
.ms-form input::placeholder,
.ms-form textarea::placeholder,
.ms-composer textarea::placeholder {
    color: var(--text-muted, #8a7f72);
}
.ms-form input:focus,
.ms-form textarea:focus,
.ms-composer textarea:focus {
    border-color: var(--gold, #c9a84c);
    background: #1f1f1f;
}
.ms-form textarea {
    resize: vertical;
    min-height: 80px;
    max-height: 200px;
}

.ms-contact-choice {
    margin-bottom: 12px;
}
.ms-contact-tabs {
    display: flex;
    gap: 4px;
    background: #141414;
    border: 1px solid var(--border, rgba(201,168,76,0.15));
    border-radius: 6px;
    padding: 3px;
    margin-bottom: 8px;
}
.ms-contact-tab {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--text-muted, #8a7f72);
    padding: 8px 12px;
    border-radius: 4px;
    font-family: var(--body-font, sans-serif);
    font-size: 13px;
    cursor: pointer;
    transition: background 0.2s, color 0.2s;
}
.ms-contact-tab:hover { color: var(--text, #e0d9ce); }
.ms-contact-tab.is-active {
    background: var(--gold, #c9a84c);
    color: #080808;
    font-weight: 600;
}
.ms-tg-wrap {
    position: relative;
    display: flex;
    align-items: center;
}
.ms-tg-at {
    position: absolute;
    left: 14px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted, #8a7f72);
    pointer-events: none;
    font-size: 14px;
    line-height: 1;
    z-index: 1;
}
.ms-form .ms-tg-wrap input[type="text"] {
    padding-left: 30px;
}

.ms-form-bottom {
    display: flex;
    gap: 12px;
    align-items: center;
    justify-content: flex-end;
    margin-top: 14px;
}
/* attach остаётся слева, send — справа (круглая печать) */
.ms-form-bottom .ms-attach-btn { margin-right: auto; }
.ms-attach-btn {
    background: transparent;
    border: 1px solid var(--border, rgba(201,168,76,0.2));
    color: var(--text-muted, #8a7f72);
    width: 40px;
    height: 40px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 18px;
    transition: background 0.2s, color 0.2s, border-color 0.2s;
    flex-shrink: 0;
}
.ms-attach-btn:hover {
    background: rgba(201,168,76,0.1);
    color: var(--gold, #c9a84c);
    border-color: var(--gold, #c9a84c);
}
/* Кнопка «Отправить» — реалистичная восковая печать с бумажным самолётиком (Bridge-generated PNG) */
.ms-send-btn {
    width: 64px;
    height: 64px;
    flex: 0 0 64px;
    border-radius: 50%;
    background: url('../assets/images/support-seal.png') center/contain no-repeat;
    color: transparent;
    border: none;
    padding: 0;
    cursor: pointer;
    transition: transform 0.15s, filter 0.2s;
    filter: drop-shadow(0 3px 5px rgba(60,15,15,0.5));
    position: relative;
    font-size: 0;
    -webkit-tap-highlight-color: transparent;
}
.ms-send-btn:hover {
    transform: rotate(-4deg) scale(1.04);
    filter: drop-shadow(0 5px 10px rgba(60,15,15,0.6)) brightness(1.05);
}
.ms-send-btn:active {
    transform: scale(0.94) rotate(-2deg);
    filter: drop-shadow(0 2px 3px rgba(60,15,15,0.55));
}
.ms-send-btn:disabled { cursor: wait; filter: drop-shadow(0 1px 2px rgba(60,15,15,0.3)) brightness(0.85) saturate(0.7); }

.ms-agreement {
    font-size: 11px;
    color: var(--text-muted, #8a7f72);
    line-height: 1.5;
    margin-top: 10px;
}

/* ───────────── attachments (preview before send) ───────────── */
.ms-attachments {
    margin: 8px 0;
}
.ms-att-pending {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: #161616;
    border: 1px solid var(--border, rgba(201,168,76,0.15));
    border-radius: 4px;
    padding: 4px 8px;
    margin: 2px 4px 2px 0;
    font-size: 12px;
    color: var(--text, #e0d9ce);
}
.ms-att-pending.is-uploading { opacity: 0.6; }
.ms-att-pending .ms-att-name { max-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ms-att-pending .ms-att-size { color: var(--text-muted, #8a7f72); }
.ms-att-remove {
    background: transparent;
    border: none;
    color: var(--text-muted, #8a7f72);
    cursor: pointer;
    padding: 0 4px;
    font-size: 16px;
    line-height: 1;
}
.ms-att-remove:hover { color: #c62828; }

/* ───────────── chat (dark gold v1) ───────────── */
.ms-chat {
    flex: 1;
    overflow-y: auto;
    padding: 14px 14px 4px;
    scroll-behavior: smooth;
}
.ms-msg {
    display: flex;
    margin-bottom: 10px;
}
.ms-msg--user { justify-content: flex-end; }
.ms-msg--admin,
.ms-msg--system,
.ms-msg--bot { justify-content: flex-start; }

.ms-bubble {
    max-width: 80%;
    padding: 10px 14px 8px;
    border-radius: 14px;
    word-wrap: break-word;
    white-space: pre-wrap;
    box-shadow: 0 2px 6px rgba(0,0,0,0.35);
}
/* Сообщение клиента — тёплый золотистый, светлее фона */
.ms-msg--user .ms-bubble {
    background: linear-gradient(180deg, #4a3f1f 0%, #3a3017 100%);
    border: 1px solid rgba(201,168,76,0.35);
    border-top-right-radius: 4px;
}
/* Сообщение оператора — графитовый с золотой полоской */
.ms-msg--admin .ms-bubble {
    background: linear-gradient(180deg, #2e2e2e 0%, #232323 100%);
    border: 1px solid rgba(201,168,76,0.18);
    border-left: 3px solid var(--gold, #c9a84c);
    border-top-left-radius: 4px;
}
.ms-msg--system { justify-content: center; }
.ms-msg--system .ms-bubble {
    background: rgba(201,168,76,0.08);
    border: 1px solid rgba(201,168,76,0.18);
    color: #c9a84c;
    font-style: italic;
    font-size: 12.5px;
    text-align: center;
    max-width: 100%;
    border-radius: 8px;
    padding: 8px 14px;
    box-shadow: none;
}
.ms-bubble-body {
    color: #f4ede0;
    font-size: 15px;
    line-height: 1.55;
    font-weight: 400;
}
.ms-bubble-time {
    font-size: 11px;
    color: rgba(244,237,224,0.55);
    text-align: right;
    margin-top: 5px;
    letter-spacing: 0.4px;
}

.ms-msg-atts {
    margin-top: 6px;
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}
.ms-att-img {
    display: block;
    border-radius: 6px;
    overflow: hidden;
    max-width: 200px;
    max-height: 200px;
}
.ms-att-img img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
}
.ms-att-file {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: rgba(0,0,0,0.3);
    padding: 6px 10px;
    border-radius: 6px;
    color: var(--text, #e0d9ce);
    text-decoration: none;
    font-size: 13px;
    border: 1px solid var(--border, rgba(201,168,76,0.15));
}
.ms-att-file:hover { background: rgba(0,0,0,0.5); }
.ms-att-icon { font-size: 14px; }
.ms-att-name { max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ms-att-size { color: var(--text-muted, #8a7f72); font-size: 11px; }

/* ───────────── composer ───────────── */
.ms-composer {
    border-top: 1px solid var(--border, rgba(201,168,76,0.15));
    padding: 10px 12px;
    background: #0c0c0c;
}
.ms-composer-row {
    display: flex;
    gap: 8px;
    align-items: flex-end;
}
.ms-composer textarea {
    flex: 1;
    min-height: 44px;
    max-height: 120px;
    resize: vertical;
}
.ms-composer .ms-send-btn {
    /* В composer печать чуть меньше формы (54 vs 64) — экономим место */
    width: 54px;
    height: 54px;
    flex: 0 0 54px;
}
.ms-composer .ms-attach-btn {
    height: 44px;
    width: 44px;
}

/* ───────────── popup invitation ───────────── */
.ms-invite {
    position: fixed;
    right: 24px;
    bottom: 96px;
    width: 320px;
    max-width: calc(100vw - 48px);
    background: var(--bg2, #0f0f0f);
    color: var(--text, #e0d9ce);
    border: 1px solid var(--gold, #c9a84c);
    border-radius: 12px;
    padding: 16px 18px 14px;
    z-index: 9997;
    box-shadow: 0 16px 40px rgba(0,0,0,0.6);
    font-family: var(--body-font, sans-serif);
    animation: msInviteIn 0.4s ease-out;
}
@keyframes msInviteIn {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}
.ms-invite-close {
    position: absolute;
    top: 4px;
    right: 8px;
    background: transparent;
    border: none;
    color: var(--text-muted, #8a7f72);
    font-size: 20px;
    cursor: pointer;
    line-height: 1;
    padding: 4px 8px;
}
.ms-invite-close:hover { color: var(--gold, #c9a84c); }
.ms-invite-title {
    font-family: var(--heading-font, 'BluuNext', Georgia, serif);
    font-size: 18px;
    color: #fff;
    margin-bottom: 6px;
}
.ms-invite-text {
    font-size: 13px;
    line-height: 1.5;
    color: var(--text, #e0d9ce);
    margin-bottom: 12px;
}
.ms-invite-actions {
    display: flex;
    gap: 8px;
}
.ms-invite-cta {
    flex: 1;
    background: var(--gold, #c9a84c);
    color: #080808;
    border: none;
    padding: 9px 14px;
    border-radius: 6px;
    font-weight: 700;
    font-size: 13px;
    cursor: pointer;
    transition: background 0.2s;
}
.ms-invite-cta:hover { background: var(--gold-light, #e4c97e); }
.ms-invite-skip {
    background: transparent;
    color: var(--text-muted, #8a7f72);
    border: 1px solid var(--border, rgba(201,168,76,0.25));
    padding: 9px 14px;
    border-radius: 6px;
    font-size: 13px;
    cursor: pointer;
    transition: color 0.2s, border-color 0.2s;
}
.ms-invite-skip:hover {
    color: var(--text, #e0d9ce);
    border-color: var(--text-muted, #8a7f72);
}

@media (max-width: 639px) {
    .ms-invite { right: 16px; left: 16px; width: auto; bottom: 92px; }
}

/* ───────────── scrollbars ───────────── */
.ms-chat::-webkit-scrollbar,
.ms-form::-webkit-scrollbar { width: 8px; }
.ms-chat::-webkit-scrollbar-track,
.ms-form::-webkit-scrollbar-track { background: transparent; }
.ms-chat::-webkit-scrollbar-thumb,
.ms-form::-webkit-scrollbar-thumb { background: rgba(201,168,76,0.2); border-radius: 4px; }
.ms-chat::-webkit-scrollbar-thumb:hover,
.ms-form::-webkit-scrollbar-thumb:hover { background: rgba(201,168,76,0.4); }
