/* ==========================================================================
   Advance Care Assistant
   Brand: berry + navy (taken from the Advance Care logo)
   Type:  Lexend (designed for easy reading, a good fit for a patient-facing tool)
   ========================================================================== */

   :root {
    /* Brand */
    --ac-berry: #971D51;
    --ac-berry-deep: #7B1542;
    --ac-navy: #253156;
    --ac-navy-deep: #1A2342;

    /* Surfaces */
    --ac-white: #ffffff;
    --ac-canvas: #FCFAFB;
    --ac-blush: #F8EEF2;
    --ac-blush-line: #EDD9E2;
    --ac-line: #E8E2E6;

    /* Text */
    --ac-text: #2A3354;
    --ac-muted: #656C88;

    /* Type */
    --ac-font: "Lexend", "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;

    /* Layout */
    --ac-width: 400px;
    --ac-width-expanded: 540px;
    --ac-radius: 18px;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: var(--ac-font);
}

button,
input,
textarea,
select {
    font-family: var(--ac-font);
}

/* Visible keyboard focus everywhere */
#chat-toggle:focus-visible,
.chat-action:focus-visible,
#chat-send:focus-visible,
.faq-question:focus-visible,
.message-cta:focus-visible,
.chat-disclaimer a:focus-visible {
    outline: 3px solid rgba(151, 29, 81, .4);
    outline-offset: 2px;
}

/* ==========================================================================
   Launcher: text only
   ========================================================================== */

#chat-toggle {
    position: fixed;
    right: 24px;
    bottom: 24px;
    height: 48px;
    padding: 0 22px;
    border: 0;
    border-radius: 14px;
    background: var(--ac-berry);
    color: var(--ac-white);
    font-size: 15px;
    font-weight: 500;
    line-height: 1;
    letter-spacing: .01em;
    white-space: nowrap;
    cursor: pointer;
    box-shadow: 0 8px 24px rgba(151, 29, 81, .28);
    z-index: 99999;
    transition: background-color .2s ease, transform .2s ease, box-shadow .2s ease;
}

#chat-toggle:hover {
    background: var(--ac-berry-deep);
    transform: translateY(-1px);
    box-shadow: 0 12px 28px rgba(151, 29, 81, .34);
}

#chat-toggle .label-close { display: none; }

#chat-toggle.is-open {
    background: var(--ac-navy);
    box-shadow: 0 8px 24px rgba(37, 49, 86, .26);
}

#chat-toggle.is-open:hover { background: var(--ac-navy-deep); }
#chat-toggle.is-open .label-open { display: none; }
#chat-toggle.is-open .label-close { display: inline; }

/* ==========================================================================
   Widget shell
   ========================================================================== */

.chat-widget {
    position: fixed;
    right: 24px;
    bottom: 84px;
    width: var(--ac-width);
    max-width: calc(100vw - 32px);
    height: 680px;
    max-height: calc(100vh - 108px);
    max-height: calc(100dvh - 108px);
    background: var(--ac-white);
    border: 1px solid var(--ac-line);
    border-radius: var(--ac-radius);
    box-shadow: 0 24px 64px rgba(37, 49, 86, .22);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    z-index: 99998;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transform: translateY(14px) scale(.98);
    transform-origin: bottom right;
    transition: opacity .25s ease, transform .25s ease, visibility .25s ease, width .3s ease, height .3s ease;
}

.chat-widget.open {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    transform: translateY(0) scale(1);
}

.chat-widget.is-expanded {
    width: var(--ac-width-expanded);
    height: calc(100vh - 108px);
    height: calc(100dvh - 108px);
}

/* ==========================================================================
   Header: logo on white, two-tone bar echoing the logo's berry and navy
   ========================================================================== */

.chat-header {
    position: relative;
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 18px 12px 14px 20px;
    background: var(--ac-white);
    border-bottom: 1px solid var(--ac-line);
}

