/* ===== Chat Widget (Phase 3) ===== */

.chat-widget {
    position: fixed;
    bottom: 16px;
    right: 16px;
    z-index: 1500;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
}

/* Toggle Button */
.chat-toggle {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    border: none;
    background: #2d2d2d;
    color: #e0e0e0;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
    transition: background 0.2s, transform 0.15s;
    position: relative;
}
.chat-toggle:hover {
    background: #3a3a3a;
    transform: scale(1.05);
}
.chat-toggle-active {
    background: #4a90d9;
}
.chat-toggle-active:hover {
    background: #5aa0e9;
}
.chat-toggle svg {
    pointer-events: none;
}

/* Badge */
.chat-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    min-width: 18px;
    height: 18px;
    border-radius: 9px;
    background: #e74c3c;
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 4px;
    line-height: 1;
}
@keyframes badgePulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.3); }
    100% { transform: scale(1); }
}
.chat-badge-pulse {
    animation: badgePulse 0.4s ease;
}

/* Panel */
.chat-panel {
    width: 340px;
    max-height: 50vh;
    background: #1e1e1e;
    border: 1px solid #333;
    border-radius: 12px;
    margin-bottom: 8px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
    animation: chatSlideUp 0.2s ease;
}
@keyframes chatSlideUp {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Tabs */
.chat-tabs {
    display: flex;
    border-bottom: 1px solid #333;
    flex-shrink: 0;
}
.chat-tab {
    flex: 1;
    padding: 10px 0;
    border: none;
    background: transparent;
    color: #888;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: color 0.15s, border-color 0.15s;
    border-bottom: 2px solid transparent;
}
.chat-tab:hover {
    color: #bbb;
}
.chat-tab-active {
    color: #e0e0e0;
    border-bottom-color: #4a90d9;
}

/* Messages */
.chat-messages {
    flex: 1;
    min-height: 120px;
    max-height: 35vh;
    overflow-y: auto;
    padding: 10px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.chat-messages::-webkit-scrollbar {
    width: 4px;
}
.chat-messages::-webkit-scrollbar-thumb {
    background: #444;
    border-radius: 2px;
}

/* Message Bubble */
.chat-message {
    max-width: 80%;
    padding: 6px 10px;
    border-radius: 12px;
    font-size: 13px;
    line-height: 1.4;
    display: flex;
    flex-direction: column;
    gap: 2px;
    animation: msgFadeIn 0.2s ease;
}
@keyframes msgFadeIn {
    from { opacity: 0; transform: translateY(4px); }
    to { opacity: 1; transform: translateY(0); }
}

.chat-message-own {
    align-self: flex-end;
    background: #2a5a8a;
    color: #e0e0e0;
    border-bottom-right-radius: 4px;
}
.chat-message-other {
    align-self: flex-start;
    background: #333;
    color: #e0e0e0;
    border-bottom-left-radius: 4px;
}
.chat-message-quick {
    font-style: italic;
}

.chat-message-pseudo {
    font-size: 11px;
    font-weight: 600;
    color: #8ab4f8;
    margin-bottom: 1px;
}
.chat-message-own .chat-message-pseudo {
    color: #a8d4ff;
}

.chat-message-text {
    word-break: break-word;
}

.chat-message-time {
    font-size: 10px;
    color: #777;
    align-self: flex-end;
}

/* Input Container */
.chat-input-container {
    display: flex;
    padding: 8px;
    gap: 6px;
    border-top: 1px solid #333;
    flex-shrink: 0;
}
.chat-input {
    flex: 1;
    padding: 8px 12px;
    border: 1px solid #444;
    border-radius: 20px;
    background: #2a2a2a;
    color: #e0e0e0;
    font-size: 13px;
    outline: none;
    transition: border-color 0.15s;
}
.chat-input:focus {
    border-color: #4a90d9;
}
.chat-input::placeholder {
    color: #666;
}
.chat-send-btn {
    padding: 8px 14px;
    border: none;
    border-radius: 20px;
    background: #4a90d9;
    color: #fff;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s;
    white-space: nowrap;
}
.chat-send-btn:hover {
    background: #5aa0e9;
}

/* Quick Messages Grid */
.quick-messages {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
    padding: 10px;
    flex-shrink: 0;
}
.quick-message-btn {
    padding: 8px 6px;
    border: 1px solid #444;
    border-radius: 8px;
    background: #2a2a2a;
    color: #ccc;
    font-size: 12px;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
}
.quick-message-btn:hover {
    background: #3a3a3a;
    border-color: #4a90d9;
    color: #e0e0e0;
}

/* Rate limit warning */
.chat-rate-limit {
    padding: 6px 10px;
    background: #e74c3c22;
    color: #e74c3c;
    font-size: 11px;
    text-align: center;
    border-top: 1px solid #e74c3c44;
}

/* ===== Responsive ===== */
@media (max-width: 600px) {
    .chat-widget {
        bottom: 12px;
        right: 12px;
    }
    .chat-panel {
        width: calc(100vw - 24px);
        max-height: 40vh;
        border-radius: 10px;
    }
}
