/* =====================================================
   CHAT WIDGET — "Christy" AI Design Consultant
   Apple Messages-inspired design
   ===================================================== */

/* Tab trigger */
.chat-tab {
    position: fixed;
    right: 0;
    top: 50%;
    transform: translateY(-50%);
    z-index: 9990;
    background: var(--brand-orange);
    color: white;
    padding: 16px 10px;
    border-radius: 12px 0 0 12px;
    cursor: pointer;
    writing-mode: vertical-rl;
    text-orientation: mixed;
    font-size: 13px;
    font-weight: 700;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    box-shadow: -2px 2px 12px rgba(0,0,0,0.15);
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: 8px;
}

.chat-tab:hover {
    padding-right: 14px;
    box-shadow: -4px 2px 20px rgba(0,0,0,0.2);
}

.chat-tab i {
    writing-mode: horizontal-tb;
    font-size: 16px;
}

.chat-tab.has-unread::after {
    content: '';
    position: absolute;
    top: 8px;
    left: 8px;
    width: 10px;
    height: 10px;
    background: #10b981;
    border-radius: 50%;
    border: 2px solid var(--brand-orange);
}

/* Chat container */
.chat-container {
    position: fixed;
    right: 8px;
    bottom: 8px;
    top: auto;
    width: 340px;
    height: 500px;
    max-height: calc(100vh - 100px);
    z-index: 9995;
    background: #f2f2f7;
    box-shadow: 0 8px 30px rgba(0,0,0,0.18);
    border-radius: 16px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transform: scale(0.9) translateY(20px);
    opacity: 0;
    pointer-events: none;
    transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.3s ease;
}

.chat-container.open {
    transform: scale(1) translateY(0);
    opacity: 1;
    pointer-events: auto;
}

/* Header */
.chat-header {
    background: var(--brand-dark);
    color: white;
    padding: 16px 20px;
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
}

.chat-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--brand-orange);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 16px;
    flex-shrink: 0;
}

.chat-header-info {
    flex: 1;
    min-width: 0;
}

.chat-header-name {
    font-weight: 700;
    font-size: 15px;
}

.chat-header-status {
    font-size: 11px;
    color: #10b981;
    display: flex;
    align-items: center;
    gap: 4px;
}

.chat-header-status::before {
    content: '';
    width: 6px;
    height: 6px;
    background: #10b981;
    border-radius: 50%;
    display: inline-block;
}

.chat-close {
    background: none;
    border: none;
    color: rgba(255,255,255,0.7);
    font-size: 20px;
    cursor: pointer;
    padding: 4px;
    transition: color 0.15s;
}

.chat-close:hover {
    color: white;
}

/* Messages area */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    -webkit-overflow-scrolling: touch;
}

.chat-messages::-webkit-scrollbar {
    width: 4px;
}

.chat-messages::-webkit-scrollbar-thumb {
    background: rgba(0,0,0,0.15);
    border-radius: 2px;
}

/* Message bubbles — Apple Messages style */
.chat-msg {
    max-width: 80%;
    padding: 10px 14px;
    border-radius: 18px;
    font-size: 14px;
    line-height: 1.45;
    word-wrap: break-word;
    position: relative;
    animation: msgFadeIn 0.25s ease;
}

@keyframes msgFadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

.chat-msg.assistant {
    background: white;
    color: #1c1c1e;
    align-self: flex-start;
    border-bottom-left-radius: 6px;
    box-shadow: 0 1px 2px rgba(0,0,0,0.06);
}

.chat-msg.user {
    background: var(--brand-orange);
    color: white;
    align-self: flex-end;
    border-bottom-right-radius: 6px;
}

/* Typing indicator */
.chat-typing {
    display: none;
    align-self: flex-start;
    background: white;
    border-radius: 18px;
    border-bottom-left-radius: 6px;
    padding: 12px 18px;
    box-shadow: 0 1px 2px rgba(0,0,0,0.06);
}

.chat-typing.active {
    display: flex;
}

.chat-typing-dot {
    width: 7px;
    height: 7px;
    background: #a0a0a0;
    border-radius: 50%;
    margin: 0 2px;
    animation: typingBounce 1.2s infinite ease-in-out;
}

.chat-typing-dot:nth-child(2) { animation-delay: 0.15s; }
.chat-typing-dot:nth-child(3) { animation-delay: 0.3s; }

@keyframes typingBounce {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
    30% { transform: translateY(-6px); opacity: 1; }
}

/* Input area */
.chat-input-area {
    padding: 12px 16px;
    background: white;
    border-top: 1px solid #e5e5ea;
    display: flex;
    align-items: flex-end;
    gap: 8px;
    flex-shrink: 0;
}

.chat-input {
    flex: 1;
    border: 1px solid #e5e5ea;
    border-radius: 20px;
    padding: 10px 16px;
    font-size: 14px;
    font-family: inherit;
    resize: none;
    max-height: 100px;
    line-height: 1.4;
    outline: none;
    transition: border-color 0.15s;
}

.chat-input:focus {
    border-color: var(--brand-orange);
}

.chat-input::placeholder {
    color: #a0a0a0;
}

.chat-send {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--brand-orange);
    color: white;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.15s, transform 0.15s;
}

.chat-send:hover {
    background: var(--brand-dark-orange);
    transform: scale(1.05);
}

.chat-send:disabled {
    background: #c0c0c0;
    cursor: not-allowed;
    transform: none;
}

/* Powered by */
.chat-powered {
    text-align: center;
    padding: 6px;
    font-size: 10px;
    color: #a0a0a0;
    background: white;
    border-top: 1px solid #f0f0f0;
    flex-shrink: 0;
}

.chat-powered a {
    color: var(--brand-orange);
    font-weight: 600;
    text-decoration: none;
}

/* Overlay — mobile only */
.chat-overlay {
    display: none;
}

/* =====================================================
   MOBILE — Full screen iMessage style
   ===================================================== */
@media (max-width: 640px) {
    .chat-tab {
        display: none;
    }

    .chat-container {
        width: 100%;
        height: 100%;
        max-height: 100vh;
        right: 0;
        bottom: 0;
        border-radius: 0;
        transform: translateY(100%);
        opacity: 1;
    }

    .chat-container.open {
        transform: translateY(0);
    }

    .chat-input-area {
        padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
    }

    .chat-overlay {
        display: none;
        position: fixed;
        inset: 0;
        background: rgba(0,0,0,0.4);
        z-index: 9994;
    }

    .chat-overlay.active {
        display: block;
    }
}

/* Product images in messages */
.chat-img {
    max-width: 100%;
    border-radius: 10px;
    margin: 6px 0;
    display: block;
}

/* Links in messages */
.chat-link {
    color: var(--brand-orange);
    font-weight: 600;
    text-decoration: underline;
    text-underline-offset: 2px;
}

.chat-msg.user .chat-link {
    color: white;
}

/* Timestamp */
.chat-time {
    text-align: center;
    font-size: 11px;
    color: #8e8e93;
    padding: 8px 0 4px;
}
