/**
 * Magic AI Assistant Widget Styles
 * 
 * @package MagicAIAssistant
 * @since 2.7.0
 */

/* Widget Container */
#magic-ai-widget {
    position: fixed;
    z-index: 999999;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-size: 14px;
    line-height: 1.4;
}

/* Positioning */
.magic-ai-bottom-right {
    bottom: 20px;
    right: 20px;
}

.magic-ai-bottom-left {
    bottom: 20px;
    left: 20px;
}

/* Trigger Button */
.magic-ai-button {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 16px;
    border-radius: 25px;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    font-weight: 500;
}

.magic-ai-dark .magic-ai-button {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

.magic-ai-light .magic-ai-button {
    background: white;
    color: #2d3748;
    border: 1px solid #e2e8f0;
}

.magic-ai-button:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.2);
}

.magic-ai-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: auto;
    height: auto;
    font-size: 20px;
    color: white;
    text-shadow: 0 1px 2px rgba(0,0,0,0.3);
}

.magic-ai-label {
    font-weight: 500;
    white-space: nowrap;
}

/* Chat Container - Fixed Sizing */
.magic-ai-chat-container {
    position: absolute;
    bottom: 70px;
    right: 0;
    width: 350px;
    height: 500px;
    max-height: 500px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    width: 380px;
    height: 500px;
    max-width: calc(100vw - 40px);
    max-height: calc(100vh - 140px);
    border-radius: 12px;
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.2);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transform-origin: bottom right;
    animation: magic-ai-slide-up 0.3s ease-out;
}

/* Ensure fixed size behavior */
.magic-ai-chat-container * {
    box-sizing: border-box;
}

/* Mobile responsive adjustments */
@media (max-height: 600px) {
    .magic-ai-chat-container {
        height: calc(100vh - 140px);
        max-height: calc(100vh - 140px);
    }
}

@media (max-width: 480px) {
    .magic-ai-chat-container {
        width: calc(100vw - 20px);
        right: 10px;
    }
}

.magic-ai-dark .magic-ai-chat-container {
    background: #1a202c;
    color: white;
    border: 1px solid #2d3748;
}

.magic-ai-light .magic-ai-chat-container {
    background: white;
    color: #2d3748;
    border: 1px solid #e2e8f0;
}

/* Header */
.magic-ai-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    flex: 0 0 auto;
    position: sticky;
    top: 0;
    z-index: 2;
    min-height: 64px;
}

.magic-ai-dark .magic-ai-header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

.magic-ai-light .magic-ai-header {
    background: #f7fafc;
    color: #2d3748;
    border-bottom-color: #e2e8f0;
}

.magic-ai-header-content {
    display: flex;
    align-items: center;
    gap: 10px;
}

.magic-ai-avatar {
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    color: white;
    text-shadow: 0 1px 2px rgba(0,0,0,0.3);
}

.magic-ai-title {
    font-weight: 600;
    font-size: 16px;
}

.magic-ai-close {
    background: none;
    border: none;
    color: inherit;
    font-size: 18px;
    cursor: pointer;
    padding: 4px;
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: background 0.2s;
}

.magic-ai-close:hover {
    background: rgba(255, 255, 255, 0.1);
}

/* Messages - Account for Fixed Bottom Elements */
.magic-ai-messages {
    flex: 1 1 auto;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 20px;
    padding-bottom: 140px; /* Increased space for input + footer */
    display: flex;
    flex-direction: column;
    gap: 12px;
    scroll-behavior: smooth;
    min-height: 0;
    max-height: calc(100% - 140px);
}

.magic-ai-message {
    max-width: 85%;
    padding: 12px 16px;
    border-radius: 18px;
    line-height: 1.4;
    word-wrap: break-word;
    animation: magic-ai-message-in 0.3s ease-out;
}

.magic-ai-user {
    align-self: flex-end;
    border-bottom-right-radius: 6px;
}

.magic-ai-dark .magic-ai-user {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

.magic-ai-light .magic-ai-user {
    background: #4299e1;
    color: white;
}

.magic-ai-bot {
    align-self: flex-start;
    border-bottom-left-radius: 6px;
}

.magic-ai-dark .magic-ai-bot {
    background: #2d3748;
    color: #e2e8f0;
}

.magic-ai-light .magic-ai-bot {
    background: #f7fafc;
    color: #2d3748;
}

/* Typing Indicator */
.magic-ai-typing {
    display: flex;
    align-items: center;
    gap: 8px;
}

.magic-ai-typing-dots {
    display: flex;
    gap: 3px;
}

.magic-ai-typing-dots span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: currentColor;
    opacity: 0.4;
    animation: magic-ai-typing 1.4s infinite ease-in-out;
}

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

