/* ==========================================================================
   Design Tokens
   ========================================================================== */
:root {
    /* Brand palette */
    --brand-50: #e9f2ff;
    --brand-100: #d5e8ff;
    --brand-200: #b3d5ff;
    --brand-300: #86bdf7;
    --brand-400: #5aa3ee;
    --brand-500: #2f86d6;
    --brand-600: #226db8;
    --brand-700: #195a99;

    /* Surface & text */
    --bg: #f7f9fb;
    --card: #ffffff;
    --ink: #0b1a33;
    --muted: #6c7a89;
    --line: #e5ecf5;

    /* Shadows */
    --shadow-1: 0 1px 2px rgba(0, 0, 0, .04);
    --shadow-2: 0 8px 24px rgba(0, 0, 0, .06);
    --shadow-3: 0 10px 28px rgba(0, 0, 0, .08);

    /* Layout */
    --container: 1200px;
    --radius-sm: 10px;
    --radius-md: 12px;
    --radius-lg: 14px;
    --radius-pill: 999px;

    /* Chat sizing */
    --chat-h-desktop: 65vh;
    --chat-h-mobile: 58vh;

    /* Safe area (iOS) */
    --safe-bottom: env(safe-area-inset-bottom, 0px);
}

/* ==========================================================================
   Base
   ========================================================================== */
* {
    box-sizing: border-box;
}

html,
body {
    height: 100%;
}

body {
    margin: 0;
    color: var(--ink);
    background: var(--bg);
    font-family: 'Montserrat', system-ui, -apple-system, 'Segoe UI', Roboto, Arial, sans-serif;
    font-size: 16px;
    line-height: 1.5;
    text-rendering: optimizeLegibility;
    -webkit-font-smoothing: antialiased;
}

.container {
    max-width: var(--container);
    margin: 0 auto;
    padding: 0 16px;
}

.hidden {
    display: none !important;
}

.visually-hidden {
    position: absolute !important;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
    border: 0;
}

/* ==========================================================================
   Header
   ========================================================================== */
