/**
 * Sovica chatbot (template-parts/chatbot.php, assets/js/modules/chatbot.js)
 * Corner owl, "Potrebuješ pomoč?" bubble and chat panel. Mobile first.
 * Square corners everywhere except .btn (CLAUDE.md).
 */

/* === WRAPPER === */
.chatbot {
    position: fixed;
    right: var(--spacing-4);
    bottom: var(--spacing-4);
    /* Below the newsletter popup overlay (9999) it opens, above page content */
    z-index: 9997;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: var(--spacing-2);
    font-family: var(--font-tertiary);
}

.chatbot[hidden],
.chatbot [hidden] {
    display: none;
}

.chatbot .screen-reader-text {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
}

/* === OWL === */
.chatbot__owl {
    width: 64px;
    padding: 0;
    background: transparent;
    border: none;
    cursor: pointer;
    filter: drop-shadow(0 4px 8px var(--color-shadow-lg));
}

.chatbot__owl img {
    display: block;
    width: 100%;
    height: auto;
}

/* Teaser showing: owl as big as the production newsletter owl */
.chatbot--teaser .chatbot__owl {
    width: 80px;
}

/* Closed conversation: a small owl in the corner */
.chatbot--minimized .chatbot__owl {
    width: 27px;
}

.chatbot__owl:focus-visible,
.chatbot__bubble:focus-visible,
.chatbot__teaser-close:focus-visible,
.chatbot__close:focus-visible,
.chatbot__restart:focus-visible,
.chatbot__choice:focus-visible {
    outline: 2px solid var(--color-primary-alt);
    outline-offset: 2px;
}

/* === TEASER BUBBLE ===
   Same hand-drawn bubble as the newsletter corner teaser
   (newsletter-popup.css), left of the owl, tail pointing at it,
   × on the owl's top right corner. */
.chatbot--teaser {
    flex-direction: row;
    align-items: center;
    gap: var(--spacing-3);
}

.chatbot__bubble {
    position: relative;
    padding: 15px 20px;
    background: var(--color-secondary-4);
    color: var(--color-black); /* the bubble stays cream in the dark theme */
    font-family: 'ComforterBrush', cursive;
    font-size: 24px;
    line-height: 1.2;
    white-space: nowrap;
    border: 3px solid var(--color-primary);
    border-radius: 73% 27% 62% 38% / 45% 58% 42% 55%;
    box-shadow: 0 4px 12px var(--color-shadow);
    transform: rotate(10deg);
    cursor: pointer;
}

.chatbot__bubble::before,
.chatbot__bubble::after {
    content: '';
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 0;
    height: 0;
}

.chatbot__bubble::before {
    right: -12px;
    border-left: 15px solid var(--color-primary);
    border-top: 12px solid transparent;
    border-bottom: 12px solid transparent;
}

.chatbot__bubble::after {
    right: -7px;
    border-left: 12px solid var(--color-secondary-4);
    border-top: 9px solid transparent;
    border-bottom: 9px solid transparent;
}

.chatbot__teaser-close {
    position: absolute;
    top: -8px;
    right: -8px;
    width: 24px;
    height: 24px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--color-primary); /* white × on orange is only 3.25:1 */
    color: var(--color-white);
    border: 2px solid var(--color-white);
    border-radius: 50%;
    font-size: 12px;
    cursor: pointer;
}

/* === PANEL ===
   Phones: the whole screen. From 768px: a window above the owl. */
.chatbot__panel {
    position: fixed;
    inset: 0;
    z-index: 1;
    display: flex;
    flex-direction: column;
    background: var(--color-surface);
    color: var(--color-text);
}

/* Open on a phone: above everything (also the staging/local bar), the
   page under it doesn't scroll and the owl hides */
.chatbot--open {
    z-index: 100000;
}

/* The page under the full-screen panel doesn't scroll, the owl hides */
html.chatbot-open {
    overflow: hidden;
}

.chatbot--open .chatbot__owl {
    display: none;
}

.chatbot__header {
    display: flex;
    align-items: center;
    gap: var(--spacing-2);
    padding: var(--spacing-2) var(--spacing-2) var(--spacing-2) var(--spacing-4);
    background: var(--color-surface);
    border-bottom: 3px solid var(--color-primary-alt);
}

