/* ---------------------------------------------------------------------------
   Customer-service chat.

   Its own file rather than an addition to site.css: the widget rides over every
   page and owns a fixed corner of the viewport, so keeping it separable is what
   makes it removable. It borrows the public palette's custom properties and
   defines none of its own colours.

   Stacking: above the header (1000/1100) so the panel is not cut off at the top
   on a phone, and below the mobile navigation drawer (1200) so opening the menu
   covers the chat rather than fighting it.
   --------------------------------------------------------------------------- */

.chat {
    position: fixed;
    right: calc(28px + env(safe-area-inset-right, 0px));

    /* v3 sets the button 76px up from 601px wide, so the footer's legal row, which now runs
       to the bottom of the page, stays clear of it; phones keep it in the corner.

       The closed button is the disc with the credit chip under it; open, it is the 56px
       close disc alone. They share a centre, so clicking one does not make it jump: the
       open state rises by the chip and gap below the disc, less half the difference in
       disc size — --chat-lift. */
    --chat-anchor: 76px;
    --chat-lift: 25px;      /* 22px of chip and gap, plus half of 62 - 56 */

    bottom: calc(var(--chat-anchor) + env(safe-area-inset-bottom, 0px));

    z-index: 1150;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 12px;
    font-family: var(--font-body);
    transition: bottom 0.25s ease;
}

.chat--open {
    bottom: calc(var(--chat-anchor) + var(--chat-lift) + env(safe-area-inset-bottom, 0px));
}

/* --- launcher ----------------------------------------------------------- */

/* v3's AI Assistant button (genero-v4.css .ai-fab): a column of the disc and the credit
   chip, drifting gently. The drift pauses under the pointer and on keyboard focus, so the
   target holds still for anyone aiming at it. */
.chat__launcher {
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    margin: 0;
    padding: 0;
    border: 0;
    background: none;
    font: inherit;
    cursor: pointer;
    transition: scale 0.3s var(--ease);
    animation: chat-float 6s ease-in-out infinite;
}

.chat__launcher:hover,
.chat__launcher:focus-visible { animation-play-state: paused; scale: 1.05; }

.chat__launcher:active { scale: 0.96; }

/* The disc carries the only shadow. White, because the Genero mark is teal and gold. */
.chat__seal {
    flex: none;
    display: grid;
    place-items: center;
    width: 62px;
    height: 62px;
    border-radius: 50%;
    background: #fff;
    color: #fff;
    overflow: hidden;
    box-shadow: 0 14px 34px rgba(11, 76, 95, 0.28), 0 2px 8px rgba(11, 76, 95, 0.16);
    transition: box-shadow 0.3s var(--ease), background 0.2s ease, width 0.2s ease, height 0.2s ease;
}

.chat__launcher:hover .chat__seal,
.chat__launcher:focus-visible .chat__seal {
    box-shadow: 0 18px 44px rgba(11, 76, 95, 0.34), 0 3px 10px rgba(11, 76, 95, 0.18);
}

/* The whole mark inside the circle, never cropped. */
.chat__seal img {
    display: block;
    width: 70%;
    height: 70%;
    object-fit: contain;
}

/* A small white chip, so the credit reads over the hero photograph, the white sections and
   the navy footer alike. */
.chat__credit {
    display: block;
    white-space: nowrap;
    color: var(--grey);
    font-size: 0.5rem;
    font-weight: 600;
    letter-spacing: 0.03em;
    line-height: 1;
    padding: 4px 9px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.94);
    box-shadow: 0 3px 10px rgba(11, 76, 95, 0.16);
}

@keyframes chat-float {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-7px); }
}

.chat__launcher:focus-visible { outline: none; }

.chat__launcher:focus-visible .chat__seal {
    outline: 3px solid var(--yellow);
    outline-offset: 3px;
}

/* Open, it is a close button rather than a mark: smaller, teal, still, and out of the way
   of the conversation it sits under. */
.chat--open .chat__launcher { animation: none; }

.chat--open .chat__seal {
    width: 56px;
    height: 56px;
    background: var(--teal);
}

/* Only while it is the close button. A white disc darkening to teal on hover would be the
   mark changing colour under the pointer. */
.chat--open .chat__launcher:hover .chat__seal { background: var(--teal-deep); }

.chat__launcher-icon { font-size: 1.15rem; line-height: 1; }

/* --- panel -------------------------------------------------------------- */

