/* ===================================
   Artemis Chat System - CSS Styling
   Mobile-first design for iPhone 15 Pro
   =================================== */

/* Override unified-modal for chatbox */
.chatbox-modal {
    /* Height fallback chain for iOS Safari viewport bug */
    height: 100vh; /* Fallback for older browsers */
    height: -webkit-fill-available; /* iOS Safari 13-14 */
    height: 100dvh; /* Modern browsers (iOS 15+, Chrome 108+) - dynamic viewport */
    display: grid;
    grid-template-rows: auto 1fr auto;
}

/* Chatbox Body */
.chatbox-body {
    height: 100%;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    padding: 0;
    min-height: 0;
}

/* Messages Container */
.chatbox-messages {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 15px;
    background: rgba(0, 10, 20, 0.3);
    scroll-behavior: smooth;
}

/* Custom Scrollbar */
.chatbox-messages::-webkit-scrollbar {
    width: 8px;
}

.chatbox-messages::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.2);
    border-radius: 4px;
}

.chatbox-messages::-webkit-scrollbar-thumb {
    background: rgba(0, 212, 255, 0.5);
    border-radius: 4px;
}

.chatbox-messages::-webkit-scrollbar-thumb:hover {
    background: rgba(0, 212, 255, 0.7);
}

/* Single Message */
.chat-message {
    margin-bottom: 12px;
    padding: 10px 12px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 12px;
    border-left: 3px solid rgba(0, 212, 255, 0.3);
    transition: all 0.2s ease;
    position: relative;
    cursor: pointer;
}

.chat-message:hover {
    background: rgba(255, 255, 255, 0.08);
    transform: translateX(2px);
}

/* Own Message */
.chat-message.own {
    background: rgba(0, 212, 255, 0.1);
    border-left-color: rgba(0, 212, 255, 0.8);
}

/* Message Header */
.chat-message-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 6px;
}

.chat-username {
    font-weight: 600;
    font-size: 13px;
    color: #00d4ff;
    text-shadow: 0 0 10px rgba(0, 212, 255, 0.5);
    cursor: pointer;
    transition: all 0.2s ease;
}

.chat-username:hover {
    color: #00ffff;
    text-decoration: underline;
}

.chat-level {
    display: inline-block;
    margin-left: 6px;
    padding: 2px 6px;
    background: rgba(255, 215, 0, 0.2);
    border: 1px solid rgba(255, 215, 0, 0.4);
    border-radius: 8px;
    font-size: 10px;
    color: #ffd700;
    font-weight: bold;
}

.chat-timestamp {
    font-size: 11px;
    color: rgba(255, 255, 255, 0.5);
}

/* Message Body */
.chat-message-body {
    font-size: 14px;
    color: rgba(255, 255, 255, 0.9);
    line-height: 1.4;
    word-wrap: break-word;
    white-space: pre-wrap;
}

/* Message Reactions */
.chat-message-reactions {
    display: flex;
    gap: 6px;
    margin-top: 8px;
    flex-wrap: wrap;
}

