#mary-g-chat-container {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 999999;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

#mary-g-trigger {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    border: 3px solid #fff;
    box-shadow: 0 10px 25px rgba(0,0,0,0.2);
    cursor: pointer;
    overflow: hidden;
    padding: 0;
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    display: flex;
    align-items: center;
    justify-content: center;
}

#mary-g-trigger:hover { transform: scale(1.1); }
#mary-g-trigger img { width: 100%; height: 100%; object-fit: cover; }

#mary-g-window {
    position: absolute;
    bottom: 80px;
    right: 0;
    width: 420px;
    height: 700px;
    max-height: calc(100vh - 120px);
    max-width: calc(100vw - 48px);
    background: #fff;
    border-radius: 28px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.2);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: all 0.3s ease;
    border: 1px solid #f1f5f9;
}

#mary-g-window.hidden {
    display: none;
    opacity: 0;
    transform: translateY(20px);
}

.mary-g-header {
    padding: 16px 20px;
    color: #fff;
    display: flex;
    justify-content: space-between;
    align-items: center;
    z-index: 100;
}

.mary-g-header-left { display: flex; align-items: center; gap: 12px; }
#mary-g-menu-btn { background: none; border: none; color: #fff; font-size: 24px; cursor: pointer; padding: 4px; line-height: 1; }

.mary-g-title-stack { display: flex; flex-direction: column; }
.mary-g-title { font-weight: 700; font-size: 18px; }
#mary-g-model-select { 
    background: transparent; 
    border: none; 
    color: rgba(255,255,255,0.9); 
    font-size: 11px; 
    font-weight: 600;
    text-transform: uppercase; 
    padding: 0; 
    cursor: pointer;
    outline: none;
}
#mary-g-model-select option { color: #000; }

#mary-g-messages {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
    background: #fdfdfd;
    display: flex;
    flex-direction: column;
    gap: 16px;
    scroll-behavior: smooth;
}

.mary-g-msg { display: flex; gap: 12px; max-width: 85%; align-items: flex-end; margin-bottom: 4px; }
.mary-g-msg.ai { align-self: flex-start; }
.mary-g-msg.user { align-self: flex-end; flex-direction: row-reverse; }

