/* ==========================================================================
   QD Chatbot Widget
   Adapted to AM Suisse brand design (flat design, no border-radius, UniversLT)
   ========================================================================== */

/* --- Default: AM Suisse colors (link color = #e50064) --- */
:root {
    --qd-chatbot-primary: #e50064;
    --qd-chatbot-primary-hover: #c00054;
    --qd-chatbot-primary-light: #fce8f0;
    --qd-chatbot-text: #1a1a1a;
    --qd-chatbot-text-light: #666666;
    --qd-chatbot-bg: #dcddde;
    --qd-chatbot-bg-light: #ffffff;
    --qd-chatbot-border: #dcddde;
    --qd-chatbot-error: #C73333;
    --qd-chatbot-error-bg: #fdecea;
    --qd-chatbot-shadow: none;
}

/* --- Brand overrides per sub-organisation (set via data-chatbot-brand on html) --- */

/* Metaltec Suisse (link color = #0086c4) */
[data-chatbot-brand="metaltec"] {
    --qd-chatbot-primary: #0086c4;
    --qd-chatbot-primary-hover: #006b9d;
    --qd-chatbot-primary-light: #e5f2fa;
}

/* Agrotec Suisse (link color = #79b420) */
[data-chatbot-brand="agrotec"] {
    --qd-chatbot-primary: #79b420;
    --qd-chatbot-primary-hover: #618f1a;
    --qd-chatbot-primary-light: #eef5e3;
}

/* Farriertec Suisse (link color = #f07d00) */
[data-chatbot-brand="farriertec"] {
    --qd-chatbot-primary: #f07d00;
    --qd-chatbot-primary-hover: #d86e00;
    --qd-chatbot-primary-light: #fef0e0;
}

/* --- FAB Button --- */

.qd-chatbot-fab {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 9999;
    width: 56px;
    height: 56px;
    border-radius: 0;
    border: none;
    background: var(--qd-chatbot-primary);
    color: #ffffff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--qd-chatbot-shadow);
    transition: background-color 0.2s ease;
}

.qd-chatbot-fab:hover {
    background: var(--qd-chatbot-primary-hover);
}

.qd-chatbot-fab:focus-visible {
    outline: 2px solid var(--qd-chatbot-primary);
    outline-offset: 2px;
}

/* --- Chat Panel --- */

.qd-chatbot-panel {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 9998;
    width: 400px;
    max-height: 600px;
    background: var(--qd-chatbot-bg);
    border-radius: 0;
    box-shadow: -1px 2px 1px -1px #c2c4c7;
    border: none;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    font-family: 'UniversLT-Condensed', Helvetica, Arial, sans-serif;
    font-size: 14px;
    line-height: 1.5;
    color: var(--qd-chatbot-text);
}

/* --- Header --- */

.qd-chatbot-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    background: var(--qd-chatbot-primary);
    color: #ffffff;
    flex-shrink: 0;
}

.qd-chatbot-title {
    font-weight: 700;
    font-size: 23px;
    line-height: normal;
    letter-spacing: 0.02em;
    text-transform: uppercase;
}

/* Firefox font metrics fix */
@-moz-document url-prefix() {
    .qd-chatbot-title {
        padding-top: 0.2em;
    }
}

.qd-chatbot-header-actions {
    display: flex;
    align-items: center;
    gap: 4px;
}

.qd-chatbot-btn-icon {
    background: none;
    border: none;
    color: #ffffff;
    cursor: pointer;
    padding: 4px;
    border-radius: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.15s ease;
}

.qd-chatbot-btn-icon:hover {
    background: rgba(255, 255, 255, 0.2);
}

.qd-chatbot-btn-icon:focus-visible {
    outline: 2px solid #ffffff;
    outline-offset: 1px;
}

/* --- Messages --- */

.qd-chatbot-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    min-height: 200px;
    max-height: 400px;
}

