/* ========== Discussion Widget - Floating Chat ========== */

/* Floating Button */
.dw-fab {
    position: fixed;
    bottom: 74px;
    right: 24px;
    z-index: 700;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: linear-gradient(135deg, #00d4aa 0%, #00b894 100%);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 16px rgba(0, 212, 170, 0.35);
    transition: transform 0.2s, box-shadow 0.2s;
}
.dw-fab:hover {
    transform: scale(1.08);
    box-shadow: 0 6px 24px rgba(0, 212, 170, 0.5);
}
.dw-fab:active {
    transform: scale(0.96);
}
.dw-fab svg {
    width: 26px;
    height: 26px;
    color: #fff;
    pointer-events: none;
}

/* New post notification — expanding ring + bounce */
.dw-fab.notify {
    animation: dw-fab-bounce 0.6s ease;
}
.dw-fab.notify::before,
.dw-fab.notify::after {
    content: '';
    position: absolute;
    inset: -4px;
    border-radius: 50%;
    border: 2px solid rgba(0, 212, 170, 0.6);
    animation: dw-ring-expand 1.2s ease-out forwards;
}
.dw-fab.notify::after {
    animation-delay: 0.3s;
}
@keyframes dw-ring-expand {
    0% {
        transform: scale(1);
        opacity: 1;
    }
    100% {
        transform: scale(1.8);
        opacity: 0;
    }
}
@keyframes dw-fab-bounce {
    0%, 100% { transform: scale(1); }
    30% { transform: scale(1.18); }
    50% { transform: scale(0.95); }
    70% { transform: scale(1.08); }
}

/* Badge */
.dw-badge {
    position: absolute;
    top: -2px;
    right: -2px;
    min-width: 20px;
    height: 20px;
    border-radius: 10px;
    background: #ef4444;
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 0 5px;
    box-shadow: 0 2px 6px rgba(239, 68, 68, 0.4);
    animation: dw-pulse 2s infinite;
}
.dw-badge.visible {
    display: flex;
}
@keyframes dw-pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.15); }
}

/* Panel */
.dw-panel {
    position: fixed;
    bottom: 140px;
    right: 24px;
    z-index: 700;
    width: 400px;
    max-height: 600px;
    background: #0f1420;
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 20px;
    display: none;
    flex-direction: column;
    overflow: hidden;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
    opacity: 0;
    transform: translateY(12px);
    transition: opacity 0.25s ease, transform 0.25s ease;
}
.dw-panel.open {
    display: flex;
    opacity: 1;
    transform: translateY(0);
}

/* Panel Header */
.dw-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px 10px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
    flex-shrink: 0;
}
.dw-header-title {
    font-size: 15px;
    font-weight: 600;
    color: #e8eaed;
    display: flex;
    align-items: center;
    gap: 8px;
}
.dw-header-title svg {
    width: 18px;
    height: 18px;
    color: #00d4aa;
}
/* Header Actions */
.dw-header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* Auto Hide Checkbox */
.dw-auto-hide-label {
    display: flex;
    align-items: center;
    gap: 5px;
    cursor: pointer;
    user-select: none;
    padding: 3px 8px;
    border-radius: 8px;
    transition: background 0.15s;
}
.dw-auto-hide-label:hover {
    background: rgba(255, 255, 255, 0.04);
}
.dw-auto-hide-label input {
    display: none;
}
.dw-auto-hide-check {
    width: 14px;
    height: 14px;
    border-radius: 4px;
    border: 1.5px solid #6b7280;
    background: transparent;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: all 0.15s;
    position: relative;
}
.dw-auto-hide-check::after {
    content: '';
    display: none;
    width: 4px;
    height: 7px;
    border: solid #0f1420;
    border-width: 0 2px 2px 0;
    transform: rotate(45deg);
    margin-top: -1px;
}
.dw-auto-hide-label input:checked + .dw-auto-hide-check {
    background: #00d4aa;
    border-color: #00d4aa;
}
.dw-auto-hide-label input:checked + .dw-auto-hide-check::after {
    display: block;
}
.dw-auto-hide-text {
    font-size: 11px;
    color: #6b7280;
    white-space: nowrap;
    transition: color 0.15s;
}
.dw-auto-hide-label:hover .dw-auto-hide-text {
    color: #9ca3af;
}
.dw-auto-hide-label input:checked ~ .dw-auto-hide-text {
    color: #00d4aa;
}