.mary-g-msg .avatar { width: 40px; height: 40px; border-radius: 50%; object-fit: cover; border: 2px solid #fff; box-shadow: 0 4px 10px rgba(0,0,0,0.1); }
.mary-g-msg .content-wrapper { display: flex; flex-direction: column; gap: 4px; }
.mary-g-msg .content { 
    padding: 12px 16px; 
    border-radius: 20px; 
    font-size: 15px; 
    line-height: 1.5; 
    box-shadow: 0 2px 8px rgba(0,0,0,0.05);
    position: relative;
    word-wrap: break-word;
}
.mary-g-msg .time { font-size: 11px; color: #94a3b8; padding: 0 4px; margin-top: 2px; }
.mary-g-msg.user .time { text-align: right; }

.mary-g-msg.ai .content { background: #fff; color: #1e293b; border-bottom-left-radius: 4px; border: 1px solid #f1f5f9; }
.mary-g-msg.user .content { background: #ff8c00; color: #fff; border-bottom-right-radius: 4px; }

.mary-g-typing-container {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 12px;
}
.mary-g-status-text {
    font-size: 12px;
    color: #ff8c00;
    font-weight: 600;
    margin-left: 52px;
}
.mary-g-typing { 
    display: flex; 
    gap: 4px; 
    padding: 10px 14px; 
    background: #fff; 
    border-radius: 16px; 
    border: 1px solid #f1f5f9; 
    width: fit-content; 
    box-shadow: 0 4px 12px rgba(0,0,0,0.05);
}
.mary-g-typing span { width: 8px; height: 8px; background: #ff8c00; border-radius: 50%; animation: mary-typing 1.4s infinite both; }
.mary-g-typing span:nth-child(2) { animation-delay: 0.2s; }
.mary-g-typing span:nth-child(3) { animation-delay: 0.4s; }

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

#mary-g-history-panel {
    position: absolute;
    top: 0;
    left: 0;
    width: 80%;
    height: 100%;
    background: #fff;
    z-index: 200;
    border-right: 1px solid #f1f5f9;
    display: flex;
    flex-direction: column;
    box-shadow: 20px 0 50px rgba(0,0,0,0.1);
    transform: translateX(0);
    transition: transform 0.3s ease;
}
#mary-g-history-panel.hidden {
    transform: translateX(-100%);
    display: flex; /* keep flex for transition */
    pointer-events: none;
}
.panel-header { 
    padding: 20px; 
    font-weight: 700; 
    border-bottom: 1px solid #f1f5f9; 
    display: flex; 
    justify-content: space-between; 
    align-items: center;
    background: #f8fafc;
}
#mary-g-new-chat-btn { 
    font-size: 13px; 
    padding: 8px 16px; 
    border-radius: 12px; 
    border: none; 
    background: #ff8c00; 
    color: #fff;
    cursor: pointer; 
    font-weight: 600;
}

#mary-g-session-list {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
}
.mary-g-session-item {
    padding: 12px 16px;
    border-radius: 12px;
    cursor: pointer;
    margin-bottom: 4px;
    transition: background 0.2s;
    font-size: 14px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    border: 1px solid transparent;
}
.mary-g-session-item:hover { background: #fff7ed; }
.mary-g-session-item.active { background: #fff7ed; border-color: #ff8c00; color: #ff8c00; font-weight: 600; }

.mary-g-footer { padding: 16px 20px; border-top: 1px solid #f1f5f9; background: #fff; }
.mary-g-tools { display: flex; gap: 20px; margin-bottom: 12px; }
.mary-g-tools button { 
    background: none; 
    border: none; 
    font-size: 22px; 
    cursor: pointer; 
    color: #ff8c00;
    opacity: 0.9; 
    transition: transform 0.2s, opacity 0.2s; 
    padding: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
}
.mary-g-tools button:hover { transform: scale(1.2); opacity: 1; }

.mary-g-input-area { display: flex; gap: 12px; align-items: flex-end; }
#mary-g-input { 
    flex: 1; 
    padding: 12px 20px; 
    border-radius: 20px; 
    border: 1px solid #e2e8f0; 
    outline: none; 
    font-size: 15px; 
    resize: none;
    max-height: 120px;
    background: #f8fafc;
    line-height: 1.4;
}
#mary-g-input:focus { border-color: #ff8c00; background: #fff; }

#mary-g-send-btn { 
    width: 44px; 
    height: 44px; 
    border-radius: 50%; 
    border: none; 
    color: #fff; 
    cursor: pointer; 
    display: flex; 
    align-items: center; 
    justify-content: center; 
    transition: transform 0.2s, background-color 0.2s;
    flex-shrink: 0;
    background-color: #ff8c00;
    box-shadow: 0 4px 12px rgba(255,140,0,0.3);
}
#mary-g-send-btn:hover { transform: scale(1.1); background-color: #e67e00; }

.mary-g-action-btns {
    display: flex;
    gap: 12px;
    margin-top: 8px;
    padding: 0 4px;
}
.mary-g-action-btn {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 16px;
    color: #94a3b8;
    transition: color 0.2s, transform 0.2s;
    padding: 2px;
}
.mary-g-action-btn:hover { color: #ff8c00; transform: scale(1.2); }

@media (max-width: 640px) {
    #mary-g-chat-container { bottom: 0; right: 0; width: 100%; height: 0; }
    #mary-g-trigger { bottom: 20px; right: 20px; position: fixed; }
    #mary-g-window {
        width: 100vw;
        height: 100vh;
        bottom: 0;
        right: 0;
        border-radius: 0;
        max-width: 100vw;
        max-height: 100vh;
        position: fixed;
    }
    #mary-g-history-panel { width: 85%; }
}
