/* =========================================================
   Support Chat Floating Widget
   Bottom-right popup chat between user and admin support.
   ========================================================= */

.support-chat-widget {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 9998;
    direction: rtl;
    font-family: 'Tajawal', 'Cairo', sans-serif;
}

/* ---------- Floating Action Button ---------- */
.support-fab {
    position: relative;
    width: 64px;
    height: 64px;
    border-radius: 50%;
    border: none;
    background: linear-gradient(135deg, #2176ff 0%, #19335c 100%);
    color: #fff;
    font-size: 1.6rem;
    cursor: pointer;
    box-shadow: 0 12px 32px rgba(33, 118, 255, 0.45);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.25s ease, box-shadow 0.25s ease;
}

.support-fab:hover {
    transform: translateY(-3px) scale(1.05);
    box-shadow: 0 16px 40px rgba(33, 118, 255, 0.55);
}

.support-fab:active {
    transform: translateY(0) scale(1);
}

.support-fab.is-active {
    background: linear-gradient(135deg, #19335c 0%, #2176ff 100%);
}

.support-fab-guest {
    background: linear-gradient(135deg, #6c757d 0%, #19335c 100%);
}

.support-fab-pulse {
    position: absolute;
    inset: 0;
    border-radius: 50%;
    background: rgba(33, 118, 255, 0.45);
    animation: support-pulse 2s ease-out infinite;
    z-index: -1;
}

@keyframes support-pulse {
    0% {
        transform: scale(0.95);
        opacity: 0.7;
    }
    70% {
        transform: scale(1.4);
        opacity: 0;
    }
    100% {
        transform: scale(0.95);
        opacity: 0;
    }
}

.support-fab-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    min-width: 22px;
    height: 22px;
    padding: 0 6px;
    border-radius: 999px;
    background: #ef4444;
    color: #fff;
    font-size: 0.72rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid #fff;
    box-shadow: 0 2px 6px rgba(239, 68, 68, 0.5);
}

/* ---------- Chat Panel ---------- */
.support-chat-panel {
    position: absolute;
    bottom: 80px;
    right: 0;
    width: 380px;
    max-width: calc(100vw - 32px);
    height: 560px;
    max-height: calc(100vh - 120px);
    background: #fff;
    border-radius: 18px;
    box-shadow: 0 24px 60px rgba(15, 23, 42, 0.25), 0 0 0 1px rgba(15, 23, 42, 0.06);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transform-origin: bottom right;
    animation: support-pop 0.28s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes support-pop {
    from {
        transform: translateY(20px) scale(0.92);
        opacity: 0;
    }
    to {
        transform: translateY(0) scale(1);
        opacity: 1;
    }
}

/* ---------- Header ---------- */
.support-chat-header {
    background: linear-gradient(135deg, #2176ff 0%, #19335c 100%);
    color: #fff;
    padding: 14px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

.support-chat-header-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.support-chat-avatar {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.18);
    backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    color: #ffe082;
}

.support-chat-titles {
    line-height: 1.25;
}

.support-chat-title {
    font-weight: 800;
    font-size: 1rem;
}

.support-chat-subtitle {
    font-size: 0.78rem;
    opacity: 0.85;
    display: flex;
    align-items: center;
    gap: 5px;
}

.support-online-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #22c55e;
    box-shadow: 0 0 0 2px rgba(34, 197, 94, 0.35);
    animation: support-online-blink 2s ease-in-out infinite;
}

@keyframes support-online-blink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.support-chat-close {
    background: rgba(255, 255, 255, 0.15);
    color: #fff;
    border: none;
    width: 34px;
    height: 34px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.85rem;
    transition: background 0.2s;
}

.support-chat-close:hover {
    background: rgba(255, 255, 255, 0.28);
}

/* ---------- Messages area ---------- */
.support-chat-body {
    flex: 1;
    background: linear-gradient(180deg, #f8faff 0%, #eff4ff 100%);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.support-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px 14px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    scroll-behavior: smooth;
}

.support-chat-messages::-webkit-scrollbar {
    width: 5px;
}

.support-chat-messages::-webkit-scrollbar-thumb {
    background: rgba(33, 118, 255, 0.25);
    border-radius: 10px;
}

.support-chat-messages::-webkit-scrollbar-thumb:hover {
    background: rgba(33, 118, 255, 0.45);
}

.support-chat-loading,
.support-chat-empty {
    margin: auto;
    text-align: center;
    color: #64748b;
    padding: 1.2rem;
}

.support-chat-loading i {
    font-size: 1.4rem;
    color: #2176ff;
    margin-inline-end: 6px;
}

.support-chat-empty i {
    font-size: 3rem;
    color: #c4d2eb;
    margin-bottom: 0.5rem;
}

.support-chat-empty h4 {
    font-size: 1rem;
    font-weight: 700;
    color: #1e293b;
    margin: 0 0 0.4rem 0;
}

.support-chat-empty p {
    font-size: 0.85rem;
    line-height: 1.6;
    color: #64748b;
    margin: 0;
}

/* ---------- Bubbles ---------- */
.support-bubble-row {
    display: flex;
    flex-direction: column;
    max-width: 82%;
    animation: support-msg-in 0.2s ease-out;
}

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

.support-bubble-row.mine {
    align-self: flex-start;
}

.support-bubble-row.theirs {
    align-self: flex-end;
}

.support-bubble-meta {
    font-size: 0.7rem;
    color: #64748b;
    margin: 0 0.5rem 0.2rem;
    display: flex;
    align-items: center;
    gap: 0.35rem;
    font-weight: 600;
}

.support-bubble-row.theirs .support-bubble-meta {
    flex-direction: row-reverse;
}

.support-bubble-meta .support-role-pill {
    background: linear-gradient(135deg, #2176ff, #19335c);
    color: #fff;
    padding: 1px 8px;
    border-radius: 999px;
    font-size: 0.62rem;
    font-weight: 700;
}

.support-bubble-row.mine .support-bubble-meta .support-role-pill {
    background: #94a3b8;
}

.support-bubble {
    padding: 0.55rem 0.85rem;
    border-radius: 16px;
    font-size: 0.92rem;
    line-height: 1.55;
    word-wrap: break-word;
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.08);
}

.support-bubble-row.mine .support-bubble {
    background: #fff;
    color: #1e293b;
    border: 1px solid #e2e8f0;
    border-bottom-right-radius: 16px;
    border-bottom-left-radius: 4px;
}

.support-bubble-row.theirs .support-bubble {
    background: linear-gradient(135deg, #2176ff 0%, #1e5bb8 100%);
    color: #fff;
    border-bottom-left-radius: 16px;
    border-bottom-right-radius: 4px;
}

.support-bubble-text {
    white-space: pre-wrap;
}

.support-bubble-time {
    font-size: 0.65rem;
    opacity: 0.75;
    margin-top: 4px;
    text-align: left;
}

.support-bubble-row.theirs .support-bubble-time {
    text-align: right;
}

/* Bubble media */
.support-media-wrapper {
    position: relative;
    margin-bottom: 0.35rem;
}

.support-bubble-image,
.support-bubble-video {
    max-width: 100%;
    max-height: 220px;
    border-radius: 10px;
    display: block;
}

.support-bubble-image {
    cursor: zoom-in;
}

.support-bubble-file {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.45rem 0.7rem;
    border-radius: 8px;
    font-size: 0.85rem;
    font-weight: 600;
    text-decoration: none;
    margin-bottom: 0.35rem;
}

.support-bubble-row.theirs .support-bubble-file {
    background: rgba(255, 255, 255, 0.2);
    color: #fff;
}

.support-bubble-row.mine .support-bubble-file {
    background: #f0f4ff;
    color: #2176ff;
}

.support-download-btn {
    position: absolute;
    top: 6px;
    left: 6px;
    width: 28px;
    height: 28px;
    background: rgba(0, 0, 0, 0.55);
    color: #fff;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.7rem;
    text-decoration: none;
    opacity: 0;
    transition: opacity 0.2s;
}

.support-media-wrapper:hover .support-download-btn {
    opacity: 1;
}

.support-download-btn:hover {
    background: rgba(0, 0, 0, 0.85);
    color: #fff;
}

/* ---------- File preview bar ---------- */
.support-chat-file-preview {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    background: #eff6ff;
    border-top: 1px solid #dbeafe;
    color: #1e40af;
    font-size: 0.82rem;
    flex-shrink: 0;
}

.support-file-preview-name {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-weight: 600;
}

.support-file-preview-remove {
    background: none;
    border: none;
    color: #ef4444;
    cursor: pointer;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    transition: background 0.2s;
}

.support-file-preview-remove:hover {
    background: rgba(239, 68, 68, 0.12);
}

/* ---------- Input row ---------- */
.support-chat-form {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 10px 12px;
    background: #fff;
    border-top: 1px solid #e2e8f0;
    flex-shrink: 0;
}

.support-text-input {
    flex: 1;
    border: 1px solid #e2e8f0;
    border-radius: 999px;
    padding: 9px 16px;
    font-size: 0.92rem;
    background: #f8fafc;
    outline: none;
    transition: border-color 0.2s, background 0.2s, box-shadow 0.2s;
    direction: rtl;
    color: #1e293b;
}

.support-text-input:focus {
    border-color: #2176ff;
    background: #fff;
    box-shadow: 0 0 0 3px rgba(33, 118, 255, 0.15);
}

.support-attach-btn,
.support-send-btn {
    border: none;
    border-radius: 50%;
    width: 38px;
    height: 38px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
    font-size: 0.95rem;
    transition: transform 0.15s, background 0.2s;
}

.support-attach-btn {
    background: #f1f5f9;
    color: #2176ff;
}

.support-attach-btn:hover {
    background: #e2e8f0;
    transform: scale(1.08);
}

.support-send-btn {
    background: linear-gradient(135deg, #2176ff, #19335c);
    color: #fff;
    box-shadow: 0 4px 10px rgba(33, 118, 255, 0.35);
}

.support-send-btn:hover:not(:disabled) {
    transform: scale(1.08);
}

.support-send-btn:disabled {
    background: #cbd5e1;
    box-shadow: none;
    cursor: not-allowed;
    transform: none;
}

/* ---------- Guest variant ---------- */
.support-chat-guest-panel {
    height: auto;
}

.support-chat-guest-body {
    padding: 2rem 1.5rem;
    text-align: center;
    color: #1e293b;
}

.support-chat-guest-body i {
    font-size: 3rem;
    color: #2176ff;
    margin-bottom: 0.8rem;
}

.support-chat-guest-body h4 {
    font-size: 1.05rem;
    font-weight: 800;
    margin: 0 0 0.5rem 0;
}

.support-chat-guest-body p {
    font-size: 0.88rem;
    color: #64748b;
    margin: 0 0 1.2rem 0;
    line-height: 1.6;
}

.support-guest-btn,
.support-guest-btn-outline {
    display: block;
    padding: 0.7rem 1rem;
    border-radius: 10px;
    font-weight: 700;
    text-decoration: none;
    margin-bottom: 0.5rem;
    transition: transform 0.15s, box-shadow 0.2s;
}

.support-guest-btn {
    background: linear-gradient(135deg, #2176ff, #19335c);
    color: #fff;
    box-shadow: 0 6px 16px rgba(33, 118, 255, 0.3);
}

.support-guest-btn:hover {
    color: #fff;
    transform: translateY(-2px);
}

.support-guest-btn-outline {
    background: transparent;
    color: #2176ff;
    border: 1.5px solid #2176ff;
}

.support-guest-btn-outline:hover {
    color: #19335c;
    border-color: #19335c;
}

/* ---------- Responsive ---------- */
@media (max-width: 768px) {
    .support-chat-widget {
        bottom: calc(96px + env(safe-area-inset-bottom));
    }
}

@media (max-width: 480px) {
    .support-chat-widget {
        bottom: calc(96px + env(safe-area-inset-bottom));
        right: 16px;
    }

    .support-chat-panel {
        width: calc(100vw - 32px);
        height: calc(100vh - 120px);
        max-height: 600px;
    }

    .support-fab {
        width: 56px;
        height: 56px;
        font-size: 1.4rem;
    }
}