.qd-chatbot-msg {
    max-width: 85%;
    padding: 10px 14px;
    border-radius: 0;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.qd-chatbot-msg a {
    color: var(--qd-chatbot-primary);
    text-decoration: underline;
}

.qd-chatbot-msg-user {
    align-self: flex-end;
    background: var(--qd-chatbot-primary);
    color: #ffffff;
}

.qd-chatbot-msg-bot {
    align-self: flex-start;
    background: var(--qd-chatbot-bg-light);
    color: var(--qd-chatbot-text);
}

.qd-chatbot-msg-error {
    align-self: flex-start;
    background: var(--qd-chatbot-error-bg);
    color: var(--qd-chatbot-error);
    font-size: 13px;
}

/* --- Citation link in text --- */

.qd-chatbot-cite-link {
    color: var(--qd-chatbot-primary) !important;
    text-decoration: none !important;
    font-weight: 700;
}

.qd-chatbot-cite-link:hover {
    text-decoration: underline !important;
}

/* --- Citation cards --- */

.qd-chatbot-citations {
    display: flex;
    flex-direction: column;
    gap: 6px;
    align-self: flex-start;
    max-width: 85%;
}

.qd-chatbot-citation-card {
    display: block;
    padding: 8px 12px;
    background: var(--qd-chatbot-primary-light);
    border-radius: 0;
    border-left: 3px solid var(--qd-chatbot-primary);
    text-decoration: none;
    color: var(--qd-chatbot-text);
    font-size: 12px;
    line-height: 1.4;
    transition: background-color 0.15s ease;
}

.qd-chatbot-citation-card:hover {
    background: var(--qd-chatbot-border);
}

.qd-chatbot-citation-number {
    font-weight: 700;
    color: var(--qd-chatbot-primary);
}

.qd-chatbot-citation-title {
    color: var(--qd-chatbot-text);
}

/* --- Follow-up suggestions --- */

.qd-chatbot-suggestions {
    padding: 0 16px 8px;
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    flex-shrink: 0;
}

.qd-chatbot-suggestion {
    background: transparent;
    color: var(--qd-chatbot-primary);
    border: 1px solid var(--qd-chatbot-primary);
    border-radius: 0;
    padding: 6px 14px;
    font-size: 13px;
    font-family: inherit;
    cursor: pointer;
    transition: background-color 0.15s ease, color 0.15s ease;
    white-space: nowrap;
}

.qd-chatbot-suggestion:hover {
    background: var(--qd-chatbot-primary);
    color: #ffffff;
}

.qd-chatbot-suggestion:focus-visible {
    outline: 2px solid var(--qd-chatbot-primary);
    outline-offset: 2px;
}

/* --- Input area --- */

.qd-chatbot-input-area {
    padding: 12px 16px;
    border-top: none;
    flex-shrink: 0;
    position: relative;
}

.qd-chatbot-input-area::before {
    content: '';
    position: absolute;
    top: 0;
    left: 16px;
    right: 16px;
    height: 1px;
    background: #000000;
}

.qd-chatbot-input-wrapper {
    display: flex;
    align-items: stretch;
    gap: 8px;
    background: none;
    border-radius: 0;
    padding: 0;
}

.qd-chatbot-input {
    flex: 1;
    border: 1px solid #000000;
    background: var(--qd-chatbot-bg-light);
    font-size: 14px;
    line-height: 1;
    height: 38px;
    box-sizing: border-box;
    color: var(--qd-chatbot-text);
    outline: none;
    padding: 0 12px;
    font-family: inherit;
    transition: border-color 0.15s ease;
}

.qd-chatbot-input:focus {
    border-color: var(--qd-chatbot-primary);
}

.qd-chatbot-input::placeholder {
    color: var(--qd-chatbot-text-light);
}

.qd-chatbot-send {
    width: 40px;
    border-radius: 0;
    border: none;
    background: var(--qd-chatbot-primary);
    color: #ffffff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background-color 0.15s ease, opacity 0.15s ease;
}

.qd-chatbot-send:hover:not(:disabled) {
    background: var(--qd-chatbot-primary-hover);
}

.qd-chatbot-send:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.qd-chatbot-send:focus-visible {
    outline: 2px solid var(--qd-chatbot-primary);
    outline-offset: 2px;
}

/* --- Character count --- */

.qd-chatbot-charcount {
    font-size: 11px;
    color: var(--qd-chatbot-text-light);
    text-align: right;
    padding-top: 4px;
}

.qd-chatbot-charcount-over {
    color: var(--qd-chatbot-error);
    font-weight: 700;
}

/* --- Loading animation --- */

.qd-chatbot-loading {
    display: flex;
    gap: 4px;
    padding: 12px 16px;
}

.qd-chatbot-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--qd-chatbot-text-light);
    animation: qd-chatbot-bounce 1.4s infinite ease-in-out both;
}