/* Footer - Fixed to Very Bottom */
.magic-ai-footer {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    text-align: center;
    padding: 10px 16px;
    font-size: 11px;
    opacity: 0.7;
    border-top: 1px solid;
    flex: 0 0 auto;
    min-height: 40px;
    z-index: 10;
}

.magic-ai-dark .magic-ai-footer {
    background: #1a202c;
    color: #a0aec0;
    border-top-color: #2d3748;
}

.magic-ai-light .magic-ai-footer {
    background: #f7fafc;
    color: #718096;
    border-top-color: #e2e8f0;
}

.magic-ai-footer a {
    color: inherit;
    text-decoration: none;
}

.magic-ai-footer a:hover {
    text-decoration: underline;
}

/* Input Container - Fixed to Bottom */
.magic-ai-input-container {
    display: flex;
    padding: 16px;
    gap: 8px;
    border-top: 1px solid;
    flex: 0 0 auto;
    position: absolute;
    bottom: 40px;
    left: 0;
    right: 0;
    min-height: 68px;
    z-index: 10;
}

.magic-ai-dark .magic-ai-input-container {
    border-top-color: #2d3748;
    background: #2d3748;
}

.magic-ai-light .magic-ai-input-container {
    border-top-color: #e2e8f0;
    background: #f7fafc;
}

#magic-ai-input {
    flex: 1;
    border: 1px solid;
    border-radius: 20px;
    padding: 10px 16px;
    outline: none;
    font-size: 14px;
    font-family: inherit;
    transition: border-color 0.2s;
}

.magic-ai-dark #magic-ai-input {
    background: #1a202c;
    border-color: #4a5568;
    color: white;
}

.magic-ai-dark #magic-ai-input:focus {
    border-color: #667eea;
}

.magic-ai-dark #magic-ai-input::placeholder {
    color: #a0aec0;
}

.magic-ai-light #magic-ai-input {
    background: white;
    border-color: #e2e8f0;
    color: #2d3748;
}

.magic-ai-light #magic-ai-input:focus {
    border-color: #4299e1;
}

.magic-ai-light #magic-ai-input::placeholder {
    color: #a0aec0;
}

#magic-ai-send {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    border-radius: 20px;
    padding: 10px 20px;
    cursor: pointer;
    font-weight: 500;
    font-size: 14px;
    transition: transform 0.2s, box-shadow 0.2s;
    white-space: nowrap;
}

#magic-ai-send:hover {
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(102, 126, 234, 0.3);
}

#magic-ai-send:active {
    transform: translateY(0);
}

/* Animations */
@keyframes magic-ai-slide-up {
    from {
        opacity: 0;
        transform: translateY(20px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

@keyframes magic-ai-message-in {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes magic-ai-typing {
    0%, 60%, 100% {
        opacity: 0.4;
        transform: translateY(0);
    }
    30% {
        opacity: 1;
        transform: translateY(-10px);
    }
}

/* Mobile Responsive */
@media (max-width: 480px) {
    .magic-ai-chat-container {
        width: calc(100vw - 20px);
        height: calc(100vh - 100px);
        position: fixed;
        bottom: 10px;
        left: 10px;
        right: 10px;
    }
    
    .magic-ai-bottom-left,
    .magic-ai-bottom-right {
        left: 10px;
        right: 10px;
        bottom: 10px;
    }
    
    .magic-ai-button {
        width: 100%;
        justify-content: center;
    }
}

/* Scrollbar Styling */
.magic-ai-messages::-webkit-scrollbar {
    width: 4px;
}

.magic-ai-messages::-webkit-scrollbar-track {
    background: transparent;
}

.magic-ai-messages::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 2px;
}

.magic-ai-light .magic-ai-messages::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.1);
}

/* --- Additions / Enhancements --- */

/* Make links clickable and styled inside bot messages */
.magic-ai-bot a {
    color: #4299e1; /* or #667eea for brand match */
    text-decoration: underline;
    word-break: break-word;
}
.magic-ai-bot a:hover {
    opacity: 0.85;
}

/* Highlight phone/email links a bit more */
.magic-ai-bot a[href^="mailto:"],
.magic-ai-bot a[href^="tel:"] {
    font-weight: 500;
}

/* Reduce gap when bot sends multiple short replies */
.magic-ai-message.magic-ai-bot + .magic-ai-message.magic-ai-bot {
    margin-top: -4px;
}

/* Header polish with subtle drop shadow */
.magic-ai-header {
    box-shadow: 0 2px 6px rgba(0,0,0,0.08);
}
