/**
 * 609 Studios Chatbot - widget styling
 *
 * Vanilla CSS, ingen build-process. Använder CSS custom properties så att
 * Mattias kan justera färger utan att redigera flera ställen.
 *
 * Brand: svart och vit bas med Amber Rust (#a94828) som accent.
 * Typografi: Isidora Sans för rubriker, Source Sans Pro för text.
 * Faller tillbaka till system-stack om brand-fonts inte finns laddade.
 */

:root {
    --c609-bg-page:        rgba(0, 0, 0, 0.45);
    --c609-bg-panel:       #ffffff;
    --c609-bg-bot:         #f5f1ea;
    --c609-bg-user:        #1a1a1a;
    --c609-bg-input:       #ffffff;
    --c609-bg-header:      #1a1a1a;
    --c609-color-text:     #1a1a1a;
    --c609-color-text-bot: #1a1a1a;
    --c609-color-text-usr: #ffffff;
    --c609-color-muted:    #6b6b6b;
    --c609-color-accent:   #a94828;
    --c609-color-accent-h: #8c3a1f;
    --c609-color-border:   #e0d9cf;
    --c609-color-focus:    #a94828;

    --c609-font-heading: "Isidora Sans", "Poppins", "Helvetica Neue", Arial, sans-serif;
    --c609-font-body:    "Source Sans Pro", "Helvetica Neue", Arial, sans-serif;

    --c609-radius:       12px;
    --c609-radius-lg:    20px;
    --c609-shadow:       0 16px 40px rgba(0, 0, 0, 0.18);

    --c609-z-button:     2147483600;
    --c609-z-panel:      2147483601;
}

/* ----------------------------------------------------------------------
   Floating action button
   ---------------------------------------------------------------------- */

.c609-fab {
    position: fixed;
    right: 20px;
    bottom: 20px;
    z-index: var(--c609-z-button);
    width: 60px;
    height: 60px;
    border-radius: 50%;
    border: none;
    background: var(--c609-color-accent);
    color: #ffffff;
    cursor: pointer;
    box-shadow: var(--c609-shadow);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.18s ease, background-color 0.18s ease;
    font-family: var(--c609-font-body);
}

.c609-fab:hover,
.c609-fab:focus-visible {
    background: var(--c609-color-accent-h);
    transform: scale(1.05);
    outline: 2px solid var(--c609-color-focus);
    outline-offset: 2px;
}

.c609-fab[aria-expanded="true"] .c609-fab__icon-chat {
    display: none;
}

.c609-fab[aria-expanded="false"] .c609-fab__icon-close {
    display: none;
}

.c609-fab__icon-chat,
.c609-fab__icon-close {
    width: 24px;
    height: 24px;
    pointer-events: none;
}

/* ----------------------------------------------------------------------
   Panel container
   ---------------------------------------------------------------------- */

.c609-panel {
    position: fixed;
    right: 20px;
    bottom: 92px;
    z-index: var(--c609-z-panel);
    width: 380px;
    max-width: calc(100vw - 40px);
    height: 560px;
    max-height: calc(100vh - 120px);
    background: var(--c609-bg-panel);
    border-radius: var(--c609-radius-lg);
    box-shadow: var(--c609-shadow);
    display: none;
    flex-direction: column;
    overflow: hidden;
    font-family: var(--c609-font-body);
    color: var(--c609-color-text);
    font-size: 15px;
    line-height: 1.45;
}

.c609-panel[data-open="true"] {
    display: flex;
}

/* ----------------------------------------------------------------------
   Panel header
   ---------------------------------------------------------------------- */

.c609-header {
    background: var(--c609-bg-header);
    color: #ffffff;
    padding: 16px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.c609-header__title {
    font-family: var(--c609-font-heading);
    font-weight: 700;
    font-size: 16px;
    margin: 0;
    color: #ffffff;
}

.c609-header__subtitle {
    margin: 0;
    font-size: 12px;
    color: rgba(255, 255, 255, 0.7);
}

.c609-header__close {
    background: transparent;
    border: none;
    color: #ffffff;
    cursor: pointer;
    padding: 4px;
    border-radius: 6px;
}

.c609-header__close:focus-visible {
    outline: 2px solid #ffffff;
    outline-offset: 2px;
}

/* ----------------------------------------------------------------------
   GDPR-notis (visas vid första öppning)
   ---------------------------------------------------------------------- */

.c609-gdpr {
    padding: 16px 20px;
    background: var(--c609-bg-bot);
    border-bottom: 1px solid var(--c609-color-border);
    font-size: 13px;
    line-height: 1.5;
}

.c609-gdpr p {
    margin: 0 0 12px 0;
    color: var(--c609-color-text);
}

.c609-gdpr__actions {
    display: flex;
    gap: 8px;
}

.c609-gdpr__btn {
    flex: 1;
    padding: 8px 12px;
    border-radius: 8px;
    border: 1px solid var(--c609-color-border);
    background: #ffffff;
    cursor: pointer;
    font-family: inherit;
    font-size: 13px;
    transition: background 0.15s ease;
}

.c609-gdpr__btn--accept {
    background: var(--c609-color-accent);
    color: #ffffff;
    border-color: var(--c609-color-accent);
}

.c609-gdpr__btn--accept:hover {
    background: var(--c609-color-accent-h);
    border-color: var(--c609-color-accent-h);
}

/* ----------------------------------------------------------------------
   Meddelandelista
   ---------------------------------------------------------------------- */

.c609-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px 20px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    scroll-behavior: smooth;
}

