/* ═══════════════════════════════════════════════════════════
   WELLE 7: Challenge-Chat CSS
   Datei: chat.css
   ═══════════════════════════════════════════════════════════ */

/* ── Modal Overlay ── */
.chat-modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.65);
    backdrop-filter: blur(8px);
    z-index: 99996;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    opacity: 0;
    transition: opacity 0.2s;
}

.chat-modal-overlay.show {
    opacity: 1;
}

.chat-modal-overlay.closing {
    opacity: 0;
}

/* ── Modal Content ── */
.chat-modal-content {
    background: #1a1a1a;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 16px;
    width: 100%;
    max-width: 640px;
    height: 85vh;
    height: 85dvh; /* dynamic viewport — berücksichtigt mobile URL-bar */
    max-height: 85vh;
    max-height: 85dvh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 30px 80px rgba(0, 0, 0, 0.7);
    overflow: hidden;
    margin: 12px;
    transform: scale(0.96);
    transition: transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.chat-modal-overlay.show .chat-modal-content {
    transform: scale(1);
}

/* ── Header ── */
.chat-modal-header {
    padding: 16px 20px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.07);
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
}

.chat-modal-header h2 {
    margin: 0;
    font-family: 'Bebas Neue', sans-serif;
    font-size: 24px;
    color: #ff9f43;
    letter-spacing: 0.04em;
}

.chat-modal-subtitle {
    margin: 2px 0 0;
    font-size: 12px;
    color: #888;
}

.chat-modal-close {
    background: transparent;
    border: none;
    color: #888;
    font-size: 28px;
    line-height: 1;
    cursor: pointer;
    padding: 0 4px;
    transition: color 0.15s;
}

.chat-modal-close:hover {
    color: #fff;
}

/* ── Messages Area ── */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px 20px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    background: rgba(0, 0, 0, 0.15);
}

.chat-empty {
    text-align: center;
    color: #555;
    font-size: 13px;
    padding: 40px 20px;
}

/* ── Single Message ── */
.chat-msg {
    display: flex;
    gap: 10px;
    align-items: flex-start;
}

.chat-msg.is-mine {
    flex-direction: row-reverse;
}

.chat-msg-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    flex-shrink: 0;
    background: #2a2a2a;
    color: #ff9f43;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 13px;
    overflow: hidden;
}

.chat-msg-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.chat-msg-bubble {
    max-width: 75%;
    padding: 10px 14px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 14px;
    word-wrap: break-word;
}

.chat-msg.is-mine .chat-msg-bubble {
    background: rgba(255, 159, 67, 0.10);
    border-color: rgba(255, 159, 67, 0.30);
}

.chat-msg.is-sponsor .chat-msg-bubble {
    background: linear-gradient(135deg, rgba(102, 153, 255, 0.15), rgba(102, 153, 255, 0.05));
    border: 1px solid rgba(102, 153, 255, 0.45);
    box-shadow: 0 0 14px rgba(102, 153, 255, 0.15);
}

.chat-msg.is-creator .chat-msg-bubble {
    background: rgba(46, 204, 113, 0.08);
    border-color: rgba(46, 204, 113, 0.30);
}

.chat-msg-header {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 4px;
    flex-wrap: wrap;
}

.chat-msg-username {
    font-size: 12px;
    font-weight: 600;
    color: #c0c8d0;
}

.chat-msg.is-sponsor .chat-msg-username {
    color: #6699ff;
}

.chat-msg.is-creator .chat-msg-username {
    color: #2ecc71;
}