.chat__panel {
    display: flex;
    flex-direction: column;
    width: min(380px, calc(100vw - 32px));
    /* Room above the close button, which now sits 76px up rather than in the corner. */
    height: min(560px, calc(100vh - 230px));
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: 18px;
    background: #fff;
    box-shadow: var(--shadow);

    /* The launcher comes first in the source, so tabbing reaches it before the
       conversation it opens. Visually the panel belongs above it. */
    order: -1;
}

.chat__header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    padding: 16px 18px;
    background: linear-gradient(135deg, var(--teal) 0%, var(--teal-deep) 100%);
    color: #fff;
}

.chat__title {
    margin: 0;
    font-family: var(--font-display);
    font-size: 1.05rem;
    font-weight: 700;
}

.chat__subtitle {
    margin: 2px 0 0;
    font-size: 0.75rem;
    opacity: 0.85;
}

.chat__close {
    flex: none;
    width: 32px;
    height: 32px;
    border: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.16);
    color: #fff;
    font-size: 0.9rem;
    line-height: 1;
    cursor: pointer;
}

.chat__close:hover { background: rgba(255, 255, 255, 0.28); }

.chat__close:focus-visible {
    outline: 2px solid var(--yellow);
    outline-offset: 2px;
}

/* --- transcript --------------------------------------------------------- */

.chat__log {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 18px;
    background: var(--ice);
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.chat__line { display: flex; }

.chat__line--bot { justify-content: flex-start; }

.chat__line--me { justify-content: flex-end; }

.chat__bubble {
    max-width: 85%;
    padding: 10px 14px;
    border-radius: 16px;
    font-size: 0.875rem;
    line-height: 1.55;

    /* An assistant can answer with a long unbroken string — a URL or a product
       code — and without this it widens the bubble past the panel. */
    overflow-wrap: anywhere;
}

.chat__bubble p { margin: 0; }

.chat__bubble p + p { margin-top: 0.6em; }

/* Added by Taufik Thareq on 20261128 — Outside TSD next to TSD-17: an answer the API cleaned to ul, ol, li,
   b, i and br. Lists indented inside the bubble, with a little room above and below. */
.chat__rich ul,
.chat__rich ol { margin: 0.4em 0; padding-left: 1.25em; }
.chat__rich li + li { margin-top: 0.2em; }
.chat__rich > :first-child { margin-top: 0; }
.chat__rich > :last-child { margin-bottom: 0; }

.chat__line--bot .chat__bubble {
    background: #fff;
    color: var(--ink);
    border: 1px solid var(--line);
    border-bottom-left-radius: 4px;
}

.chat__line--me .chat__bubble {
    background: var(--teal);
    color: #fff;
    border-bottom-right-radius: 4px;
}

.chat__bubble--error {
    background: #FFF4F4;
    border-color: #F3C9C9;
    color: #8C2B2B;
}

/* --- typing indicator --------------------------------------------------- */

.chat__bubble--typing {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 14px;
}

.chat__bubble--typing span {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--grey);
    animation: chat-dot 1.2s infinite ease-in-out;
}

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

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

@keyframes chat-dot {
    0%, 60%, 100% { opacity: 0.3; transform: translateY(0); }
    30% { opacity: 1; transform: translateY(-3px); }
}

/* An answer can take the better part of a minute, so the indicator is the only
   sign anything is happening — it stays, but it stops moving. */
@media (prefers-reduced-motion: reduce) {
    /* The seal drifts on a loop; someone who asked for less motion did not ask
       for a logo that never stops bobbing. */
    .chat__launcher { animation: none; }

    .chat__bubble--typing span { animation: none; opacity: 0.6; }

    .chat__launcher { transition: none; }
}

/* --- composer ----------------------------------------------------------- */

.chat__composer {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px;
    border-top: 1px solid var(--line);
    background: #fff;
}

/* The visible placeholder is the label for a sighted visitor; this is the same
   text for a screen reader, which does not treat a placeholder as a name. */
