/* ── Rail724 Support Widget v2 ── */
#r724-support-root {
    --sw-gold: #d4a017;
    --sw-gold-light: #f5c518;
    --sw-gold-glow: rgba(212, 160, 23, 0.5);
    --sw-bg: #0a1020;
    --sw-bg2: #121c34;
    --sw-glass: linear-gradient(165deg, rgba(18, 28, 52, 0.97) 0%, rgba(8, 12, 24, 0.98) 100%);
    --sw-border: rgba(212, 160, 23, 0.25);
    --sw-text: #eef2f8;
    --sw-muted: #8d97ab;
    --sw-radius: 22px;
    --sw-shadow: 0 28px 90px rgba(0, 0, 0, 0.6), 0 0 0 1px var(--sw-border),
                 inset 0 1px 0 rgba(255, 255, 255, 0.06);

    position: fixed;
    bottom: 28px;
    right: 28px;
    z-index: 99990;
    font-family: 'Vazirmatn', Tahoma, sans-serif;
    direction: rtl;
    pointer-events: none;
}

#r724-support-root * { box-sizing: border-box; }

#r724-support-root .sw-fab,
#r724-support-root .sw-panel { pointer-events: auto; }

/* FAB */
.sw-fab {
    width: 64px; height: 64px; border: none; border-radius: 50%;
    cursor: pointer; display: flex; align-items: center; justify-content: center;
    background: linear-gradient(145deg, #ffe066, var(--sw-gold-light), var(--sw-gold), #9a7209);
    color: #0a0f1f; font-size: 27px;
    box-shadow: 0 10px 36px var(--sw-gold-glow), 0 4px 14px rgba(0,0,0,0.45);
    transition: transform 0.35s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.3s;
    position: relative;
}
.sw-fab:hover { transform: scale(1.09) translateY(-3px); }
.sw-fab.is-open {
    background: linear-gradient(145deg, #1e2d4d, #10182c);
    color: var(--sw-gold-light);
    border: 2px solid var(--sw-gold);
    box-shadow: var(--sw-shadow);
    transform: scale(1);
}
.sw-fab-pulse {
    position: absolute; inset: -5px; border-radius: 50%;
    border: 2px solid var(--sw-gold-light);
    animation: swPulse 2.4s ease-out infinite; pointer-events: none;
}
.sw-fab:not(.is-open) .sw-fab-pulse { opacity: 1; }
.sw-fab.is-open .sw-fab-pulse { opacity: 0; }
@keyframes swPulse {
    0% { transform: scale(1); opacity: 0.75; }
    100% { transform: scale(1.5); opacity: 0; }
}
.sw-fab-badge {
    position: absolute; top: -3px; right: -3px;
    min-width: 22px; height: 22px; padding: 0 6px; border-radius: 11px;
    background: linear-gradient(135deg, #ff6b6b, #e74c3c);
    color: #fff; font-size: 11px; font-weight: 700;
    display: none; align-items: center; justify-content: center;
    border: 2px solid var(--sw-bg); font-family: Tahoma, sans-serif;
    box-shadow: 0 2px 8px rgba(231,76,60,0.5);
}
.sw-fab-badge.show { display: flex; }

/* Panel — بزرگ‌تر دسکتاپ */
.sw-panel {
    position: absolute; bottom: 82px; right: 0;
    width: min(430px, calc(100vw - 36px));
    height: min(640px, calc(100vh - 110px));
    background: var(--sw-glass);
    backdrop-filter: blur(24px) saturate(1.5);
    -webkit-backdrop-filter: blur(24px) saturate(1.5);
    border-radius: var(--sw-radius);
    box-shadow: var(--sw-shadow);
    display: flex; flex-direction: column; overflow: hidden;
    opacity: 0; visibility: hidden;
    transform: translateY(20px) scale(0.95);
    transition: opacity 0.35s ease, transform 0.4s cubic-bezier(0.34, 1.2, 0.64, 1), visibility 0.35s;
    border: 1px solid var(--sw-border);
}
.sw-panel.is-open { opacity: 1; visibility: visible; transform: translateY(0) scale(1); }

/* Header */
.sw-header {
    padding: 20px 20px 16px;
    background: linear-gradient(135deg, rgba(212,160,23,0.2) 0%, transparent 55%),
                linear-gradient(180deg, var(--sw-bg2) 0%, var(--sw-bg) 100%);
    border-bottom: 1px solid var(--sw-border);
    flex-shrink: 0;
}
.sw-header-top { display: flex; align-items: flex-start; gap: 14px; }
.sw-avatar {
    width: 48px; height: 48px; border-radius: 16px;
    background: linear-gradient(135deg, #ffe566, var(--sw-gold));
    display: flex; align-items: center; justify-content: center;
    font-size: 22px; color: #0a0f1f; flex-shrink: 0;
    box-shadow: 0 6px 16px var(--sw-gold-glow);
}
.sw-header-text { flex: 1; min-width: 0; }
.sw-header-text h3 {
    margin: 0; font-size: 18px; font-weight: 800; color: var(--sw-text);
    font-family: 'Lalezar', 'Vazirmatn', sans-serif;
}
.sw-header-text p { margin: 3px 0 0; font-size: 12px; color: var(--sw-muted); }
.sw-online {
    display: inline-flex; align-items: center; gap: 6px;
    font-size: 11px; color: #5eead4; margin-top: 6px;
    background: rgba(94, 234, 212, 0.1); padding: 3px 10px; border-radius: 20px;
}
.sw-wait-hint {
    margin: 6px 0 0;
    font-size: 11px;
    color: var(--sw-gold-light);
    line-height: 1.5;
}
.sw-online-dot {
    width: 7px; height: 7px; border-radius: 50%;
    background: #4ade80; box-shadow: 0 0 6px #4ade80;
    animation: swBlink 2s ease infinite;
}
@keyframes swBlink { 0%, 100% { opacity: 1; } 50% { opacity: 0.35; } }
.sw-header-close {
    width: 34px; height: 34px; border: 1px solid var(--sw-border);
    border-radius: 10px; background: rgba(255,255,255,0.04);
    color: var(--sw-muted); cursor: pointer; font-size: 14px;
    display: flex; align-items: center; justify-content: center;
    transition: all 0.2s; flex-shrink: 0;
}
.sw-header-close:hover { color: var(--sw-gold-light); border-color: var(--sw-gold); }

/* Scroll body */
.sw-scroll {
    flex: 1; overflow-y: auto; overflow-x: hidden;
    scrollbar-width: thin; scrollbar-color: var(--sw-gold) transparent;
}
.sw-scroll::-webkit-scrollbar { width: 5px; }
.sw-scroll::-webkit-scrollbar-thumb { background: var(--sw-gold); border-radius: 4px; }

.sw-section-label {
    font-size: 12px; font-weight: 700; color: var(--sw-gold-light);
    padding: 14px 18px 10px;
    display: flex; align-items: center; gap: 8px;
    letter-spacing: 0.3px;
}
.sw-section-label i { font-size: 13px; opacity: 0.9; }

/* FAQ boxes */
.sw-faq-block { padding-bottom: 4px; }
.sw-faq-list { padding: 0 14px; display: flex; flex-direction: column; gap: 8px; }
.sw-faq-item {
    background: rgba(255,255,255,0.04);
    border: 1px solid rgba(255,255,255,0.07);
    border-radius: 14px; overflow: hidden;
    transition: border-color 0.25s, background 0.25s, box-shadow 0.25s;
    cursor: pointer;
}
.sw-faq-item:hover { border-color: rgba(212,160,23,0.35); background: rgba(212,160,23,0.05); }
.sw-faq-item.open {
    border-color: var(--sw-border);
    background: rgba(212,160,23,0.08);
    box-shadow: 0 4px 16px rgba(0,0,0,0.2);
}
.sw-faq-q {
    width: 100%; padding: 13px 15px; border: none; background: transparent;
    color: var(--sw-text); font-size: 13px; font-weight: 600;
    font-family: inherit; text-align: right; cursor: pointer;
    display: flex; justify-content: space-between; align-items: center; gap: 10px;
    line-height: 1.55;
}
.sw-faq-q i {
    color: var(--sw-gold); font-size: 11px; flex-shrink: 0;
    width: 22px; height: 22px; border-radius: 50%;
    background: rgba(212,160,23,0.15);
    display: flex; align-items: center; justify-content: center;
    transition: transform 0.25s;
}
.sw-faq-item.open .sw-faq-q i { transform: rotate(180deg); }
.sw-faq-a {
    display: none; padding: 0 15px 14px;
    font-size: 12.5px; color: var(--sw-muted); line-height: 1.9;
    border-top: 1px solid rgba(255,255,255,0.06);
    padding-top: 12px; margin-top: 0;
}
.sw-faq-item.open .sw-faq-a { display: block; animation: swFaqOpen 0.25s ease; }
@keyframes swFaqOpen { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: none; } }
.sw-faq-more {
    display: block; text-align: center; padding: 10px 18px 14px;
    font-size: 12px; color: var(--sw-muted); text-decoration: none;
    transition: color 0.2s;
}
.sw-faq-more:hover { color: var(--sw-gold-light); }
.sw-faq-more i { font-size: 10px; margin-right: 4px; }

/* Messages — چت تلگرامی */
.sw-chat-block {
    border-top: 1px solid rgba(255,255,255,0.06);
    margin-top: 4px;
}
.sw-chat-area {
    display: flex; flex-direction: column; min-height: 220px; flex: 1;
    margin: 0 10px 10px;
    border-radius: 16px;
    overflow: hidden;
    border: 1px solid rgba(212,160,23,0.15);
    background-color: #0c1222;
    background-image:
        url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='%23ffffff' fill-opacity='0.02'%3E%3Cpath d='M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2V6h4V4h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V4H6z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
}
.sw-chat-area[hidden] { display: none !important; }
.sw-messages {
    padding: 10px 12px 20px;
    display: flex; flex-direction: column; gap: 4px;
    min-height: 200px;
    flex: 1;
}
.sw-msg {
    display: flex; flex-direction: column;
    width: fit-content; max-width: 82%;
    animation: swMsgIn 0.25s ease;
}
@keyframes swMsgIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.sw-msg.user { align-self: flex-end; align-items: flex-end; }
.sw-msg.admin { align-self: flex-start; align-items: flex-start; }
.sw-msg.system { align-self: center; max-width: 90%; align-items: center; }
.sw-bubble {
    position: relative;
    padding: 7px 11px 5px;
    border-radius: 14px;
    font-size: 14px; line-height: 1.45;
    word-break: break-word; white-space: pre-wrap;
}
.sw-msg.user .sw-bubble {
    background: linear-gradient(135deg, #ffe566, var(--sw-gold-light), var(--sw-gold));
    color: #0a0f1f; font-weight: 500;
    border-bottom-left-radius: 4px;
    box-shadow: 0 3px 12px rgba(212,160,23,0.25);
}
.sw-msg.admin .sw-bubble {
    background: #1e3a5f;
    color: #eef2f8;
    border-bottom-right-radius: 4px;
    border: 1px solid rgba(56, 189, 248, 0.15);
}
.sw-msg.system .sw-bubble {
    background: rgba(212,160,23,0.1);
    color: var(--sw-gold-light);
    border: 1px dashed rgba(212,160,23,0.3);
    font-size: 12px; text-align: center; padding: 8px 12px;
}
.sw-bubble.sticker {
    font-size: 44px; line-height: 1; padding: 2px 4px;
    background: transparent !important; border: none !important; box-shadow: none !important;
    font-family: "Segoe UI Emoji", "Apple Color Emoji", "Noto Color Emoji", sans-serif;
}
.sw-bubble img { max-width: 200px; max-height: 240px; border-radius: 10px; display: block; cursor: pointer; }
.sw-msg-time {
    font-size: 9px; color: rgba(255,255,255,0.35);
    margin-top: 2px; padding: 0 4px;
}
.sw-msg.user .sw-msg-time { text-align: left; }
.sw-msg.admin .sw-msg-time { text-align: right; }

/* Footer — نوار پایین + پنل ایموجی بالای compose */
.sw-footer {
    position: relative;
    flex-shrink: 0;
    z-index: 12;
    border-top: 1px solid rgba(255, 255, 255, 0.06);
}
.sw-compose {
    padding: 6px 8px calc(8px + env(safe-area-inset-bottom, 0px));
    background: #17212b;
}
.sw-compose[hidden] { display: none !important; }
.sw-compose-bar {
    display: flex; align-items: flex-end; gap: 2px;
}
.sw-input-wrap {
    flex: 1; min-width: 0;
    background: #242f3d;
    border: none;
    border-radius: 20px;
    padding: 0 14px;
    min-height: 36px;
    display: flex; align-items: center;
    overflow: hidden;
}
.sw-tool-btn {
    width: 40px; height: 40px; border: none; border-radius: 50%;
    background: transparent;
    color: #7d8da8; cursor: pointer;
    display: flex; align-items: center; justify-content: center; font-size: 22px;
    flex-shrink: 0; transition: color 0.15s;
}
.sw-tool-btn:hover { color: #a8b4c8; }
.sw-textarea {
    width: 100%; border: none; background: transparent;
    color: #f5f5f5; font-size: 15px; font-family: inherit;
    padding: 8px 0; resize: none; outline: none;
    line-height: 1.35;
    min-height: 22px;
    max-height: 96px;
    overflow: hidden;
    field-sizing: content;
}
.sw-textarea::placeholder { color: #6d7f96; }
.sw-send-btn {
    width: 36px; height: 36px; border: none; border-radius: 50%;
    background: #3390ec;
    color: #fff; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    font-size: 15px; flex-shrink: 0;
    box-shadow: none;
    transition: background 0.15s, transform 0.15s;
    margin-bottom: 2px;
}
.sw-send-btn:hover { background: #2b7fd4; transform: none; }
.sw-send-btn:disabled { opacity: 0.45; }

/* پنل ایموجی — بالای باکس پیام (مثل تلگرام) */
#r724-support-root.sw-emoji-open .sw-scroll { overflow: hidden; }
.sw-emoji-backdrop {
    position: absolute;
    left: 0; right: 0; top: -2000px; bottom: 0;
    z-index: 1;
    background: rgba(0, 0, 0, 0.35);
}
.sw-emoji-backdrop[hidden], .sw-emoji-sheet[hidden] { display: none !important; }
.sw-emoji-sheet {
    position: relative;
    z-index: 2;
    background: #17212b;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    max-height: min(240px, 38vh);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
}
.sw-emoji-handle {
    width: 36px; height: 4px; border-radius: 2px;
    background: rgba(255, 255, 255, 0.18); margin: 8px auto 2px; flex-shrink: 0;
}
.sw-emoji-body {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
}
.sw-emoji-panes {
    flex: 1; min-height: 0; overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}
.sw-emoji-pane { display: none; padding: 4px 6px 8px; }
.sw-emoji-pane.active { display: block; }
.sw-emoji-tabs {
    display: flex; gap: 0; padding: 0 4px;
    overflow-x: auto; flex-shrink: 0;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    scrollbar-width: none;
}
.sw-emoji-tabs::-webkit-scrollbar { display: none; }
.sw-emoji-tab {
    flex-shrink: 0;
    width: 48px; height: 48px;
    padding: 0; border: none; border-radius: 0;
    background: transparent; color: inherit;
    font-size: 26px; cursor: pointer;
    font-family: "Segoe UI Emoji", "Apple Color Emoji", "Noto Color Emoji", sans-serif;
    position: relative;
    display: flex; align-items: center; justify-content: center;
    transition: opacity 0.15s;
}
.sw-emoji-tab:not(.active) { opacity: 0.55; }
.sw-emoji-tab.active { opacity: 1; }
.sw-emoji-tab.active::after {
    content: '';
    position: absolute; bottom: 0; left: 10px; right: 10px;
    height: 3px; background: #6ab2f2; border-radius: 3px 3px 0 0;
}
.sw-emoji-grid {
    display: grid; grid-template-columns: repeat(7, 1fr); gap: 0;
}
@media (min-width: 400px) {
    .sw-emoji-grid { grid-template-columns: repeat(8, 1fr); }
}
.sw-emoji-btn {
    border: none; border-radius: 50%;
    background: transparent; font-size: 32px; cursor: pointer; padding: 0;
    min-height: 48px;
    font-family: "Segoe UI Emoji", "Apple Color Emoji", "Noto Color Emoji", sans-serif;
    line-height: 1;
    transition: background 0.12s;
    display: flex; align-items: center; justify-content: center;
}
.sw-emoji-btn:hover { background: rgba(255, 255, 255, 0.08); }
.sw-emoji-btn:active { background: rgba(106, 178, 242, 0.2); }

@media (max-width: 768px) {
    .sw-emoji-sheet { max-height: min(280px, 42vh); }
    .sw-emoji-body {
        flex-direction: row-reverse;
        align-items: stretch;
    }
    .sw-emoji-tabs {
        flex-direction: column;
        overflow-x: hidden;
        overflow-y: auto;
        width: 44px;
        padding: 4px 0;
        border-top: none;
        border-inline-start: 1px solid rgba(255, 255, 255, 0.08);
        -webkit-overflow-scrolling: touch;
    }
    .sw-emoji-tab {
        width: 44px;
        height: 44px;
        font-size: 24px;
    }
    .sw-emoji-tab.active::after {
        bottom: 8px;
        top: 8px;
        left: auto;
        right: 0;
        width: 3px;
        height: auto;
        border-radius: 3px 0 0 3px;
    }
    .sw-emoji-grid {
        grid-template-columns: repeat(6, 1fr);
    }
}

.sw-guest-card {
    margin: 0 14px 16px;
    padding: 20px 18px;
    background: rgba(0,0,0,0.28);
    border: 1px solid var(--sw-border);
    border-radius: 16px;
    display: flex; flex-direction: column; gap: 11px;
    box-shadow: inset 0 1px 0 rgba(255,255,255,0.04);
}
.sw-guest-card[hidden] { display: none !important; }
.sw-guest-icon {
    text-align: center; font-size: 36px; color: var(--sw-gold);
    opacity: 0.85; margin-bottom: 2px;
}
.sw-guest-hint {
    margin: 0; text-align: center; font-size: 12.5px;
    color: var(--sw-muted); line-height: 1.7;
}
.sw-input {
    width: 100%; padding: 13px 15px; border-radius: 13px;
    border: 1px solid rgba(212,160,23,0.2);
    background: rgba(0,0,0,0.35); color: var(--sw-text);
    font-size: 14px; font-family: inherit; outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
    pointer-events: auto;
}
.sw-input:focus {
    border-color: var(--sw-gold);
    box-shadow: 0 0 0 3px rgba(212,160,23,0.18);
}
.sw-input::placeholder { color: #5c6678; }
.sw-btn-gold {
    width: 100%; padding: 14px; border: none; border-radius: 13px;
    background: linear-gradient(135deg, #ffe566, var(--sw-gold-light), var(--sw-gold));
    color: #0a0f1f; font-size: 14px; font-weight: 800; font-family: inherit;
    cursor: pointer; display: flex; align-items: center; justify-content: center; gap: 8px;
    transition: transform 0.2s, box-shadow 0.2s, opacity 0.2s;
    pointer-events: auto;
    box-shadow: 0 4px 18px var(--sw-gold-glow);
}
.sw-btn-gold:hover:not(:disabled) { transform: translateY(-2px); box-shadow: 0 8px 24px var(--sw-gold-glow); }
.sw-btn-gold:disabled { opacity: 0.65; cursor: wait; transform: none; }

.sw-error {
    margin: 0 14px 10px; padding: 10px 13px; border-radius: 11px;
    background: rgba(231,76,60,0.14); border: 1px solid rgba(231,76,60,0.35);
    color: #fca5a5; font-size: 12px; display: none; line-height: 1.6;
}
.sw-error.show { display: block; }

.sw-ticket-link {
    display: block; text-align: center; padding: 10px;
    font-size: 11.5px; color: var(--sw-muted); text-decoration: none;
    border-top: 1px solid rgba(255,255,255,0.06);
    transition: color 0.2s; flex-shrink: 0;
}
.sw-ticket-link:hover { color: var(--sw-gold-light); }

@media (max-width: 480px) {
    #r724-support-root { bottom: 18px; right: 18px; }
    .sw-panel { width: calc(100vw - 28px); height: calc(100vh - 96px); bottom: 74px; }
    .sw-fab { width: 58px; height: 58px; font-size: 24px; }
}

@media (min-width: 769px) {
    .sw-panel {
        width: 430px;
        height: min(640px, calc(100vh - 110px));
        max-height: calc(100dvh - 110px);
    }
}