.chat-reaction {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 8px;
    background: rgba(0, 212, 255, 0.1);
    border: 1px solid rgba(0, 212, 255, 0.3);
    border-radius: 12px;
    font-size: 12px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.chat-reaction:hover {
    background: rgba(0, 212, 255, 0.2);
    transform: scale(1.05);
}

.chat-reaction.user-reacted {
    background: rgba(0, 212, 255, 0.3);
    border-color: rgba(0, 212, 255, 0.6);
}

.chat-reaction-emoji {
    font-size: 14px;
}

.chat-reaction-count {
    font-size: 11px;
    color: rgba(255, 255, 255, 0.8);
    font-weight: 600;
}

/* Footer */
.chatbox-footer {
    display: flex;
    gap: 10px;
    padding: 15px;
    background: rgba(0, 15, 30, 0.5);
    border-top: 1px solid rgba(0, 212, 255, 0.3);
}

.chatbox-input {
    flex: 1;
    padding: 12px 15px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(0, 212, 255, 0.3);
    border-radius: 12px;
    color: #fff;
    font-size: 14px;
    outline: none;
    transition: all 0.3s ease;
    font-family: inherit;
}

.chatbox-input:focus {
    background: rgba(255, 255, 255, 0.08);
    border-color: rgba(0, 212, 255, 0.6);
    box-shadow: 0 0 15px rgba(0, 212, 255, 0.2);
}

.chatbox-input::placeholder {
    color: rgba(255, 255, 255, 0.4);
}

.chatbox-send-btn {
    padding: 12px 24px;
    background: linear-gradient(135deg, #00d4ff, #0099cc);
    border: none;
    border-radius: 12px;
    color: #fff;
    font-weight: 600;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 15px rgba(0, 212, 255, 0.3);
}

.chatbox-send-btn:hover {
    background: linear-gradient(135deg, #00ffff, #00d4ff);
    box-shadow: 0 6px 20px rgba(0, 212, 255, 0.5);
    transform: translateY(-2px);
}

.chatbox-send-btn:active {
    transform: translateY(0);
}

.chatbox-send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

/* Load Older Button */
.chatbox-load-older {
    margin: 10px auto;
    padding: 8px 20px;
    background: rgba(0, 212, 255, 0.1);
    border: 1px solid rgba(0, 212, 255, 0.3);
    border-radius: 20px;
    color: #00d4ff;
    font-size: 12px;
    cursor: pointer;
    transition: all 0.2s ease;
    display: block;
}

.chatbox-load-older:hover {
    background: rgba(0, 212, 255, 0.2);
    transform: scale(1.05);
}

/* Loading State */
.chatbox-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px;
    color: rgba(255, 255, 255, 0.6);
}

.loading-spinner {
    width: 40px;
    height: 40px;
    border: 4px solid rgba(0, 212, 255, 0.2);
    border-top-color: #00d4ff;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 15px;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Unread Badge */
.chat-unread-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    min-width: 20px;
    height: 20px;
    padding: 0 6px;
    background: linear-gradient(135deg, #ff6b6b, #ee5a52);
    border: 2px solid #1a1a2e;
    border-radius: 10px;
    color: #fff;
    font-size: 11px;
    font-weight: bold;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: badgePulse 2s ease-in-out infinite;
    box-shadow: 0 2px 8px rgba(255, 107, 107, 0.5);
}

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

/* Reaction Popup */
.chat-reaction-popup {
    position: fixed;
    background: rgba(10, 25, 47, 0.95);
    border: 1px solid rgba(0, 212, 255, 0.5);
    border-radius: 30px;
    padding: 8px 12px;
    display: flex;
    gap: 8px;
    box-shadow: 0 8px 32px rgba(0, 212, 255, 0.3);
    backdrop-filter: blur(10px);
    z-index: 10001;
    animation: popupSlideIn 0.2s ease;
}

@keyframes popupSlideIn {
    from {
        opacity: 0;
        transform: translateY(10px) scale(0.9);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.reaction-btn {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 50%;
    width: 40px;
    height: 40px;
    font-size: 20px;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.reaction-btn:hover {
    background: rgba(0, 212, 255, 0.2);
    border-color: rgba(0, 212, 255, 0.5);
    transform: scale(1.15);
}

.reaction-btn:active {
    transform: scale(1.05);
}

/* ===================================
   Mobile Responsive
   =================================== */

/* Portrait Mobile (iPhone 15 Pro and similar) */
@media (max-width: 430px) and (orientation: portrait) {
    .chatbox-modal {
        position: fixed;
        inset: 0;
        border-radius: 0;
        /* Reinforce height for iOS Safari */
        height: 100vh;
        height: -webkit-fill-available;
        height: 100dvh;
        max-height: 100dvh;
        max-height: -webkit-fill-available;
    }

    .chatbox-footer {
        padding: 12px;
        padding-bottom: max(12px, env(safe-area-inset-bottom));
    }

    .chatbox-input {
        font-size: 16px; /* Prevent iOS zoom on focus */
    }

    .chat-message-body {
        font-size: 13px;
    }

    .chatbox-send-btn {
        padding: 12px 18px;
        font-size: 13px;
    }

    .chatbox-messages {
        padding: 12px;
    }
}

/* Landscape Mobile */
@media (max-height: 430px) and (orientation: landscape) {
    .chatbox-modal {
        position: fixed;
        inset: 0;
        border-radius: 0;
    }

    .chatbox-messages {
        padding: 10px;
    }

    .chat-message {
        margin-bottom: 8px;
        padding: 8px 10px;
    }

    .chatbox-footer {
        padding: 10px;
    }

    .chatbox-input {
        padding: 10px 12px;
        font-size: 13px;
    }

    .chatbox-send-btn {
        padding: 10px 16px;
        font-size: 12px;
    }

    .chat-message-body {
        font-size: 12px;
    }
}

/* Small Phones (iPhone SE, etc) */
@media (max-width: 375px) {
    .chat-username {
        font-size: 12px;
    }

    .chat-message-body {
        font-size: 12px;
    }

    .chat-reaction {
        padding: 3px 6px;
        font-size: 11px;
    }

    .chatbox-send-btn {
        padding: 10px 16px;
    }
}

/* Tablet Portrait */
@media (min-width: 768px) and (max-width: 1024px) and (orientation: portrait) {
    .chatbox-modal {
        max-width: 700px;
        height: 85vh;
    }

    .chat-message-body {
        font-size: 15px;
    }
}

/* High Contrast Mode */
@media (prefers-contrast: high) {
    .chat-message {
        background: #000;
        border-left-color: #00ffff;
    }

    .chatbox-input {
        background: #000;
        border-color: #00ffff;
        color: #fff;
    }
}

/* Reduced Motion */
@media (prefers-reduced-motion: reduce) {
    .chat-message,
    .reaction-btn,
    .chatbox-send-btn,
    .chat-reaction-popup {
        animation: none;
        transition: none;
    }

    .chat-message:hover,
    .reaction-btn:hover {
        transform: none;
    }
}

/* Dark Mode Support (if needed) */
@media (prefers-color-scheme: dark) {
    /* Already dark by default */
}
