/* MyChat CSS Styles */

#mychat-container {
    max-width: 800px;
    margin: 20px auto;
    border: 1px solid #ddd;
    border-radius: 10px;
    overflow: hidden;
    background: #f9f9f9;
    height: 600px;
    display: flex;
    flex-direction: column;
}

#mychat-admin-container {
    display: flex;
    height: 600px;
    border: 1px solid #ddd;
    border-radius: 10px;
    overflow: hidden;
}

#mychat-user-list {
    width: 250px;
    background: #f0f0f0;
    border-right: 1px solid #ddd;
    padding: 10px;
    overflow-y: auto;
}

#mychat-conversation {
    flex: 1;
    display: flex;
    flex-direction: column;
}

#chat-header {
    background: #007cba;
    color: white;
    padding: 15px;
    text-align: center;
}

#chat-header h3 {
    margin: 0;
    font-size: 16px;
}

#chat-messages {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
    background: #fff;
    display: flex;
    flex-direction: column;
    gap: 10px;
    max-height: 400px; /* Ensure scrollable area */
    min-height: 200px;
}

.message {
    max-width: 70%;
    padding: 10px 15px;
    border-radius: 18px;
    word-wrap: break-word;
    position: relative;
}

.message-text {
    white-space: pre-wrap;
}

.message a {
    text-decoration: underline;
    word-break: break-all;
}

.message.user a {
    color: #007cba;
}

.message.admin a {
    color: #fff;
}

.message.admin {
    background: #007cba;
    color: white;
    align-self: flex-start;
    margin-right: auto;
}

.message.user {
    background: #e1f5fe;
    color: #333;
    align-self: flex-end;
    margin-left: auto;
}

.message.admin::before {
    content: "管理員";
    font-size: 10px;
    opacity: 0.7;
    display: block;
    margin-bottom: 5px;
}

.message.user::before {
    content: "我";
    font-size: 10px;
    opacity: 0.7;
    display: block;
    margin-bottom: 5px;
}

.message-time {
    font-size: 10px;
    opacity: 0.6;
    margin-top: 5px;
}

.message img {
    max-width: 200px;
    max-height: 200px;
    border-radius: 10px;
    cursor: pointer;
}

#chat-input-area {
    display: flex;
    padding: 15px;
    background: #f9f9f9;
    border-top: 1px solid #ddd;
    gap: 10px;
    align-items: center;
}

#message-input {
    flex: 1;
    padding: 10px 15px;
    border: 1px solid #ddd;
    border-radius: 20px;
    outline: none;
    font-size: 14px;
}

#message-input:focus {
    border-color: #007cba;
}

#send-btn, #image-btn {
    background: #007cba;
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 20px;
    cursor: pointer;
    font-size: 14px;
    transition: background 0.3s;
}

#send-btn:hover, #image-btn:hover {
    background: #005a87;
}

#image-btn {
    padding: 10px 15px;
    font-size: 16px;
}

.user-item {
    padding: 10px;
    border: 1px solid #ddd;
    border-radius: 5px;
    margin-bottom: 10px;
    cursor: pointer;
    background: white;
    transition: background 0.3s;
}

.user-item:hover {
    background: #e3f2fd;
}

.user-item.active {
    background: #007cba;
    color: white;
}

.user-item h4 {
    margin: 0 0 5px 0;
    font-size: 14px;
}

.user-item .last-message {
    font-size: 12px;
    opacity: 0.7;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.unread-count {
    background: #f44336;
    color: white;
    border-radius: 50%;
    padding: 2px 6px;
    font-size: 10px;
    float: right;
    margin-top: -2px;
}

/* Loading animation */
.typing-indicator {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 10px 15px;
    background: #f0f0f0;
    border-radius: 18px;
    align-self: flex-start;
    margin-right: auto;
}

.typing-indicator span {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #999;
    animation: typing 1.4s infinite ease-in-out;
}

.typing-indicator span:nth-child(1) { animation-delay: -0.32s; }
.typing-indicator span:nth-child(2) { animation-delay: -0.16s; }

@keyframes typing {
    0%, 80%, 100% { transform: scale(0); }
    40% { transform: scale(1); }
}

/* Responsive design */
@media (max-width: 768px) {
    #mychat-container {
        height: 500px;
        margin: 10px;
    }
    
    #mychat-admin-container {
        flex-direction: column;
        height: auto;
    }
    
    #mychat-user-list {
        width: 100%;
        height: 200px;
    }
    
    .message {
        max-width: 85%;
    }
    
    #chat-input-area {
        padding: 10px;
    }
    
    #message-input {
        font-size: 16px; /* Prevent zoom on iOS */
    }
}

/* Scrollbar styling */
#chat-messages::-webkit-scrollbar,
#mychat-user-list::-webkit-scrollbar {
    width: 6px;
}

#chat-messages::-webkit-scrollbar-track,
#mychat-user-list::-webkit-scrollbar-track {
    background: #f1f1f1;
}

#chat-messages::-webkit-scrollbar-thumb,
#mychat-user-list::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: 3px;
}

#chat-messages::-webkit-scrollbar-thumb:hover,
#mychat-user-list::-webkit-scrollbar-thumb:hover {
    background: #a8a8a8;
}

/* Read status styles */
.message {
    position: relative;
}

/* Unread indicator for messages from OTHER person */
.unread-indicator {
    position: absolute;
    top: -8px;
    right: -8px;
    background: #ff6b6b;
    color: white;
    font-size: 10px;
    padding: 2px 6px;
    border-radius: 10px;
    font-weight: bold;
    z-index: 10;
}