.qd-chatbot-dot:nth-child(1) {
    animation-delay: -0.32s;
}

.qd-chatbot-dot:nth-child(2) {
    animation-delay: -0.16s;
}

@keyframes qd-chatbot-bounce {
    0%, 80%, 100% {
        transform: scale(0.6);
        opacity: 0.4;
    }
    40% {
        transform: scale(1);
        opacity: 1;
    }
}

/* --- Scrollbar --- */

.qd-chatbot-messages::-webkit-scrollbar {
    width: 6px;
}

.qd-chatbot-messages::-webkit-scrollbar-track {
    background: transparent;
}

.qd-chatbot-messages::-webkit-scrollbar-thumb {
    background: var(--qd-chatbot-border);
    border-radius: 3px;
}

/* --- Responsive --- */

@media (max-width: 480px) {
    .qd-chatbot-panel {
        bottom: 0;
        right: 0;
        left: 0;
        width: 100%;
        max-height: 100vh;
        max-height: 100dvh;
        border-radius: 0;
    }

    .qd-chatbot-messages {
        max-height: calc(100vh - 160px);
        max-height: calc(100dvh - 160px);
    }

    .qd-chatbot-fab {
        bottom: 16px;
        right: 16px;
    }
}

/* --- Feedback bar (like/dislike under each bot answer) --- */

.qd-chatbot-feedback {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 4px 0 12px 0;
    padding: 0 4px;
    flex-wrap: wrap;
}

.qd-chatbot-feedback-btn {
    background: transparent;
    color: #666;
    border: 1px solid transparent;
    border-radius: 0;
    padding: 4px 6px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: color 0.15s ease, border-color 0.15s ease, background-color 0.15s ease;
}

.qd-chatbot-feedback-btn:hover {
    color: var(--qd-chatbot-primary);
    border-color: var(--qd-chatbot-primary);
}

.qd-chatbot-feedback-btn:focus-visible {
    outline: 2px solid var(--qd-chatbot-primary);
    outline-offset: 1px;
}

.qd-chatbot-feedback-btn:disabled {
    cursor: default;
    opacity: 0.5;
}

.qd-chatbot-feedback-commenting {
    flex-direction: column;
    align-items: stretch;
    gap: 6px;
}

.qd-chatbot-feedback-comment {
    width: 100%;
    box-sizing: border-box;
    font-family: inherit;
    font-size: 13px;
    padding: 8px;
    border: 1px solid #ccc;
    border-radius: 0;
    resize: vertical;
    min-height: 48px;
    color: inherit;
    background: #ffffff;
}

.qd-chatbot-feedback-comment:focus-visible {
    outline: 2px solid var(--qd-chatbot-primary);
    outline-offset: 1px;
    border-color: var(--qd-chatbot-primary);
}

.qd-chatbot-feedback-actions {
    display: flex;
    gap: 6px;
    justify-content: flex-end;
}

.qd-chatbot-feedback-submit,
.qd-chatbot-feedback-skip {
    background: transparent;
    color: var(--qd-chatbot-primary);
    border: 1px solid var(--qd-chatbot-primary);
    border-radius: 0;
    padding: 4px 12px;
    font-size: 13px;
    font-family: inherit;
    cursor: pointer;
    transition: background-color 0.15s ease, color 0.15s ease;
}

.qd-chatbot-feedback-submit:hover,
.qd-chatbot-feedback-skip:hover {
    background: var(--qd-chatbot-primary);
    color: #ffffff;
}

.qd-chatbot-feedback-skip {
    color: #666;
    border-color: #ccc;
}

.qd-chatbot-feedback-skip:hover {
    background: #ccc;
    color: #000;
}

.qd-chatbot-feedback-submit:focus-visible,
.qd-chatbot-feedback-skip:focus-visible {
    outline: 2px solid var(--qd-chatbot-primary);
    outline-offset: 1px;
}

.qd-chatbot-feedback-submit:disabled,
.qd-chatbot-feedback-skip:disabled,
.qd-chatbot-feedback-comment:disabled {
    opacity: 0.5;
    cursor: default;
}

.qd-chatbot-feedback-done {
    justify-content: flex-start;
}

.qd-chatbot-feedback-thanks {
    font-size: 13px;
    color: #666;
    font-style: italic;
}