.dw-close-btn {
    background: none;
    border: none;
    color: #9ca3af;
    cursor: pointer;
    padding: 4px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s, color 0.15s;
}
.dw-close-btn:hover {
    background: rgba(255, 255, 255, 0.06);
    color: #e8eaed;
}
.dw-close-btn svg {
    width: 18px;
    height: 18px;
}

/* Symbol Tabs Wrapper */
.dw-tabs-wrap {
    display: flex;
    align-items: center;
    flex-shrink: 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.04);
    position: relative;
}
.dw-tabs-arrow {
    flex-shrink: 0;
    width: 28px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    color: #6b7280;
    cursor: pointer;
    transition: color 0.15s;
    padding: 0;
}
.dw-tabs-arrow:hover {
    color: #00d4aa;
}
.dw-tabs-arrow.hidden {
    visibility: hidden;
}
.dw-tabs-arrow svg {
    width: 14px;
    height: 14px;
}
.dw-tabs {
    display: flex;
    gap: 6px;
    padding: 8px 4px;
    overflow-x: hidden;
    flex: 1;
    scrollbar-width: none;
    -ms-overflow-style: none;
    scroll-behavior: smooth;
}
.dw-tabs::-webkit-scrollbar {
    display: none;
}
.dw-tab {
    flex-shrink: 0;
    padding: 5px 12px;
    font-size: 12px;
    font-weight: 500;
    color: #6b7280;
    background: transparent;
    border: 1px solid transparent;
    border-radius: 20px;
    cursor: pointer;
    transition: all 0.15s;
    white-space: nowrap;
}
.dw-tab:hover {
    color: #9ca3af;
    background: rgba(255, 255, 255, 0.04);
}
.dw-tab.active {
    color: #00d4aa;
    border-color: rgba(0, 212, 170, 0.3);
    background: rgba(0, 212, 170, 0.08);
}

/* Posts Area */
.dw-posts {
    flex: 1;
    overflow-y: auto;
    padding: 8px 0;
    min-height: 200px;
    max-height: 400px;
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, 0.1) transparent;
}
.dw-posts::-webkit-scrollbar {
    width: 4px;
}
.dw-posts::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 2px;
}

/* Load Older Button */
.dw-load-older {
    display: flex;
    justify-content: center;
    padding: 8px;
}
.dw-load-older-btn {
    font-size: 12px;
    color: #00d4aa;
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px 12px;
    border-radius: 12px;
    transition: background 0.15s;
}
.dw-load-older-btn:hover {
    background: rgba(0, 212, 170, 0.08);
}

/* Single Post (compact chat style) */
.dw-post {
    display: flex;
    gap: 10px;
    padding: 8px 16px;
    transition: background 0.15s;
}
.dw-post:hover {
    background: rgba(255, 255, 255, 0.02);
}

/* New post glow animation */
.dw-post-new {
    animation: dw-glow 1.5s ease-out;
}
@keyframes dw-glow {
    0% {
        background: rgba(0, 212, 170, 0.2);
        box-shadow: inset 0 0 12px rgba(0, 212, 170, 0.15);
    }
    40% {
        background: rgba(0, 212, 170, 0.1);
        box-shadow: inset 0 0 6px rgba(0, 212, 170, 0.08);
    }
    100% {
        background: transparent;
        box-shadow: none;
    }
}

.dw-post-avatar {
    flex-shrink: 0;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: rgba(0, 212, 170, 0.15);
    color: #00d4aa;
    font-size: 12px;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}