.chat-header::before {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 4px;
    background: linear-gradient(90deg, var(--ac-berry) 0 72%, var(--ac-navy) 72% 100%);
}

.chat-logo {
    display: block;
    height: 38px;
    width: auto;
    max-width: 62%;
}

.chat-actions {
    display: flex;
    align-items: center;
    gap: 2px;
}

.chat-action {
    width: 36px;
    height: 36px;
    padding: 0;
    border: 0;
    border-radius: 10px;
    background: transparent;
    color: var(--ac-navy);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background-color .2s ease, color .2s ease;
}

.chat-action svg { width: 16px; height: 16px; }

.chat-action:hover {
    background: var(--ac-blush);
    color: var(--ac-berry);
}

#chat-expand .ico-collapse { display: none; }
.chat-widget.is-expanded #chat-expand .ico-expand { display: none; }
.chat-widget.is-expanded #chat-expand .ico-collapse { display: block; }

/* ==========================================================================
   Body
   ========================================================================== */

.chat-body {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    background: var(--ac-canvas);
}

.chat-messages {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 24px 20px 12px;
    scroll-behavior: smooth;
    overscroll-behavior: contain;
}

.chat-messages::-webkit-scrollbar { width: 6px; }
.chat-messages::-webkit-scrollbar-thumb { background: rgba(37, 49, 86, .16); border-radius: 6px; }

/* ==========================================================================
   Intro
   ========================================================================== */

.chat-intro { padding-bottom: 8px; }

.intro-title {
    margin: 0 0 10px;
    font-size: 26px;
    font-weight: 500;
    line-height: 1.2;
    letter-spacing: -.015em;
    color: var(--ac-navy);
}

.intro-text {
    margin: 0;
    max-width: 34ch;
    font-size: 14px;
    font-weight: 300;
    line-height: 1.6;
    color: var(--ac-muted);
}

.faq-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-top: 22px;
}

.faq-question {
    display: flex;
    align-items: flex-start;
    min-height: 68px;
    padding: 12px 14px;
    border: 1px solid var(--ac-blush-line);
    border-radius: 14px;
    background: var(--ac-blush);
    color: var(--ac-navy);
    font-size: 13.5px;
    font-weight: 400;
    line-height: 1.4;
    text-align: left;
    cursor: pointer;
    transition: background-color .2s ease, color .2s ease, border-color .2s ease;
}

.faq-question:hover,
.faq-question:active {
    background: var(--ac-navy);
    border-color: var(--ac-navy);
    color: var(--ac-white);
}

/* ==========================================================================
   Conversation
   ========================================================================== */

.message {
    display: flex;
    flex-direction: column;
    margin-top: 14px;
    animation: messageIn .22s ease both;
}

.message.bot  { align-items: flex-start; }
.message.user { align-items: flex-end; }

.message-text {
    font-size: 14.5px;
    font-weight: 400;
    line-height: 1.55;
    overflow-wrap: anywhere;
    white-space: pre-line;
}

/* User: berry, square corner bottom-right */
.message.user .message-text {
    max-width: 84%;
    padding: 11px 15px;
    border-radius: 16px 16px 4px 16px;
    background: var(--ac-berry);
    color: var(--ac-white);
}

/* Assistant: blush bubble, square corner bottom-left */
.bot-bubble {
    max-width: 94%;
    padding: 12px 15px;
    background: var(--ac-blush);
    border-radius: 16px 16px 16px 4px;
    color: var(--ac-text);
}

/* Links sit in divided rows inside the bubble */
.message-ctas {
    display: flex;
    flex-direction: column;
    margin-top: 10px;
    border-top: 1px solid var(--ac-blush-line);
}

.message-cta {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 11px 2px;
    border-bottom: 1px solid var(--ac-blush-line);
    color: var(--ac-berry);
    font-size: 13.5px;
    font-weight: 500;
    line-height: 1.3;
    text-decoration: none;
    transition: color .2s ease;
}

