:root {
    color-scheme: light;
    --primary: #3f6fc4;
    --secondary: #f3c98b;
    --background: #eef4f4;
    --surface: #ffffff;
    --text: #172033;
    --on-primary: #ffffff;
    --on-secondary: #172033;
    --muted: #687386;
    --border: #d9e3e7;
    --danger: #b42318;
    --primary-soft: color-mix(in srgb, var(--primary) 12%, white);
    --secondary-soft: color-mix(in srgb, var(--secondary) 30%, white);
    --shadow: 0 28px 90px rgba(49, 74, 98, .17);
}

* { box-sizing: border-box; }

html { min-height: 100%; }

body {
    position: relative;
    overflow-x: hidden;
    min-height: 100vh;
    margin: 0;
    font-family: Inter, Montserrat, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    color: var(--text);
    background: var(--background);
    overflow: hidden;
}

body::before,
body::after {
    position: fixed;
    z-index: -1;
    border-radius: 50%;
    content: "";
    pointer-events: none;
}

body::before {
    top: -20rem;
    left: -23rem;
    width: 42rem;
    height: 42rem;
    background: color-mix(in srgb, var(--primary) 11%, transparent);
}

body::after {
    right: -18rem;
    bottom: -20rem;
    width: 40rem;
    height: 40rem;
    border: 6rem solid color-mix(in srgb, var(--primary) 7%, transparent);
}

button, input, textarea, select { font: inherit; }
button, a, input, textarea, select { -webkit-tap-highlight-color: transparent; }

.page-shell {
    display: flex;
    width: min(960px, calc(100% - 32px));
    height: calc(var(--app-viewport-height, 100dvh) - 28px);
    margin: 14px auto;
    flex-direction: column;
}

.embed-mode .page-shell { width:100%; height:var(--app-viewport-height,100dvh); margin:0; }
.embed-mode .medical-notices { margin-inline:10px; }
.embed-mode .chat-card { border-radius:0; box-shadow:none; }

body.embed-inline { background: transparent; }
body.embed-inline::before,
body.embed-inline::after { display: none; }
.embed-inline .chat-card {
    border-color: transparent;
    background: transparent;
    backdrop-filter: none;
}
.embed-inline .chat-header,
.embed-inline .composer { background: transparent; }

body.embed-auto-height { min-height:0; overflow:hidden; touch-action:pan-y; }
.embed-auto-height .page-shell { height:auto; min-height:0; overflow:visible; }
.embed-auto-height .chat-card { min-height:0; overflow:visible; flex:0 0 auto; }
.embed-auto-height .messages { min-height:64px; overflow:visible; flex:0 0 auto; }
.embed-auto-height .composer:has(.choice-form) { height:auto; max-height:none; overflow:visible; }
.embed-auto-height .choice-form { height:auto; }
.embed-auto-height .choices { overflow:visible; overscroll-behavior:auto; flex:0 0 auto; }

.chat-card {
    display: flex;
    height: auto;
    overflow: hidden;
    min-height: 0;
    flex: 1 1 auto;
    flex-direction: column;
    border: 1px solid rgba(255,255,255,.8);
    border-radius: 30px;
    background: color-mix(in srgb, var(--surface) 91%, transparent);
    box-shadow: var(--shadow);
    backdrop-filter: blur(16px);
    overscroll-behavior: contain;
}

.chat-header {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 18px 24px;
    border-bottom: 1px solid color-mix(in srgb, var(--primary) 12%, transparent);
    background: color-mix(in srgb, var(--surface) 94%, transparent);
    flex: 0 0 auto;
}

.header-avatar,
.message-avatar {
    flex: 0 0 auto;
    border: 3px solid color-mix(in srgb, var(--primary) 68%, white);
    border-radius: 50%;
    object-fit: cover;
    background: var(--primary-soft);
}

.header-avatar { width: 58px; height: 58px; }
.message-avatar { width: 42px; height: 42px; margin-bottom: 2px; }