.chatbot__header-owl {
    width: 32px;
    height: auto;
}

.chatbot__heading {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.chatbot__title {
    margin: 0;
    color: var(--color-heading);
    font-family: var(--font-primary);
    font-size: var(--font-size-lg);
    line-height: 1.1;
}

.chatbot__subtitle {
    color: var(--color-text-muted);
    font-size: var(--font-size-xs);
}

.chatbot__icon-btn {
    width: 44px;
    height: 44px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    color: var(--color-heading);
    border: none;
    cursor: pointer;
}

/* === START SCREEN (phones) === */
.chatbot__intro {
    display: none;
}

.chatbot--start .chatbot__intro {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: var(--spacing-4);
    padding: var(--spacing-4) var(--spacing-6);
    background: var(--color-secondary-4);
    color: var(--color-black); /* cream in the dark theme too */
    text-align: center;
}

.chatbot--start .chatbot__header {
    background: var(--color-secondary-4);
    border-bottom: none;
}

.chatbot--start .chatbot__header-owl,
.chatbot--start .chatbot__heading {
    visibility: hidden;
}

.chatbot--start .chatbot__header .chatbot__icon-btn {
    color: var(--color-primary);
}

.chatbot--start .chatbot__messages {
    display: none;
}

.chatbot__intro-bubble {
    margin: 0;
    padding: 16px 24px;
    background: var(--color-white);
    border: 3px solid var(--color-primary);
    border-radius: 73% 27% 62% 38% / 45% 58% 42% 55%;
    transform: rotate(-4deg);
    font-family: 'ComforterBrush', cursive;
    font-size: 32px;
    line-height: 1.1;
}

.chatbot__intro-owl {
    width: 130px;
    height: auto;
}

.chatbot__intro-title {
    margin: 0;
    color: var(--color-primary);
    font-family: var(--font-primary);
    font-size: var(--font-size-2xl);
    font-weight: var(--font-weight-bold);
}

.chatbot__intro-text {
    margin: 0;
    max-width: 300px;
    font-size: var(--font-size-base);
    line-height: 1.5;
}

/* Short phones (iPhone SE, Safari's bars shown): the choices, the input and
   the AI note must stay on screen - the start screen gives way, the bubble first */
@media (max-height: 720px) {
    .chatbot--start .chatbot__intro {
        min-height: 0;
        overflow: hidden;
        gap: var(--spacing-2);
        padding-block: var(--spacing-2);
    }

    .chatbot__intro-bubble {
        display: none;
    }

    .chatbot__intro-owl {
        width: 96px;
    }
}

@media (max-height: 600px) {
    .chatbot__intro-owl {
        width: 64px;
    }

    .chatbot__intro-title {
        font-size: var(--font-size-xl);
    }

    .chatbot__intro-text {
        display: none;
    }
}

.chatbot--start .chatbot__choices,
.chatbot--start .chatbot__form {
    background: var(--color-secondary-4);
}

.chatbot--start .chatbot__choices {
    flex-direction: column;
    padding: 0 var(--spacing-6) var(--spacing-2);
}

.chatbot--start .chatbot__choice.btn {
    width: 100%;
    min-height: 52px;
    justify-content: flex-start;
    font-size: var(--font-size-base);
    text-align: left;
}

.chatbot--start .chatbot__form {
    padding: var(--spacing-3) var(--spacing-6) var(--spacing-6);
    border-top: none;
}

/* === MESSAGES === */
.chatbot__messages {
    flex: 1;
    min-height: 120px;
    overflow-y: auto;
    padding: var(--spacing-4);
    display: flex;
    flex-direction: column;
    gap: var(--spacing-3);
    background: var(--color-surface-warm);
}

.chatbot__message {
    max-width: 85%;
    margin: 0;
    padding: var(--spacing-2) var(--spacing-3);
    font-size: var(--font-size-base);
    line-height: 1.45;
    white-space: pre-line;
}

/* Small owl next to Sovica's messages */
.chatbot__message--bot {
    position: relative;
    align-self: flex-start;
    margin-left: 36px;
    background: var(--color-surface);
    color: var(--color-heading);
}

.chatbot__message--bot::before {
    content: '';
    position: absolute;
    top: 2px;
    left: -36px;
    width: 28px;
    height: 31px;
    background: url('../images/owl-mascot.svg') no-repeat center / contain;
}

.chatbot__message--user {
    align-self: flex-end;
    background: var(--color-primary);
    color: var(--color-white);
}

.chatbot__message--thinking {
    font-style: italic;
    color: var(--color-text-muted);
}

/* Red text alone looked like an ordinary answer on the cream panel -
   the red edge marks it as an error at a glance. */
.chatbot__message--error {
    background: var(--color-error-bg);
    color: var(--color-error-text);
    border-left: 4px solid var(--color-error);
}

/* === THINKING OWL ===
   chatbot.js switches the --move class every 2.4 s, in random order. */
.chatbot__message--thinking {
    display: flex;
    align-items: center;
    gap: var(--spacing-3);
    margin-left: 0;
    background: transparent;
}

.chatbot__message--thinking::before {
    display: none;
}

.chatbot__thinking-owl {
    position: relative;
    flex: none;
    width: 44px;
}

.chatbot-owl {
    display: block;
    width: 100%;
    height: auto;
    overflow: visible;
}

.chatbot-owl__eye-l,
.chatbot-owl__eye-r,
.chatbot-owl__jewel {
    transform-box: fill-box;
    transform-origin: center;
}

.chatbot__thinking-question,
.chatbot__thinking-loupe {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.chatbot__thinking-question {
    top: -14px;
    right: -8px;
    color: var(--color-primary-alt);
    font-family: var(--font-primary);
    font-size: 20px;
    font-weight: var(--font-weight-bold);
    line-height: 1;
}

/* Lens centred on the left eye (32.6 % across, 65 % down the owl) */
.chatbot__thinking-loupe {
    left: calc(32.6% - 11px);
    top: calc(65% - 11px);
    width: 22px;
    height: 22px;
    border: 3px solid var(--color-primary);
    border-radius: 50%;
    background: rgba(102, 216, 221, 0.25);
    box-sizing: border-box;
}

.chatbot__thinking-loupe::after {
    content: '';
    position: absolute;
    right: -7px;
    bottom: -5px;
    width: 9px;
    height: 4px;
    border-radius: 2px;
    background: var(--color-primary);
    transform: rotate(45deg);
}

/* 1 nod */
.chatbot__thinking-owl--nod .chatbot-owl {
    transform-origin: 50% 85%;
    animation: chatbot-nod 2.4s ease-in-out;
}

/* 3 wink */
.chatbot__thinking-owl--wink .chatbot-owl__eye-l {
    animation: chatbot-blink 1.2s 2;
}

.chatbot__thinking-owl--wink .chatbot-owl__eye-r {
    animation: chatbot-wink 1.2s 2;
}

/* 4 look left and right */
.chatbot__thinking-owl--look .chatbot-owl__eye-l,
.chatbot__thinking-owl--look .chatbot-owl__eye-r {
    animation: chatbot-look 2.4s ease-in-out;
}

/* 7 crown jewels hop one after another */
.chatbot__thinking-owl--crown .chatbot-owl__jewel {
    animation: chatbot-jewel 1.2s ease-in-out 2;
}

.chatbot__thinking-owl--crown .chatbot-owl__jewel--c {
    animation-delay: 0.15s;
}

.chatbot__thinking-owl--crown .chatbot-owl__jewel--r {
    animation-delay: 0.3s;
}

/* 10 question mark */
.chatbot__thinking-owl--question .chatbot__thinking-question {
    animation: chatbot-question 2.4s ease-out;
}

/* 9 the loupe comes onto the eye, which grows behind the lens */
.chatbot__thinking-owl--loupe .chatbot__thinking-loupe {
    animation: chatbot-loupe 2.4s ease-in-out;
}

.chatbot__thinking-owl--loupe .chatbot-owl__eye-l {
    animation: chatbot-eye-zoom 2.4s ease-in-out;
}

@keyframes chatbot-nod {
    0%, 100% { transform: rotate(0); }
    25% { transform: rotate(-6deg); }
    50% { transform: rotate(5deg); }
    75% { transform: rotate(-3deg); }
}

@keyframes chatbot-blink {
    0%, 40%, 52%, 100% { transform: scaleY(1); }
    46% { transform: scaleY(0.1); }
}

@keyframes chatbot-wink {
    0%, 65%, 100% { transform: scale(1); }
    80% { transform: scale(1.2); }
}

@keyframes chatbot-look {
    0%, 10%, 100% { transform: translateX(0); }
    25%, 40% { transform: translateX(-15%); }
    60%, 80% { transform: translateX(15%); }
}

@keyframes chatbot-jewel {
    0%, 50%, 100% { transform: translateY(0); }
    25% { transform: translateY(-25%); }
}

@keyframes chatbot-question {
    0% { opacity: 0; transform: translateY(6px) scale(0.4); }
    25% { opacity: 1; transform: translateY(0) scale(1.15); }
    40%, 80% { opacity: 1; transform: scale(1) rotate(10deg); }
    100% { opacity: 0; transform: translateY(-4px); }
}

@keyframes chatbot-loupe {
    0% { opacity: 0; transform: translate(-26px, 14px) rotate(-20deg); }
    25% { opacity: 1; transform: translate(0, 0) rotate(0); }
    75% { opacity: 1; transform: translate(0, 0) rotate(0); }
    100% { opacity: 0; transform: translate(-26px, 14px) rotate(-20deg); }
}

@keyframes chatbot-eye-zoom {
    0%, 22%, 80%, 100% { transform: scale(1); }
    32%, 70% { transform: scale(1.55); }
}

@media (prefers-reduced-motion: reduce) {
    .chatbot__thinking-owl *,
    .chatbot__thinking-owl .chatbot-owl {
        animation: none;
    }
}

/* === GAME ROWS === */
.chatbot__games {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-2);
    margin: 0;
    padding: 0;
    list-style: none;
}

.chatbot__game {
    display: flex;
    align-items: center;
    gap: var(--spacing-3);
    padding: var(--spacing-2);
    background: var(--color-surface);
    border: 1px solid var(--color-border);
}

.chatbot__game-image {
    flex: none;
    width: 72px;
    height: 72px;
    object-fit: contain;
    background: var(--color-white);
}

.chatbot__game-body {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.chatbot__game-title {
    color: var(--color-heading);
    font-family: var(--font-primary);
    font-size: var(--font-size-base);
    font-weight: var(--font-weight-bold);
    line-height: 1.2;
}

.chatbot__game-meta {
    color: var(--color-text-muted);
    font-size: var(--font-size-sm);
}

.chatbot__game-price {
    color: var(--color-heading);
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-bold);
}

/* Orange arrow square, the same panel as .btn--arrow */
.chatbot__game-link {
    flex: none;
    width: 44px;
    height: 44px;
    border-radius: 6px;
    background: var(--color-primary-alt) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='%23fff'%3E%3Cpath d='M13.2 5.3 19.9 12l-6.7 6.7-1.4-1.4 4.3-4.3H4v-2h12.1l-4.3-4.3z'/%3E%3C/svg%3E") no-repeat center / 20px;
}

/* === CHOICES === */
.chatbot__choices {
    display: flex;
    flex-wrap: wrap;
    gap: var(--spacing-2);
    padding: var(--spacing-3) var(--spacing-4) 0;
    background: var(--color-surface);
}

.chatbot__choices:empty {
    display: none;
}

.chatbot__choice.btn {
    width: auto;
    padding: var(--spacing-2) var(--spacing-3);
    font-size: var(--font-size-sm);
    white-space: normal;
}

.chatbot__choice.btn.btn--arrow {
    padding-right: calc(var(--btn-icon-panel-width) + var(--spacing-4));
}

/* Quick replies under games: one scrolling row */
.chatbot__choices:has(.chatbot__choice--quick) {
    flex-wrap: nowrap;
    overflow-x: auto;
    scrollbar-width: none;
}

.chatbot__choice--quick.btn {
    flex: none;
    white-space: nowrap;
}

.chatbot__choice--secondary {
    padding: var(--spacing-2) var(--spacing-3);
    background: transparent;
    color: var(--color-text-muted);
    border: none;
    font-family: inherit;
    font-size: var(--font-size-sm);
    text-decoration: underline;
    cursor: pointer;
}

/* === INPUT === */
.chatbot__form {
    display: flex;
    gap: var(--spacing-2);
    padding: var(--spacing-3) var(--spacing-4) var(--spacing-5);
    background: var(--color-surface);
}

.chatbot__input {
    flex: 1;
    min-width: 0;
    height: 48px;
    border-radius: 0;
    border: 1px solid var(--color-border);
    padding: 0 var(--spacing-3);
    background: var(--color-surface);
    color: var(--color-text);
    font-family: inherit;
    /* 16px keeps iOS Safari from zooming in on focus */
    font-size: var(--font-size-base);
}

.chatbot__input:focus {
    outline: 2px solid var(--color-secondary-1);
    outline-offset: -1px;
}

.chatbot__send.btn {
    width: auto;
}

.chatbot__send:disabled,
.chatbot__input:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* "Sovica je umetna inteligenca …" under the input (or the choices while she rests) */
.chatbot__note {
    margin: 0;
    padding: var(--spacing-2) var(--spacing-4) var(--spacing-3);
    background: var(--color-surface);
    color: var(--color-text-muted);
    font-size: var(--font-size-xs);
    line-height: 1.4;
    text-align: center;
}

.chatbot__note a {
    color: inherit;
    text-decoration: underline;
}

.chatbot__form:not([hidden]) + .chatbot__note {
    margin-top: calc(-1 * var(--spacing-3));
}

.chatbot--start .chatbot__note {
    background: var(--color-secondary-4);
}

/* === TABLET AND UP === */
@media (min-width: 768px) {
    .chatbot {
        right: var(--spacing-6);
        bottom: var(--spacing-6);
    }

    /* A window above the owl, no start screen */
    .chatbot__panel {
        position: static;
        width: 380px;
        height: min(600px, calc(100vh - 140px));
        border: 2px solid var(--color-primary);
        box-shadow: var(--shadow-lg);
    }

    .chatbot--open {
        z-index: 9997;
    }

    html.chatbot-open {
        overflow: visible;
    }

    .chatbot--open .chatbot__owl {
        display: block;
    }

    .chatbot--start .chatbot__intro {
        display: none;
    }

    .chatbot--start .chatbot__messages {
        display: flex;
    }

    .chatbot--start .chatbot__header {
        background: var(--color-surface);
        border-bottom: 3px solid var(--color-primary-alt);
    }

    .chatbot--start .chatbot__header-owl,
    .chatbot--start .chatbot__heading {
        visibility: visible;
    }

    .chatbot--start .chatbot__header .chatbot__icon-btn {
        color: var(--color-heading);
    }

    .chatbot--start .chatbot__choices,
    .chatbot--start .chatbot__form {
        background: var(--color-surface);
    }

    .chatbot--start .chatbot__choices {
        padding: var(--spacing-3) var(--spacing-4) 0;
    }

    .chatbot--start .chatbot__form {
        padding: var(--spacing-3) var(--spacing-4) var(--spacing-5);
    }

    .chatbot--start .chatbot__note {
        background: var(--color-surface);
    }

    .chatbot__owl {
        width: 80px;
    }

    .chatbot--teaser .chatbot__owl {
        width: 120px;
    }

    .chatbot--minimized .chatbot__owl {
        width: 30px;
    }

    .chatbot--teaser {
        gap: var(--spacing-4);
    }

    .chatbot__bubble {
        padding: 20px 25px;
        font-size: 32px;
    }

    .chatbot__bubble::before {
        right: -15px;
        border-left-width: 20px;
        border-top-width: 15px;
        border-bottom-width: 15px;
    }

    .chatbot__bubble::after {
        right: -9px;
        border-left-width: 15px;
        border-top-width: 11px;
        border-bottom-width: 11px;
    }
}

/* Hover only with a real mouse/trackpad (CLAUDE.md). .btn has its own. */
@media (hover: hover) and (pointer: fine) {
    .chatbot__bubble:hover,
    .chatbot__teaser-close:hover,
    .chatbot__choice--secondary:hover,
    .chatbot__icon-btn:hover,
    .chatbot__game-link:hover {
        filter: brightness(0.92);
    }
}