/* Read indicator for YOUR OWN messages */
.read-indicator {
    font-size: 12px;
    margin-left: 5px;
    font-weight: bold;
}

.read-indicator.read {
    color: #4CAF50; /* Green for read */
    background: #e8f5e8;
    padding: 2px 6px;
    border-radius: 10px;
    font-size: 10px;
}

/* New style for MY unread messages - red flashing */
.my-message-unread {
    background: #ff6b6b;
    color: white;
    font-size: 10px;
    padding: 2px 6px;
    border-radius: 10px;
    font-weight: bold;
    margin-left: 5px;
    animation: flash-red 2s infinite;
    box-shadow: 0 0 5px rgba(255, 107, 107, 0.5);
}

/* Highlight messages from other person that are unread */
.message.user.unread {
    border-left: 3px solid #ff6b6b;
}

.message.admin.unread {
    border-left: 3px solid #ff6b6b;
}

.message.read {
    border-left: 3px solid transparent;
}

/* Special styling for your own messages with read status */
.message.user .read-indicator,
.message.admin .read-indicator {
    display: inline-block;
}

/* Animation for read status change */
.read-indicator {
    transition: color 0.3s ease;
}

.unread-indicator {
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0% { opacity: 1; }
    50% { opacity: 0.5; }
    100% { opacity: 1; }
}

/* Red flashing animation for my unread messages */
@keyframes flash-red {
    0% {
        background: #ff6b6b;
        box-shadow: 0 0 5px rgba(255, 107, 107, 0.5);
    }
    50% {
        background: #ff4757;
        box-shadow: 0 0 10px rgba(255, 107, 107, 0.8);
        transform: scale(1.05);
    }
    100% {
        background: #ff6b6b;
        box-shadow: 0 0 5px rgba(255, 107, 107, 0.5);
    }
}

/* Floating Chat Button */
#floating-chat-button {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 60px;
    height: 60px;
    background: linear-gradient(135deg, #007cba, #005a87);
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 12px rgba(0, 124, 186, 0.3);
    transition: all 0.3s ease;
    z-index: 9999;
}

#floating-chat-button:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 20px rgba(0, 124, 186, 0.4);
    background: linear-gradient(135deg, #005a87, #007cba);
}

#floating-chat-button svg {
    transition: transform 0.3s ease;
}

#floating-chat-button:hover svg {
    transform: scale(1.1);
}

/* Responsive design for mobile */
@media (max-width: 768px) {
    #floating-chat-button {
        width: 50px;
        height: 50px;
        bottom: 15px;
        right: 15px;
    }

    #floating-chat-button svg {
        width: 20px;
        height: 20px;
    }
}

/* Floating button unread notification - red with shake */
#floating-chat-button.has-unread {
    background: linear-gradient(135deg, #ff4757, #ff6b6b) !important;
    box-shadow: 0 4px 15px rgba(255, 71, 87, 0.5);
    animation: shake-button 2s infinite;
}

#floating-chat-button.has-unread:hover {
    background: linear-gradient(135deg, #ff6b6b, #ff4757) !important;
    box-shadow: 0 6px 25px rgba(255, 71, 87, 0.6);
}

/* Unread count badge on floating button */
#floating-chat-button .unread-badge {
    position: absolute;
    top: -5px;
    right: -5px;
    background: #fff;
    color: #ff4757;
    font-size: 12px;
    font-weight: bold;
    min-width: 20px;
    height: 20px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 5px;
    box-shadow: 0 2px 5px rgba(0,0,0,0.2);
}

/* Shake animation - triggers every 1.5 seconds with rotation + horizontal shake */
@keyframes shake-button {
    0%, 80%, 100% {
        transform: rotate(0deg) translateX(0);
    }
    82% {
        transform: rotate(-25deg) translateX(-16px);
    }
    84% {
        transform: rotate(25deg) translateX(16px);
    }
    86% {
        transform: rotate(-20deg) translateX(-12px);
    }
    88% {
        transform: rotate(20deg) translateX(12px);
    }
    90% {
        transform: rotate(-15deg) translateX(-8px);
    }
    92% {
        transform: rotate(15deg) translateX(8px);
    }
    94% {
        transform: rotate(-10deg) translateX(-4px);
    }
    96% {
        transform: rotate(10deg) translateX(4px);
    }
    98% {
        transform: rotate(0deg) translateX(0);
    }
}

/* Guest login modal (floating chat button) */
#mychat-login-modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 10000;
    padding: 16px;
}

#mychat-login-modal-backdrop.is-open {
    display: flex;
}

#mychat-login-modal {
    width: min(520px, 94vw);
    background: #fff;
    border-radius: 14px;
    padding: 18px 18px 16px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.25);
}

.mychat-login-modal-title {
    font-size: 18px;
    font-weight: 700;
    color: #111;
    margin-bottom: 10px;
}

.mychat-login-modal-body {
    font-size: 14px;
    line-height: 1.6;
    color: #333;
    margin-bottom: 16px;
}

.mychat-login-modal-actions {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
    flex-wrap: wrap;
}

.mychat-modal-btn {
    appearance: none;
    border: 1px solid #ddd;
    background: #fff;
    color: #111;
    border-radius: 10px;
    padding: 10px 14px;
    cursor: pointer;
    font-size: 14px;
}

.mychat-modal-login-btn {
    border-color: #007cba;
    background: #007cba;
    color: #fff;
}

.mychat-modal-login-btn:hover {
    background: #005a87;
    border-color: #005a87;
}

.mychat-modal-exit-btn:hover {
    background: #f3f5f6;
}