.chat-identity { min-width: 0; flex: 1 1 auto; }
.chat-logo {
    display: block;
    width: auto;
    max-width: 110px;
    height: auto;
    max-height: 44px;
    margin-left: auto;
    object-fit: contain;
    flex: 0 1 auto;
}
.chat-logo[hidden] { display: none; }
.chat-kicker { color: var(--primary); font-size: 11px; font-weight: 800; letter-spacing: .09em; text-transform: uppercase; }
.chat-header h1 { overflow: hidden; margin: 1px 0 0; font-size: 20px; text-overflow: ellipsis; white-space: nowrap; }
.chat-header p { margin: 3px 0 0; color: var(--muted); font-size: 13px; }
.status-dot { display: inline-block; width: 8px; height: 8px; margin-right: 5px; border-radius: 50%; background: #35b978; box-shadow: 0 0 0 3px rgba(53,185,120,.12); }

.restart-button {
    margin-left: 4px;
    padding: 9px 13px;
    border: 1px solid color-mix(in srgb, var(--primary) 28%, transparent);
    border-radius: 999px;
    color: var(--primary);
    background: var(--primary-soft);
    cursor: pointer;
    font-weight: 700;
}
.restart-button:hover { transform: translateY(-1px); filter: brightness(.98); }

.progress-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: 40px;
    padding: 10px 24px 0;
    flex: 0 0 auto;
}
.progress { color: var(--muted); font-size: 12px; font-weight: 650; }
.privacy-chip { color: #3c6d59; font-size: 11px; font-weight: 700; }
.privacy-chip::before { content: "●"; margin-right: 5px; color: #35b978; }

.messages {
    min-height: 80px;
    overflow-y: auto;
    flex: 1 1 auto;
    padding: 18px 24px 30px;
    scroll-behavior: smooth;
    scrollbar-color: color-mix(in srgb, var(--primary) 25%, transparent) transparent;
    scrollbar-width: thin;
    overscroll-behavior: contain;
    overflow-anchor: none;
    scrollbar-gutter: stable;
    touch-action: pan-y;
}

.message { display: flex; align-items: flex-end; gap: 10px; margin: 0 0 17px; }
.message.user { justify-content: flex-end; }
.bubble {
    position: relative;
    max-width: min(78%, 680px);
    padding: 16px 19px;
    border-radius: 24px;
    font-size: 16px;
    line-height: 1.55;
    white-space: pre-wrap;
}
.message.bot .bubble {
    border-bottom-right-radius: 7px;
    color: var(--on-primary);
    background: var(--primary);
    box-shadow: 0 10px 24px color-mix(in srgb, var(--primary) 18%, transparent);
}
.message.user .bubble {
    border: 1px solid color-mix(in srgb, var(--secondary) 72%, var(--primary));
    border-bottom-right-radius: 7px;
    color: var(--on-secondary);
    background: var(--secondary);
    box-shadow: 0 9px 22px color-mix(in srgb, var(--secondary) 28%, transparent);
}
.message.user .bubble::after {
    position: absolute;
    right: -7px;
    bottom: -1px;
    width: 14px;
    height: 14px;
    background: var(--secondary);
    clip-path: polygon(0 0, 0 100%, 100% 100%);
    content: "";
}
.message.bot .bubble a { color: var(--on-primary); }
.message.user .bubble a { color: var(--on-secondary); }
.bubble a { font-weight: 750; text-underline-offset: 3px; }

.composer {
    min-height: 174px;
    flex: 0 0 auto;
    padding: 20px 24px 24px;
    border-top: 1px solid var(--border);
    background: color-mix(in srgb, var(--surface) 96%, var(--background));
}
.composer > p { margin: 0; color: var(--muted); font-size: 14px; }

.composer:has(.choice-form) {
    height: min(385px, 52dvh);
    min-height: 190px;
    overflow: hidden;
    flex: 0 0 auto;
}

.answer-form { min-height: 0; }
.choice-form {
    display: flex;
    height: 100%;
    min-height: 0;
    flex-direction: column;
}
.choice-form .question-label,
.choice-form .error-message,
.choice-form .form-actions { flex: 0 0 auto; }

.composer:has(.choice-form.compact-choice-form) {
    height: auto;
    min-height: 0;
    overflow: visible;
    flex: 0 0 auto;
}
.compact-choice-form .choices {
    min-height: 0;
    overflow-y: visible;
    flex: 0 1 auto;
}

.welcome-actions, .form-actions { display: flex; align-items: center; gap: 10px; margin-top: 15px; }
.primary-button, .cta-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 46px;
    padding: 12px 22px;
    border: 0;
    border-radius: 999px;
    color: var(--on-primary);
    background: var(--primary);
    box-shadow: 0 10px 22px color-mix(in srgb, var(--primary) 21%, transparent);
    cursor: pointer;
    font-weight: 780;
    text-decoration: none;
    transition: transform .16s ease, filter .16s ease;
}
.back-button {
    display: inline-flex;
    min-height: 46px;
    align-items: center;
    justify-content: center;
    padding: 11px 18px;
    border: 1px solid var(--primary);
    border-radius: 999px;
    color: var(--primary);
    background: var(--on-primary);
    box-shadow: 0 8px 18px color-mix(in srgb, var(--on-primary) 28%, transparent);
    cursor: pointer;
    font-weight: 750;
    transition: transform .16s ease, filter .16s ease;
}
.back-button:hover { transform: translateY(-1px); filter: brightness(.97); }
.back-button:focus-visible { outline: 3px solid color-mix(in srgb, var(--primary) 30%, white); outline-offset: 3px; }
.back-button:disabled { cursor: wait; opacity:.58; }
.primary-button:hover, .cta-button:hover { transform: translateY(-1px); filter: brightness(1.04); }
.primary-button:focus-visible, .cta-button:focus-visible, .restart-button:focus-visible { outline: 3px solid color-mix(in srgb, var(--primary) 30%, white); outline-offset: 3px; }
.primary-button:disabled { opacity: .58; cursor: wait; transform: none; }

.question-label { display: block; margin-bottom: 11px; font-size: 13px; font-weight: 780; }
.keyboard-question { display:none; }
.required { color: var(--danger); }
.optional { color: var(--muted); font-weight: 550; }
.text-input, .select-input {
    width: 100%;
    padding: 14px 16px;
    border: 1px solid color-mix(in srgb, var(--secondary) 72%, var(--primary));
    border-radius: 18px 18px 7px 18px;
    outline: none;
    color: var(--on-secondary);
    background: var(--secondary);
    box-shadow: 0 8px 20px color-mix(in srgb, var(--secondary) 20%, transparent);
}
.text-input:focus, .select-input:focus { border-color: var(--primary); box-shadow: 0 0 0 4px color-mix(in srgb, var(--primary) 13%, transparent), 0 8px 20px color-mix(in srgb, var(--secondary) 20%, transparent); }
textarea.text-input { min-height: 100px; resize: vertical; }

.choices { display: grid; min-height: 40px; overflow-y: auto; flex: 1 1 auto; align-content: start; grid-auto-rows: max-content; gap: 10px; padding: 2px 5px 8px 2px; overscroll-behavior: contain; scrollbar-gutter: stable; }
.choice {
    display: flex;
    align-items: flex-start;
    gap: 11px;
    padding: 13px 15px;
    border: 1px solid color-mix(in srgb, var(--primary) 18%, var(--border));
    border-radius: 16px;
    color: var(--on-secondary);
    background: color-mix(in srgb, var(--secondary) 24%, var(--surface));
    cursor: pointer;
    line-height: 1.45;
    transition: border-color .16s ease, background .16s ease, transform .16s ease;
}
.choice:hover { transform: translateY(-1px); border-color: color-mix(in srgb, var(--secondary) 70%, var(--primary)); background: color-mix(in srgb, var(--secondary) 52%, var(--surface)); }
.choice:has(input:checked) { border-color: color-mix(in srgb, var(--secondary) 68%, var(--primary)); background: var(--secondary); box-shadow: 0 0 0 2px color-mix(in srgb, var(--secondary) 24%, transparent); }
.choice input { width: 18px; height: 18px; margin-top: 2px; flex: 0 0 auto; accent-color: var(--primary); }
.choice a { color: var(--on-secondary); font-weight: 750; text-underline-offset: 3px; }

.error-message { min-height: 20px; margin: 10px 0 0; color: var(--danger); font-size: 13px; }
.typing { display: flex; gap: 5px; width: fit-content; padding: 15px 18px; border: 1px solid color-mix(in srgb, var(--secondary) 70%, var(--primary)); border-radius: 22px 22px 7px 22px; background: var(--secondary-soft); }
.typing span { width: 7px; height: 7px; border-radius: 50%; background: color-mix(in srgb, var(--text) 60%, transparent); animation: pulse 1s infinite alternate; }
.typing span:nth-child(2) { animation-delay: .2s; }
.typing span:nth-child(3) { animation-delay: .4s; }
@keyframes pulse { to { opacity: .25; transform: translateY(-2px); } }

.processing-card {
    display: flex;
    align-items: center;
    gap: 17px;
    padding: 19px 21px;
    border: 1px solid color-mix(in srgb, var(--primary) 30%, var(--border));
    border-radius: 20px;
    background: color-mix(in srgb, var(--primary) 7%, var(--surface));
    box-shadow: 0 10px 28px color-mix(in srgb, var(--primary) 11%, transparent);
}
.processing-card > div:last-child { min-width: 0; flex: 1 1 auto; }
.processing-card h2 { margin: 0 0 5px; color: var(--primary); font-size: 18px; }
.processing-card p { margin: 0; color: var(--muted); font-size: 14px; line-height: 1.5; }
.processing-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    width: 54px;
    height: 54px;
    flex: 0 0 auto;
    border-radius: 50%;
    background: var(--primary);
    box-shadow: 0 8px 20px color-mix(in srgb, var(--primary) 24%, transparent);
}
.processing-icon span { width: 7px; height: 7px; border-radius: 50%; background: var(--on-primary); animation: pulse 1s infinite alternate; }
.processing-icon span:nth-child(2) { animation-delay: .2s; }
.processing-icon span:nth-child(3) { animation-delay: .4s; }
.processing-track { height: 7px; overflow: hidden; margin-top: 13px; border-radius: 999px; background: color-mix(in srgb, var(--primary) 13%, white); }
.processing-track span { display: block; width: 100%; height: 100%; border-radius: inherit; background: var(--primary); transform: scaleX(0); transform-origin: left; animation: process-data 15s linear forwards; }
@keyframes process-data { to { transform: scaleX(1); } }