.chat__label {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.chat__input {
    flex: 1;
    min-width: 0;
    min-height: 44px;
    padding: 10px 14px;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: #fff;
    color: var(--ink);
    font: inherit;

    /* Anything under 16px makes iOS Safari zoom the page when the field takes
       focus, and it never zooms back out. */
    font-size: 16px;
}

.chat__input:focus-visible {
    outline: 2px solid var(--teal);
    outline-offset: 1px;
}

.chat__input:disabled { background: var(--ice); }

.chat__send {
    flex: none;
    width: 44px;
    height: 44px;
    border: 0;
    border-radius: 50%;
    background: var(--teal);
    color: #fff;
    font-size: 1rem;
    cursor: pointer;
    transition: background 0.2s ease;
}

.chat__send:hover:not(:disabled) { background: var(--teal-deep); }

.chat__send:disabled { background: var(--grey); cursor: default; }

/* The empty-box appearance, without actually disabling the button: a disabled
   default button stops Enter from submitting the form at all. */
.chat__input:placeholder-shown ~ .chat__send:not(:disabled) {
    background: var(--grey);
}

.chat__send:focus-visible {
    outline: 3px solid var(--yellow);
    outline-offset: 2px;
}

/* --- tablet ------------------------------------------------------------- */

/* The hero hides its scroll cue below 720px, so the seal takes the corner back —
   the same handover the design makes, at the same width. */
/* Stepped down as the design steps its button down. At 56px the launcher and the
   close button are the same size, so there is nothing left to lift. */
@media (max-width: 900px) {
    .chat {
        right: calc(22px + env(safe-area-inset-right, 0px));
        --chat-lift: 22px;  /* the disc is already 56px, so only the chip and gap remain */
    }

    .chat__launcher { gap: 5px; }
    .chat__seal { width: 56px; height: 56px; }
    .chat__credit { font-size: 0.48rem; padding: 4px 8px; }
}

/* Phones keep it in the corner; the footer gives its legal row room above it instead. */
@media (max-width: 600px) {
    .chat {
        right: calc(16px + env(safe-area-inset-right, 0px));
        --chat-anchor: 16px;
    }

    .chat__seal { width: 52px; height: 52px; }
    .chat__credit { font-size: 0.46rem; padding: 3px 7px; letter-spacing: 0.02em; }
}

@media (max-width: 360px) {
    .chat__seal { width: 48px; height: 48px; }
}

/* --- phone -------------------------------------------------------------- */

@media (max-width: 600px) {
    .chat--open {
        inset: 0;
        right: 0;
        bottom: 0;
        padding: 0;
        gap: 0;
    }

    .chat--open .chat__panel {
        width: 100%;
        height: 100%;
        border: 0;
        border-radius: 0;
    }

    /* Closing is the header's ✕ once the sheet fills the screen; a second
       floating button over the conversation would only be in the way. */
    .chat--open .chat__launcher { display: none; }

    /* With the launcher gone this is the only way out of the sheet, so it has to be
       a full touch target rather than the 32px that reads fine under a mouse. */
    .chat__close {
        width: 44px;
        height: 44px;
        font-size: 1.05rem;
    }

    .chat__log { padding-bottom: calc(18px + env(safe-area-inset-bottom, 0)); }

    .chat__composer { padding-bottom: calc(12px + env(safe-area-inset-bottom, 0)); }
}

/* Printing a floating chat button onto a page of content helps nobody. */
@media print {
    .chat { display: none; }
}

/* --- when a line was said ------------------------------------------------ */

/* The bubble and its time stack, and the pair aligns to the speaker's side —
   .chat__line is a flex row that pushes the group left or right, and without a
   group between them the time would sit beside the bubble rather than under it. */
.chat__group {
    display: flex;
    flex-direction: column;
    max-width: 82%;
}

.chat__line--me .chat__group { align-items: flex-end; }

.chat__group .chat__bubble { max-width: 100%; }

.chat__time {
    margin-top: 4px;
    padding: 0 4px;
    font-size: 0.66rem;
    line-height: 1;
    color: var(--ink-soft);
    opacity: 0.72;
}

/* Added by Taufik Thareq on 20261127 — Q261100000041, TSD-17: the pages an answer came from,
   one small link per line under the bubble. */
.chat__sources {
    list-style: none;
    margin: 6px 0 0;
    padding: 0 4px;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.chat__source {
    font-size: 0.74rem;
    line-height: 1.35;
    color: var(--ink-soft);
    text-decoration: underline;
    text-underline-offset: 2px;
}

.chat__source:hover,
.chat__source:focus-visible { color: inherit; }

/* Added by Taufik Thareq on 20261127 — Q261100000041, TSD-19: the AI notice and the privacy notice
   above the question box. Nothing takes space while neither has text. */
.chat__notices {
    padding: 8px 12px 0;
    border-top: 1px solid var(--line);
    background: #fff;
}

.chat__notices:not(:has(.site-notice)) { display: none; }

.chat__notices + .chat__composer { border-top: 0; }

.chat__notices .site-notice {
    margin: 0 0 4px;
    font-size: 0.66rem;
    line-height: 1.45;
    color: var(--ink-soft);
}

.chat__notices .site-notice a { color: inherit; text-decoration: underline; text-underline-offset: 2px; }