.chat-msg-role-badge {
    font-size: 10px;
    padding: 2px 6px;
    border-radius: 50px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.chat-msg-role-badge.sponsor {
    background: rgba(102, 153, 255, 0.20);
    color: #6699ff;
}

.chat-msg-role-badge.creator {
    background: rgba(46, 204, 113, 0.20);
    color: #2ecc71;
}

.chat-msg-time {
    font-size: 10px;
    color: #555;
    margin-left: auto;
}

.chat-msg-text {
    font-size: 14px;
    color: #e0e0e0;
    line-height: 1.45;
    white-space: pre-wrap;
}

.chat-msg-deleted {
    font-style: italic;
    color: #555;
    font-size: 13px;
}

/* @-Mentions im Text */
.chat-mention {
    background: rgba(255, 159, 67, 0.20);
    color: #ff9f43;
    padding: 1px 6px;
    border-radius: 4px;
    font-weight: 600;
}

.chat-mention.is-me {
    background: rgba(255, 159, 67, 0.40);
    color: #fff;
    box-shadow: 0 0 8px rgba(255, 159, 67, 0.4);
}

/* Delete-Button bei eigenen Messages */
.chat-msg-actions {
    margin-top: 4px;
    display: flex;
    gap: 6px;
    opacity: 0;
    transition: opacity 0.15s;
}

.chat-msg:hover .chat-msg-actions {
    opacity: 1;
}

.chat-msg-delete {
    background: transparent;
    border: none;
    color: #888;
    font-size: 11px;
    cursor: pointer;
    padding: 2px 6px;
    border-radius: 4px;
}

.chat-msg-delete:hover {
    background: rgba(231, 76, 60, 0.15);
    color: #e74c3c;
}

/* ── Input-Area ── */
.chat-input-wrap {
    padding: 12px 20px;
    border-top: 1px solid rgba(255, 255, 255, 0.07);
    background: rgba(0, 0, 0, 0.25);
    flex-shrink: 0;
    position: relative;
}

.chat-input-row {
    display: flex;
    gap: 10px;
    align-items: flex-end;
}

.chat-input {
    flex: 1;
    min-height: 42px;
    max-height: 140px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.10);
    border-radius: 10px;
    padding: 10px 14px;
    color: #e0e0e0;
    font-family: 'DM Sans', sans-serif;
    font-size: 14px;
    line-height: 1.4;
    resize: none;
    outline: none;
    transition: border-color 0.15s;
}

.chat-input:focus {
    border-color: rgba(255, 159, 67, 0.45);
}

.chat-send-btn {
    padding: 10px 18px;
    background: rgba(255, 159, 67, 0.18);
    border: 1px solid rgba(255, 159, 67, 0.45);
    border-radius: 10px;
    color: #ff9f43;
    font-family: 'DM Sans', sans-serif;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s;
    flex-shrink: 0;
    height: 42px;
}

.chat-send-btn:hover:not(:disabled) {
    background: rgba(255, 159, 67, 0.30);
}

.chat-send-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

/* ── @-Mention Autocomplete ── */
.chat-mention-popup {
    position: absolute;
    bottom: calc(100% + 4px);
    left: 20px;
    right: 20px;
    background: #1c1c1e;
    border: 1px solid rgba(255, 159, 67, 0.30);
    border-radius: 10px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
    max-height: 200px;
    overflow-y: auto;
    z-index: 10;
}

.chat-mention-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    cursor: pointer;
    transition: background 0.1s;
}

.chat-mention-item:hover,
.chat-mention-item.active {
    background: rgba(255, 159, 67, 0.10);
}

.chat-mention-username {
    font-size: 13px;
    color: #c0c8d0;
    font-weight: 500;
}

.chat-mention-role {
    font-size: 10px;
    color: #888;
    margin-left: auto;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.chat-mention-role.sponsor { color: #6699ff; }
.chat-mention-role.creator { color: #2ecc71; }

/* ── Chat-Button im Challenge-Panel ── */
.btn-ch-chat {
    position: relative;
    padding: 9px 16px;
    background: rgba(102, 153, 255, 0.10);
    border: 1px solid rgba(102, 153, 255, 0.35);
    border-radius: 8px;
    color: #6699ff;
    font-family: 'DM Sans', sans-serif;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s;
}

.btn-ch-chat:hover {
    background: rgba(102, 153, 255, 0.20);
}

.chat-unread-badge {
    position: absolute;
    top: -6px;
    right: -6px;
    background: #e74c3c;
    color: #fff;
    font-size: 10px;
    font-weight: 700;
    border-radius: 50px;
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 8px rgba(231, 76, 60, 0.5);
    animation: chat-pulse 1.5s ease-in-out infinite;
}

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

/* ── Mobile ── */
@media (max-width: 600px) {
    .chat-modal-overlay {
        padding: 0;
        align-items: flex-end; /* Modal "klebt" am unteren Rand */
    }
    
    .chat-modal-content {
        height: 92vh;
        height: 92dvh;
        max-height: 92vh;
        max-height: 92dvh;
        border-radius: 16px 16px 0 0;
        margin: 0;
        width: 100%;
        max-width: 100%;
    }
    
    .chat-modal-header {
        padding: 12px 16px;
    }
    
    .chat-modal-header h2 {
        font-size: 20px;
    }
    
    .chat-messages {
        padding: 12px 14px;
    }
    
    .chat-msg-bubble {
        max-width: 80%;
        padding: 8px 12px;
    }
    
    .chat-input-wrap {
        padding: 10px 14px;
        /* iOS Safe-Area-Inset für Notch-Geräte */
        padding-bottom: calc(10px + env(safe-area-inset-bottom));
    }
    
    .chat-input {
        max-height: 80px;
        font-size: 14px;
    }
    
    .chat-send-btn {
        padding: 10px 14px;
        font-size: 13px;
    }
}