.site-header {
    background: linear-gradient(180deg, var(--brand-100), #fff);
    border-bottom: 1px solid rgba(0, 0, 0, .04);
    box-shadow: var(--shadow-2);
    backdrop-filter: saturate(120%) blur(4px);
    position: sticky;
    top: 0;
    z-index: 10;
}

.header-stack {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    padding: 16px 0 12px;
}

/* Brand */
.brand,
.brand-centered {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 16px;
}

.logo {
    width: clamp(360px, 34vw, 560px);
    height: auto;
    object-fit: contain;
}

.brand-text {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.brand-doctor {
    font-weight: 900;
    font-size: clamp(28px, 4.4vw, 44px);
    line-height: 1.06;
    letter-spacing: .01em;
    color: var(--ink);
}

.brand-clinic {
    font-weight: 700;
    font-size: clamp(18px, 2.6vw, 26px);
    line-height: 1.15;
    letter-spacing: .02em;
    color: var(--ink);
}

/* Legacy no-ops */
.brand-line1,
.brand-line2 {
    display: none !important;
}

/* Nav pills */
.menu,
.menu-centered {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 10px;
}

.menu a,
.menu button {
    appearance: none;
    border: 1px solid #e6edf7;
    background: #fff;
    padding: 9px 14px;
    border-radius: var(--radius-pill);
    cursor: pointer;
    color: var(--ink);
    font-weight: 600;
    text-decoration: none;
    transition: border-color .15s, background .15s, transform .02s;
}

.menu a:hover,
.menu button:hover {
    background: #f8fbff;
    border-color: #d8e6ff;
    transform: translateY(-1px);
}

.menu .cta {
    background: #0e5ecb;
    color: #fff !important;
    padding: 10px 18px;
    border-radius: var(--radius-pill);
    box-shadow: 0 8px 22px rgba(14, 94, 203, .28);
}

.menu .cta:hover {
    background: #0b4aa2;
}

/* ==========================================================================
   Main Split
   ========================================================================== */
.split {
    display: grid;
    grid-template-columns: 340px 1fr;
    gap: 18px;
    padding: 18px 0;
}

/* Left Pane */
.left-pane {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: var(--radius-md);
    padding: 16px;
    box-shadow: var(--shadow-1);
}

.left-pane h2 {
    margin-top: 0;
}

.topics {
    list-style: none;
    padding: 0;
    margin: 0 0 12px;
}

.topics li {
    margin-bottom: 8px;
}

.topics .group-title {
    margin: 12px 0 6px;
    font-size: 13px;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: .06em;
    font-weight: 700;
}

.topics button {
    width: 100%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px;
    border: 1px solid var(--line);
    background: #f6faff;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-weight: 600;
    transition: border-color .15s, background .15s, transform .02s;
}

.topics button:hover {
    border-color: var(--brand-300);
    background: var(--brand-100);
    transform: translateY(-1px);
}

.topics button.primary {
    background: linear-gradient(180deg, #f1f7ff, #e7f0ff);
    border-color: #cfe2ff;
    box-shadow: 0 1px 0 rgba(13, 110, 253, .12);
}

.lead-card {
    border-top: 1px dashed var(--line);
    padding-top: 14px;
}

.lead-card input,
.lead-card textarea {
    width: 100%;
    margin: 6px 0;
    padding: 10px;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    background: #fbfdff;
}

.lead-card button {
    width: 100%;
    padding: 10px;
    background: var(--brand-600);
    color: #fff;
    border: 0;
    border-radius: var(--radius-sm);
    cursor: pointer;
}

.lead-card button:hover {
    background: var(--brand-700);
}

.fine {
    color: var(--muted);
    font-size: 12px;
}

.status {
    margin-top: 6px;
    font-size: 13px;
    color: #000;
}

/* Right Pane / Chat */
.right-pane {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.chat {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: var(--radius-md);
    padding: 14px;
    height: var(--chat-h-desktop);
    overflow: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    padding-bottom: max(16px, var(--dbg-footprint, 0px));
    box-shadow: var(--shadow-1);
}

/* ==========================================================================
   Text-message style bubbles
   ========================================================================== */
.msg {
    display: flex;
    margin: 8px 0;
}

.msg+.msg {
    margin-top: 6px;
}

/* tighter alternation */

.msg .bubble {
    max-width: 70ch;
    padding: 10px 14px;
    border: none !important;
    background-clip: padding-box;
    line-height: 1.35;
    box-shadow: 0 1px 0 rgba(0, 0, 0, .03);
}

.msg.bot {
    justify-content: flex-start;
}

.msg.bot .bubble {
    background: #f1f5f9;
    color: var(--ink);
    border-radius: 18px 18px 18px 6px;
    /* small left "tail" */
}

.msg.user {
    justify-content: flex-end;
}

.msg.user .bubble {
    background: #0e5ecb;
    color: #fff;
    border-radius: 18px 18px 6px 18px;
    /* small right "tail" */
}

.msg .bubble a {
    color: inherit;
    text-decoration: underline;
}

.msg .bubble p {
    margin: 0 0 6px;
}

.msg .bubble p:last-child {
    margin-bottom: 0;
}

.msg.user .bubble ::selection {
    background: rgba(255, 255, 255, .25);
}

/* ==========================================================================
   Composer
   ========================================================================== */
.composer {
    display: flex;
    gap: 8px;
    position: sticky;
    bottom: 0;
    background: transparent;
    padding-top: 4px;
    padding-bottom: calc(var(--safe-bottom) + 0px);
}

.composer input {
    flex: 1;
    padding: 14px;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    background: #fff;
    font-size: 15px;
}

.composer input.busy {
    background: #f3f7ff;
    border-color: var(--brand-300);
}

.composer input:focus {
    border-color: var(--brand-400);
    box-shadow: 0 0 0 3px rgba(47, 134, 214, .12);
    outline: none;
}

.composer button {
    font-weight: 700;
    letter-spacing: .02em;
    border-radius: var(--radius-sm);
    box-shadow: 0 8px 18px rgba(34, 109, 184, .18);
}

.composer button:hover {
    box-shadow: 0 10px 22px rgba(25, 90, 153, .22);
}

.composer button:disabled {
    opacity: .65;
    cursor: not-allowed;
}

/* Typing indicator */
.typing {
    font-size: 13px;
    color: var(--brand-700);
    display: flex;
    align-items: center;
    gap: 8px;
    padding-left: 2px;
}

.typing .dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--brand-600);
    animation: bounce 1s infinite;
}

.typing .dot:nth-child(2) {
    animation-delay: .2s;
}

.typing .dot:nth-child(3) {
    animation-delay: .4s;
}

@keyframes bounce {

    0%,
    80%,
    100% {
        transform: scale(.6);
        opacity: .4
    }

    40% {
        transform: scale(1);
        opacity: 1
    }
}

/* ==========================================================================
   Footer
   ========================================================================== */
.site-footer {
    margin-top: 12px;
    background: linear-gradient(180deg, var(--brand-400), var(--brand-500));
}

.site-footer .container {
    padding: 12px 0;
    text-align: center;
}

.site-footer small {
    color: #000;
}

/* ==========================================================================
   Hero Strip Under Header
   ========================================================================== */
.hero-banner {
    background: transparent;
    padding: 0;
    border: 0;
}

.hero-card {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 18px;
    background: linear-gradient(180deg, #fff, #fcfdff);
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    margin: 12px auto 16px;
    padding: 16px 20px;
    box-shadow: var(--shadow-3);
}

.hero-photo {
    width: 70px;
    height: 70px;
    object-fit: cover;
    border-radius: var(--radius-lg);
    border: 2px solid #fff;
    box-shadow: 0 6px 18px rgba(0, 0, 0, .08);
}

.hero-quote {
    font-weight: 800;
    font-size: 22px;
    line-height: 1.22;
}

/* ==========================================================================
   Skeletons
   ========================================================================== */
.skel {
    height: 38px;
    border-radius: var(--radius-sm);
    background: linear-gradient(90deg, #f1f4f9, #e9eef6, #f1f4f9);
    background-size: 200% 100%;
    animation: shimmer 1.2s infinite;
    border: 1px solid var(--line);
}

@keyframes shimmer {
    0% {
        background-position: 0 0
    }

    100% {
        background-position: -200% 0
    }
}

/* ==========================================================================
   Focus & A11y
   ========================================================================== */
.menu a:focus-visible,
.menu button:focus-visible,
.topics button:focus-visible,
.composer button:focus-visible,
input:focus-visible,
textarea:focus-visible {
    outline: 2px solid var(--brand-500);
    outline-offset: 2px;
    border-radius: var(--radius-sm);
}

/* ==========================================================================
   Mobile “Chat with Agent” Button (sticky)
   ========================================================================== */
.mobile-chat-btn {
    display: none;
}

@media (max-width: 640px) {
    .mobile-chat-btn {
        display: inline-flex;
        position: fixed;
        left: 0;
        right: 0;
        bottom: calc(16px + var(--safe-bottom));
        margin: 0 auto;
        width: calc(100% - 2rem);
        max-width: 700px;
        justify-content: center;
        align-items: center;
        padding: 14px 16px;
        border-radius: var(--radius-pill);
        background: #1a73e8;
        color: #fff;
        font-weight: 700;
        text-decoration: none;
        box-shadow: 0 8px 24px rgba(0, 0, 0, .18);
        z-index: 9999;
    }

    .mobile-chat-btn:active {
        transform: translateY(1px);
    }
}

/* ==========================================================================
   Responsive
   ========================================================================== */
@media (max-width: 900px) {
    .split {
        grid-template-columns: 1fr;
    }

    .chat {
        height: var(--chat-h-mobile);
    }

    .logo {
        width: 220px;
    }

    .msg .bubble {
        max-width: 85%;
    }

    .brand-doctor {
        font-size: 24px;
    }

    .brand-clinic {
        font-size: 16px;
    }

    /* Larger touch targets */
    .topics button,
    .menu a,
    .menu button {
        padding: 12px 14px;
    }
}

@media (min-width: 1100px) {
    .hero-quote {
        white-space: nowrap;
    }
}

@media (max-width: 900px) {
    .hero-card {
        grid-template-columns: 1fr;
        text-align: center;
    }

    .hero-photo {
        width: 50px;
        height: 50px;
    }

    .hero-quote {
        font-size: 18px;
        white-space: normal;
    }
}