.c609-msg {
    max-width: 85%;
    padding: 10px 14px;
    border-radius: var(--c609-radius);
    word-wrap: break-word;
    white-space: pre-wrap;
}

.c609-msg--bot {
    background: var(--c609-bg-bot);
    color: var(--c609-color-text-bot);
    align-self: flex-start;
    border-bottom-left-radius: 4px;
    /* Bot-bubblor renderas som markdown till HTML; radbrytningar kommer
       från <br>, så normal whitespace räcker. */
    white-space: normal;
}

/* Markdown-element inuti bot-bubblor */
.c609-msg--bot strong { font-weight: 600; }
.c609-msg--bot em { font-style: italic; }
.c609-msg--bot code {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 0.92em;
    background: rgba(0, 0, 0, 0.06);
    padding: 1px 5px;
    border-radius: 4px;
}
.c609-msg--bot ul,
.c609-msg--bot ol {
    margin: 6px 0;
    padding-left: 22px;
}
.c609-msg--bot li {
    margin: 2px 0;
}
.c609-msg--bot a {
    color: inherit;
    text-decoration: underline;
    text-underline-offset: 2px;
}
.c609-msg--bot a:hover {
    text-decoration-thickness: 2px;
}

.c609-msg--user {
    background: var(--c609-bg-user);
    color: var(--c609-color-text-usr);
    align-self: flex-end;
    border-bottom-right-radius: 4px;
}

.c609-msg--error {
    background: #fdecea;
    color: #8c1a1a;
    align-self: stretch;
    text-align: center;
    border-radius: 8px;
    font-size: 13px;
}

.c609-msg__streaming-cursor {
    display: inline-block;
    width: 2px;
    height: 1em;
    background: currentColor;
    margin-left: 2px;
    animation: c609-blink 1s infinite;
    vertical-align: text-bottom;
}

@keyframes c609-blink {
    0%, 50% { opacity: 1; }
    51%, 100% { opacity: 0; }
}

/* ----------------------------------------------------------------------
   Quick reply-knappar för funnel-spår
   ---------------------------------------------------------------------- */

.c609-quick-replies {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 0 20px 12px 20px;
}

.c609-quick-replies__btn {
    padding: 8px 14px;
    border: 1px solid var(--c609-color-accent);
    background: #ffffff;
    color: var(--c609-color-accent);
    border-radius: 999px;
    cursor: pointer;
    font-family: inherit;
    font-size: 13px;
    transition: background 0.15s ease, color 0.15s ease;
}

.c609-quick-replies__btn:hover,
.c609-quick-replies__btn:focus-visible {
    background: var(--c609-color-accent);
    color: #ffffff;
    outline: 2px solid var(--c609-color-focus);
    outline-offset: 2px;
}

/* ----------------------------------------------------------------------
   Input-fält
   ---------------------------------------------------------------------- */

.c609-input {
    border-top: 1px solid var(--c609-color-border);
    padding: 12px 16px;
    display: flex;
    gap: 8px;
    align-items: flex-end;
    background: var(--c609-bg-input);
}

.c609-input__textarea {
    flex: 1;
    min-height: 40px;
    max-height: 120px;
    padding: 8px 12px;
    border: 1px solid var(--c609-color-border);
    border-radius: 10px;
    resize: none;
    font-family: inherit;
    font-size: 15px;
    line-height: 1.4;
    background: #ffffff;
    color: var(--c609-color-text);
}

.c609-input__textarea:focus {
    outline: 2px solid var(--c609-color-focus);
    outline-offset: 1px;
    border-color: var(--c609-color-focus);
}

.c609-input__send {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: none;
    background: var(--c609-color-accent);
    color: #ffffff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.15s ease;
}

.c609-input__send:hover,
.c609-input__send:focus-visible {
    background: var(--c609-color-accent-h);
    outline: 2px solid var(--c609-color-focus);
    outline-offset: 2px;
}

.c609-input__send:disabled {
    background: #c5c5c5;
    cursor: not-allowed;
}

.c609-input__send-icon {
    width: 18px;
    height: 18px;
}

/* Honeypot-fält (osynligt för människor, fångar bots) */
.c609-honeypot {
    position: absolute;
    left: -9999px;
    top: -9999px;
    width: 1px;
    height: 1px;
    opacity: 0;
}

/* ----------------------------------------------------------------------
   Footer med branding-tagg
   ---------------------------------------------------------------------- */

.c609-footer {
    padding: 6px 20px 10px 20px;
    text-align: center;
    font-size: 11px;
    color: var(--c609-color-muted);
}

/* ----------------------------------------------------------------------
   Mobile
   ---------------------------------------------------------------------- */

@media (max-width: 480px) {
    .c609-panel {
        right: 10px;
        left: 10px;
        bottom: 82px;
        width: auto;
        max-width: none;
        height: calc(100vh - 110px);
    }
    .c609-fab {
        right: 14px;
        bottom: 14px;
        width: 56px;
        height: 56px;
    }
}

/* ----------------------------------------------------------------------
   Reduced motion
   ---------------------------------------------------------------------- */

@media (prefers-reduced-motion: reduce) {
    .c609-fab,
    .c609-gdpr__btn,
    .c609-quick-replies__btn,
    .c609-input__send {
        transition: none;
    }
    .c609-msg__streaming-cursor {
        animation: none;
    }
}
