/* ============================================
   QUANTUM ENTANGLEMENT WIDGET - FIXED VERSION
   ============================================ */

.quantum-widget {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 999;
    background: rgba(26, 26, 26, 0.95);
    border: 2px solid #00d4ff;
    padding: 0;
    min-width: 320px;
    max-width: 380px;
    max-height: 600px;
    box-shadow: 0 0 30px rgba(0, 212, 255, 0.5);
    backdrop-filter: blur(10px);
    animation: slideIn 0.5s ease;
    font-family: 'Courier New', monospace;
    display: flex;
    flex-direction: column;
    transition: all 0.3s ease;
    cursor: default;
}

/* Drag Handle */
.drag-handle {
    background: rgba(0, 212, 255, 0.1);
    border-bottom: 1px solid rgba(0, 212, 255, 0.3);
    padding: 0.8rem 1rem;
    cursor: grab;
    display: flex;
    align-items: center;
    user-select: none;
    color: #00d4ff;
    font-size: 0.85rem;
    letter-spacing: 0.1em;
    transition: background 0.3s ease;
}

    .drag-handle:hover {
        background: rgba(0, 212, 255, 0.2);
    }

    .drag-handle:active {
        cursor: grabbing;
        background: rgba(0, 212, 255, 0.3);
    }

    .drag-handle span:first-child {
        font-size: 1.2rem;
        animation: rotate 4s linear infinite;
    }

/* Fix widget content scrolling */
.widget-content {
    padding: 1rem;
    overflow-y: auto;
    max-height: 530px;
    display: flex;
    flex-direction: column;
}

    /* Scrollbar for widget content */
    .widget-content::-webkit-scrollbar {
        width: 6px;
    }

    .widget-content::-webkit-scrollbar-track {
        background: rgba(0, 0, 0, 0.3);
    }

    .widget-content::-webkit-scrollbar-thumb {
        background: #00d4ff;
        border-radius: 3px;
    }

/* RAINBOW PULSE EFFECT */
.rainbow-pulse {
    animation: rainbow-border 10s linear infinite, pulse-glow-rainbow 4s ease-in-out infinite;
}

@keyframes rainbow-border {
    0% {
        border-color: #ff0033;
        box-shadow: 0 0 30px rgba(255, 0, 51, 0.5);
    }

    14% {
        border-color: #ff7700;
        box-shadow: 0 0 30px rgba(255, 119, 0, 0.5);
    }

    28% {
        border-color: #ffdd00;
        box-shadow: 0 0 30px rgba(255, 221, 0, 0.5);
    }

    42% {
        border-color: #00ff88;
        box-shadow: 0 0 30px rgba(0, 255, 136, 0.5);
    }

    57% {
        border-color: #00d4ff;
        box-shadow: 0 0 30px rgba(0, 212, 255, 0.5);
    }

    71% {
        border-color: #0088ff;
        box-shadow: 0 0 30px rgba(0, 136, 255, 0.5);
    }

    85% {
        border-color: #aa00ff;
        box-shadow: 0 0 30px rgba(170, 0, 255, 0.5);
    }

    100% {
        border-color: #ff0033;
        box-shadow: 0 0 30px rgba(255, 0, 51, 0.5);
    }
}

@keyframes pulse-glow-rainbow {
    0%, 100% {
        transform: scale(1);
        filter: brightness(1);
    }

    50% {
        transform: scale(1.01);
        filter: brightness(1.2);
    }
}

@keyframes slideIn {
    from {
        transform: translateX(400px);
        opacity: 0;
    }

    to {
        transform: translateX(0);
        opacity: 1;
    }
}

/* Notification pulse */
@keyframes pulse-notify {
    0%, 100% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.05);
    }
}

.quantum-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 1rem;
    padding-bottom: 0.8rem;
    border-bottom: 1px solid rgba(0, 212, 255, 0.3);
}

.quantum-icon {
    font-size: 1.5rem;
    animation: rotate 4s linear infinite;
}

@keyframes rotate {
    from {
        transform: rotate(0deg);
    }

    to {
        transform: rotate(360deg);
    }
}

.quantum-title {
    color: #00d4ff;
    font-size: 0.85rem;
    letter-spacing: 0.1em;
}

.entanglement-status {
    margin-bottom: 1rem;
}

.status-label {
    color: #666;
    font-size: 0.7rem;
    letter-spacing: 0.1em;
    margin-bottom: 0.3rem;
}

.partner-id {
    color: #00d4ff;
    font-size: 0.9rem;
    font-weight: bold;
    text-shadow: 0 0 10px #00d4ff;
    animation: pulsate 2s infinite;
}

@keyframes pulsate {
    0%, 100% {
        opacity: 1;
    }

    50% {
        opacity: 0.6;
    }
}

/* ⭐ FIXED: Connection line with proper state management */
.connection-line {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin: 0.8rem 0;
    opacity: 1 !important; /* ⭐ FORCE full opacity by default */
    transition: opacity 0.3s ease, transform 0.3s ease;
}

    /* Override opacity ONLY when decay classes are present */
    .connection-line.decay-critical {
        opacity: 0.5 !important;
    }

    .connection-line.decay-unstable {
        opacity: 0.7 !important;
    }

    .connection-line.decay-weakening {
        opacity: 0.85 !important;
    }