.dw-post-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}
.dw-post-body {
    flex: 1;
    min-width: 0;
}
.dw-post-meta {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 2px;
    flex-wrap: wrap;
}
.dw-post-username {
    font-size: 12px;
    font-weight: 600;
    color: #e8eaed;
}
.dw-post-username a {
    color: inherit;
    text-decoration: none;
}
.dw-post-username a:hover {
    color: #00d4aa;
}
.dw-post-rep {
    font-size: 9px;
    font-weight: 600;
    padding: 1px 5px;
    border-radius: 6px;
    color: #fff;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}
.dw-post-time {
    font-size: 11px;
    color: #6b7280;
    margin-left: auto;
}
.dw-post-content {
    font-size: 13px;
    line-height: 1.4;
    color: #d1d5db;
    word-break: break-word;
}
.dw-post-content.truncated {
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
    cursor: pointer;
}
.dw-post-content.truncated:hover {
    color: #e8eaed;
}
.dw-post-stats {
    display: flex;
    gap: 12px;
    margin-top: 4px;
}
.dw-post-stat {
    font-size: 11px;
    color: #6b7280;
    display: flex;
    align-items: center;
    gap: 3px;
}
.dw-post-stat svg {
    width: 12px;
    height: 12px;
}

/* Reply indicator */
.dw-reply-indicator {
    font-size: 11px;
    color: #6b7280;
    margin-bottom: 2px;
    display: flex;
    align-items: center;
    gap: 4px;
}
.dw-reply-indicator svg {
    width: 12px;
    height: 12px;
}

/* Loading / Empty States */
.dw-loading, .dw-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 32px 16px;
    color: #6b7280;
    font-size: 13px;
    text-align: center;
    gap: 8px;
}
.dw-loading-spinner {
    width: 24px;
    height: 24px;
    border: 2px solid rgba(0, 212, 170, 0.2);
    border-top-color: #00d4aa;
    border-radius: 50%;
    animation: dw-spin 0.7s linear infinite;
}
@keyframes dw-spin {
    to { transform: rotate(360deg); }
}

/* Input Area */
.dw-input-area {
    padding: 10px 16px 14px;
    border-top: 1px solid rgba(255, 255, 255, 0.06);
    flex-shrink: 0;
}
.dw-input-wrap {
    display: flex;
    gap: 8px;
    align-items: flex-end;
}
.dw-textarea {
    flex: 1;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.08);
    color: #e8eaed;
    font-size: 13px;
    line-height: 1.4;
    padding: 8px 12px;
    border-radius: 14px;
    resize: none;
    min-height: 36px;
    max-height: 80px;
    outline: none;
    transition: border-color 0.15s;
    font-family: inherit;
}
.dw-textarea::placeholder {
    color: #6b7280;
}
.dw-textarea:focus {
    border-color: rgba(0, 212, 170, 0.4);
}
.dw-send-btn {
    flex-shrink: 0;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: linear-gradient(135deg, #00d4aa, #00b894);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: opacity 0.15s, transform 0.15s;
}
.dw-send-btn:hover {
    transform: scale(1.05);
}
.dw-send-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    transform: none;
}
.dw-send-btn svg {
    width: 16px;
    height: 16px;
    color: #fff;
}
.dw-login-prompt {
    text-align: center;
    padding: 10px 16px 14px;
    border-top: 1px solid rgba(255, 255, 255, 0.06);
    flex-shrink: 0;
}
.dw-login-prompt a {
    color: #00d4aa;
    text-decoration: none;
    font-size: 13px;
    font-weight: 500;
}
.dw-login-prompt a:hover {
    text-decoration: underline;
}

