/*
 * ix-chat.css — the consumer's half of the driver seam.
 *
 * `italix/chat` emits class names and no styling, on purpose: a library that
 * shipped a stylesheet would fight every consumer's design system. This is the
 * stylesheet for this consumer, and it is the whole of it.
 *
 * Two constraints it is written under, both of which come from where the widget
 * ends up rather than from taste:
 *
 * 1. **Nothing here may leak.** Every selector is under `.ix-chat-launcher`,
 *    and no element selectors are used, because this file is eventually going
 *    to load on somebody else's WordPress page. (The embed script will put the
 *    whole thing in a shadow root, which makes this belt as well as braces —
 *    but the braces are what work today, on the demo page.)
 * 2. **The host page's fonts and colours are not assumed.** Sizes are in rem
 *    against an explicit base, colours are declared here, and the dark variant
 *    is by `prefers-color-scheme` rather than by a class the host would have to
 *    set.
 */

.ix-chat-launcher {
    --ix-chat-bg: #ffffff;
    --ix-chat-fg: #1a1d21;
    --ix-chat-muted: #6b7280;
    --ix-chat-line: #e5e7eb;
    --ix-chat-accent: #2563eb;
    --ix-chat-accent-fg: #ffffff;
    --ix-chat-visitor-bg: #eef2ff;
    --ix-chat-radius: 0.75rem;
    --ix-chat-shadow: 0 10px 40px rgba(0, 0, 0, 0.18);

    position: fixed;
    right: 1.25rem;
    bottom: 1.25rem;
    z-index: 2147483000;
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    font-size: 15px;
    line-height: 1.5;
    color: var(--ix-chat-fg);
}

@media (prefers-color-scheme: dark) {
    .ix-chat-launcher {
        --ix-chat-bg: #16181d;
        --ix-chat-fg: #e8eaed;
        --ix-chat-muted: #9aa0a6;
        --ix-chat-line: #2b2f36;
        --ix-chat-visitor-bg: #1e2534;
        --ix-chat-shadow: 0 10px 40px rgba(0, 0, 0, 0.55);
    }
}

/* x-cloak: the panel is `x-show`n, and until Alpine boots that attribute does
   nothing. Without this rule the panel flashes open on every page load. */
.ix-chat-launcher [x-cloak] { display: none !important; }

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

.ix-chat-fab {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.7rem 1.15rem;
    border: 0;
    border-radius: 999px;
    background: var(--ix-chat-accent);
    color: var(--ix-chat-accent-fg);
    font: inherit;
    font-weight: 600;
    cursor: pointer;
    box-shadow: var(--ix-chat-shadow);
}

.ix-chat-fab:hover  { filter: brightness(1.07); }
.ix-chat-fab:focus-visible { outline: 2px solid var(--ix-chat-fg); outline-offset: 2px; }

.ix-chat-badge {
    min-width: 1.25rem;
    padding: 0 0.35rem;
    border-radius: 999px;
    background: var(--ix-chat-accent-fg);
    color: var(--ix-chat-accent);
    font-size: 0.75rem;
    font-weight: 700;
    text-align: center;
}

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

.ix-chat-panel {
    position: absolute;
    right: 0;
    bottom: 3.6rem;
    display: flex;
    flex-direction: column;
    width: min(23rem, calc(100vw - 2.5rem));
    height: min(32rem, calc(100vh - 6rem));
    background: var(--ix-chat-bg);
    border: 1px solid var(--ix-chat-line);
    border-radius: var(--ix-chat-radius);
    box-shadow: var(--ix-chat-shadow);
    overflow: hidden;
}

.ix-chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    padding: 0.75rem 0.5rem 0.75rem 1rem;
    border-bottom: 1px solid var(--ix-chat-line);
}

.ix-chat-title { margin: 0; font-size: 0.95rem; font-weight: 600; }

.ix-chat-close {
    border: 0;
    background: transparent;
    color: var(--ix-chat-muted);
    font-size: 1.5rem;
    line-height: 1;
    padding: 0 0.5rem;
    cursor: pointer;
}