.message-cta:last-child { border-bottom: 0; padding-bottom: 2px; }

.message-cta svg {
    flex: 0 0 auto;
    width: 12px;
    height: 12px;
    transition: transform .2s ease;
}

.message-cta:hover { color: var(--ac-navy); }
.message-cta:hover svg { transform: translate(2px, -2px); }

/* Typing indicator */
.typing .bot-bubble { padding: 15px 16px; }

.thinking-dots { display: flex; gap: 5px; }

.thinking-dots span {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--ac-berry);
    animation: thinking 1.1s infinite ease-in-out;
}

.thinking-dots span:nth-child(2) { animation-delay: .15s; }
.thinking-dots span:nth-child(3) { animation-delay: .3s; }

/* ==========================================================================
   Input + footer
   ========================================================================== */

.chat-footer {
    flex: 0 0 auto;
    padding: 12px 16px 14px;
    background: var(--ac-white);
    border-top: 1px solid var(--ac-line);
}

.chat-input-area {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 6px 6px 6px 14px;
    background: var(--ac-white);
    border: 1.5px solid var(--ac-line);
    border-radius: 14px;
    transition: border-color .2s ease, box-shadow .2s ease;
}

.chat-input-area:focus-within {
    border-color: var(--ac-berry);
    box-shadow: 0 0 0 3px rgba(151, 29, 81, .12);
}

#chat-input {
    flex: 1;
    min-width: 0;
    height: 24px;
    max-height: 96px;
    margin: 7px 0;
    padding: 0;
    resize: none;
    border: 0;
    outline: none;
    background: transparent;
    color: var(--ac-text);
    font-size: 14px;
    line-height: 24px;
}

#chat-input::placeholder { color: #8A90A8; }

#chat-send {
    flex: 0 0 38px;
    width: 38px;
    height: 38px;
    padding: 0;
    border: 0;
    border-radius: 11px;
    background: var(--ac-berry);
    color: var(--ac-white);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background-color .2s ease, opacity .2s ease;
}

#chat-send svg { width: 18px; height: 18px; }

#chat-send:hover:not(:disabled) { background: var(--ac-berry-deep); }
#chat-send:disabled { opacity: .5; cursor: not-allowed; }

.chat-disclaimer {
    margin: 10px 2px 0;
    color: var(--ac-muted);
    font-size: 11px;
    font-weight: 300;
    line-height: 1.5;
}

.chat-disclaimer a {
    color: var(--ac-berry);
    font-weight: 400;
}

/* ==========================================================================
   Motion
   ========================================================================== */

@keyframes messageIn {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: translateY(0); }
}

@keyframes thinking {
    0%, 60%, 100% { opacity: .3; transform: translateY(0); }
    30%           { opacity: 1;  transform: translateY(-3px); }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation: none !important;
        transition: none !important;
        scroll-behavior: auto !important;
    }
}

/* ==========================================================================
   Mobile: bottom sheet
   ========================================================================== */

@media (max-width: 600px) {
    #chat-toggle { right: 16px; bottom: 16px; }
    body.chat-is-open #chat-toggle { opacity: 0; pointer-events: none; }

    .chat-widget,
    .chat-widget.is-expanded {
        top: 12px;
        right: 0;
        bottom: 0;
        left: 0;
        width: auto;
        max-width: none;
        height: auto;
        max-height: none;
        border-radius: var(--ac-radius) var(--ac-radius) 0 0;
        border-bottom: 0;
    }

    #chat-expand { display: none; }

    .chat-header { padding-left: 16px; }
    .chat-messages { padding: 20px 16px 8px; }
    .chat-footer { padding: 12px 16px calc(14px + env(safe-area-inset-bottom, 0px)); }
    .intro-title { font-size: 24px; }
    #chat-input { font-size: 16px; }   /* prevents iOS zoom on focus */
}

/* Very small screens: single column tiles */
@media (max-width: 340px) {
    .faq-grid { grid-template-columns: 1fr; }
}