/* New Posts Banner */
.dw-new-posts-banner {
    display: none;
    justify-content: center;
    padding: 6px 16px;
    flex-shrink: 0;
}
.dw-new-posts-banner.visible {
    display: flex;
}
.dw-new-posts-btn {
    font-size: 12px;
    color: #00d4aa;
    background: rgba(0, 212, 170, 0.08);
    border: 1px solid rgba(0, 212, 170, 0.2);
    border-radius: 16px;
    padding: 4px 14px;
    cursor: pointer;
    transition: background 0.15s;
}
.dw-new-posts-btn:hover {
    background: rgba(0, 212, 170, 0.15);
}

/* ===== Mobile (<640px) ===== */
@media (max-width: 639px) {
    /* Hide FAB when mobile footer is present (footer button takes over) */
    body:has(.mobile-action-bar) .dw-fab {
        display: none !important;
    }
    .dw-fab {
        width: 48px;
        height: 48px;
        bottom: calc(80px + env(safe-area-inset-bottom, 0px));
        right: 16px;
    }
    .dw-fab svg {
        width: 22px;
        height: 22px;
    }
    .dw-panel {
        top: calc(56px + env(safe-area-inset-top, 0px));
        left: 0;
        right: 0;
        bottom: calc(72px + env(safe-area-inset-bottom, 0px));
        width: 100%;
        max-height: none;
        border-radius: 0;
        z-index: 10002; /* Above mobile header (9999), menu overlay (10000), menu (10001) */
    }
    .dw-posts {
        max-height: none;
    }
    /* Hide auto-hide on mobile — bad UX, panel should stay open */
    .dw-auto-hide-label {
        display: none !important;
    }
}

/* ===== RTL (Arabic) ===== */
[dir="rtl"] .dw-fab,
html[lang="ar"] .dw-fab {
    right: auto;
    left: 24px;
}
[dir="rtl"] .dw-panel,
html[lang="ar"] .dw-panel {
    right: auto;
    left: 24px;
}
[dir="rtl"] .dw-post-time,
html[lang="ar"] .dw-post-time {
    margin-left: 0;
    margin-right: auto;
}
@media (max-width: 639px) {
    [dir="rtl"] .dw-panel,
    html[lang="ar"] .dw-panel {
        left: 0;
        right: 0;
    }
    [dir="rtl"] .dw-fab,
    html[lang="ar"] .dw-fab {
        left: 16px;
        right: auto;
        bottom: calc(80px + env(safe-area-inset-bottom, 0px));
    }
}

/* Cooldown state on send button */
.dw-send-btn.dw-cooldown {
    background: linear-gradient(135deg, #6b7280, #4b5563);
    opacity: 0.7;
    cursor: not-allowed;
    pointer-events: none;
}
.dw-cd-num {
    font-size: 12px;
    font-weight: 700;
    color: #fff;
    line-height: 1;
}

/* Toast notification */
.dw-toast {
    position: absolute;
    bottom: 60px;
    left: 12px;
    right: 12px;
    background: rgba(239, 68, 68, 0.95);
    color: #fff;
    font-size: 12px;
    padding: 8px 12px;
    border-radius: 8px;
    text-align: center;
    opacity: 0;
    transform: translateY(8px);
    transition: opacity 0.25s, transform 0.25s;
    z-index: 10;
    pointer-events: none;
}
.dw-toast-show {
    opacity: 1;
    transform: translateY(0);
}

/* ========== Symbol Tags in Posts ========== */
.dw-symbol-tag {
    display: inline-block;
    padding: 1px 6px;
    border: 1px solid rgba(255, 255, 255, 0.5);
    border-radius: 4px;
    color: #00d4aa;
    font-weight: 600;
    font-size: 0.88em;
    letter-spacing: 0.3px;
    cursor: pointer;
    transition: all 0.2s ease;
    background: rgba(0, 212, 170, 0.08);
    text-decoration: none;
    vertical-align: baseline;
}
.dw-symbol-tag:hover {
    border-color: #00d4aa;
    background: rgba(0, 212, 170, 0.18);
    color: #00ffcc;
    box-shadow: 0 0 8px rgba(0, 212, 170, 0.25);
}