.ix-chat-close:hover { color: var(--ix-chat-fg); }

/* --------------------------------------------------------------- messages */

.ix-chat-log {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.85rem;
}

.ix-chat-message { max-width: 88%; }

.ix-chat-visitor {
    align-self: flex-end;
    background: var(--ix-chat-visitor-bg);
    border-radius: var(--ix-chat-radius);
    padding: 0.5rem 0.75rem;
}

.ix-chat-author {
    display: block;
    font-size: 0.7rem;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    color: var(--ix-chat-muted);
}

/* pre-wrap, not a markdown renderer: the body is text somebody typed, and
   turning it into markup is how a chat widget becomes a cross-site scripting
   hole. The driver binds it with x-text for the same reason. */
.ix-chat-body { margin: 0.15rem 0 0; white-space: pre-wrap; overflow-wrap: anywhere; }

.ix-chat-choices { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-top: 0.6rem; }

.ix-chat-choice {
    padding: 0.3rem 0.8rem;
    border: 1px solid var(--ix-chat-accent);
    border-radius: 999px;
    background: transparent;
    color: var(--ix-chat-accent);
    font: inherit;
    font-size: 0.85rem;
    cursor: pointer;
}

.ix-chat-choice:hover:not(:disabled) { background: var(--ix-chat-accent); color: var(--ix-chat-accent-fg); }
.ix-chat-choice:disabled { opacity: 0.5; cursor: default; }

.ix-chat-sources { margin: 0.5rem 0 0; padding-left: 1.1rem; font-size: 0.85rem; }
.ix-chat-sources a { color: var(--ix-chat-accent); }

.ix-chat-pending { margin: 0; color: var(--ix-chat-muted); font-style: italic; }

.ix-chat-refusal {
    margin: 0;
    padding: 0.6rem 1rem;
    border-top: 1px solid var(--ix-chat-line);
    color: #b00020;
    font-size: 0.875rem;
}

@media (prefers-color-scheme: dark) {
    .ix-chat-refusal { color: #ff8a80; }
}

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

.ix-chat-composer {
    display: flex;
    gap: 0.5rem;
    padding: 0.75rem;
    border-top: 1px solid var(--ix-chat-line);
}

.ix-chat-input {
    flex: 1;
    min-width: 0;
    padding: 0.5rem 0.7rem;
    border: 1px solid var(--ix-chat-line);
    border-radius: 0.4rem;
    background: transparent;
    color: inherit;
    font: inherit;
}

.ix-chat-input:focus-visible { outline: 2px solid var(--ix-chat-accent); outline-offset: -1px; }

.ix-chat-send {
    padding: 0.5rem 1rem;
    border: 0;
    border-radius: 0.4rem;
    background: var(--ix-chat-accent);
    color: var(--ix-chat-accent-fg);
    font: inherit;
    font-weight: 600;
    cursor: pointer;
}

.ix-chat-send:disabled { opacity: 0.45; cursor: default; }

/* A phone: the panel takes the screen rather than floating in a corner of it. */
@media (max-width: 30rem) {
    .ix-chat-launcher { right: 0.75rem; bottom: 0.75rem; }

    .ix-chat-panel {
        width: calc(100vw - 1.5rem);
        height: min(70vh, calc(100vh - 5rem));
    }
}

/* ------------------------------------------------------------------ inline
 *
 * `data-mount="#selector"` on the embed script puts the widget inside an
 * element instead of floating over the page. Same markup, same stylesheet: the
 * only difference is that nothing is fixed to the viewport. The panel being
 * always open is the script's decision, not a `!important` here — the state it
 * reasons about and the state on screen have to agree.
 */

.ix-chat-launcher.ix-chat-inline {
    position: static;
    display: block;
    width: 100%;
}

.ix-chat-inline .ix-chat-fab { display: none; }

.ix-chat-inline .ix-chat-panel {
    position: static;
    width: 100%;
    height: 30rem;
    box-shadow: none;
}