/* ⭐ FIXED: Default node styling - NO inline style overrides */
.node {
    width: 10px;
    height: 10px;
    background: #00d4ff;
    border-radius: 50%;
    box-shadow: 0 0 10px #00d4ff;
    animation: nodePulse 2s infinite;
    transition: all 0.3s ease;
}

    /* ⭐ CRITICAL FIX: Use data attributes instead of inline styles for state management */
    .node[data-state="stable"] {
        background: #00d4ff !important;
        box-shadow: 0 0 10px #00d4ff !important;
        animation: nodePulse 2s infinite !important;
    }

    .node[data-state="weakening"] {
        background: #ffaa00 !important;
        box-shadow: 0 0 10px #ffaa00 !important;
        animation: nodePulse 1.5s infinite !important;
    }

    .node[data-state="unstable"] {
        background: #ff8800 !important;
        box-shadow: 0 0 10px #ff8800 !important;
        animation: nodePulse 1s infinite !important;
    }

    .node[data-state="critical"] {
        background: #ff3366 !important;
        box-shadow: 0 0 10px #ff3366 !important;
        animation: nodePulse 0.5s infinite !important;
    }

@keyframes nodePulse {
    0%, 100% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.3);
    }
}

/* ⭐ FIXED: Wave styling with data attributes */
.connection-wave {
    flex: 1;
    height: 2px;
    background: linear-gradient(90deg, transparent 0%, #00d4ff 20%, #00d4ff 80%, transparent 100%);
    position: relative;
    overflow: hidden;
    transition: all 0.3s ease;
}

    .connection-wave[data-state="stable"] {
        background: linear-gradient(90deg, transparent 0%, #00d4ff 20%, #00d4ff 80%, transparent 100%);
    }

    .connection-wave[data-state="weakening"] {
        background: linear-gradient(90deg, transparent 0%, #ffaa00 20%, #ffaa00 80%, transparent 100%);
    }

    .connection-wave[data-state="unstable"] {
        background: linear-gradient(90deg, transparent 0%, #ff8800 20%, #ff8800 80%, transparent 100%);
    }

    .connection-wave[data-state="critical"] {
        background: linear-gradient(90deg, transparent 0%, #ff3366 20%, #ff3366 80%, transparent 100%);
    }

    .connection-wave::after {
        content: '';
        position: absolute;
        top: 0;
        left: -100%;
        width: 50%;
        height: 100%;
        background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.8), transparent);
        animation: wave 2s linear infinite;
    }

@keyframes wave {
    to {
        left: 200%;
    }
}

/* ⭐ FIXED: Stage-specific styles using classes on .connection-line */
/* NOTE: Opacity is handled above in the base .connection-line rules! */

.connection-line.decay-critical .connection-wave::after {
    animation: wave 0.5s linear infinite;
}

.connection-line.decay-unstable .connection-wave::after {
    animation: wave 1s linear infinite;
}

.connection-line.decay-weakening .connection-wave::after {
    animation: wave 1.5s linear infinite;
}

.shared-message {
    background: rgba(0, 212, 255, 0.1);
    border-left: 3px solid #00d4ff;
    padding: 0.8rem;
    margin-top: 1rem;
    font-size: 0.8rem;
    line-height: 1.5;
    color: #cccccc;
    font-style: italic;
    animation: messageReveal 0.8s ease;
}

@keyframes messageReveal {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.message-id {
    color: #00d4ff;
    font-size: 0.65rem;
    margin-top: 0.5rem;
    opacity: 0.6;
}

.searching {
    color: #666;
    font-size: 0.85rem;
    font-style: italic;
    animation: blink 1.5s infinite;
}

@keyframes blink {
    0%, 49% {
        opacity: 1;
    }

    50%, 100% {
        opacity: 0.3;
    }
}

/* Disconnect Notice */
.disconnect-notice {
    background: rgba(255, 0, 51, 0.1);
    border: 1px solid #ff0033;
    padding: 1rem;
    margin-top: 1rem;
    animation: fadeIn 0.5s ease;
}

/* Buttons */
.close-btn, .minimize-btn, .maximize-btn {
    position: absolute;
    background: transparent;
    border: 1px solid #ff0033;
    color: #ff0033;
    width: 24px;
    height: 24px;
    cursor: pointer;
    font-size: 0.8rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    font-weight: bold;
    z-index: 10;
}

.close-btn {
    top: 0.8rem;
    right: 0.5rem;
}

.minimize-btn {
    top: 0.8rem;
    right: 2rem;
    border-color: #00d4ff;
    color: #00d4ff;
}

.maximize-btn {
    right: 2rem;
    border-color: #00d4ff;
    color: #00d4ff;
    margin-left: auto;
}

.close-btn:hover {
    background: #ff0033;
    color: white;
    transform: rotate(90deg);
}

.minimize-btn:hover, .maximize-btn:hover {
    background: #00d4ff;
    color: #0a0a0a;
}

/* Minimized State */
.minimized-state {
    display: none;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem;
    cursor: pointer;
    position: relative;
}

.quantum-icon-mini {
    font-size: 1.2rem;
    animation: rotate 4s linear infinite;
}

/* Hide close and minimize buttons when widget is minimized */
.quantum-widget.minimized .close-btn,
.quantum-widget.minimized .minimize-btn {
    display: none;
}

.unread-badge {
    background: #ff0033;
    color: white;
    border-radius: 50%;
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.7rem;
    font-weight: bold;
    animation: pulse-badge 1s infinite;
}

@keyframes pulse-badge {
    0%, 100% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.2);
    }
}

/* ============================================
   QUANTUM CHAT
   ============================================ */
.quantum-chat {
    margin-top: 1rem;
    border-top: 1px solid rgba(0, 212, 255, 0.3);
    padding-top: 1rem;
    display: flex;
    flex-direction: column;
    max-height: 300px;
    min-height: 200px;
    flex-shrink: 0;
}

.chat-header {
    color: #00d4ff;
    font-size: 0.7rem;
    letter-spacing: 0.1em;
    margin-bottom: 0.5rem;
    opacity: 0.8;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    max-height: 200px;
    margin-bottom: 0.5rem;
    padding-right: 0.5rem;
}

.chat-msg {
    margin-bottom: 0.8rem;
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(5px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.msg-sender {
    color: #00d4ff;
    font-size: 0.65rem;
    margin-bottom: 0.2rem;
    letter-spacing: 0.05em;
}

.msg-text {
    color: #cccccc;
    font-size: 0.8rem;
    line-height: 1.4;
    background: rgba(0, 212, 255, 0.05);
    padding: 0.5rem;
    border-left: 2px solid rgba(0, 212, 255, 0.3);
}

.chat-msg.me .msg-sender {
    color: #00ff88;
}

.chat-msg.me .msg-text {
    background: rgba(0, 255, 136, 0.05);
    border-left-color: rgba(0, 255, 136, 0.3);
}

.chat-input-wrapper {
    display: flex;
    gap: 0.5rem;
    margin-top: auto;
    flex-shrink: 0;
}

#chatInput {
    flex: 1;
    background: rgba(0, 0, 0, 0.5);
    border: 1px solid rgba(0, 212, 255, 0.5);
    color: #00d4ff;
    padding: 0.5rem;
    font-family: 'Courier New', monospace;
    font-size: 0.8rem;
    transition: all 0.3s ease;
    min-width: 0;
}

    #chatInput:focus {
        outline: none;
        border-color: #00d4ff;
        box-shadow: 0 0 10px rgba(0, 212, 255, 0.3);
    }

#sendBtn {
    background: transparent;
    border: 2px solid #00d4ff;
    color: #00d4ff;
    padding: 0.5rem 1rem;
    cursor: pointer;
    font-family: 'Courier New', monospace;
    font-weight: bold;
    font-size: 1rem;
    transition: all 0.3s ease;
    flex-shrink: 0;
}

    #sendBtn:hover {
        background: #00d4ff;
        color: #0a0a0a;
        box-shadow: 0 0 10px #00d4ff;
    }