.chat-card:has(.result-card) .messages { min-height:0; max-height:120px; flex:0 1 120px; }
.composer:has(.result-card) { min-height:0; overflow:hidden; flex:1 1 auto; }
.result-card { display:flex; height:100%; min-height:0; padding:21px; flex-direction:column; border:1px solid color-mix(in srgb, #35a56c 42%, white); border-radius:20px; background:#f0faf3; box-shadow:0 12px 30px rgba(38,114,72,.08); }
.result-content { min-height:0; overflow-y:auto; flex:1 1 auto; padding-right:5px; overscroll-behavior:contain; scrollbar-width:thin; touch-action:pan-y; -webkit-overflow-scrolling:touch; }
.result-card h2 { margin: 0 0 11px; color: #245f3a; font-size: 19px; }
.result-card p { line-height: 1.6; white-space: pre-wrap; }
.diagnosis-text { margin: 0; font-size: 17px; font-weight: 760; }
.tenant-claim { display:grid; gap:8px; margin:19px 0 21px; padding-top:17px; border-top:1px solid #cfe2d5; }
.tenant-claim p { margin:0; }
.result-card > .cta-button { flex:0 0 auto; align-self:flex-start; margin-top:16px; }
.embed-auto-height .chat-card:has(.result-card) .messages { max-height:none; flex:0 0 auto; }
.embed-auto-height .composer:has(.result-card) { overflow:visible; flex:0 0 auto; }
.embed-auto-height .result-card { height:auto; }
.embed-auto-height .result-content { overflow:visible; }
.medical-notices { display:grid; gap:6px; margin:8px 18px 0; flex:0 0 auto; }
.medical-note { margin:0; color:var(--muted); text-align:center; font-size:11px; line-height:1.4; }
.medical-warning { margin:0; padding:8px 11px; border:1px solid #e8ce86; border-radius:10px; color:#604a12; background:#fff8df; text-align:left; font-size:10.5px; line-height:1.4; }
.medical-warning strong:first-child { color:#8a5700; letter-spacing:.02em; }

@media (max-width: 640px) {
    body::before { top: -25rem; left: -29rem; }
    .page-shell { width:100%; height:var(--app-viewport-height,100dvh); margin:0; }
    .chat-card { height: auto; min-height: 0; border: 0; border-radius: 0; box-shadow: none; }
    .chat-header { padding: 13px 15px; }
    .header-avatar { width: 50px; height: 50px; }
    .chat-header h1 {
        display: -webkit-box;
        overflow: hidden;
        font-size: 17px;
        line-height: 1.18;
        white-space: normal;
        -webkit-box-orient: vertical;
        -webkit-line-clamp: 2;
    }
    .chat-kicker { font-size: 9px; }
    .chat-logo { max-width: 72px; max-height: 34px; }
    .restart-button { width: 40px; height: 40px; padding: 0; font-size: 20px; }
    .restart-button span { display: none; }
    .progress-row { padding-inline: 15px; }
    .privacy-chip { font-size: 10px; }
    .messages { height: auto; min-height: 64px; padding: 15px 14px 24px; }
    .bubble { max-width: calc(100% - 48px); padding: 14px 16px; border-radius: 20px; font-size: 15px; }
    .message-avatar { width: 36px; height: 36px; }
    .composer { padding: 17px 15px 21px; }
    .composer:has(.choice-form) { height: min(370px, 50dvh); min-height: 185px; }
    .primary-button, .cta-button { width: 100%; }
    .result-card > .cta-button { align-self:stretch; }
    .form-actions .back-button { flex: 0 0 auto; }
    .form-actions .primary-button { width: auto; flex: 1 1 auto; }
    .processing-card { align-items: flex-start; padding: 16px; }
    .processing-icon { width: 46px; height: 46px; }
    .medical-notices { gap:4px; margin:0; padding:5px 8px 7px; }
    .embed-mode .medical-notices { margin:0; }
    .medical-note { font-size:9px; }
    .medical-warning { padding:5px 7px; border-radius:8px; font-size:8.5px; line-height:1.3; }
    .keyboard-open .medical-notices { display:none; }
    .keyboard-open .chat-header { gap:9px; padding:7px 12px; }
    .keyboard-open .header-avatar { width:40px; height:40px; }
    .keyboard-open .chat-logo { max-width:66px; max-height:27px; }
    .keyboard-open .restart-button { width:36px; height:36px; }
    .keyboard-open .progress-row { min-height:30px; padding:6px 12px 0; }
    .keyboard-open .messages { min-height:35px; padding:8px 12px 12px; }
    .keyboard-open .composer {
        height:clamp(164px,42dvh,230px);
        min-height:164px;
        max-height:230px;
        overflow-y:auto;
        padding:10px 12px 12px;
        overscroll-behavior-y:auto;
        scroll-padding-block:8px;
        scrollbar-gutter:stable;
        touch-action:pan-y;
        -webkit-overflow-scrolling:touch;
    }
    .keyboard-open .answer-form { min-height:max-content; padding-bottom:max(2px,env(safe-area-inset-bottom)); }
    body.embedded-keyboard-fallback {
        overflow-y:auto;
        overscroll-behavior-y:contain;
        touch-action:pan-y;
        -webkit-overflow-scrolling:touch;
    }
    .embedded-keyboard-fallback .page-shell {
        height:auto;
        min-height:var(--app-viewport-height,100dvh);
        overflow:visible;
        padding-bottom:min(45vh,360px);
    }
    .embedded-keyboard-fallback .chat-card {
        min-height:var(--app-viewport-height,100dvh);
        flex:0 0 auto;
    }
    .keyboard-open .keyboard-question {
        display:grid;
        gap:2px;
        margin-bottom:8px;
        padding:7px 10px;
        border-radius:10px;
        color:var(--on-primary);
        background:var(--primary);
        font-size:11px;
        line-height:1.3;
    }
    .keyboard-open .keyboard-question strong {
        font-size:9px;
        letter-spacing:.04em;
        text-transform:uppercase;
        opacity:.8;
    }
    .keyboard-open .keyboard-question p { margin:0; }
    .keyboard-open textarea.text-input {
        min-height:64px;
        max-height:76px;
        resize:none;
        overflow-y:auto;
    }
    .keyboard-open .question-label { margin-bottom:6px; }
    .keyboard-open .error-message { min-height:14px; margin-top:5px; }
    .keyboard-open .primary-button,
    .keyboard-open .back-button { min-height:42px; padding-block:8px; }
    .keyboard-open .welcome-actions,
    .keyboard-open .form-actions { margin-top:9px; }
}

@media (max-width: 360px) {
    .chat-header {
        display: grid;
        grid-template-columns: 44px minmax(0, 1fr) 36px;
        gap: 6px 10px;
        padding-inline: 12px;
    }
    .header-avatar {
        width: 44px;
        height: 44px;
        align-self: start;
        grid-column: 1;
        grid-row: 1 / span 2;
    }
    .chat-identity { grid-column: 2; grid-row: 1; }
    .chat-kicker { display: none; }
    .chat-header h1 { font-size: 16px; }
    .chat-header p { font-size: 12px; }
    .chat-logo {
        max-width: 76px;
        max-height: 24px;
        margin: 0;
        grid-column: 2;
        grid-row: 2;
    }
    .restart-button {
        width: 36px;
        height: 36px;
        margin: 0;
        align-self: start;
        grid-column: 3;
        grid-row: 1 / span 2;
    }
    .progress-row { gap: 8px; padding-inline: 10px; }
}

@media (max-height: 520px) {
    .page-shell { height:var(--app-viewport-height,100dvh); margin-block:0; }
    .chat-header { gap: 10px; padding: 7px 18px; }
    .header-avatar { width: 40px; height: 40px; }
    .chat-header h1 { font-size: 16px; }
    .chat-header p { margin-top: 0; font-size: 11px; }
    .chat-logo { max-width: 78px; max-height: 30px; }
    .restart-button { padding: 7px 10px; }
    .progress-row { min-height: 32px; padding: 6px 18px 0; }
    .messages { min-height: 0; padding: 9px 18px 14px; }
    .composer:has(.choice-form) { height: min(226px, 52dvh); min-height: 185px; padding: 12px 18px 14px; flex: 0 1 auto; }
    .composer:has(.choice-form.compact-choice-form) { height: auto; min-height: 0; flex: 0 0 auto; }
    .choice-form .question-label { margin-bottom: 7px; }
    .choice-form .choices { gap: 8px; }
    .choice-form .choice { padding: 9px 12px; }
    .choice-form .error-message { min-height: 16px; margin-top: 5px; }
    .choice-form .form-actions { margin-top: 7px; }
    .choice-form .primary-button { min-height: 40px; padding-block: 8px; }
    .medical-notices { gap:3px; padding-block:3px; }
    .medical-warning { padding-block:4px; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
