/* ============================================
   Attefall AI Chatbot Widget
   ============================================ */

:root {
    --aac-color: #6366f1;
    --aac-bg: #ffffff;
    --aac-text: #111111;
    --aac-text-light: #111111;
    --aac-border: #e5e7eb;
    --aac-user-bg: var(--aac-color);
    --aac-bot-bg: #f3f4f6;
    --aac-radius: 12px;
    --aac-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
}

/* Trigger-knapp */
#aac-trigger {
    position: fixed;
    bottom: 24px;
    z-index: 99999;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--aac-color);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

#aac-trigger:hover {
    transform: scale(1.08);
    box-shadow: 0 6px 24px rgba(0, 0, 0, 0.25);
}

#aac-trigger svg {
    width: 26px;
    height: 26px;
    fill: #111111 !important;
}

#aac-trigger.bottom-right { right: 24px; }
#aac-trigger.bottom-left { left: 24px; }

/* Chat-fönstret */
#aac-chat-window {
    position: fixed;
    bottom: 96px;
    z-index: 99999;
    width: 420px;
    max-height: 600px;
    background: var(--aac-bg);
    border-radius: var(--aac-radius);
    box-shadow: var(--aac-shadow);
    display: none;
    flex-direction: column;
    overflow: hidden;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-size: 14px;
    line-height: 1.5;
    color: #111111 !important;
    border: 1px solid var(--aac-border);
}

#aac-chat-window.open {
    display: flex;
    animation: aac-slide-up 0.25s ease-out;
}

#aac-chat-window.bottom-right { right: 24px; }
#aac-chat-window.bottom-left { left: 24px; }

@keyframes aac-slide-up {
    from { opacity: 0; transform: translateY(16px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Header */
.aac-header {
    padding: 16px 20px;
    background: var(--aac-color);
    color: #000000 !important;
    font-weight: 600;
    font-size: 16px !important;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

.aac-header-close {
    background: none;
    border: none;
    color: #111111 !important;
    cursor: pointer;
    font-size: 20px;
    padding: 0;
    line-height: 1;
    opacity: 0.8;
}

.aac-header-close:hover {
    opacity: 1;
}

/* Meddelandeyta */
.aac-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    min-height: 200px;
    max-height: 420px;
}

/* Enskilt meddelande */
.aac-msg {
    max-width: 85%;
    padding: 10px 14px;
    border-radius: 10px;
    word-wrap: break-word;
    white-space: pre-wrap;
}

.aac-msg-user {
    align-self: flex-end;
    background: var(--aac-user-bg);
    color: #111111 !important;
    border-bottom-right-radius: 4px;
}

.aac-msg-bot {
    align-self: flex-start;
    background: var(--aac-bot-bg);
    color: #111111 !important;
    border-bottom-left-radius: 4px;
}

/* Källor — accordion */
.aac-sources {
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid var(--aac-border);
    font-size: 12px;
    color: #111111 !important;
}

.aac-sources-toggle {
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px 0;
    font-size: 12px;
    font-family: inherit;
    color: #555555 !important;
    display: flex;
    align-items: center;
    gap: 6px;
}

.aac-sources-toggle:hover {
    color: #111111 !important;
}

.aac-sources-arrow {
    font-size: 9px;
    transition: transform 0.2s;
}

.aac-sources-count {
    background: #e5e7eb;
    color: #111111 !important;
    border-radius: 10px;
    padding: 1px 7px;
    font-size: 11px;
    font-weight: 600;
}

.aac-sources-list {
    list-style: none;
    margin: 6px 0 0 0;
    padding: 0;
}

.aac-sources-list li {
    padding: 4px 0;
    border-bottom: 1px solid #f0f0f0;
    display: flex;
    align-items: baseline;
    gap: 6px;
}

.aac-sources-list li:last-child {
    border-bottom: none;
}

.aac-sources-list a {
    color: #0073aa !important;
    text-decoration: none;
    flex: 1;
}

.aac-sources-list a:hover {
    text-decoration: underline;
}

.aac-sources-score {
    color: #888888 !important;
    font-size: 11px;
    white-space: nowrap;
}

/* Laddningsindikator */
.aac-typing {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 10px 14px;
    align-self: flex-start;
}

.aac-typing span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--aac-text-light);
    animation: aac-bounce 1.2s infinite;
}

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

@keyframes aac-bounce {
    0%, 60%, 100% { transform: translateY(0); }
    30% { transform: translateY(-6px); }
}

/* Inmatningsfält */
.aac-input-area {
    display: flex;
    align-items: center;
    padding: 12px 16px;
    border-top: 1px solid var(--aac-border);
    gap: 8px;
    flex-shrink: 0;
}

.aac-input-area input {
    flex: 1;
    border: 1px solid var(--aac-border);
    border-radius: 8px;
    padding: 10px 14px;
    font-size: 14px;
    outline: none;
    font-family: inherit;
    color: #111111 !important;
    background: var(--aac-bg);
}

.aac-input-area input::placeholder {
    color: #111111 !important;
}

.aac-input-area input:focus {
    border-color: var(--aac-color);
    box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.15);
}

.aac-input-area button {
    width: 38px;
    height: 38px;
    border-radius: 8px;
    background: var(--aac-color);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: opacity 0.15s;
}

.aac-input-area button:hover {
    opacity: 0.9;
}

.aac-input-area button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.aac-input-area button svg {
    width: 18px;
    height: 18px;
    fill: #111111 !important;
}

/* Powered by */
.aac-powered {
    text-align: center;
    padding: 6px;
    font-size: 11px;
    color: #111111 !important;
    border-top: 1px solid var(--aac-border);
}

/* Dölj chatbot när fullskärmsmeny är öppen */
body.menu-open #aac-trigger,
body.menu-open #aac-chat-window {
    z-index: 0 !important;
}

/* Responsiv — fullskärm på mobil */
@media (max-width: 600px) {
    #aac-chat-window {
        width: 100vw !important;
        height: 100vh !important;
        max-height: 100vh !important;
        top: 0 !important;
        left: 0 !important;
        right: 0 !important;
        bottom: 0 !important;
        border-radius: 0;
        border: none;
    }

    #aac-chat-window .aac-messages {
        max-height: none;
        flex: 1;
    }

    #aac-trigger {
        bottom: 16px;
    }

    #aac-trigger.bottom-right { right: 16px; }
    #aac-trigger.bottom-left { left: 16px; }
}