/* Scrollbar for chat */
.chat-messages::-webkit-scrollbar {
    width: 6px;
}

.chat-messages::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.3);
}

.chat-messages::-webkit-scrollbar-thumb {
    background: #00d4ff;
    border-radius: 3px;
}

/* ============================================
   LAUNCH BUTTON (in footer)
   ============================================ */
.qe-launch-btn {
    position: fixed;
    bottom: 20px;
    left: 20px;
    z-index: 9998;
    background: rgba(0, 212, 255, 0.1);
    border: 2px solid #00d4ff;
    color: #00d4ff;
    padding: 0.8rem 1.5rem;
    font-family: 'Courier New', monospace;
    font-size: 0.85rem;
    font-weight: bold;
    letter-spacing: 0.1em;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 0 20px rgba(0, 212, 255, 0.3);
    animation: pulse-launch 3s ease-in-out infinite;
}

    .qe-launch-btn:hover {
        background: #00d4ff;
        color: #0a0a0a;
        box-shadow: 0 0 30px rgba(0, 212, 255, 0.8);
        transform: translateY(-2px);
    }

@keyframes pulse-launch {
    0%, 100% {
        box-shadow: 0 0 20px rgba(0, 212, 255, 0.3);
    }

    50% {
        box-shadow: 0 0 30px rgba(0, 212, 255, 0.6);
    }
}

/* Mobile responsive */
@media (max-width: 768px) {
    .quantum-widget {
        bottom: 10px;
        right: 10px;
        left: 10px;
        min-width: auto;
        max-width: none;
    }

    .chat-messages {
        max-height: 150px;
    }

    .qe-launch-btn {
        bottom: 10px;
        left: 10px;
        padding: 0.6rem 1rem;
        font-size: 0.75rem;
    }
}
