/* CSS-variabler för enklare anpassning */
:root {
    /* Dessa variabler kommer att uppdateras via JavaScript */
    --primary-color: #0078FF;
    --secondary-color: #e5e5ea;
    
    /* Statiska variabler */
    --text-color-light: #fff;
    --text-color-dark: #000;
    --border-color: #ddd;
    --background-light: #f5f7fa;
    --chat-window-bg: #fff;
    --input-bg: #fff;
    
    /* Nya tema-specifika variabler */
    --primary-hover: color-mix(in srgb, var(--primary-color) 85%, black);
    --primary-active: color-mix(in srgb, var(--primary-color) 70%, black);
    --secondary-hover: color-mix(in srgb, var(--secondary-color) 90%, black);
    --button-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
    --transition-speed: 0.3s;
}

/* Dark mode - system preference */
@media (prefers-color-scheme: dark) {
    :root[data-theme="auto"] {
        --text-color-dark: #fff;
        --border-color: #3d3d3d;
        --background-light: #1c1c1e;
        --chat-window-bg: #000;
        --input-bg: #1c1c1e;
        --button-shadow: 0 2px 5px rgba(0, 0, 0, 0.3);
    }
}

/* Force dark mode */
:root[data-theme="dark"] {
    --secondary-color: #2c2c2e;
    --text-color-dark: #fff;
    --border-color: #3d3d3d;
    --background-light: #1c1c1e;
    --chat-window-bg: #000;
    --input-bg: #1c1c1e;
}

/* Force light mode */
:root[data-theme="light"] {
    --secondary-color: #e5e5ea;
    --text-color-dark: #000;
    --border-color: #ddd;
    --background-light: #f5f7fa;
    --chat-window-bg: #fff;
    --input-bg: #fff;
}

/* Grundläggande positionering */
#ai-chatbot-widget {
    position: fixed !important;
    bottom: 20px !important;
    right: 20px !important;
    left: auto !important;
    z-index: 9999;
    font-family: 'Segoe UI', sans-serif;
}

/* Chat ikon */
#ai-chat-icon {
    position: fixed !important;
    bottom: 20px !important;
    right: 20px !important;
    left: auto !important;
    z-index: 10000;
    cursor: pointer;
    background: transparent;
    border: none;
    padding: 0;
    transition: transform var(--transition-speed) ease, box-shadow var(--transition-speed) ease;
}

#ai-chat-icon img {
    width: 80px;
    height: 80px;
    display: block;
    animation: pulse 2s infinite;
    will-change: transform, opacity;
    object-fit: cover;
    border-radius: 50%;
}

#ai-chat-icon:hover {
    transform: scale(1.05);
    box-shadow: var(--button-shadow);
}

#ai-chat-icon:active {
    transform: scale(0.95);
}

/* Chattfönster */
#ai-chat-window {
    position: fixed !important;
    bottom: 140px !important;
    right: 20px !important;
    left: auto !important;
    width: 360px;
    max-width: calc(100vw - 40px);
    height: 500px;
    max-height: calc(100vh - 160px);
    background: var(--chat-window-bg);
    border-radius: 12px;
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.2);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border: 1px solid var(--border-color);
    z-index: 10000;
    transition: all 0.3s ease-in-out;
}

#ai-chat-window.hidden {
    display: none;
}

/* Header */
#ai-chat-header {
    background-color: var(--primary-color);
    color: var(--text-color-light);
    padding: 16px;
    font-size: 16px;
    font-weight: 600;
    text-align: center;
    border-bottom: 1px solid rgba(0, 0, 0, 0.1);
    border-radius: 12px 12px 0 0;
    transition: background-color var(--transition-speed) ease;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

/* Meddelandecontainer */
#ai-chat-messages {
    flex: 1;
    padding: 16px;
    overflow-y: auto;
    background-color: var(--background-light);
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* Användarmeddelanden */
.user {
    align-self: flex-end;
    background-color: var(--primary-color);
    color: var(--text-color-light);
    padding: 10px 14px;
    border-radius: 18px 18px 0 18px;
    max-width: 80%;
    font-size: 15px;
    word-wrap: break-word;
    animation: fadeIn 0.3s ease-out;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
    transition: background-color var(--transition-speed) ease;
}

/* Botmeddelanden */
.bot {
    align-self: flex-start;
    background-color: var(--secondary-color);
    color: var(--text-color-dark);
    padding: 10px 14px;
    border-radius: 18px 18px 18px 0;
    max-width: 80%;
    font-size: 15px;
    word-wrap: break-word;
    animation: fadeIn 0.3s ease-out;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.05);
    transition: background-color var(--transition-speed) ease;
}

/* Input */
.input-container {
    display: flex;
    align-items: center;
    border-top: 1px solid var(--border-color);
    background-color: var(--input-bg);
    border-radius: 0 0 12px 12px;
}

#ai-chat-input {
    border: none;
    padding: 16px;
    font-size: 15px;
    flex: 1;
    box-sizing: border-box;
    outline: none;
    background-color: transparent;
    color: var(--text-color-dark);
    transition: all 0.3s ease;
}

#ai-chat-send {
    background: none;
    border: none;
    padding: 8px 16px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--primary-color);
    transition: color 0.3s ease;
}

#ai-chat-send:hover {
    color: var(--primary-hover);
}

#ai-chat-send svg {
    width: 20px;
    height: 20px;
}

/* Typing indicator */
.typing {
    align-self: flex-start;
    background-color: var(--secondary-color);
    padding: 15px;
    border-radius: 18px 18px 18px 0;
    margin: 4px 0;
    min-width: 60px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color var(--transition-speed) ease;
}

.typing-dots {
    display: flex;
    gap: 4px;
}

.typing-dots span {
    width: 8px;
    height: 8px;
    background-color: color-mix(in srgb, var(--primary-color) 50%, var(--text-color-dark));
    border-radius: 50%;
    display: inline-block;
    opacity: 0.6;
    animation: bounce 1.4s infinite ease-in-out;
}

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

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

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

@keyframes pulse {
    0% { transform: scale(1); opacity: 1; }
    50% { transform: scale(1.05); opacity: 0.8; }
    100% { transform: scale(1); opacity: 1; }
}

/* Scrollbar styling */
#ai-chat-messages::-webkit-scrollbar {
    width: 8px;
}

#ai-chat-messages::-webkit-scrollbar-track {
    background: var(--background-light);
}

#ai-chat-messages::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.2);
    border-radius: 4px;
}

#ai-chat-messages::-webkit-scrollbar-thumb:hover {
    background: rgba(0, 0, 0, 0.3);
}