/* === 0. MONOCHROMATIC THEME VARIABLES === */
:root {
    --qai-bg-dark: #2d2d2d;
    --qai-bg-light: #ffffff;
    --qai-text-primary: #2d2d2d;
    --qai-text-secondary: #666666;
    --qai-border: #e0e0e0;
    --qai-hover: #f5f5f5;
    --qai-bg-secondary: #f9f9f9;
    --qai-border-dark: #999999;
    --qai-shadow: rgba(0,0,0,0.08);
    --explorer-panel-width: 55%; /* Desktop default, 50-60% range */
    --explorer-panel-mobile-width: 95%; /* Mobile full-width */
}

/* === 1. BASIC RESET & DIVI OVERRIDES === */
    * {
        box-sizing: border-box;
        margin: 0;
        padding: 0;
    }
    html, body, #page-container, #main-content, .entry-content {
        margin: 0 !important;
        padding: 0 !important;
    }
    html, body {
        overflow: hidden;
        font-family: "Montserrat", sans-serif;
        background-color: var(--qai-bg-light);
        color: var(--qai-text-primary);
    }

    /* === 2. QAI PAGE WRAPPER === */
    .qai-page-wrapper {
        display: flex;
        flex-direction: column;
        width: calc(100% - 60px); /* Account for minimized panel */
        height: 100svh;
        background-color: transparent; /* Page is transparent, uses body background */
        position: fixed;
        top: 0;
        left: 60px; /* Start after minimized panel */
        transition: left 0.3s ease, width 0.3s ease;
    }
    
    /* Adjust page wrapper when panel is maximized */
    body.side-panel-open .qai-page-wrapper {
        left: 280px;
        width: calc(100% - 280px); /* Account for maximized panel */
    }
    
    /* Adjust page wrapper when explorer panel is open */
    body.explorer-panel-open .qai-page-wrapper {
        width: calc(100% - 60px - var(--explorer-panel-width)); /* Account for minimized side panel and explorer panel */
    }
    
    /* When both side panel and explorer panel are open */
    body.side-panel-open.explorer-panel-open .qai-page-wrapper {
        left: 280px;
        width: calc(100% - 280px - var(--explorer-panel-width)); /* Account for maximized side panel and explorer panel */
    }
    body.logged-in .qai-page-wrapper {
        top: 32px;
        height: calc(100svh - 32px);
    }
    @media (max-width: 782px) {
        body.logged-in .qai-page-wrapper {
            top: 46px;
            height: calc(100svh - 46px);
        }
    }
    
    /* === 3. QAI HEADER (MONOCHROMATIC) === */
    .qai-header {
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 8px 24px;
        background-color: var(--qai-bg-light);
        color: var(--qai-text-primary);
        flex-shrink: 0;
        z-index: 1000;
        min-height: 48px;
        position: relative;
        width: 100%; /* Full width of page-wrapper */
        box-sizing: border-box;
    }
    
    .qai-header-left {
        display: flex;
        align-items: center;
        gap: 15px;
        flex-shrink: 0;
        min-width: 60px; /* Reserve space for consistency */
    }
    
    /* Mobile burger menu button - hidden on desktop */
    .qai-mobile-burger {
        display: none; /* Hidden on desktop */
        flex-direction: column;
        justify-content: space-around;
        width: 24px;
        height: 24px;
        background: transparent;
        border: none;
        cursor: pointer;
        padding: 0;
        z-index: 1001;
    }
    
    .qai-mobile-burger span {
        width: 100%;
        height: 2px;
        background-color: var(--qai-text-primary);
        border-radius: 2px;
        transition: all 0.3s ease;
    }
    
    .qai-mobile-burger:hover span {
        background-color: var(--qai-bg-dark);
    }
    
    .qai-mobile-burger.active span:nth-child(1) {
        transform: rotate(45deg) translate(5px, 5px);
    }
    
    .qai-mobile-burger.active span:nth-child(2) {
        opacity: 0;
    }
    
    .qai-mobile-burger.active span:nth-child(3) {
        transform: rotate(-45deg) translate(7px, -6px);
    }
    
    /* Header center - logo and title */
    .qai-header-center {
        display: flex;
        align-items: center;
        gap: 10px;
    }
    
    /* Mobile overlay - hidden by default */
    .qai-mobile-overlay {
        display: none; /* Hidden on desktop */
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background: rgba(0, 0, 0, 0.5);
        z-index: 998; /* Below side panel (999) */
        opacity: 0;
        visibility: hidden;
        transition: opacity 0.3s ease, visibility 0.3s ease;
    }
    
    /* Burger Menu Button */
    .qai-burger-menu {
        display: flex;
        flex-direction: column;
        justify-content: space-around;
        width: 24px;
        height: 24px;
        background: transparent;
        border: none;
        cursor: pointer;
        padding: 0;
        z-index: 1001;
    }
    
    .qai-burger-menu span {
        width: 100%;
        height: 2px;
        background-color: var(--qai-text-primary);
        border-radius: 2px;
        transition: all 0.3s ease;
    }
    
    .qai-burger-menu:hover span {
        background-color: var(--qai-bg-dark);
    }
    
    .qai-burger-menu.active span:nth-child(1) {
        transform: rotate(45deg) translate(5px, 5px);
    }
    
    .qai-burger-menu.active span:nth-child(2) {
        opacity: 0;
    }
    
    .qai-burger-menu.active span:nth-child(3) {
        transform: rotate(-45deg) translate(7px, -6px);
    }
    .qai-header-logo-link {
        display: flex;
        align-items: center;
    }
    .qai-header-logo {
        height: 32px; 
        width: auto;
    }
    .qai-header-title {
        font-size: 22px;
        font-weight: 600;
        margin: 0;
        color: var(--qai-text-primary);
    }
    .qai-phase-badge {
        display: inline-block;
        font-size: 11px;
        font-weight: 600;
        padding: 2px 8px;
        margin-left: 8px;
        border-radius: 4px;
        background-color: var(--qai-bg-secondary);
        color: var(--qai-text-secondary);
        border: 1px solid var(--qai-border);
        vertical-align: middle;
    }
    .qai-header-nav a {
        font-size: 15px;
        font-weight: 500;
        color: var(--qai-text-primary);
        text-decoration: none;
        padding: 8px 12px;
        border: 1px solid var(--qai-border);
        background-color: var(--qai-bg-light);
        border-radius: 6px;
        transition: all 0.2s ease;
    }
    .qai-header-nav a:hover {
        background-color: var(--qai-bg-dark);
        border-color: var(--qai-bg-dark);
        color: var(--qai-bg-light);
    }
    
    /* Side Panel - Starts as thin strip, expands to full width on click */
    .qai-side-panel {
        position: fixed;
        left: 0;
        top: 0;
        width: 60px; /* Minimized width */
        height: 100vh;
        background-color: var(--qai-bg-light);
        border-right: 1px solid var(--qai-border);
        z-index: 999; /* Below header */
        transition: width 0.3s ease;
        overflow: hidden; /* Clip content to panel width */
    }
    
    body.logged-in .qai-side-panel {
        top: 0;
        height: 100vh;
    }
    
    @media (max-width: 782px) {
        body.logged-in .qai-side-panel {
            top: 0;
            height: 100vh;
        }
    }
    
    /* Expanded state */
    .qai-side-panel.open {
        width: 280px;
    }
    
    .qai-side-panel-content {
        display: flex;
        flex-direction: column;
        height: 100%;
        width: 100%; /* Match panel width */
        padding: 12px 10px 20px 10px; /* Top padding matches header, side padding for centering */
        position: relative;
        overflow-y: auto; /* Allow scrolling for content */
        overflow-x: hidden; /* Prevent horizontal overflow */
        align-items: center; /* Center items in minimized state */
        box-sizing: border-box; /* Include padding in width */
    }
    
    /* When minimized, center content and constrain width */
    .qai-side-panel:not(.open) .qai-side-panel-content {
        align-items: center;
        width: 60px; /* Match minimized panel width */
        padding-left: 10px;
        padding-right: 10px;
    }
    
    /* When expanded, align items to start but keep burger menu in same position */
    .qai-side-panel.open .qai-side-panel-content {
        align-items: flex-start;
        width: 280px; /* Match expanded panel width */
        padding-left: 20px;
        padding-right: 20px;
    }
    
    /* Keep burger menu in same position when expanded - align to left like minimized */
    .qai-side-panel.open .qai-side-panel-burger {
        align-self: flex-start; /* Override parent alignment */
        margin-left: 0; /* Align to left edge */
    }
    
    body.logged-in .qai-side-panel-content {
        padding-top: 44px; /* WordPress admin bar (32px) + header padding (12px) */
    }
    
    @media (max-width: 782px) {
        body.logged-in .qai-side-panel-content {
            padding-top: 58px; /* WordPress admin bar (46px) + header padding (12px) */
        }
    }
    
    /* Burger menu - always visible, stays in same position */
    .qai-side-panel-burger {
        display: flex;
        flex-direction: column;
        justify-content: space-around;
        width: 24px;
        height: 24px;
        background: transparent;
        border: none;
        cursor: pointer;
        padding: 0;
        margin: 0 0 20px 0; /* Left aligned, space below */
        flex-shrink: 0; /* Don't shrink */
        position: relative;
        align-self: flex-start; /* Always align to left */
    }
    
    /* Center burger menu when panel is minimized */
    .qai-side-panel:not(.open) .qai-side-panel-burger {
        margin-left: auto;
        margin-right: auto;
    }
    
    /* Keep burger menu at left when panel is expanded */
    .qai-side-panel.open .qai-side-panel-burger {
        margin-left: 0;
        margin-right: auto;
    }
    
    .qai-side-panel-burger span {
        width: 100%;
        height: 2px;
        background-color: var(--qai-text-primary);
        border-radius: 2px;
        transition: all 0.3s ease;
    }
    
    .qai-side-panel-burger:hover span {
        background-color: var(--qai-bg-dark);
    }
    
    /* Burger menu active state when panel is open */
    .qai-side-panel.open .qai-side-panel-burger span:nth-child(1) {
        transform: rotate(45deg) translate(5px, 5px);
    }
    
    .qai-side-panel.open .qai-side-panel-burger span:nth-child(2) {
        opacity: 0;
    }
    
    .qai-side-panel.open .qai-side-panel-burger span:nth-child(3) {
        transform: rotate(-45deg) translate(7px, -6px);
    }
    
    /* Help icon (visible in minimized state) - centered */
    .qai-help-icon {
        width: 40px;
        height: 40px;
        border-radius: 50%;
        border: 1px solid var(--qai-border);
        background-color: var(--qai-bg-light);
        color: var(--qai-text-primary);
        cursor: pointer;
        display: flex;
        align-items: center;
        justify-content: center;
        transition: all 0.2s ease;
        padding: 0;
        opacity: 1;
        pointer-events: auto;
        margin: 0 auto; /* Center horizontally */
        flex-shrink: 0; /* Don't shrink */
        position: relative;
    }
    
    .qai-help-icon svg {
        width: 20px;
        height: 20px;
    }
    
    .qai-help-icon:hover {
        background-color: var(--qai-bg-dark);
        color: var(--qai-bg-light);
        border-color: var(--qai-bg-dark);
    }
    
    /* Hide help icon when panel is expanded */
    .qai-side-panel.open .qai-help-icon {
        display: none;
    }
    
    /* Data Quality icon (minimized state) - below Help icon */
    .qai-data-quality-icon {
        width: 40px;
        height: 40px;
        border-radius: 50%;
        border: 1px solid var(--qai-border);
        background-color: var(--qai-bg-light);
        color: var(--qai-text-primary);
        cursor: pointer;
        display: flex;
        align-items: center;
        justify-content: center;
        transition: all 0.2s ease;
        padding: 0;
        margin: 10px auto 0 auto;
        flex-shrink: 0;
    }
    .qai-data-quality-icon svg {
        width: 20px;
        height: 20px;
    }
    .qai-data-quality-icon:hover {
        background-color: var(--qai-bg-dark);
        color: var(--qai-bg-light);
        border-color: var(--qai-bg-dark);
    }
    .qai-side-panel.open .qai-data-quality-icon {
        display: none;
    }
    
    /* Account icons (minimized state) - same order as expanded: account then help */
    .qai-account-icons {
        display: none;
        flex-direction: column;
        gap: 10px;
        align-items: center;
        margin: 0 auto 20px auto;
        flex-shrink: 0;
    }
    .qai-side-panel:not(.open) .qai-account-icons {
        display: flex;
    }
    .qai-side-panel.open .qai-account-icons {
        display: none;
    }
    .qai-account-icon {
        width: 40px;
        height: 40px;
        border-radius: 50%;
        border: 1px solid var(--qai-border);
        background-color: var(--qai-bg-light);
        color: var(--qai-text-primary);
        cursor: pointer;
        display: flex;
        align-items: center;
        justify-content: center;
        transition: all 0.2s ease;
        padding: 0;
        flex-shrink: 0;
    }
    .qai-account-icon svg {
        width: 20px;
        height: 20px;
    }
    .qai-account-icon:hover {
        background-color: var(--qai-bg-dark);
        color: var(--qai-bg-light);
        border-color: var(--qai-bg-dark);
    }
    
    /* Account entry: Sign In / Register or Manage Account + Log Out (above Help when panel open) */
    .qai-account-entry {
        display: none;
        flex-direction: column;
        gap: 10px;
        width: 100%;
        margin-bottom: 20px;
        box-sizing: border-box;
    }
    .qai-side-panel.open .qai-account-entry {
        display: flex;
    }
    /* Hide Help when any account view is open (Sign In, Register, or Manage Account) */
    .qai-side-panel.qai-account-view-open .qai-help-link {
        display: none !important;
    }
    .qai-side-panel.qai-account-view-open .qai-data-quality-link {
        display: none !important;
    }
    .qai-side-panel.qai-account-view-open .qai-account-entry {
        display: none !important;
    }
    /* When showing Help or Data Quality content, hide buttons and account entry so only content is visible */
    .qai-side-panel.qai-showing-panel-content .qai-help-link,
    .qai-side-panel.qai-showing-panel-content .qai-data-quality-link,
    .qai-side-panel.qai-showing-panel-content .qai-account-entry {
        display: none !important;
    }
    /* Hide account entry when Manage Account screen is open */
    .qai-side-panel.qai-manage-account-open .qai-account-entry {
        display: none !important;
    }
    .qai-account-entry-btn {
        padding: 12px 16px;
        background-color: transparent;
        border: 1px solid var(--qai-border);
        color: var(--qai-text-primary);
        font-size: 15px;
        font-weight: 500;
        line-height: 1.4;
        cursor: pointer;
        border-radius: 8px;
        transition: all 0.2s ease;
        text-align: left;
        width: 100%;
        box-sizing: border-box;
        font-family: inherit;
        display: flex;
        align-items: center;
        gap: 8px;
    }
    .qai-account-entry-btn svg {
        width: 20px;
        height: 20px;
        flex-shrink: 0;
    }
    .qai-account-entry-btn:hover {
        background-color: var(--qai-bg-dark);
        color: var(--qai-bg-light);
        border-color: var(--qai-bg-dark);
    }
    
    /* Help button (visible in maximized state) - full width */
    .qai-help-link {
        padding: 12px 16px;
        background-color: transparent;
        border: 1px solid var(--qai-border);
        color: var(--qai-text-primary);
        font-size: 15px;
        font-weight: 500;
        line-height: 1.4;
        font-family: inherit;
        cursor: pointer;
        border-radius: 8px;
        transition: all 0.2s ease;
        text-align: left;
        margin-top: 0;
        margin-bottom: 20px;
        display: none; /* Hidden by default */
        align-items: center;
        gap: 8px;
        width: 100%; /* Full width */
        box-sizing: border-box; /* Include padding in width */
    }
    
    .qai-help-link svg {
        width: 20px;
        height: 20px;
        flex-shrink: 0;
    }
    
    .qai-help-link:hover {
        background-color: var(--qai-bg-dark);
        color: var(--qai-bg-light);
        border-color: var(--qai-bg-dark);
    }
    
    /* Show help button when panel is expanded */
    .qai-side-panel.open .qai-help-link {
        display: flex;
    }
    
    /* Data Quality button (maximized state) - below Help link */
    .qai-data-quality-link {
        border: 1px solid var(--qai-border);
        color: var(--qai-text-primary);
        font-size: 15px;
        font-weight: 500;
        line-height: 1.4;
        font-family: inherit;
        cursor: pointer;
        border-radius: 8px;
        transition: all 0.2s ease;
        text-align: left;
        margin-top: 0;
        margin-bottom: 20px;
        display: none;
        align-items: center;
        gap: 8px;
        width: 100%;
        box-sizing: border-box;
        padding: 10px 14px;
        background-color: var(--qai-bg-light);
    }
    .qai-data-quality-link svg {
        width: 20px;
        height: 20px;
        flex-shrink: 0;
    }
    .qai-data-quality-link:hover {
        background-color: var(--qai-bg-dark);
        color: var(--qai-bg-light);
        border-color: var(--qai-bg-dark);
    }
    .qai-side-panel.open .qai-data-quality-link {
        display: flex;
    }
    
    /* Ensure header nav (Overview button) stays visible */
    .qai-header-nav {
        flex-shrink: 0;
        white-space: nowrap;
        margin-right: 0; /* Ensure button stays at right edge */
    }
    
    /* Ensure Overview button has proper spacing from right edge */
    .qai-header-nav a {
        margin-right: 0; /* No extra margin, padding in header handles spacing */
    }
    
    /* Help Panel Content (inside side panel) - hidden when minimized */
    .qai-help-panel-content {
        display: none;
        flex-direction: column;
        flex-grow: 1;
        overflow: hidden;
        margin-top: 0;
        position: relative;
        min-height: 0;
        opacity: 0;
        pointer-events: none;
    }
    
    /* Show help content only when panel is open AND visible class is added */
    .qai-side-panel.open .qai-help-panel-content.visible {
        display: flex;
        opacity: 1;
        pointer-events: auto;
    }
    
    /* Toggle between Help and Data Quality views inside help panel */
    .qai-panel-view-hidden {
        display: none !important;
    }
    .qai-help-panel-content .qai-data-quality-panel-content {
        flex-grow: 1;
        min-height: 0;
        overflow-y: auto;
        padding: 0;
    }
    .qai-help-panel-content .qai-data-quality-panel-content h2 {
        color: var(--qai-text-primary);
        font-size: 18px;
        font-weight: 600;
        margin: 0 0 16px 0;
    }
    .qai-help-panel-content .qai-data-quality-panel-content p {
        color: var(--qai-text-secondary);
        font-size: 14px;
        line-height: 1.5;
        margin: 0 0 12px 0;
    }
    .qai-help-panel-content .qai-data-quality-panel-content p:last-child {
        margin-bottom: 0;
    }
    .qai-help-panel-content .qai-data-quality-panel-content a {
        color: var(--qai-text-primary);
        text-decoration: underline;
    }
    .qai-help-panel-content .qai-data-quality-panel-content a:hover {
        color: var(--qai-bg-dark);
    }
    
    .qai-side-panel-footer {
        margin-top: auto;
        padding-top: 20px;
        border-top: 1px solid var(--qai-border);
        opacity: 0;
        pointer-events: none;
        overflow: hidden;
        max-height: 0;
        transition: opacity 0.2s ease 0.1s, max-height 0.3s ease;
    }
    
    /* Show footer only when panel is open */
    .qai-side-panel.open .qai-side-panel-footer {
        opacity: 1;
        pointer-events: auto;
        max-height: 200px;
    }
    
    .qai-side-panel-footer .data-source {
        font-size: 12px;
        color: var(--qai-text-secondary);
        line-height: 1.5;
    }
    
    .qai-side-panel-footer .data-source a {
        color: var(--qai-text-primary);
        text-decoration: underline;
    }

    /* Phase 2: Account block in side panel footer */
    .qai-account-block {
        margin-bottom: 12px;
    }
    .qai-account-block-inner {
        font-size: 13px;
        color: var(--qai-text-primary);
    }
    .qai-account-link {
        color: var(--qai-text-primary);
        text-decoration: underline;
    }
    .qai-account-link:hover {
        color: var(--qai-bg-dark);
    }
    .qai-account-email {
        display: inline-block;
        max-width: 100%;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }
    .qai-account-sep {
        color: var(--qai-text-secondary);
        margin: 0 2px;
    }

    /* Account view (Sign in / Register / Settings) in side panel */
    .qai-account-view {
        display: flex;
        flex-direction: column;
        flex-grow: 1;
        min-height: 0;
        margin-top: 0;
    }
    .qai-account-view.qai-account-view-hidden {
        display: none;
    }
    .qai-account-view-header {
        display: flex;
        justify-content: space-between;
        align-items: center;
        gap: 20px;
        margin-bottom: 16px;
        flex-shrink: 0;
    }
    .qai-account-view-title {
        font-size: 18px;
        font-weight: 600;
        color: var(--qai-text-primary);
        margin: 0;
        flex-shrink: 0;
    }
    .qai-account-view-back {
        font-size: 13px;
        background: none;
        border: none;
        color: var(--qai-text-secondary);
        cursor: pointer;
        padding: 4px 0;
        flex-shrink: 0;
        margin-left: auto;
    }
    .qai-account-view-back:hover {
        color: var(--qai-text-primary);
    }
    .qai-account-view-back.qai-account-view-close {
        font-size: 24px;
        line-height: 1;
        padding: 4px 8px;
        min-width: 36px;
        min-height: 36px;
        display: flex;
        align-items: center;
        justify-content: center;
    }
    .qai-account-view-back.qai-account-view-close:hover {
        color: var(--qai-bg-dark);
    }
    .qai-account-view-body {
        overflow-y: auto;
        flex-grow: 1;
    }
    .qai-auth-form label {
        display: block;
        font-size: 13px;
        font-weight: 500;
        color: var(--qai-text-primary);
        margin-top: 12px;
        margin-bottom: 4px;
    }
    .qai-auth-form label:first-of-type {
        margin-top: 0;
    }
    .qai-auth-form input {
        width: 100%;
        padding: 10px 12px;
        font-size: 14px;
        border: 1px solid var(--qai-border);
        border-radius: 6px;
        font-family: inherit;
        box-sizing: border-box;
    }
    .qai-auth-form input:focus {
        outline: none;
        border-color: var(--qai-border-dark);
    }
    .qai-auth-submit {
        margin-top: 16px;
        width: 100%;
        padding: 12px;
        font-size: 15px;
        font-weight: 600;
        color: var(--qai-bg-light);
        background-color: var(--qai-bg-dark);
        border: none;
        border-radius: 8px;
        cursor: pointer;
        font-family: inherit;
    }
    .qai-auth-submit:hover:not(:disabled) {
        background-color: #1a1a1a;
    }
    .qai-auth-submit:disabled {
        opacity: 0.7;
        cursor: not-allowed;
    }
    .qai-auth-forgot {
        display: inline-block;
        font-size: 12px;
        color: var(--qai-text-secondary);
        margin-top: 8px;
    }
    .qai-auth-forgot:hover {
        color: var(--qai-text-primary);
    }
    .qai-auth-switch {
        margin-top: 16px;
        margin-bottom: 0;
        font-size: 13px;
        color: var(--qai-text-secondary);
    }
    .qai-auth-switch-link {
        color: var(--qai-text-primary);
        text-decoration: underline;
    }
    .qai-auth-switch-link:hover {
        color: var(--qai-bg-dark);
    }
    .qai-auth-error {
        font-size: 13px;
        color: #c62828;
        margin-bottom: 12px;
    }
    .qai-auth-success {
        font-size: 13px;
        color: #2e7d32;
        margin-bottom: 12px;
    }
    .qai-account-settings p {
        margin: 0 0 12px;
        font-size: 14px;
    }
    .qai-account-delete {
        margin-top: 20px;
        padding-top: 16px;
        border-top: 1px solid var(--qai-border);
    }
    .qai-auth-delete {
        font-size: 13px;
        color: var(--qai-text-secondary);
        background: none;
        border: none;
        cursor: pointer;
        text-decoration: underline;
    }
    .qai-auth-delete:hover {
        color: var(--qai-text-primary);
    }
    .qai-429-signin {
        color: var(--qai-bg-dark);
        text-decoration: underline;
    }
    .qai-429-signin:hover {
        color: var(--qai-text-secondary);
    }
    
    /* === 4. MAIN CONTENT LAYOUT === */
    .qai-main-content {
        flex-grow: 1;
        height: 100%;
        overflow: hidden;
        position: relative;
        display: flex;
        align-items: center;
        justify-content: center;
        padding: 40px 20px;
    }
    
    .qai-main-content.chat-maximized {
        align-items: flex-start;
        justify-content: flex-start;
        padding: 20px;
    }
    
    .chat-container {
        display: flex;
        flex-direction: column;
        width: 100%;
        max-width: 800px;
        height: 100%;
        position: relative;
    }
    
    .qai-main-content:not(.chat-maximized) .chat-container {
        max-height: auto;
    }
    
    .qai-main-content.chat-maximized .chat-container {
        max-width: 100%;
        height: 100%;
    }
    
    /* Introduction Text */
    .qai-intro-text {
        text-align: center;
        margin-bottom: 24px;
        padding: 0 20px;
    }
    
    .qai-intro-text p {
        font-size: 18px;
        color: var(--qai-text-primary);
        line-height: 1.6;
        font-weight: 400;
    }
    
    .qai-intro-text .qai-name-bold {
        font-weight: 700;
        color: var(--qai-text-primary);
    }
    
    .qai-main-content.chat-maximized .qai-intro-text {
        display: none !important;
    }
    
    /* Data quality notice under intro (GLA wording) - contained with grey line on left and right */
    .qai-data-quality-intro {
        margin-top: 20px;
        padding: 14px 16px;
        border-left: 4px solid var(--qai-border);
        border-right: 4px solid var(--qai-border);
        background-color: var(--qai-bg-light);
        border-radius: 8px;
    }
    .qai-data-quality-intro p {
        font-size: 14px;
        color: var(--qai-text-secondary);
        line-height: 1.5;
        margin: 0 0 10px 0;
    }
    .qai-data-quality-intro p:last-child {
        margin-bottom: 0;
    }
    .qai-data-quality-intro a {
        color: var(--qai-text-primary);
        text-decoration: underline;
    }
    .qai-data-quality-intro a:hover {
        color: var(--qai-bg-dark);
    }

    /* === 5. HELP PANEL STYLING (MONOCHROMATIC - inside side panel) === */
    .qai-help-panel-content .qai-info-middle-wrapper {
        flex-grow: 1;
        position: relative;
        overflow: hidden;
        min-height: 0; /* Allow flex shrinking */
    }
    
    .qai-help-panel-content .qai-info-middle {
        height: 100%;
        overflow-y: auto;
        padding: 0;
        margin-top: 0;
        /* Text will be cropped naturally by overflow, no fade effect */
    }
    
    /* Ensure h2 doesn't get hidden - add padding to account for help button above */
    .qai-help-panel-content .qai-info-middle h2 {
        padding-top: 0;
        margin-top: 0;
        position: relative;
    }
    
    .qai-help-panel-content .qai-info-middle h2 {
        color: var(--qai-text-primary);
        font-size: 18px;
        margin-bottom: 16px;
        font-weight: 600;
        margin-top: 0;
    }
    
    /* Remove fade effects - just crop text */

    .qai-help-panel-content .qai-info-middle .example-questions-list {
        list-style: none;
        padding: 0;
        margin: 0;
        display: flex;
        flex-direction: column;
        gap: 10px;
    }
    .qai-help-panel-content .qai-info-middle .example-questions-list li {
        background-color: var(--qai-bg-light);
        color: var(--qai-text-primary);
        border: 1px solid var(--qai-border); 
        border-radius: 20px;
        padding: 10px 16px;
        cursor: pointer;
        font-size: 14px;
        font-weight: 500;
        transition: all 0.2s ease;
    }
    .qai-help-panel-content .qai-info-middle .example-questions-list li:hover {
        background-color: var(--qai-bg-dark);
        color: var(--qai-bg-light);
        border-color: var(--qai-bg-dark);
        transform: translateY(-1px);
    }
    
    .qai-info-bottom {
        flex-shrink: 0;
        height: 72px; 
        padding: 15px 20px;
        border-top: none;
        background-color: #ffffff;
        position: relative;
        z-index: 1001;
        border-bottom-left-radius: 12px;
        border-bottom-right-radius: 12px;
    }
    .qai-info-panel .data-source {
        font-size: 12px;
        color: #777;
    }
    
    /* --- Divider Column (Hidden - using burger menu now) --- */
    .qai-divider {
        display: none;
    }


    /* === 6. CHAT CONTAINER === */
    
    .message-list {
        flex-grow: 1;
        overflow-y: auto;
        display: none;
        flex-direction: column;
        gap: 8px; 
        width: 100%;
        max-width: 800px;
        margin: 0 auto;
        padding: 20px 20px 200px 10px; /* Added right padding for scrollbar, increased bottom padding for chips */
        box-sizing: border-box;
    }
    
    /* Custom scrollbar styling to prevent overlap */
    .message-list::-webkit-scrollbar {
        width: 8px;
    }
    
    .message-list::-webkit-scrollbar-track {
        background: transparent;
    }
    
    .message-list::-webkit-scrollbar-thumb {
        background: var(--qai-border-dark);
        border-radius: 4px;
    }
    
    .message-list::-webkit-scrollbar-thumb:hover {
        background: var(--qai-text-secondary);
    }
    
    .qai-main-content.chat-maximized .message-list {
        display: flex;
    }
    
   /* === NEW 7b. MESSAGE LIST FADE-OUT === */
        .chat-container::after {
            content: '';
            position: absolute;
            bottom: 0;
            left: 0;
            right: 0; 
            height: 180px; /* Increased to account for suggestion chips */
            background: linear-gradient(
                to bottom,
                rgba(255, 255, 255, 0) 0%,
                rgba(255, 255, 255, 1) 70%
            );
            pointer-events: none; /* Lets you click/scroll through it */
            z-index: 2; /* Sits above messages, but below input (z-index: 3) and chips (z-index: 5) */
        }
    
    /* === 7. THEMED CHAT BUBBLES (UPDATED) === */
    
    .message-container {
        display: flex;
        flex-direction: column;
        gap: 5px;
        width: 100%; 
    }
    .message-container.bot {
        align-items: flex-start;
        align-self: flex-start;
    }
    .message-container.user {
        align-items: flex-end;
        align-self: flex-end;
        width: 75%; 
    }

    .message-avatar {
        width: 36px;
        height: 36px;
        border-radius: 50%;
        flex-shrink: 0;
        background-size: cover;
        background-position: center;
        background-repeat: no-repeat;
        box-shadow: 0 1px 3px rgba(0,0,0,0.1);
        margin-left: 5px; 
    }
    .message-container.user .message-avatar {
        margin-left: 0;
        margin-right: 5px;
    }
    
    .message-container.bot .message-avatar {
        background-color: #ffffff; /* UPDATED: White background */
        /* UPDATED: Make sure to replace the placeholder below
          with your actual coloured logo URL 
        */
        background-image: url('https://quixotifai.com/wp-content/uploads/Quixotifai-Logo-no-text.png');
        background-size: 100%; /* UPDATED: Show full logo */
        border: 1px solid #e0e0e0; /* UPDATED: Light grey border */
    }
    .message-container.user .message-avatar {
        background-color: var(--qai-bg-dark);
        background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='white'%3E%3Cpath d='M12 12c2.21 0 4-1.79 4-4s-1.79-4-4-4-4 1.79-4 4 1.79 4 4 4zm0 2c-2.67 0-8 1.34-8 4v2h16v-2c0-2.66-5.33-4-8-4z'/%3E%3C/svg%3E");
        background-size: 20px;
    }

    .message {
        padding: 18px 22px;
        border-radius: 18px; 
        word-wrap: break-word;
        line-height: 1.6;
        font-size: 15px;
        width: 100%; 
        box-shadow: 0 2px 8px var(--qai-shadow);
    }
    
    .message-container.user .message {
        background-color: var(--qai-bg-dark);
        color: var(--qai-bg-light);
        border-bottom-right-radius: 5px; 
        box-shadow: 0 4px 12px var(--qai-shadow);
    }
    
    .message-container.bot .message {
        background-color: var(--qai-hover);
        color: var(--qai-text-primary);
        border-bottom-left-radius: 5px; 
        box-shadow: 0 2px 6px var(--qai-shadow);
    }
    

    @keyframes bot-message-fade-in {
        from {
            opacity: 0;
            transform: translateY(10px);
        }
        to {
            opacity: 1;
            transform: translateY(0);
        }
    }
    .new-bot-message {
        animation: bot-message-fade-in 0.4s ease-out;
    }
    
    
    /* === 8. THEMED SUGGESTION CHIPS === */
    .suggestion-chips {
        position: absolute;
        bottom: 100px; 
        left: 50%;
        transform: translateX(-50%);
        max-width: 800px;
        width: 90%;
        z-index: 5;
        
        display: flex;
        flex-wrap: wrap;
        gap: 10px;
        padding: 0; 
        background-color: transparent;
        border-top: none;
        flex-shrink: 0;
        justify-content: center;
        transition: bottom 0.2s ease;
    }
    
    /* Chips position adjusts based on input height - will be set dynamically by JS */
    .qai-main-content.chat-maximized .suggestion-chips {
        bottom: 100px; /* Default, will be adjusted by JS */
    }
    .chip {
        background-color: var(--qai-bg-light);
        color: var(--qai-text-primary);
        border: 1px solid var(--qai-border); 
        border-radius: 20px;
        padding: 8px 16px;
        cursor: pointer;
        font-size: 14px;
        font-weight: 500;
        transition: all 0.2s ease;
        box-shadow: 0 2px 6px rgba(0,0,0,0.1);
    }
    .chip:hover {
        background-color: var(--qai-bg-dark); 
        color: var(--qai-bg-light);
        border-color: var(--qai-bg-dark);
        box-shadow: 0 4px 8px rgba(0,0,0,0.15);
    }
    
    /* === 9. THEMED INPUT AREA (FLOATING) === */
    .input-form {
        display: flex;
        gap: 10px;
        align-items: center; 
        
        position: absolute;
        bottom: 20px; 
        left: 0;
        right: 0;
        width: 100%;
        max-width: 800px;
        margin: 0 auto;
        z-index: 3;
        
        background-color: var(--qai-bg-light); 
        border-radius: 24px;
        box-shadow: 0 4px 12px rgba(0,0,0,0.1);
        border: 1px solid var(--qai-border);
        
        padding: 10px 10px 10px 20px;
        min-height: 62px; 
    }
    
    .qai-main-content:not(.chat-maximized) .input-form {
        position: relative;
        bottom: auto;
        margin-top: 20px;
        width: 100%;
    }
    
    .input-form textarea {
        flex-grow: 1;
        border: none;
        padding: 10px 0; 
        font-size: 16px;
        font-family: "Montserrat", sans-serif;
        transition: height 0.2s ease;
        resize: none; 
        overflow-y: auto;
        line-height: 1.5;
        background: transparent;
        color: var(--qai-text-primary);
    }
    
    /* Initial state - 3 lines */
    .qai-main-content:not(.chat-maximized) .input-form textarea {
        min-height: 80px;
        height: 80px;
        max-height: none;
    }
    
    /* Maximized state - 2 lines default, max 10 lines */
    .qai-main-content.chat-maximized .input-form textarea {
        min-height: 48px; /* 2 lines: 16px * 1.5 * 2 = 48px */
        max-height: 240px; /* 10 lines: 16px * 1.5 * 10 = 240px */
        height: 48px; /* Default 2 lines */
    }
    
    .input-form textarea::placeholder {
        color: var(--qai-text-secondary);
    }
    
    .input-form textarea:focus {
        outline: none;
    }
    
    .input-form button {
        border: none;
        background-color: var(--qai-bg-dark);
        color: var(--qai-bg-light);
        width: 42px; 
        height: 42px;
        padding: 0;
        border-radius: 50%; 
        font-size: 0; 
        font-weight: 600;
        cursor: pointer;
        transition: background-color 0.2s;
        flex-shrink: 0;
        align-self: center;
        
        background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='white' width='24px' height='24px'%3E%3Cpath d='M2.01 21L23 12 2.01 3 2 10l15 2-15 2z'/%3E%3C/svg%3E");
        background-repeat: no-repeat;
        background-position: center;
        margin: 0;
    }
    .input-form button:hover {
        background-color: #1a1a1a;
    }
    
    /* === 10. THEMED HELP PANEL === */
    .message-container.help-panel .message {
        background-color: var(--qai-bg-secondary);
        color: var(--qai-text-primary);
        border-left: 4px solid var(--qai-border-dark);
    }
    .message-container.help-panel ul { margin-left: 20px; padding-top: 5px; }
    .message-container.help-panel li { margin-bottom: 8px; }
    .message-container.help-panel p { margin-bottom: 10px; }
    .message-container.help-panel p:last-child { margin-bottom: 0; }
    .message-container.help-panel strong { color: var(--qai-text-primary); }


    /* === 10b. NEW: APPLICATION DETAILS (REPLACED) === */
    .message-container.application-details-button .message {
        background-color: var(--qai-bg-secondary);
        border-left: 4px solid var(--qai-border-dark);
    }
    .qai-view-details-button {
        background-color: var(--qai-bg-dark);
        color: var(--qai-bg-light);
        border: none;
        border-radius: 8px;
        padding: 12px 18px;
        font-size: 15px;
        font-weight: 600;
        cursor: pointer;
        transition: all 0.2s ease;
        margin-top: 10px;
    }
    .qai-view-details-button:hover {
        background-color: #1a1a1a;
        box-shadow: 0 4px 10px var(--qai-shadow);
        transform: translateY(-1px);
    }

    /* Methodology link: "(?) How was this calculated?" – bottom-right of data bubbles */
    .qai-methodology-link {
        display: block;
        margin-top: 10px;
        text-align: right;
        font-size: 11px;
        color: #5a6c7d;
        cursor: pointer;
        text-decoration: none;
    }
    .qai-methodology-link:hover {
        text-decoration: underline;
        color: #3d4f5f;
    }

    /* === 11. ANIMATIONS (LOADER & SHIMMER) === */
    .message-container.loader-message .message {
        padding: 10px 18px; 
    }
    .loader {
        display: flex;
        gap: 8px;
        align-items: center;
    }
    .loader-dot {
        width: 10px;
        height: 10px;
        border-radius: 50%;
        animation: loader-bounce 1.4s infinite ease-in-out both;
    }
    .loader-dot:nth-child(1) { background-color: var(--qai-text-secondary); animation-delay: -0.32s; }
    .loader-dot:nth-child(2) { background-color: var(--qai-border-dark); animation-delay: -0.16s; }
    .loader-dot:nth-child(3) { background-color: var(--qai-text-primary); }
    
    @keyframes loader-bounce {
        0%, 80%, 100% { transform: scale(0); }
        40% { transform: scale(1.0); }
    }
    
    /* === 12. MOBILE RESPONSIVE STYLES (GEMINI-STYLE LAYOUT) === */
    @media (max-width: 768px) {
        /* --- PAGE WRAPPER: No shifting on mobile --- */
        .qai-page-wrapper {
            left: 0;
            width: 100%;
            transition: none; /* No transitions on mobile */
        }
        
        /* Page wrapper should NOT shift when panel opens on mobile */
        body.side-panel-open .qai-page-wrapper {
            left: 0;
            width: 100%;
        }
        
        /* --- HEADER: Three-point layout with centered logo --- */
        .qai-header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            padding: 10px 15px;
            position: relative;
        }
        
        .qai-header-left {
            flex: 0 0 auto;
            min-width: 40px;
            z-index: 2; /* Above centered content */
        }
        
        /* Show mobile burger on mobile */
        .qai-mobile-burger {
            display: flex;
        }
        
        /* Center the logo absolutely */
        .qai-header-center {
            position: absolute;
            left: 50%;
            top: 50%;
            transform: translate(-50%, -50%);
            display: flex;
            align-items: center;
            gap: 8px;
        }
        
        .qai-header-title {
            font-size: 20px;
            font-weight: 700;
            margin: 0;
            color: var(--qai-text-primary);
            line-height: 1;
        }
        
        .qai-header-logo {
            height: 28px;
            width: auto;
            display: block;
        }
        
        .qai-header-nav {
            flex: 0 0 auto;
            z-index: 2; /* Above centered content */
        }
        
        /* Show Overview link on mobile (styled as compact button) */
        .qai-header-nav a {
            display: inline-block;
            font-size: 13px;
            padding: 6px 12px;
            border-radius: 6px;
        }
        
        /* Hide the ? info toggle on mobile (using burger menu instead) */
        .qai-header-nav .qai-info-panel-toggle {
            display: none;
        }
        
        /* --- MOBILE OVERLAY: Full-screen backdrop --- */
        .qai-mobile-overlay {
            display: block; /* Enable on mobile */
        }
        
        /* Show overlay when side panel is open */
        body.side-panel-open .qai-mobile-overlay {
            opacity: 1;
            visibility: visible;
        }
        
        /* --- SIDE PANEL: Slide-in drawer from left --- */
        .qai-side-panel {
            width: 70vw;
            max-width: 320px;
            height: 100vh;
            transform: translateX(-100%); /* Hidden off-screen by default */
            transition: transform 0.3s ease;
            z-index: 999;
            box-shadow: none;
        }
        
        /* Slide in when open */
        .qai-side-panel.open {
            transform: translateX(0);
            width: 70vw;
            max-width: 320px;
            box-shadow: 4px 0 20px rgba(0, 0, 0, 0.15);
        }
        
        /* Side panel content adjustments for mobile */
        .qai-side-panel-content {
            width: 100%;
            padding: 20px;
            padding-top: 70px; /* Space for header (48px) + extra padding */
        }
        
        .qai-side-panel.open .qai-side-panel-content {
            width: 100%;
        }
        
        /* Hide the side panel burger on mobile (using header burger instead) */
        .qai-side-panel-burger {
            display: none;
        }
        
        /* Help icon should also be hidden on mobile since we use the header burger */
        .qai-help-icon {
            display: none;
        }
        
        .qai-data-quality-icon {
            display: none;
        }
        
        .qai-account-icons {
            display: none !important;
        }
        
        /* Show help link button prominently on mobile */
        .qai-side-panel.open .qai-help-link {
            display: flex;
            margin-top: 0;
            margin-bottom: 15px;
        }
        
        .qai-side-panel.open .qai-data-quality-link {
            display: flex;
            margin-top: 0;
            margin-bottom: 15px;
        }
        
        /* Adjust side panel content padding for logged-in users (WordPress admin bar) */
        body.logged-in .qai-side-panel-content {
            padding-top: 115px; /* Header (48px) + WP admin bar (46px) + padding */
        }
        
        /* --- MAIN CONTENT: Stationary, no shifting --- */
        .qai-main-content {
            padding: 20px 10px;
            /* Main content stays stationary when panel opens */
        }
        
        /* --- CHAT STYLES --- */
        .chat-container {
            padding-right: 0;
            padding-bottom: 0;
        }
        
        /* Reduce fade-out gradient height on mobile */
        .chat-container::after {
            height: 140px;
            background: linear-gradient(
                to bottom,
                rgba(255, 255, 255, 0) 0%,
                rgba(255, 255, 255, 1) 60%
            );
        }
        
        .message-container { 
            max-width: 92%; 
        }
        
        .message-container.user { 
            width: 88%; 
        }
        
        .message-list {
            padding: 10px 12px 220px 10px; /* Increased bottom padding for chips + input + buffer */
            box-sizing: border-box;
            scroll-behavior: smooth; /* Smooth scrolling on mobile */
        }
        
        /* --- CHARTS: Centered, dynamic sizing on mobile --- */
        .qai-chart-container {
            width: 100%;
            height: 300px; /* Good height for charts with bottom legend */
            min-height: 280px;
            max-height: 400px;
            margin: 15px auto; /* Center horizontally */
            padding: 10px;
            background: #fff;
            border-radius: 8px;
            display: flex;
            justify-content: center;
            align-items: center;
        }
        
        /* ApexCharts uses divs, ensure proper sizing */
        .qai-chart-container > div {
            width: 100% !important;
            height: 100% !important;
        }
        
        /* Make bot messages with charts wider on mobile */
        .message-container.bot .message {
            padding: 15px 12px;
        }
        
        /* --- TABLES: Responsive with text wrapping + scroll fallback --- */
        .message {
            overflow-x: auto;
            -webkit-overflow-scrolling: touch;
        }
        
        .message table {
            display: table !important;
            width: 100%;
            min-width: 250px;
            margin: 15px 0;
            font-size: 13px;
            border-radius: 8px;
            border: 1px solid var(--qai-border);
            box-shadow: 0 2px 8px rgba(0,0,0,0.08);
            border-collapse: separate;
            border-spacing: 0;
            table-layout: auto; /* Auto layout allows wrapping */
        }
        
        .message table thead {
            display: table-header-group;
        }
        
        .message table tbody {
            display: table-row-group;
        }
        
        .message table tr {
            display: table-row;
        }
        
        .message table th {
            display: table-cell;
            padding: 10px 10px;
            font-size: 11px;
            font-weight: 600;
            background-color: var(--qai-bg-secondary);
            color: var(--qai-text-primary);
            border-bottom: 2px solid var(--qai-border);
            text-align: left;
            white-space: normal; /* Allow header wrapping */
            word-wrap: break-word;
            line-height: 1.3;
            min-width: 50px;
        }
        
        /* All table cells: left-aligned text with wrapping */
        .message table th,
        .message table td {
            display: table-cell;
            padding: 10px 10px;
            font-size: 13px;
            text-align: left !important; /* Force left alignment for all columns */
            white-space: normal !important; /* Force text wrapping */
            word-wrap: break-word;
            overflow-wrap: break-word;
            line-height: 1.4;
            vertical-align: top;
        }
        
        .message table th {
            font-weight: 600;
            background-color: var(--qai-bg-secondary);
            color: var(--qai-text-primary);
            border-bottom: 2px solid var(--qai-border);
        }
        
        .message table td {
            border-bottom: 1px solid var(--qai-border);
            color: var(--qai-text-primary);
            background-color: var(--qai-bg-light);
        }
        
        /* First column: slightly narrower to give more room to definitions */
        .message table th:first-child,
        .message table td:first-child {
            width: 35%;
            min-width: 80px;
            max-width: 120px;
        }
        
        /* Second/Definition column: allow more space and wrapping */
        .message table th:last-child,
        .message table td:last-child {
            width: 65%;
        }
        
        .message table tbody tr:last-child td {
            border-bottom: none;
        }
        
        .message table tbody tr:nth-child(even) td {
            background-color: var(--qai-bg-secondary);
        }
        
        /* --- ACCORDION: Cleaner mobile styling --- */
        .qai-accordion {
            margin-top: 15px;
            border-radius: 8px;
            overflow: hidden;
        }
        
        .qai-accordion-header {
            padding: 14px 15px;
            font-size: 13px;
        }
        
        .qai-accordion-content {
            padding: 0;
        }
        
        .qai-accordion-content table {
            display: table !important;
            font-size: 12px;
            width: 100%;
            table-layout: fixed;
        }
        
        /* Accordion table cells: all left-aligned with wrapping */
        .qai-accordion-content th,
        .qai-accordion-content td {
            display: table-cell;
            padding: 10px 12px;
            font-size: 12px;
            text-align: left !important;
            white-space: normal !important;
            word-wrap: break-word;
            overflow-wrap: break-word;
            line-height: 1.4;
            vertical-align: top;
        }
        
        .qai-accordion-content th {
            font-size: 11px;
            font-weight: 600;
            background-color: var(--qai-bg-secondary);
        }
        
        /* First column: field names */
        .qai-accordion-content th:first-child,
        .qai-accordion-content td:first-child {
            width: 40%;
            min-width: 80px;
            max-width: 130px;
        }
        
        /* Last column: values/definitions */
        .qai-accordion-content th:last-child,
        .qai-accordion-content td:last-child {
            width: 60%;
        }
        
        /* --- HOUSING UNIT BREAKDOWN: Nested accordion + detail table with column nav --- */
        .qai-housing-breakdown-group {
            margin-left: 12px;
        }
        .qai-housing-breakdown-group .qai-accordion-content {
            padding: 8px 0 0 8px;
        }
        .qai-housing-detail-table-scroll {
            overflow-x: auto;
            overflow-y: visible;
            -webkit-overflow-scrolling: touch;
            scroll-behavior: smooth;
            width: 100%;
            max-width: 100%;
            margin-top: 12px;
            margin-bottom: 8px;
        }
        .qai-housing-detail-table .qai-housing-detail-col,
        .qai-housing-detail-table th,
        .qai-housing-detail-table td {
            min-width: 10rem;
        }
        .qai-housing-detail-table th,
        .qai-housing-detail-table td {
            padding: 8px 10px;
            font-size: 12px;
            white-space: normal;
            word-wrap: break-word;
        }
        
        /* --- INPUT FORM --- */
        .input-form {
            width: 100%;
            bottom: 0;
            padding: 10px 10px 10px 15px;
            border-radius: 0;
            border: none;
            border-top: 1px solid #e0e0e0;
            box-shadow: none;
        }
        
        /* --- SUGGESTION CHIPS: Horizontal Scroll on Mobile --- */
        .suggestion-chips {
            position: absolute;
            left: 0;
            right: 0;
            bottom: 70px;
            width: 100%;
            max-width: 100%;
            transform: none;
            padding: 10px 0;
            
            /* Horizontal scroll layout */
            display: flex;
            flex-wrap: nowrap;
            gap: 8px;
            overflow-x: auto;
            overflow-y: hidden;
            -webkit-overflow-scrolling: touch; /* Smooth scrolling on iOS */
            scroll-behavior: smooth;
            
            /* Hide scrollbar but keep functionality */
            scrollbar-width: none; /* Firefox */
            -ms-overflow-style: none; /* IE/Edge */
            
            /* Add padding for scroll indicators and edge chips */
            padding-left: 35px;
            padding-right: 35px;
        }
        
        /* Hide scrollbar for WebKit browsers */
        .suggestion-chips::-webkit-scrollbar {
            display: none;
            height: 0;
            width: 0;
        }
        
        /* Mobile chips styling */
        .suggestion-chips .chip {
            flex-shrink: 0; /* Prevent chips from shrinking */
            white-space: nowrap; /* Keep text on one line */
            padding: 10px 16px;
            font-size: 13px;
        }
        
        /* Scroll indicator container - wraps suggestion chips */
        .chat-container {
            position: relative;
        }
        
        /* Left scroll fade/mask indicator */
        .suggestion-chips::before {
            content: '';
            position: fixed;
            left: 0;
            bottom: 70px;
            width: 30px;
            height: 44px;
            background: linear-gradient(to right, 
                rgba(255, 255, 255, 1) 0%, 
                rgba(255, 255, 255, 0) 100%);
            pointer-events: none;
            z-index: 10;
            opacity: 0;
            transition: opacity 0.2s ease;
        }
        
        /* Right scroll fade/mask indicator */
        .suggestion-chips::after {
            content: '';
            position: fixed;
            right: 0;
            bottom: 70px;
            width: 30px;
            height: 44px;
            background: linear-gradient(to left, 
                rgba(255, 255, 255, 1) 0%, 
                rgba(255, 255, 255, 0) 100%);
            pointer-events: none;
            z-index: 10;
        }
        
        /* Show left indicator when scrolled (controlled via JS class) */
        .suggestion-chips.scrolled-left::before {
            opacity: 1;
        }
        
        /* Hide right indicator when scrolled to end (controlled via JS class) */
        .suggestion-chips.scrolled-end::after {
            opacity: 0;
        }
        
        /* --- HELP PANEL --- */
        .qai-help-panel {
            width: 95%;
            max-height: 90vh;
        }
        
        /* --- TOUCH FEEDBACK: Active states for mobile interactions --- */
        .chip:active {
            transform: scale(0.95);
            opacity: 0.8;
        }
        
        .input-form button:active {
            transform: scale(0.9);
            opacity: 0.8;
        }
        
        .qai-mobile-burger:active {
            opacity: 0.6;
        }
        
        .qai-header-nav a:active {
            transform: scale(0.95);
            opacity: 0.8;
        }
        
        .qai-help-link:active,
        .qai-accordion-header:active {
            opacity: 0.7;
        }
        
        .example-questions-list li:active {
            transform: scale(0.98);
            opacity: 0.8;
        }
        
        /* --- INTRO TEXT: More compact on mobile --- */
        .qai-intro-text {
            padding: 0 15px;
            margin-bottom: 20px;
        }
        
        .qai-intro-text p {
            font-size: 16px;
            line-height: 1.5;
        }
    }
    
    @media (min-width: 769px) {
        /* Hide mobile-only elements on desktop */
        .qai-mobile-burger {
            display: none !important;
        }
        
        .qai-mobile-overlay {
            display: none !important;
        }
        
        .qai-header-nav .qai-info-panel-toggle {
            display: none;
        }
        
        .qai-info-panel .qai-info-panel-toggle {
            display: none !important;
        }
    }


    /* ==================================================
      === 12.5. NEW: EXPLORER PANEL STYLES ===
      ==================================================
    */
    
    /* Explorer Panel - slides in from right */
    .qai-explorer-panel {
        position: fixed;
        top: 0;
        right: 0;
        width: var(--explorer-panel-width);
        max-width: 60vw;
        min-width: 400px;
        height: 100vh;
        background-color: var(--qai-bg-light);
        border-left: 1px solid var(--qai-border);
        z-index: 998; /* Below header (1000) but above main content */
        transform: translateX(100%);
        transition: transform 0.3s ease;
        display: flex;
        flex-direction: column;
        overflow: hidden;
    }
    
    body.logged-in .qai-explorer-panel {
        top: 32px;
        height: calc(100vh - 32px);
    }
    
    @media (max-width: 782px) {
        body.logged-in .qai-explorer-panel {
            top: 46px;
            height: calc(100vh - 46px);
        }
    }
    
    /* Panel open state */
    .qai-explorer-panel.open {
        transform: translateX(0);
    }
    
    /* Explorer Panel Header */
    .qai-explorer-header {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 16px 24px;
        border-bottom: 1px solid var(--qai-border);
        flex-shrink: 0;
        background-color: var(--qai-bg-light);
        z-index: 1;
    }
    
    .qai-explorer-header h2 {
        font-size: 20px;
        font-weight: 600;
        color: var(--qai-text-primary);
        margin: 0;
    }
    .qai-explorer-header-title-wrap {
        display: inline-flex;
        align-items: center;
        gap: 10px;
    }
    .qai-explorer-header-icon {
        width: 22px;
        height: 22px;
        flex-shrink: 0;
        color: var(--qai-text-primary);
    }
    .qai-explorer-close {
        font-size: 28px;
        font-weight: 300;
        color: var(--qai-text-secondary);
        cursor: pointer;
        line-height: 1;
        transition: color 0.2s;
        background: none;
        border: none;
        padding: 0;
        width: 32px;
        height: 32px;
        display: flex;
        align-items: center;
        justify-content: center;
    }
    
    .qai-explorer-close:hover {
        color: var(--qai-text-primary);
    }
    
    /* Explorer Panel Body */
    .qai-explorer-body {
        display: flex;
        flex-grow: 1;
        overflow: hidden;
    }
    
    /* Explorer Panel Tabs */
    .qai-explorer-tabs {
        flex-shrink: 0;
        width: 200px;
        background: var(--qai-bg-secondary);
        border-right: 1px solid var(--qai-border);
        padding: 16px 0;
        overflow-y: auto;
    }
    
    .qai-explorer-tab {
        padding: 12px 20px;
        font-size: 15px;
        font-weight: 500;
        color: var(--qai-text-primary);
        cursor: pointer;
        border-left: 4px solid transparent;
        transition: all 0.2s ease;
    }
    
    .qai-explorer-tab:hover {
        background: var(--qai-hover);
    }
    
    .qai-explorer-tab.qai-tab-active {
        background: var(--qai-bg-light);
        color: var(--qai-text-primary);
        font-weight: 600;
        border-left: 4px solid var(--qai-text-primary);
    }
    
    /* Explorer Panel Content */
    .qai-explorer-content {
        flex-grow: 1;
        min-width: 0;
        padding: 24px;
        overflow-y: auto;
        overflow-x: auto;
    }
    
    .qai-explorer-content [data-tab-id] {
        display: none;
    }
    
    .qai-explorer-content [data-tab-id].qai-tab-pane-active {
        display: block;
    }
    
    /* Chart mode styles */
    .qai-explorer-chart-context {
        margin-bottom: 20px;
        padding-bottom: 16px;
        border-bottom: 1px solid var(--qai-border);
    }

    .qai-explorer-context-text {
        font-size: 14px;
        color: var(--qai-text-secondary);
        line-height: 1.5;
        margin: 0;
    }

    .qai-explorer-chart-container {
        height: 400px;
        width: 100%;
        margin-bottom: 24px;
        min-height: 400px;
    }

    .qai-explorer-table-container {
        overflow-x: auto;
        margin-top: 24px;
    }

    .qai-explorer-data-table {
        width: 100%;
        border-collapse: collapse;
        font-size: 14px;
        background-color: var(--qai-bg-light);
        border: 1px solid var(--qai-border);
        border-radius: 8px;
        overflow: hidden;
        box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
    }

    .qai-explorer-data-table thead {
        background-color: var(--qai-bg-secondary);
    }

    .qai-explorer-data-table th {
        padding: 12px 16px;
        text-align: left;
        font-weight: 600;
        color: var(--qai-text-primary);
        border-bottom: 2px solid var(--qai-border-dark);
        font-size: 14px;
    }

    .qai-explorer-data-table td {
        padding: 12px 16px;
        border-bottom: 1px solid var(--qai-border);
        color: var(--qai-text-primary);
        vertical-align: top;
        line-height: 1.4;
    }

    .qai-explorer-data-table tbody tr:last-child td {
        border-bottom: none;
    }

    .qai-explorer-data-table tbody tr:hover {
        background-color: var(--qai-hover);
    }

    .qai-explorer-data-table tbody tr:nth-child(even) td {
        background-color: var(--qai-bg-secondary);
    }

    /*
     * Explorer panel content typography standard
     * Use these sizes for all Explorer content (charts, app details, methodology, docs) for consistency:
     * - Body/paragraph/table text: 14px
     * - Section heading (h2): 22px
     * - Subheader (h3): 18px
     * See .qai-explorer-context-text, .qai-explorer-data-table, .qai-explorer-content h2, .app-details-subheader.
     */

    /* === Document content (User Guide, Release Notes, Methodology) in Explorer === */
    .qai-explorer-doc-content {
        font-family: "Montserrat", sans-serif;
        font-size: 14px;
        color: var(--qai-text-primary);
        background-color: var(--qai-bg-light);
        padding: 20px 0;
        line-height: 1.6;
        overflow-y: auto;
        max-height: 100%;
    }
    .qai-explorer-doc-content h1 {
        font-size: 22px;
        font-weight: 600;
        margin: 0 0 1rem;
        color: var(--qai-text-primary);
    }
    .qai-explorer-doc-content h2 {
        font-size: 22px;
        font-weight: 600;
        margin: 1.5rem 0 0.75rem;
        color: var(--qai-text-primary);
    }
    .qai-explorer-doc-content h3 {
        font-size: 18px;
        font-weight: 600;
        margin: 1.25rem 0 0.5rem;
        color: var(--qai-text-primary);
    }
    .qai-explorer-doc-content p {
        font-size: 14px;
        margin: 0 0 0.75rem;
        color: var(--qai-text-primary);
    }
    .qai-explorer-doc-content ul, .qai-explorer-doc-content ol {
        margin: 0 0 0.75rem 1.5rem;
        font-size: 14px;
    }
    .qai-explorer-doc-content li {
        margin: 0.25rem 0;
    }
    .qai-explorer-doc-content a {
        color: var(--qai-bg-dark);
        text-decoration: underline;
    }
    .qai-explorer-doc-content a:hover {
        color: var(--qai-text-secondary);
    }
    .qai-explorer-doc-content hr {
        border: none;
        border-top: 1px solid var(--qai-border);
        margin: 1.5rem 0;
    }
    .qai-doc-new-pill {
        display: inline-block;
        font-size: 0.7rem;
        font-weight: 600;
        padding: 2px 8px;
        margin-left: 6px;
        border-radius: 999px;
        background-color: #219ebc;
        color: var(--qai-bg-light);
        vertical-align: middle;
    }

    /* === Weekly News (Explorer Panel) === */
    .qai-weekly-news-masthead {
        display: flex;
        align-items: flex-start;
        justify-content: space-between;
        gap: 20px;
        padding: 20px 0 16px;
        border-bottom: 2px solid var(--qai-text-primary);
        margin-bottom: 24px;
        flex-wrap: wrap;
    }
    .qai-weekly-news-masthead-left {
        flex-shrink: 0;
    }
    .qai-weekly-news-logo {
        width: 56px;
        height: auto;
        display: block;
    }
    .qai-weekly-news-masthead-center {
        flex-grow: 1;
        min-width: 140px;
        text-align: center;
    }
    .qai-weekly-news-title {
        font-family: Montserrat, sans-serif;
        font-size: 28px;
        font-weight: 700;
        color: #000;
        margin: 0 0 4px 0;
        letter-spacing: 0.02em;
    }
    .qai-weekly-news-title .qai-brand-q {
        color: #000;
    }
    .qai-weekly-news-title .qai-brand-ai {
        color: #2d2d2d;
    }
    .qai-weekly-news-authority {
        font-size: 14px;
        color: var(--qai-text-secondary);
        margin: 0;
        font-weight: 500;
    }
    .qai-weekly-news-authority-badge {
        display: inline-block;
        background-color: var(--qai-primary, #0d9488);
        color: #fff;
        padding: 4px 12px;
        border-radius: 20px;
        font-weight: 600;
    }
    .qai-weekly-news-daterange {
        font-size: 13px;
        color: var(--qai-text-secondary);
        margin: 8px 0 0 0;
    }
    .qai-weekly-news-masthead-right {
        text-align: right;
        flex-shrink: 0;
    }
    .qai-weekly-news-timestamp-block {
        display: flex;
        flex-direction: column;
        align-items: flex-end;
        font-size: 13px;
        color: var(--qai-text-secondary);
        line-height: 1.4;
    }
    .qai-weekly-news-timestamp-line1,
    .qai-weekly-news-timestamp-line2,
    .qai-weekly-news-timestamp-line3 {
        display: block;
    }
    .qai-weekly-news-timestamp-line1 {
        font-weight: 600;
        color: var(--qai-text-primary);
    }
    .qai-weekly-news-body {
        padding: 0 24px;
    }
    .qai-weekly-news-section {
        margin-bottom: 32px;
    }
    .qai-weekly-news-section-title {
        font-size: 18px;
        font-weight: 600;
        color: var(--qai-text-primary);
        margin: 0 0 16px 0;
        padding-bottom: 8px;
        border-bottom: 1px solid var(--qai-border);
    }
    .qai-weekly-news-article {
        font-size: 14px;
        line-height: 1.6;
        color: var(--qai-text-primary);
        margin-bottom: 16px;
    }
    .qai-weekly-news-article p {
        margin: 0 0 8px 0;
    }
    .qai-weekly-news-accordion {
        margin-top: 12px;
    }
    .qai-weekly-news-accordion-item {
        border: 1px solid var(--qai-border);
        border-radius: 6px;
        margin-bottom: 8px;
        overflow: hidden;
        background: var(--qai-bg-light);
    }
    .qai-weekly-news-accordion-summary {
        padding: 10px 14px;
        font-size: 14px;
        font-weight: 500;
        color: var(--qai-text-primary);
        cursor: pointer;
        list-style: none;
        background: var(--qai-bg-secondary);
    }
    .qai-weekly-news-accordion-summary::-webkit-details-marker {
        display: none;
    }
    .qai-weekly-news-accordion-summary::before {
        content: "▶ ";
        font-size: 10px;
        margin-right: 8px;
    }
    .qai-weekly-news-accordion-item[open] .qai-weekly-news-accordion-summary::before {
        content: "▼ ";
    }
    .qai-weekly-news-accordion-content {
        padding: 12px 16px;
        overflow-x: auto;
    }
    .qai-weekly-news-table {
        width: 100%;
        border-collapse: collapse;
        font-size: 13px;
    }
    .qai-weekly-news-table th,
    .qai-weekly-news-table td {
        padding: 8px 12px;
        text-align: left;
        border-bottom: 1px solid var(--qai-border);
        color: var(--qai-text-primary);
    }
    .qai-weekly-news-table th {
        font-weight: 600;
        background: var(--qai-bg-secondary);
    }
    .qai-weekly-news-app-ref {
        font-family: inherit;
        font-size: 13px;
        font-weight: 600;
        color: var(--qai-text-primary);
        background: var(--qai-bg-secondary);
        border: 1px solid var(--qai-border-dark);
        border-radius: 4px;
        padding: 6px 10px;
        cursor: pointer;
        transition: background 0.2s, border-color 0.2s;
    }
    .qai-weekly-news-app-ref:hover {
        background: rgba(13, 148, 136, 0.15);
        border-color: var(--qai-primary, #0d9488);
        color: var(--qai-primary, #0d9488);
    }
    .qai-dev-type-major {
        background-color: rgba(13, 148, 136, 0.2);
        padding: 2px 6px;
        border-radius: 4px;
        font-weight: 600;
    }
    @media (max-width: 768px) {
        .qai-weekly-news-masthead {
            flex-direction: column;
            align-items: flex-start;
        }
        .qai-weekly-news-masthead-right {
            text-align: left;
        }
        .qai-weekly-news-title {
            font-size: 22px;
        }
    }

    /* Unit search Explorer panel */
    .qai-unit-search-banner {
        background: rgba(33, 158, 188, 0.15);
        border-left: 4px solid var(--qai-primary, #219ebc);
        padding: 12px 16px;
        margin-bottom: 20px;
        font-size: 14px;
        color: var(--qai-text-primary);
    }
    .qai-unit-search-body {
        padding: 0;
    }
    .qai-unit-search-section-title {
        font-size: 16px;
        font-weight: 700;
        margin: 0 0 8px 0;
        color: var(--qai-text-primary);
    }
    .qai-unit-search-overview-card {
        margin-bottom: 20px;
        border: 1px solid var(--qai-border);
        border-radius: 8px;
        overflow: hidden;
    }
    .qai-unit-search-overview-content {
        padding: 16px;
        font-size: 14px;
        line-height: 1.6;
        color: var(--qai-text-primary);
    }
    .qai-unit-search-overview-content p {
        margin: 0 0 10px 0;
    }
    .qai-unit-search-overview-content p:last-child {
        margin-bottom: 0;
    }
    .qai-unit-search-map {
        height: 320px;
        width: 100%;
        margin-bottom: 8px;
        border-radius: 8px;
        border: 1px solid var(--qai-border);
    }
    .qai-map-legend {
        display: flex;
        flex-wrap: wrap;
        gap: 12px 20px;
        margin-bottom: 24px;
        font-size: 13px;
        color: var(--qai-text-primary);
    }
    .qai-map-legend-item {
        display: inline-flex;
        align-items: center;
        gap: 6px;
    }
    .qai-map-legend-swatch {
        width: 14px;
        height: 14px;
        border-radius: 4px;
        flex-shrink: 0;
        border: 1px solid rgba(0, 0, 0, 0.15);
    }
    .qai-unit-search-marker-wrapper {
        background: transparent !important;
        border: none !important;
    }
    .qai-unit-search-marker-pin {
        position: relative;
        width: 24px;
        height: 24px;
        box-sizing: border-box;
    }
    .qai-unit-search-marker-pin::before {
        content: '';
        position: absolute;
        top: 0;
        left: 50%;
        transform: translateX(-50%);
        width: 20px;
        height: 20px;
        border-radius: 50%;
        border: 3px solid #1a1a1a;
        box-sizing: border-box;
    }
    .qai-unit-search-marker-pin::after {
        display: none;
    }
    .qai-unit-search-marker-pin.qai-unit-search-marker--decided::before {
        background: #1565c0;
        border-color: #1a1a1a;
    }
    .qai-unit-search-marker-pin.qai-unit-search-marker--decided::after {
        border-top-color: #1565c0;
        filter: none;
    }
    .qai-unit-search-marker-pin.qai-unit-search-marker--outstanding::before {
        background: #047857;
        border-color: #1a1a1a;
    }
    .qai-unit-search-marker-pin.qai-unit-search-marker--outstanding::after {
        border-top-color: #047857;
        filter: none;
    }
    .qai-weekly-news-marker-pin {
        position: relative;
        width: 24px;
        height: 24px;
        box-sizing: border-box;
    }
    .qai-weekly-news-marker-pin::before {
        content: '';
        position: absolute;
        top: 0;
        left: 50%;
        transform: translateX(-50%);
        width: 20px;
        height: 20px;
        border-radius: 50%;
        border: 3px solid #1a1a1a;
        box-sizing: border-box;
        background: var(--pin-color, #666);
    }
    .qai-weekly-news-marker-pin::after {
        display: none;
    }
    .qai-unit-search-chart-title {
        font-size: 16px;
        font-weight: 600;
        margin: 0 0 12px 0;
        color: var(--qai-text-primary);
    }
    .qai-unit-search-chart-wrap {
        height: 300px;
        width: 100%;
        margin-bottom: 24px;
    }
    .qai-unit-search-accordion-item {
        border: 1px solid var(--qai-border);
        border-radius: 6px;
        margin-bottom: 12px;
        overflow: hidden;
        background: var(--qai-bg-light);
    }
    .qai-unit-search-accordion-summary {
        padding: 10px 14px;
        font-size: 14px;
        font-weight: 600;
        color: var(--qai-text-primary);
        cursor: pointer;
        list-style: none;
        background: var(--qai-bg-secondary);
    }
    .qai-unit-search-accordion-summary::-webkit-details-marker {
        display: none;
    }
    .qai-unit-search-accordion-summary::before {
        content: "▶ ";
        font-size: 10px;
        margin-right: 8px;
    }
    .qai-unit-search-accordion-item[open] .qai-unit-search-accordion-summary::before {
        content: "▼ ";
    }
    .qai-unit-search-accordion-content {
        padding: 12px 16px;
        overflow-x: auto;
    }
    .qai-unit-search-section {
        margin-bottom: 24px;
    }
    .qai-unit-search-section-title {
        font-size: 18px;
        font-weight: 600;
        margin: 0 0 12px 0;
        color: var(--qai-text-primary);
    }
    .qai-unit-search-table-wrap {
        overflow-x: auto;
    }
    .qai-unit-search-table {
        width: 100%;
        border-collapse: collapse;
        font-size: 13px;
    }
    .qai-unit-search-table th,
    .qai-unit-search-table td {
        padding: 8px 12px;
        text-align: left;
        border-bottom: 1px solid var(--qai-border);
        color: var(--qai-text-primary);
        white-space: normal;
        word-wrap: break-word;
    }
    .qai-unit-search-table th {
        font-weight: 600;
        background: var(--qai-bg-secondary);
    }
    .qai-unit-search-popup {
        min-width: 140px;
        font-size: 13px;
    }
    .qai-unit-search-popup .qai-weekly-news-app-ref {
        margin-top: 8px;
    }
    @media (max-width: 768px) {
        .qai-unit-search-map {
            height: 260px;
        }
        .qai-unit-search-chart-wrap {
            height: 260px;
        }
    }

    /* Reuse modal content styles for explorer panel */
    .qai-explorer-content h2 {
        font-size: 22px;
        font-weight: 600;
        color: var(--qai-text-primary);
        margin-bottom: 20px;
        border-bottom: 2px solid var(--qai-border);
        padding-bottom: 10px;
    }
    
    .qai-explorer-content .app-details-subheader {
        font-size: 18px;
        font-weight: 600;
        color: var(--qai-text-primary);
        margin-top: 24px;
        margin-bottom: 12px;
    }

    .qai-summary-section {
        margin-bottom: 20px;
    }

    .qai-summary-section .app-details-subheader {
        margin-top: 20px;
    }

    .qai-summary-content {
        font-size: 14px;
        line-height: 1.5;
        color: var(--qai-text-primary);
    }

    .qai-summary-content p {
        margin: 0 0 0.5rem;
    }

    .qai-summary-content p:last-child {
        margin-bottom: 0;
    }
    
    /* Explorer Panel Overlay (for mobile) */
    .qai-explorer-overlay {
        display: none;
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background: rgba(0, 0, 0, 0.5);
        z-index: 997; /* Below panel (998) */
        opacity: 0;
        visibility: hidden;
        transition: opacity 0.3s ease, visibility 0.3s ease;
    }
    
    body.explorer-panel-open .qai-explorer-overlay {
        opacity: 1;
        visibility: visible;
    }
    
    /* Mobile styles for explorer panel */
    @media (max-width: 768px) {
        .qai-explorer-panel {
            width: var(--explorer-panel-mobile-width);
            max-width: 100vw;
            min-width: 0;
        }
        
        .qai-explorer-overlay {
            display: block;
        }
        
        body.explorer-panel-open .qai-page-wrapper {
            width: calc(100% - var(--explorer-panel-mobile-width));
        }
        
        body.side-panel-open.explorer-panel-open .qai-page-wrapper {
            width: calc(100% - var(--explorer-panel-mobile-width));
        }
        
        .qai-explorer-tabs {
            width: 100%;
            display: flex;
            flex-direction: row;
            overflow-x: auto;
            border-right: none;
            border-bottom: 1px solid var(--qai-border);
            padding: 0;
            -webkit-overflow-scrolling: touch;
            scrollbar-width: none;
        }
        
        .qai-explorer-tabs::-webkit-scrollbar {
            display: none;
        }
        
        .qai-explorer-tab {
            border-left: none;
            border-bottom: 4px solid transparent;
            padding: 12px 14px;
            white-space: nowrap;
            font-size: 13px;
            min-width: fit-content;
        }
        
        .qai-explorer-tab.qai-tab-active {
            border-left: none;
            border-bottom: 4px solid var(--qai-text-primary);
        }
        
        .qai-explorer-body {
            flex-direction: column;
        }
        
        .qai-explorer-content {
            padding: 12px;
        }
        
        .qai-explorer-header {
            padding: 12px 16px;
        }
        
        .qai-explorer-header h2 {
            font-size: 16px;
        }
        
        .qai-explorer-content h2 {
            font-size: 18px;
            margin-bottom: 15px;
        }
        
        .qai-explorer-content .app-details-subheader {
            font-size: 15px;
            margin-top: 18px;
            margin-bottom: 10px;
        }

        .qai-explorer-chart-container {
            height: 300px;
            min-height: 300px;
        }

        .qai-explorer-context-text {
            font-size: 13px;
        }

        .qai-explorer-data-table {
            font-size: 13px;
        }

        .qai-explorer-data-table th,
        .qai-explorer-data-table td {
            padding: 10px 12px;
        }
    }

    /* ==================================================
      === 13. NEW: MODAL POP-UP STYLES ===
      ==================================================
    */
    .qai-modal-backdrop {
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background: rgba(0, 0, 0, 0.6);
        z-index: 1000;
        display: flex;
        align-items: center;
        justify-content: center;
        opacity: 0;
        visibility: hidden;
        transition: opacity 0.3s ease, visibility 0.3s ease;
    }
    .qai-modal-backdrop.qai-modal-visible {
        opacity: 1;
        visibility: visible;
    }

    .qai-modal-window {
        background: #ffffff;
        border-radius: 12px;
        box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
        width: 90%;
        max-width: 900px;
        height: 85vh;
        display: flex;
        flex-direction: column;
        overflow: hidden;
        transform: scale(0.95);
        transition: transform 0.3s ease;
    }
    .qai-modal-visible .qai-modal-window {
        transform: scale(1);
    }

    .qai-modal-header {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 16px 24px;
        border-bottom: 1px solid #e0e0e0;
        flex-shrink: 0;
    }
    .qai-modal-header h2 {
        font-size: 20px;
        font-weight: 600;
        color: var(--qai-text-primary);
    }

    .qai-modal-close {
        font-size: 28px;
        font-weight: 300;
        color: #888;
        cursor: pointer;
        line-height: 1;
        transition: color 0.2s;
    }
    .qai-modal-close:hover {
        color: #000;
    }

    .qai-modal-body {
        display: flex;
        flex-grow: 1;
        overflow: hidden;
    }

    .qai-modal-tabs {
        flex-shrink: 0;
        width: 200px;
        background: #f9f9f9;
        border-right: 1px solid #e0e0e0;
        padding: 16px 0;
        overflow-y: auto;
    }
    .qai-modal-tab {
        padding: 12px 20px;
        font-size: 15px;
        font-weight: 500;
        color: #333;
        cursor: pointer;
        border-left: 4px solid transparent;
        transition: all 0.2s ease;
    }
    .qai-modal-tab:hover {
        background: #f0f0f0;
    }
    .qai-modal-tab.qai-tab-active {
        background: #ffffff;
        color: var(--qai-text-primary);
        font-weight: 600;
        border-left: 4px solid var(--qai-text-primary);
    }

    .qai-modal-content {
        flex-grow: 1;
        padding: 24px;
        overflow-y: auto;
    }
    
    .qai-modal-content [data-tab-id] {
        display: none;
    }
    .qai-modal-content [data-tab-id].qai-tab-pane-active {
        display: block;
    }

    /* Housing Details subtabs (4.1 Residential, 4.2 Non-Permanent Dwellings, 4.3 Other Residential) */
    .qai-housing-subtabs {
        display: flex;
        flex-wrap: wrap;
        gap: 4px;
        margin-bottom: 20px;
        border-bottom: 1px solid #e0e0e0;
        padding-bottom: 12px;
    }
    .qai-housing-subtab {
        padding: 10px 16px;
        font-size: 14px;
        font-weight: 500;
        color: #555;
        cursor: pointer;
        border-radius: 6px;
        transition: background 0.2s ease, color 0.2s ease;
    }
    .qai-housing-subtab:hover {
        background: #f0f0f0;
        color: #333;
    }
    .qai-housing-subtab.qai-tab-active {
        background: #e8f4fc;
        color: var(--qai-text-primary, #023047);
        font-weight: 600;
    }
    .qai-housing-subtab-pane {
        display: none;
    }
    .qai-housing-subtab-pane.qai-housing-subtab-pane-active {
        display: block;
    }

    /* Parking tab subtabs (by vehicle type) */
    .qai-parking-subtabs {
        display: flex;
        flex-wrap: wrap;
        gap: 4px;
        margin-bottom: 20px;
        border-bottom: 1px solid #e0e0e0;
        padding-bottom: 12px;
    }
    .qai-parking-subtab {
        padding: 10px 16px;
        font-size: 14px;
        font-weight: 500;
        color: #555;
        cursor: pointer;
        border-radius: 6px;
        transition: background 0.2s ease, color 0.2s ease;
    }
    .qai-parking-subtab:hover {
        background: #f0f0f0;
        color: #333;
    }
    .qai-parking-subtab.qai-parking-subtab-active {
        background: #e8f4fc;
        color: var(--qai-text-primary, #023047);
        font-weight: 600;
    }
    .qai-parking-subtab-pane {
        display: none;
    }
    .qai-parking-subtab-pane.qai-parking-subtab-pane-active {
        display: block;
    }

    /* Overview tab subtabs (1.1 Overview, 1.2 Core Information, 1.3 Address and Classification) */
    .qai-overview-subtabs {
        display: flex;
        flex-wrap: wrap;
        gap: 4px;
        margin-bottom: 20px;
        border-bottom: 1px solid #e0e0e0;
        padding-bottom: 12px;
    }
    .qai-overview-subtab {
        padding: 10px 16px;
        font-size: 14px;
        font-weight: 500;
        color: #555;
        cursor: pointer;
        border-radius: 6px;
        transition: background 0.2s ease, color 0.2s ease;
    }
    .qai-overview-subtab:hover {
        background: #f0f0f0;
        color: #333;
    }
    .qai-overview-subtab.qai-overview-subtab-active {
        background: #e8f4fc;
        color: var(--qai-text-primary, #023047);
        font-weight: 600;
    }
    .qai-overview-subtab-pane {
        display: none;
    }
    .qai-overview-subtab-pane.qai-overview-subtab-pane-active {
        display: block;
    }

    /* Site & Development tab subtabs (3.1 Site Details, 3.2 Constraints, 3.3 Floorspace) */
    .qai-site-subtabs {
        display: flex;
        flex-wrap: wrap;
        gap: 4px;
        margin-bottom: 20px;
        border-bottom: 1px solid #e0e0e0;
        padding-bottom: 12px;
    }
    .qai-site-subtab {
        padding: 10px 16px;
        font-size: 14px;
        font-weight: 500;
        color: #555;
        cursor: pointer;
        border-radius: 6px;
        transition: background 0.2s ease, color 0.2s ease;
    }
    .qai-site-subtab:hover {
        background: #f0f0f0;
        color: #333;
    }
    .qai-site-subtab.qai-site-subtab-active {
        background: #e8f4fc;
        color: var(--qai-text-primary, #023047);
        font-weight: 600;
    }
    .qai-site-subtab-pane {
        display: none;
    }
    .qai-site-subtab-pane.qai-site-subtab-pane-active {
        display: block;
    }

    .qai-field-group-spacer {
        height: 1em;
        margin: 0.5em 0;
    }

    /* Development Details tab subtabs (Floorspace, Residential) */
    .qai-development-subtabs {
        display: flex;
        flex-wrap: wrap;
        gap: 4px;
        margin-bottom: 20px;
        border-bottom: 1px solid #e0e0e0;
        padding-bottom: 12px;
    }
    .qai-development-subtab {
        padding: 10px 16px;
        font-size: 14px;
        font-weight: 500;
        color: #555;
        cursor: pointer;
        border-radius: 6px;
        transition: background 0.2s ease, color 0.2s ease;
    }
    .qai-development-subtab:hover {
        background: #f0f0f0;
        color: #333;
    }
    .qai-development-subtab.qai-development-subtab-active {
        background: #e8f4fc;
        color: var(--qai-text-primary, #023047);
        font-weight: 600;
    }
    .qai-development-subtab-pane {
        display: none;
    }
    .qai-development-subtab-pane.qai-development-subtab-pane-active {
        display: block;
    }

    .qai-modal-content h2 {
        font-size: 22px;
        font-weight: 600;
        color: #023047;
        margin-bottom: 20px;
        border-bottom: 2px solid #f0f0f0;
        padding-bottom: 10px;
    }
    .app-details-subheader {
        font-size: 18px;
        font-weight: 600;
        color: #333;
        margin-top: 24px;
        margin-bottom: 12px;
    }
    
    .app-details-kv-table {
        width: 100%;
        border-collapse: collapse;
        font-size: 14px;
    }
    .app-details-kv-table th,
    .app-details-kv-table td {
        padding: 10px 12px;
        border-bottom: 1px solid #f0f0f0;
        text-align: left;
        vertical-align: top;
        word-wrap: break-word;
    }
    .app-details-kv-table th {
        font-weight: 600;
        color: #333;
        width: 35%;
    }
    .app-details-kv-table td {
        color: #555;
    }
    .qai-explorer-content .app-details-kv-table .qai-kv-cell-scroll {
        max-height: 7.5em;
        overflow-y: auto;
        white-space: pre-wrap;
    }
    .app-details-kv-table tr:last-child th,
    .app-details-kv-table tr:last-child td {
        border-bottom: none;
    }
    .data-na {
        color: #999;
        font-style: italic;
    }
    .data-na {
        color: #999;
        font-style: italic;
    }

    .app-details-col-table {
        width: 100%;
        max-width: 100%;
        border-collapse: collapse;
        font-size: 14px;
        border: 1px solid #ddd;
        border-radius: 8px;
        overflow: hidden;
        table-layout: auto;
    }
    .app-details-col-table th,
    .app-details-col-table td {
        padding: 12px 15px;
        border-bottom: 1px solid #ddd;
        text-align: left;
        word-wrap: break-word;
        overflow-wrap: break-word;
    }
    .app-details-col-table th {
        background-color: #f9f9f9;
        font-weight: 600;
        color: #023047;
    }
    .app-details-col-table tr:last-child td {
        border-bottom: none;
    }
    .app-details-col-table tr:nth-child(even) td {
        background-color: #fdfdfd;
    }
    /* Description column: wider width and wrap so tables fit in explorer panel */
    .app-details-col-table th.col-description,
    .app-details-col-table td.col-description {
        min-width: 10em;
        max-width: 22em;
        word-wrap: break-word;
        overflow-wrap: break-word;
    }

    #qai-map-container {
        height: 300px;
        width: 100%;
        border-radius: 8px;
        border: 1px solid #ddd;
        margin-bottom: 20px;
    }
    .leaflet-container {
        z-index: 1001;
    }

    .custom-cluster-icon {
        background: rgba(255, 255, 255, 0.4);
        backdrop-filter: blur(4px);
        border: 2px solid #333;
        border-radius: 50%;
        display: flex;
        align-items: center;
        justify-content: center;
        font-weight: bold;
        color: #000;
    }
    
    @media (max-width: 768px) {
        .qai-modal-window {
            width: 95%;
            height: 90vh;
        }
        .qai-modal-body {
            flex-direction: column;
        }
        .qai-modal-tabs {
            width: 100%;
            display: flex;
            flex-direction: row;
            overflow-x: auto;
            border-right: none;
            border-bottom: 1px solid #e0e0e0;
            padding: 0;
            -webkit-overflow-scrolling: touch;
            scrollbar-width: none;
        }
        .qai-modal-tabs::-webkit-scrollbar {
            display: none;
        }
        .qai-modal-tab {
            border-left: none;
            border-bottom: 4px solid transparent;
            padding: 12px 14px;
            white-space: nowrap;
            font-size: 13px;
        }
        .qai-modal-tab.qai-tab-active {
            border-left: none;
            border-bottom: 4px solid var(--qai-text-primary);
        }
        .qai-modal-content {
            padding: 12px;
        }
        .qai-modal-header {
            padding: 12px 16px;
        }
        .qai-modal-header h2 {
            font-size: 16px;
        }
        
        /* Modal tables - horizontal scroll */
        .app-details-kv-table,
        .app-details-col-table {
            display: block;
            overflow-x: auto;
            -webkit-overflow-scrolling: touch;
            font-size: 13px;
        }
        .app-details-kv-table th,
        .app-details-kv-table td,
        .app-details-col-table th,
        .app-details-col-table td {
            padding: 8px 10px;
            min-width: 120px;
        }
        .app-details-kv-table th {
            width: 40%;
        }
        
        /* Map container on mobile */
        #qai-map-container {
            height: 220px;
            margin-bottom: 15px;
        }
        
        /* Modal content headings */
        .qai-modal-content h2 {
            font-size: 18px;
            margin-bottom: 15px;
        }
        .app-details-subheader {
            font-size: 15px;
            margin-top: 18px;
            margin-bottom: 10px;
        }
    }

    /* ==================================================
      === 14. NEW: CHART & ACCORDION STYLES ===
      ==================================================
    */
    .qai-chart-container {
        position: relative;
        min-height: 300px;
        height: auto;
        width: 100%;
        margin: 25px 0 15px 0; /* Increased top margin to prevent overlap with bot response */
        display: flex;
        justify-content: center;
        align-items: flex-start;
        box-sizing: border-box;
        overflow: visible; /* Allow chart elements to extend if needed */
    }
    
    /* ApexCharts uses divs, ensure proper sizing */
    .qai-chart-container > div {
        width: 100% !important;
        min-height: 300px;
        overflow: visible; /* Allow y-axis labels to be fully visible */
    }
    
    /* Ensure ApexCharts title wraps properly */
    .qai-chart-container .apexcharts-title-text {
        word-wrap: break-word;
        white-space: normal !important;
        overflow-wrap: break-word;
    }
    
    /* Ensure y-axis labels have proper spacing and wrapping */
    .qai-chart-container .apexcharts-yaxis-label {
        word-wrap: break-word;
        white-space: normal !important;
        overflow-wrap: break-word;
    }
    
    @media (min-width: 769px) {
        .qai-chart-container {
            min-height: 400px !important;
            height: auto !important;
            width: 100% !important;
            margin: 30px 0 15px 0 !important; /* Increased top margin to prevent overlap with bot response */
            padding: 0 !important; /* Remove any padding that might constrain width */
            min-width: 100% !important; /* Ensure minimum width is full */
            max-width: 100% !important; /* Ensure maximum width is full */
        }
        
        /* ApexCharts uses divs, ensure proper sizing */
        .qai-chart-container > div {
            width: 100% !important;
            min-height: 400px !important;
            overflow: visible; /* Allow y-axis labels to be fully visible */
        }
        
        /* Ensure message container with charts uses full available width */
        .message-container.bot .message {
            overflow: visible; /* Allow charts to use full width */
        }
        
        /* Ensure ApexCharts title wraps properly on desktop */
        .qai-chart-container .apexcharts-title-text {
            word-wrap: break-word;
            white-space: normal !important;
            overflow-wrap: break-word;
            max-width: 100%;
        }
        
        /* Ensure y-axis labels have proper spacing and wrapping on desktop */
        .qai-chart-container .apexcharts-yaxis-label {
            word-wrap: break-word;
            white-space: normal !important;
            overflow-wrap: break-word;
        }
    }

    .qai-accordion {
        border: 1px solid #e0e0e0;
        border-radius: 8px;
        margin-top: 20px;
        overflow: hidden;
        background: #ffffff;
        box-shadow: 0 2px 4px rgba(0,0,0,0.05);
    }
    .qai-accordion-header {
        padding: 12px 16px;
        font-size: 14px;
        font-weight: 600;
        color: var(--qai-text-primary);
        background: #f9f9f9;
        cursor: pointer;
        display: block; /* Makes the whole area clickable */
    }
    .qai-accordion-header:hover {
        background: #f0f0f0;
    }
    .qai-accordion-content {
        padding: 16px;
        border-top: 1px solid #e0e0e0;
        overflow-x: auto; /* Allow horizontal scroll if needed */
        -webkit-overflow-scrolling: touch;
    }
    .qai-accordion-content table {
        width: 100%;
        min-width: 250px;
        border-collapse: collapse;
        font-size: 14px;
        table-layout: auto;
    }
    .qai-accordion-content th,
    .qai-accordion-content td {
        padding: 8px 12px;
        border-bottom: 1px solid #f0f0f0;
        text-align: left;
        white-space: normal;
        word-wrap: break-word;
        line-height: 1.4;
        vertical-align: top;
    }
    .qai-accordion-content th {
        background-color: #f9f9f9;
        font-weight: 600;
    }
    /* All accordion columns: left-aligned with wrapping */
    .qai-accordion-content th,
    .qai-accordion-content td {
        text-align: left;
        white-space: normal;
        word-wrap: break-word;
    }
    
    /* First column: field names */
    .qai-accordion-content th:first-child,
    .qai-accordion-content td:first-child {
        width: 40%;
        min-width: 100px;
        max-width: 200px;
    }
    
    /* Last column: values/definitions */
    .qai-accordion-content th:last-child,
    .qai-accordion-content td:last-child {
        width: 60%;
    }

    /* === 15. NEW: TABLE STYLING IN CHAT MESSAGES === */
    
    /* Scrollable wrapper for tables that exceed container width */
    .message {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    .message table {
        width: 100%;
        min-width: 280px; /* Minimum table width */
        border-collapse: collapse;
        margin-top: 16px;
        margin-bottom: 8px;
        font-size: 14px;
        background-color: var(--qai-bg-light);
        border: 1px solid var(--qai-border);
        border-radius: 8px;
        overflow: hidden;
        box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
        table-layout: auto; /* Let browser calculate column widths */
    }
    
    .message table thead {
        background-color: var(--qai-bg-secondary);
    }
    
    .message table th {
        padding: 12px 16px;
        text-align: left;
        font-weight: 600;
        color: var(--qai-text-primary);
        border-bottom: 2px solid var(--qai-border-dark);
        font-size: 14px;
        white-space: normal; /* Allow header text to wrap */
        word-wrap: break-word;
        line-height: 1.4;
        min-width: 80px; /* Minimum column width */
    }
    
    /* All columns: left-aligned with text wrapping */
    .message table th,
    .message table td {
        text-align: left;
        white-space: normal;
        word-wrap: break-word;
        overflow-wrap: break-word;
    }
    
    /* First column (field names): narrower */
    .message table th:first-child,
    .message table td:first-child {
        width: 35%;
        min-width: 100px;
        max-width: 200px;
    }
    
    /* Last column (definitions/values): wider */
    .message table th:last-child,
    .message table td:last-child {
        width: 65%;
    }
    
    .message table td {
        padding: 12px 16px;
        border-bottom: 1px solid var(--qai-border);
        color: var(--qai-text-primary);
        vertical-align: top;
        line-height: 1.4;
    }
    
    .message table tbody tr:last-child td {
        border-bottom: none;
    }
    
    .message table tbody tr:hover {
        background-color: var(--qai-hover);
    }
    
    .message table td strong {
        color: var(--qai-text-primary);
        font-weight: 600;
    }

/* Hide inline data-quality notice on small screens; side-panel remains accessible */
@media (max-width: 768px) {
    .qai-intro-text .qai-data-quality-intro {
        display: none !important;
    }
}