:root {
    /* Enhanced Primary Colors - Softer and Friendlier */
    --primary-deep-blue: #2563eb;
    --primary-blue: #3b82f6;
    --primary-hover: #60a5fa;
    --primary-light-blue: #93c5fd;
    --accent-purple: #a855f7;
    --accent-teal: #2dd4bf;

    /* Legacy support */
    --primary-orange: #fbbf24;
    --primary-orange-hover: #f59e0b;

    /* Data Visualization Colors */
    --viz-green: #34d399;
    --viz-orange: #fbbf24;
    --viz-red: #fb7185;
    --viz-purple: #c084fc;

    /* Neutrals - Better contrast */
    --bg-primary: #ffffff;
    --bg-secondary: #fdfdfd;
    --bg-tertiary: #f8fafc;
    --text-color: #334155;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --border-light: #e2e8f0;
    --bg-gray: #f8f9fa;
    --light-gray: #f1f5f9;
    --medium-gray: #cbd5e1;
    --dark-gray: #94a3b8;

    /* Enhanced backgrounds for AI/User messages */
    --bg-ai-start: rgba(59, 130, 246, 0.08);
    /* Softer AI background */
    --bg-ai-end: rgba(168, 85, 247, 0.05);
    --border-ai: rgba(59, 130, 246, 0.15);
    --bg-user-start: rgba(251, 146, 60, 0.05);
    /* Softer User background */
    --bg-user-end: rgba(251, 191, 36, 0.05);
    --border-user: rgba(245, 158, 11, 0.15);

    /* Shadows for depth */
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.03);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.08);
    --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.08);

    /* Typography */
    --font-display: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;

    /* Spacing */
    --space-1: 0.25rem;
    --space-2: 0.5rem;
    --space-3: 0.75rem;
    --space-4: 1rem;
    --space-5: 1.25rem;
    --space-6: 1.5rem;
    --space-8: 2rem;
}

* {
    transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
}

html,
body {
    /* Use % only — dvh/vh resolve to the *browser* viewport, not the iframe height */
    height: 100%;
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: var(--font-display);
    color: var(--text-color);
    background-color: var(--bg-secondary);
    overflow: hidden;
    /* Prevent body scroll, main-container children will manage */
}

/* ============================================
   LAYOUT
   ============================================ */
.app-layout {
    display: flex;
    flex-direction: row;
    height: 100%;
    min-height: 0;
    /* Let flex parent control height — never 100dvh in iframe */
    overflow: hidden;
}

/* ============================================
   SIDEBAR
   ============================================ */
.sidebar {
    width: 300px;
    background: linear-gradient(180deg, #ffffff 0%, var(--bg-secondary) 100%);
    border-right: 1px solid var(--border-light);
    display: flex;
    flex-direction: column;
    transition: margin-left 0.3s ease;
    z-index: 100;
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    box-shadow: var(--shadow-md);
}

.sidebar.collapsed {
    margin-left: -300px;
}

.sidebar-header {
    padding: 1.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

.sidebar-header h2 {
    font-size: 1.25rem;
    font-weight: 700;
}

.sidebar-content {
    padding: 1.5rem;
    overflow-y: auto;
}

#close-sidebar-btn {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
    width: 32px;
    height: 32px;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

#close-sidebar-btn:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* ============================================
   MAIN CONTAINER
   ============================================ */
.main-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    /* Removed max-width: 500px — in iframe context it must fill the host container */
    width: 100%;
    max-width: 100%;
    background: white;
    position: relative;
    /* Removed box-shadow — embeds don't float */
    margin: 0;
    height: 100%;
    min-height: 0;
    /* Critical: allows flex children to shrink + scroll */
    overflow: hidden;
    /* Clip children; scrolling is on .chat-content-scroll-area */
}

/* When sidebar is open, main-container shifts right (not needed in embed/iframe) */
.sidebar:not(.collapsed)~.main-container {
    margin-left: 300px;
}

/* Responsive Chat Width — in standalone/full-page mode only.
   In iframe/embed mode these are overridden below to 100%. */
@media (min-width: 768px) {
    .main-container:not(.embed-override) {
        max-width: 900px;
    }
}

@media (min-width: 1200px) {
    .main-container:not(.embed-override) {
        max-width: 1200px;
    }
}

/* ============================================
   TOP BAR
   ============================================ */
.top-bar {
    background: #005494 !important;
    padding: 0.6rem 0.75rem !important;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: white;
    box-shadow: var(--shadow-md);
    flex-shrink: 0;
    overflow: hidden;
    min-width: 0;
}

.app-title {
    font-size: 0.875rem !important;
    font-weight: 600 !important;
    display: flex;
    align-items: center;
    gap: 0.4rem;
    flex: 1;
    min-width: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Nav buttons — always visible, compact in narrow iframe */
.nav-btn {
    flex-shrink: 0 !important;
    padding: 5px 10px !important;
    font-size: 0.75rem !important;
    border-radius: 14px !important;
    white-space: nowrap;
    display: inline-flex !important;
    align-items: center;
    gap: 4px;
}

/* Hide nav buttons on home screen — JS toggles this */
.nav-btn.hidden {
    display: none !important;
}

/* ============================================
   BUTTONS - ENHANCED
   ============================================ */
.st-button {
    background: linear-gradient(135deg, var(--primary-blue) 0%, var(--accent-purple) 100%);
    color: white;
    border: none;
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 0.875rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    margin: 2px;
    box-shadow: var(--shadow-md);
    pointer-events: auto;
    position: relative;
    overflow: hidden;
}

.st-button::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.2) 0%, rgba(255, 255, 255, 0) 100%);
    opacity: 0;
    transition: opacity 0.3s;
}

.st-button:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

body.in-iframe .st-button:hover,
body.embed-mode .st-button:hover {
    transform: none;
    box-shadow: var(--shadow-md);
}

.st-button:hover::before {
    opacity: 1;
}

.st-button:disabled {
    background: var(--light-gray);
    cursor: not-allowed;
    box-shadow: none;
    transform: none;
}

.st-button:active {
    transform: scale(0.98);
}

.st-button:focus {
    outline: 2px solid var(--primary-blue);
    outline-offset: 2px;
}

.st-button.full-width {
    width: 100%;
    margin-bottom: 8px;
    text-align: center;
}

.st-button.secondary {
    background: white;
    color: var(--text-color);
    border: 2px solid var(--border-light);
    box-shadow: var(--shadow-sm);
}

.st-button.secondary:hover {
    background: var(--bg-tertiary);
    border-color: var(--primary-blue);
}

/* ============================================
   QUICK ACTIONS - CARD BASED (TOP HIDDEN)
   ============================================ */
.quick-actions-grid-top-hidden {
    display: none;
    /* Hide the top-level cards */
    padding: 1.5rem;
    /* Keep padding for layout consistency if needed, but display:none is primary */
}

/* .quick-actions-grid styling (for in-chat use, e.g., nav buttons) */
.quick-actions-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    /* Can be adjusted to 1fr for single column if needed */
    gap: 1rem;
    padding: 1rem 0;
    /* Padding inside chat content area */
    flex-shrink: 0;
    align-self: center;
    /* Center if it's within a flex column */
    max-width: 100%;
    /* Ensure it doesn't overflow */
}

.quick-actions-grid .st-button {
    min-height: 40px;
    /* Smaller button size for in-chat */
    padding: 0.75rem 1rem;
    font-size: 0.8rem;
    border-radius: 12px;
    /* Pill shape */
    box-shadow: var(--shadow-sm);
    flex-direction: row;
    /* Horizontal layout for icon and text */
    justify-content: center;
    align-items: center;
    gap: 0.5rem;
}

/* Hide icons in quick action buttons in chat if they have them, to keep it pill style */
.quick-actions-grid .st-button i {
    font-size: 1rem;
    /* Smaller icon size */
    -webkit-text-fill-color: var(--primary-blue);
    /* Use text color, not transparent clip */
    background: none;
}


/* ============================================
   CHAT CONTENT SCROLL AREA (NEW)
   ============================================ */
.chat-content-scroll-area {
    flex: 1;
    min-height: 0;
    /* KEY: without this, flex child won't shrink below content size */
    overflow-y: auto;
    /* THE ONLY scrollbar in the app — everything else is visible */
    overflow-x: hidden;
    display: flex;
    flex-direction: column;
    background: var(--bg-secondary);
    padding: 0.75rem 1rem;
    gap: 0.75rem;
    /* Smooth scrolling for auto-scroll-to-bottom */
    scroll-behavior: smooth;
    /* WebKit scrollbar — thin, unobtrusive */
    scrollbar-width: thin;
    scrollbar-color: var(--medium-gray) transparent;
}

.chat-content-scroll-area::-webkit-scrollbar {
    width: 5px;
}

.chat-content-scroll-area::-webkit-scrollbar-track {
    background: transparent;
}

.chat-content-scroll-area::-webkit-scrollbar-thumb {
    background: var(--medium-gray);
    border-radius: 10px;
}

/* ============================================
   CHAT HISTORY - ENHANCED
   ============================================ */
.chat-history {
    /* flex: 1; Removed so it doesn't fight with widget-area height, flows naturally */
    overflow-y: visible;
    /* Let content push the parent scroll */
    padding: 0;
    /* Padding moved to .chat-content-scroll-area */
    background: none;
    /* Background moved to .chat-content-scroll-area */
    display: flex;
    /* Kept for message layout */
    flex-direction: column;
    /* Kept for message layout */
    gap: 1rem;
    /* Space between messages */
}

/* ============================================
   MESSAGE STYLING - MODERN
   ============================================ */
.message {
    padding: 1rem 1.25rem;
    border-radius: 16px;
    max-width: 75%;
    line-height: 1.5;
    position: relative;
    box-shadow: var(--shadow-md);
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    animation: fadeInUp 0.4s ease-out;
    backdrop-filter: blur(10px);
    transition: all 0.2s;
}

.message:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

/* No float-up on hover inside iframe — prevents scroll jitter */
body.in-iframe .message:hover,
body.embed-mode .message:hover {
    transform: none;
    box-shadow: var(--shadow-sm);
}

.message.ai {
    background: linear-gradient(135deg, var(--bg-ai-start) 0%, var(--bg-ai-end) 100%);
    border: 1px solid var(--border-ai);
    align-self: flex-start;
    color: var(--text-color);
    border-top-left-radius: 4px;
    font-size: 1rem;
}

.message.user {
    background: linear-gradient(135deg, var(--bg-user-start) 0%, var(--bg-user-end) 100%);
    border: 1px solid var(--border-user);
    align-self: flex-end;
    color: var(--text-color);
    border-top-right-radius: 4px;
    font-size: 0.95rem;
}

.message .avatar {
    flex-shrink: 0;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    color: white;
    box-shadow: var(--shadow-md);
}

.message.ai .avatar {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.message.user .avatar {
    background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
}

.message-content {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
}

.timestamp {
    display: block;
    font-size: 0.7rem;
    color: var(--dark-gray);
    margin-top: 0.5rem;
}

.message.ai .timestamp {
    text-align: left;
}

.message.user .timestamp {
    text-align: right;
}

/* Fade-in Animation */
@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ============================================
   WIDGET AREA
   ============================================ */
.widget-area {
    background: white;
    /* Removed top/bottom borders to blend with scroll area */
    max-height: fit-content;
    /* Allow to expand within parent scroll */
    overflow-y: visible;
    /* Let content push the parent scroll */
    padding: 1rem;
    /* Internal padding for widget content */
    margin-bottom: 1rem;
    /* Space between widget and chat input */
    flex-shrink: 0;
    /* Prevents widget area from shrinking more than necessary */
}

.hidden {
    display: none !important;
}

/* ============================================
   FILE UPLOADER
   ============================================ */
.file-uploader {
    border: 2px dashed var(--primary-blue);
    border-radius: 12px;
    padding: 2rem;
    text-align: center;
    background: linear-gradient(135deg, rgba(59, 130, 246, 0.03) 0%, rgba(139, 92, 246, 0.03) 100%);
    cursor: pointer;
    margin-bottom: 1rem;
    transition: all 0.3s;
}

.file-uploader:hover {
    background: linear-gradient(135deg, rgba(59, 130, 246, 0.08) 0%, rgba(139, 92, 246, 0.08) 100%);
    border-color: var(--accent-purple);
}

.file-uploader i {
    font-size: 3rem;
    color: var(--primary-blue);
    margin-bottom: 1rem;
}

/* ============================================
   INPUTS - ENHANCED
   ============================================ */
.form-section label {
    font-size: 0.875rem;
    margin-bottom: 0.5rem;
    font-weight: 600;
    color: var(--text-primary);
    display: block;
}

input[type="text"],
input[type="password"],
input[type="number"],
select,
textarea,
.st-input {
    /* Added .st-input for generic styling */
    width: 100%;
    padding: 0.75rem 1rem;
    border: 2px solid var(--border-light);
    border-radius: 8px;
    font-size: 0.95rem;
    margin-bottom: 1rem;
    font-family: var(--font-display);
    transition: all 0.3s;
    background: white;
}

input[type="text"]:focus,
input[type="password"]:focus,
input[type="number"]:focus,
select:focus,
textarea:focus,
.st-input:focus {
    outline: none;
    border-color: var(--primary-blue);
    box-shadow: 0 0 0 4px rgba(59, 130, 246, 0.1);
}

/* ============================================
   CHAT INPUT - ENHANCED
   ============================================ */
.chat-input-wrapper {
    padding: 0.65rem 1rem;
    background: white;
    border-top: 1px solid var(--border-light);
    flex-shrink: 0;
    /* NEVER shrink — always pinned at the bottom */
    /* Subtle separator shadow */
    box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.04);
}

.chat-input-box {
    display: flex;
    gap: 0.75rem;
    align-items: center;
}

#user-input {
    flex: 1;
    padding: 0.875rem 1.25rem;
    border: 2px solid var(--border-light);
    border-radius: 24px;
    font-size: 0.95rem;
    transition: all 0.3s;
    margin-bottom: 0;
}

#user-input:focus {
    border-color: var(--primary-blue);
    box-shadow: 0 0 0 4px rgba(59, 130, 246, 0.1);
}

#send-btn,
#mic-btn {
    /* Apply styles to both send and mic buttons */
    width: 48px;
    height: 48px;
    border-radius: 50%;
    border: none;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--shadow-md);
}

#send-btn:hover,
#mic-btn:hover {
    transform: scale(1.05);
    box-shadow: var(--shadow-lg);
}

#send-btn:active,
#mic-btn:active {
    transform: scale(0.95);
}

#mic-btn {
    background: var(--accent-teal);
    /* Different color for mic button */
    margin-right: 0.5rem;
    /* Space between mic and send */
}

#mic-btn:hover {
    background: color-mix(in srgb, var(--accent-teal) 90%, black);
    /* FIX: Replaced darken() */
}


/* ============================================
   EXPANDER
   ============================================ */
.st-expander {
    border: 1px solid var(--border-light);
    border-radius: 8px;
    background: white;
    margin-bottom: 0.75rem;
    overflow: hidden;
    box-shadow: var(--shadow-sm);
}

.st-expander summary {
    padding: 1rem;
    cursor: pointer;
    font-weight: 600;
    font-size: 0.875rem;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-light);
    display: flex;
    align-items: center;
    justify-content: space-between;
    transition: all 0.2s;
}

.st-expander summary:hover {
    background: var(--bg-tertiary);
}

.st-expander[open] summary::after {
    content: '▼';
    display: inline-block;
    transition: transform 0.2s;
    margin-left: 0.5rem;
}

.st-expander[open] summary::after {
    transform: rotate(180deg);
}

.expander-content {
    padding: 1rem;
}

/* ============================================
   LISTS & ACTION CARDS
   ============================================ */

/* Modern 2-Column Action Card Grid */
.quick-actions-chat-buttons {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 1.25rem;
    padding: 1.5rem 0;
}

.list-item.chat-button-pill {
    display: flex;
    flex-direction: column;
    /* Stack icon and text vertically */
    align-items: center;
    justify-content: center;
    padding: 1.5rem 1rem;
    background: white;
    border: 1px solid var(--border-light);
    border-radius: 16px;
    box-shadow: var(--shadow-sm);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    text-align: center;
    height: 100%;
    cursor: pointer;
}

.list-item.chat-button-pill:hover {
    transform: translateY(-5px);
    box-shadow: var(--shadow-lg);
    border-color: var(--primary-blue);
    background: linear-gradient(180deg, white 0%, var(--bg-ai-start) 100%);
}

/* Enhancing the Icons */
.list-item.chat-button-pill span:first-child {
    font-size: 2.5rem !important;
    margin-bottom: 0.75rem;
    margin-right: 0 !important;
    /* Center the icon */
    background: linear-gradient(135deg, var(--primary-blue), var(--accent-purple));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

/* Enhancing the Text */
.list-item.chat-button-pill span:nth-child(2) {
    font-weight: 700;
    font-size: 1.1rem;
    color: var(--primary-deep-blue);
    margin-bottom: 4px;
}

/* Legacy list-item for other uses */
.list-item {
    padding: 0.875rem 1rem;
    border: 1px solid var(--border-light);
    border-radius: 12px;
    background: white;
    margin-bottom: 0.5rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-size: 0.875rem;
    transition: all 0.2s;
}

.list-item:hover {
    background: var(--bg-tertiary);
    transform: translateY(-1px);
    box-shadow: var(--shadow-sm);
}

/* File list item with path subtitle */
.list-item-icon {
    flex-shrink: 0;
    white-space: nowrap;
}

.list-item-body {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}

.list-item-name {
    font-weight: 500;
    color: var(--text-primary, #1e293b);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.list-item-path {
    font-size: 0.75rem;
    color: var(--dark-gray, #64748b);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.list-item.selected .list-item-name {
    color: var(--primary-blue);
}

.list-item.selected .list-item-path {
    color: var(--primary-blue);
    opacity: 0.75;
}


.list-item.selected {
    background: linear-gradient(135deg, rgba(59, 130, 246, 0.1) 0%, rgba(139, 92, 246, 0.1) 100%);
    color: var(--primary-blue);
    border-color: var(--primary-blue);
    font-weight: 600;
}

.list-container {
    max-height: none;
    /* FIXED: Removed 250px cap that caused inner scrollbars inside iframe */
    overflow-y: visible;
    /* FIXED: Parent scroll area handles scrolling */
    border: 1px solid var(--border-light);
    border-radius: 8px;
    padding: 0.5rem;
    background: white;
    margin-bottom: 1rem;
}

/* ============================================
   SPINNER / LOADING
   ============================================ */
#loading-overlay {
    /* Use absolute within .main-container (which is position:relative) */
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.92);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    border-radius: inherit;
}

#loading-overlay.hidden {
    display: none !important;
    pointer-events: none;
    /* ADDED: Allow clicks through when hidden */
}

.spinner {
    width: 50px;
    height: 50px;
    border: 4px solid var(--border-light);
    border-top: 4px solid var(--primary-blue);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(360deg);
    }
}

#loading-text {
    margin-top: 1rem;
    font-weight: 600;
    color: var(--text-primary);
}

/* ============================================
   TOAST NOTIFICATIONS
   ============================================ */
#toast-container {
    /* absolute within .main-container so toasts stay inside the iframe */
    position: absolute;
    bottom: 5rem;
    /* above the input bar */
    right: 1rem;
    z-index: 2000;
    max-width: calc(100% - 2rem);
    pointer-events: none;
}

#toast-container .toast {
    pointer-events: auto;
}

.toast {
    padding: 1rem 1.25rem;
    margin-top: 0.75rem;
    border-radius: 8px;
    background: white;
    box-shadow: var(--shadow-xl);
    display: flex;
    align-items: center;
    gap: 0.75rem;
    animation: slideIn 0.3s ease-out;
    min-width: 250px;
}

.toast.success {
    border-left: 4px solid #10b981;
}

.toast.error {
    border-left: 4px solid #ef4444;
}

.toast.warning {
    border-left: 4px solid #f59e0b;
}

.toast.info {
    border-left: 4px solid #3b82f6;
}

@keyframes slideIn {
    from {
        transform: translateX(100%);
        opacity: 0;
    }

    to {
        transform: translateX(0);
        opacity: 1;
    }
}

/* ============================================
   SUBMIT BUTTON (Orange)
   ============================================ */
.submit-btn {
    background: linear-gradient(135deg, var(--primary-orange) 0%, var(--primary-orange-hover) 100%) !important;
    border: none !important;
    color: white !important;
    margin-top: 1rem;
    box-shadow: var(--shadow-md);
}

.submit-btn:hover {
    box-shadow: var(--shadow-lg) !important;
}

/* ============================================
   DIVIDER
   ============================================ */
.divider {
    border-top: 1px solid var(--border-light);
    margin: 1.5rem 0;
    flex-shrink: 0;
    /* Prevent from shrinking */
}

.divider.top-divider-hidden {
    display: none;
    /* Hide the divider below the top-level cards */
}

/* ============================================
   MONACO EDITOR
   ============================================ */
#monaco-container {
    border: 1px solid var(--border-light);
    border-radius: 8px;
    overflow: hidden;
    margin-bottom: 1rem;
    box-shadow: var(--shadow-sm);
}

/* ============================================
   DATA TABLE - ENHANCED
   ============================================ */
.data-table-container {
    width: 100%;
    overflow-x: auto;
    margin: 1rem 0;
    border: 1px solid var(--border-light);
    border-radius: 12px;
    background-color: white;
    box-shadow: var(--shadow-sm);
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
    min-width: 400px;
}

.data-table th,
.data-table td {
    border: 1px solid var(--border-light);
    padding: 0.875rem 1rem;
    text-align: left;
    white-space: nowrap;
}

.data-table th {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    font-weight: 600;
    text-transform: uppercase;
    font-size: 0.75rem;
    letter-spacing: 0.05em;
    position: sticky;
    top: 0;
    z-index: 10;
}

.data-table tbody tr:nth-child(even) {
    background-color: var(--bg-secondary);
}

.data-table tbody tr:hover {
    background: linear-gradient(90deg, rgba(99, 102, 241, 0.05) 0%, rgba(168, 85, 247, 0.05) 100%);
}

/* ============================================
   INFO BOXES
   ============================================ */
.info-box,
.error-box,
.warning-box,
.success-box {
    padding: 1rem;
    border-radius: 8px;
    margin-bottom: 1rem;
    font-size: 0.9rem;
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
}

.info-box {
    background-color: #dbeafe;
    border-left: 4px solid var(--primary-blue);
    color: var(--text-primary);
}

.error-box {
    background-color: #fee2e2;
    border-left: 4px solid var(--viz-red);
    color: var(--text-primary);
}

.warning-box {
    background-color: #fef3c7;
    border-left: 4px solid var(--viz-orange);
    color: var(--text-primary);
}

.success-box {
    background-color: #d1fae5;
    border-left: 4px solid var(--viz-green);
    color: var(--text-primary);
}

.info-box i,
.error-box i,
.warning-box i,
.success-box i {
    font-size: 1.25rem;
}

/* ============================================
   DB TABLES GRID
   ============================================ */
.db-tables-grid {
    display: grid;
    grid-template-columns: 1fr 2fr;
    gap: 1rem;
    padding: 0;
    margin-bottom: 1rem;
}

.db-tables-pane,
.sql-editor-pane {
    padding: 1rem;
    border: 1px solid var(--border-light);
    border-radius: 8px;
    background-color: white;
}

.db-tables-pane h3,
.sql-editor-pane h3 {
    margin-top: 0;
    margin-bottom: 1rem;
    font-size: 1.125rem;
}

/* ============================================
   ANIMATIONS
   ============================================ */
@keyframes pulse-glow {
    0% {
        box-shadow: 0 0 0 0 rgba(59, 130, 246, 0.7);
        transform: scale(1);
    }

    50% {
        box-shadow: 0 0 8px 6px rgba(59, 130, 246, 0.4);
        transform: scale(1.02);
    }

    100% {
        box-shadow: 0 0 0 0 rgba(59, 130, 246, 0.7);
        transform: scale(1);
    }
}

.primary-cta-highlight {
    animation: pulse-glow 2s infinite;
    border: 2px solid var(--primary-blue);
}

/* ============================================
   TYPING INDICATOR - ENHANCED
   ============================================ */
.typing-indicator {
    display: flex;
    align-self: flex-start;
    align-items: center;
    gap: 0.75rem;
    padding: 1rem 1.25rem;
    background: linear-gradient(135deg, var(--bg-ai-start) 0%, var(--bg-ai-end) 100%);
    border: 1px solid var(--border-ai);
    border-radius: 16px;
    border-top-left-radius: 4px;
    font-size: 0.95rem;
    color: var(--text-color);
    max-width: 200px;
    box-shadow: var(--shadow-sm);
    margin-bottom: 1rem;
    animation: fadeInUp 0.3s ease-out;
    flex-shrink: 0;
    /* Prevent from shrinking */
}

.typing-indicator.hidden {
    display: none !important;
}

.typing-indicator .avatar {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.typing-dots span {
    display: inline-block;
    width: 8px;
    height: 8px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-radius: 50%;
    margin: 0 3px;
    animation: bounce 1.4s infinite ease-in-out both;
}

.typing-dots span:nth-child(1) {
    animation-delay: -0.32s;
}

.typing-dots span:nth-child(2) {
    animation-delay: -0.16s;
}

.typing-dots span:nth-child(3) {
    animation-delay: 0s;
}

@keyframes bounce {

    0%,
    80%,
    100% {
        transform: scale(0);
    }

    40% {
        transform: scale(1.0);
    }
}

/* ============================================
   BADGES
   ============================================ */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 12px;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.badge-success {
    background: #d1fae5;
    color: #065f46;
}

.badge-warning {
    background: #fef3c7;
    color: #92400e;
}

.badge-info {
    background: #dbeafe;
    color: #1e40af;
}

.badge-error {
    background: #fee2e2;
    color: #991b1b;
}

/* ============================================
   REDUCED MOTION
   ============================================ */
@media (prefers-reduced-motion: reduce) {

    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* ============================================
   RESPONSIVE - MOBILE (full-page version)
   ============================================ */
@media (max-width: 767px) {
    .quick-actions-grid {
        grid-template-columns: 1fr;
    }

    .sidebar {
        width: 100%;
        position: fixed;
        z-index: 1000;
    }

    .message {
        max-width: 90%;
    }

    .widget-area {
        /* Removed position: fixed, will flow with parent scroll area */
        border-radius: 0;
        box-shadow: none;
        margin-bottom: 0;
    }

    .chat-input-wrapper {
        border-radius: 0;
    }

    .chat-content-scroll-area {
        /* Adjusted padding for mobile to allow full content flow */
        padding-bottom: 0;
    }
}

/* ============================================
   TABLET (full-page version)
   ============================================ */
@media (min-width: 768px) and (max-width: 1199px) {
    .quick-actions-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}


/* ============================================
   EMBED MODE OPTIMIZATIONS
   ============================================ */
body.embed-mode {
    overflow: hidden !important;
    /* Prevent iframe scrollbars from body */
    height: 100% !important;
    /* Take full iframe height */
    width: 100% !important;
    /* Take full iframe width */
    max-width: none !important;
    /* Override any max-width from full-page */
    min-width: 0 !important;
    /* Ensure no min-width */
    margin: 0 !important;
    padding: 0 !important;
    background-color: var(--bg-primary) !important;
    /* Simpler background */
}

body.embed-mode .app-layout {
    display: flex;
    flex-direction: column;
    /* Stack main-container vertically */
    height: 100%;
    width: 100%;
    margin: 0;
    padding: 0;
    box-shadow: none;
    /* No shadow on the overall layout */
}

/* Aggressively hide all full-page elements */
body.embed-mode .sidebar,
body.embed-mode .top-bar,
body.embed-mode .quick-actions-grid-top-hidden,
body.embed-mode .divider.top-divider-hidden,
body.embed-mode #app-log-display {
    /* NEW: Hide log display in embed mode */
    display: none !important;
}

body.embed-mode .main-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    width: 100%;
    max-width: 100% !important;
    min-width: 0 !important;
    min-height: 0 !important;
    /* CRITICAL — flex shrink chain */
    margin: 0 !important;
    box-shadow: none !important;
    border-radius: 0 !important;
    background: var(--bg-primary, #ffffff) !important;
    height: 100% !important;
    overflow: hidden !important;
}

body.embed-mode .chat-content-scroll-area {
    flex: 1;
    min-height: 0 !important;
    /* CRITICAL — allows scroll area to shrink */
    overflow-y: auto !important;
    overflow-x: hidden !important;
    padding: 0.65rem 0.85rem !important;
    gap: 0.65rem !important;
    background: var(--bg-secondary, #f8fafc) !important;
}

body.embed-mode .chat-input-wrapper {
    flex-shrink: 0 !important;
    /* Always pinned at the bottom of flex column */
    padding: 0.5rem 0.75rem !important;
    border-top: 1px solid var(--border-light) !important;
    background: white !important;
    /* DO NOT use margin-top: auto — with proper flex + min-height:0 on scroll area,
       the scroll area absorbs all available space. margin-top:auto fights this. */
    margin-top: 0 !important;
}

body.embed-mode .message {
    padding: 0.6rem 0.8rem !important;
    /* Compact message padding */
    max-width: calc(100% - 45px) !important;
    /* Adjusted max-width to leave space for avatar + minimal margin */
    font-size: 0.85rem !important;
    /* Slightly smaller font */
    line-height: 1.3 !important;
    box-shadow: var(--shadow-sm) !important;
    /* Lighter shadow */
    overflow: visible !important;
    /* NEW: Ensure content is not hidden/clipped, let it push parent scroll */
    height: auto !important;
    /* Allow height to adjust to content */
    max-height: none !important;
    /* Remove any max-height */
}

/* Apply same no-scrollbar rules to inner message content elements, force wrapping */
body.embed-mode .message .message-content,
body.embed-mode .message .bubble-container {
    overflow: visible !important;
    /* Ensure no internal scrollbars are created */
    word-wrap: break-word !important;
    /* Force long words to break (legacy property) */
    overflow-wrap: break-word !important;
    /* Standard property for word breaking */
    word-break: break-word !important;
    /* More aggressive break for continuous strings */
    white-space: normal !important;
    /* Ensure text wraps normally, overriding any nowrap */
    height: auto !important;
    max-height: none !important;
    flex-shrink: 1 !important;
    /* Allow it to shrink if needed by flex context */
    min-width: 0 !important;
    /* Allow flex item to shrink to 0 if necessary */
}

body.embed-mode .message code {
    /* Ensure code blocks also wrap */
    white-space: pre-wrap !important;
    /* Preserve whitespace but allow wrapping */
    word-break: break-all !important;
    /* Force break for long code lines */
    overflow-x: hidden !important;
    /* Hide potential horizontal scroll in code blocks */
    display: block !important;
    /* Ensure block-level behavior for proper wrapping */
}


body.embed-mode .message.user .avatar,
body.embed-mode .message.ai .avatar {
    width: 28px !important;
    /* Smaller avatars */
    height: 28px !important;
    font-size: 0.9rem !important;
}

body.embed-mode .timestamp {
    font-size: 0.65rem !important;
    /* Smaller timestamp */
    margin-top: 0.3rem !important;
}

body.embed-mode .chat-input-box {
    gap: 0.5rem !important;
    /* Compact gap */
}

body.embed-mode #user-input {
    flex: 1 !important;
    /* Ensure input takes available width */
    padding: 0.5rem 0.8rem !important;
    /* Compact input padding */
    font-size: 0.85rem !important;
    /* Smaller input font */
    border-radius: 18px !important;
    /* Maintain pill shape */
    margin-bottom: 0 !important;
    /* Remove any lingering margin */
}

body.embed-mode #send-btn,
body.embed-mode #mic-btn {
    /* Apply embed-specific styles to both buttons */
    width: 38px !important;
    /* Smaller buttons */
    height: 38px !important;
    box-shadow: var(--shadow-sm) !important;
    margin: 0 !important;
    /* Reset margin from full-page styles */
}

body.embed-mode #mic-btn {
    margin-right: 0.5rem !important;
    /* Space between mic and input */
    background: var(--accent-teal) !important;
    /* Different color for mic button */
}

body.embed-mode #mic-btn:hover {
    background: color-mix(in srgb, var(--accent-teal) 90%, black) !important;
    /* FIX: Replaced darken() */
}

/* NEW: Styling for initial quick action pills *inside* chat history */
.chat-history .initial-quick-actions-container {
    display: flex;
    flex-wrap: wrap;
    /* Allow wrapping */
    gap: 0.5rem;
    /* Compact spacing between pills */
    padding: 0;
    /* No extra padding */
    margin-top: 0.5rem;
    /* Space below the greeting message */
    margin-bottom: 0.75rem;
    /* Space below the pills */
    align-self: flex-start;
    /* Align with AI message */
}

/* Apply specific pill styling to items within this container */
.chat-history .initial-quick-actions-container .list-item {
    padding: 0.5rem 0.8rem !important;
    /* Smaller pill padding */
    font-size: 0.8rem !important;
    /* Smaller font */
    border-radius: 20px !important;
    /* Pill shape */
    box-shadow: var(--shadow-sm) !important;
    min-width: unset !important;
    /* Remove min-width to allow content-based sizing */
    flex-grow: 0 !important;
    /* Don't grow to fill space */
    flex-shrink: 1 !important;
    /* Allow shrinking */
    background: var(--bg-secondary) !important;
    /* Simple background */
    border: 1px solid var(--border-light) !important;
    color: var(--text-color) !important;
    margin: 0 !important;
    /* No external margins, managed by gap */
}

.chat-history .initial-quick-actions-container .list-item:hover {
    background: var(--bg-tertiary) !important;
    transform: none !important;
    /* No translateY on hover */
    box-shadow: var(--shadow-sm) !important;
}

.chat-history .initial-quick-actions-container .list-item span:first-child {
    margin-right: 0.4rem !important;
    font-size: 1em !important;
    /* Icon size proportional to text */
}

/* Adjust forms within widget area for embed mode */
body.embed-mode .widget-area {
    padding: 0.75rem !important;
    /* Compact internal padding */
    margin-bottom: 0.75rem !important;
    /* Space between widget and chat input */
    background: var(--bg-primary) !important;
    /* Ensure clean background */
}

body.embed-mode .form-section {
    padding: 0.75rem !important;
    /* Compact form section padding */
}

body.embed-mode .form-section h3 {
    font-size: 1rem !important;
    /* Smaller headings */
    margin-bottom: 0.75rem !important;
}

body.embed-mode .form-section label {
    font-size: 0.8rem !important;
    margin-bottom: 0.25rem !important;
}

body.embed-mode input[type="text"],
body.embed-mode input[type="password"],
body.embed-mode input[type="number"],
body.embed-mode select,
body.embed-mode textarea,
body.embed-mode .st-input {
    /* Added .st-input */
    padding: 0.5rem 0.75rem !important;
    /* Compact input padding */
    font-size: 0.8rem !important;
    /* Smaller font */
    margin-bottom: 0.75rem !important;
    /* Compact spacing */
    height: auto !important;
    /* Let content define height */
    min-height: 28px !important;
    /* Minimum reasonable height */
}

body.embed-mode textarea {
    min-height: 60px !important;
    /* Slightly more for textareas */
}


body.embed-mode .st-button {
    padding: 0.5rem 0.8rem !important;
    /* Compact button padding */
    font-size: 0.85rem !important;
    /* Smaller button font */
    border-radius: 16px !important;
    /* Maintain pill shape */
    box-shadow: var(--shadow-sm) !important;
    margin: 0.25rem 0 !important;
    /* Adjust margin */
}

body.embed-mode .st-button.full-width {
    margin-bottom: 0.5rem !important;
}

body.embed-mode .st-expander summary {
    padding: 0.6rem 0.8rem !important;
    /* Compact expander summary */
    font-size: 0.8rem !important;
}

body.embed-mode .expander-content {
    padding: 0.6rem !important;
    /* Compact expander content */
}

body.embed-mode .list-item {
    padding: 0.5rem 0.75rem !important;
    /* Compact list items */
    font-size: 0.8rem !important;
    border-radius: 12px !important;
    margin-bottom: 0.4rem !important;
    word-wrap: break-word !important;
    /* Ensure labels in list items wrap */
    white-space: normal !important;
}

body.embed-mode .list-container {
    /* REMOVED overflow-y: auto and max-height for embed mode to prevent nested scrolls */
    max-height: none !important;
    /* Allow content to push parent scroll */
    overflow-y: visible !important;
    /* Let content push parent scroll */
    padding: 0.4rem !important;
    margin-bottom: 0.75rem !important;
    border: none !important;
    /* Remove border for a cleaner look in embed */
    background: none !important;
    /* Remove background, blend with widget-area */
}

body.embed-mode .data-table-container {
    margin: 0.75rem 0 !important;
    border-radius: 8px !important;
    /* For data tables, overflow-x is fine, but overflow-y should be visible too */
    overflow-y: visible !important;
    max-height: none !important;
}

body.embed-mode .data-table th,
body.embed-mode .data-table td {
    padding: 0.5rem 0.75rem !important;
    /* Compact table cells */
    font-size: 0.7rem !important;
}

body.embed-mode .data-table th {
    font-size: 0.65rem !important;
}

body.embed-mode .info-box,
body.embed-mode .error-box,
body.embed-mode .warning-box,
body.embed-mode .success-box {
    padding: 0.6rem 0.8rem !important;
    /* Compact info boxes */
    font-size: 0.8rem !important;
    margin-bottom: 0.75rem !important;
}

body.embed-mode .info-box i,
body.embed-mode .error-box i,
body.embed-mode .warning-box i,
body.embed-mode .success-box i {
    font-size: 0.9rem !important;
}

body.embed-mode .db-tables-grid {
    grid-template-columns: 1fr !important;
    /* Stack panes vertically */
    gap: 0.75rem !important;
}

body.embed-mode .db-tables-pane,
body.embed-mode .sql-editor-pane {
    padding: 0.75rem !important;
    /* Compact pane padding */
}

body.embed-mode #monaco-container {
    height: 100px !important;
    /* Smaller Monaco editor */
    margin-bottom: 0.75rem !important;
}

body.embed-mode .compact-label {
    font-size: 0.8rem !important;
    margin-bottom: 0.2rem !important;
}

body.embed-mode .compact-button {
    padding: 0.5rem 0.75rem !important;
    font-size: 0.8rem !important;
    margin-bottom: 0.5rem !important;
}

body.embed-mode .file-uploader {
    padding: 1rem !important;
    /* Further reduced for compactness */
    border-radius: 8px !important;
    margin-bottom: 0.75rem !important;
}

body.embed-mode .file-uploader i {
    font-size: 2rem !important;
    /* Smaller icon */
    margin-bottom: 0.5rem !important;
}

body.embed-mode .file-uploader p {
    font-size: 0.8rem !important;
}

/* No horizontal scroll — use 100% not 100vw (vw = browser viewport, not iframe) */
body.embed-mode * {
    max-width: 100% !important;
}

/* Exceptions that need their own scroll */
body.embed-mode .data-table-container {
    max-width: 100% !important;
    overflow-x: auto !important;
}

body.embed-mode .data-table {
    max-width: none !important;
}

/* General button compacting when in widget area */
body.embed-mode .quick-actions-grid {
    display: flex !important;
    /* Use flexbox for wrapping pills */
    flex-wrap: wrap !important;
    /* Allow items to wrap */
    gap: 0.5rem !important;
    /* Space between items */
    padding: 0 !important;
    /* Remove excess padding */
    margin-bottom: 0.75rem !important;
    /* Space below the grid */
    flex-shrink: 0 !important;
    /* Keep it from shrinking too much */
}

body.embed-mode .quick-actions-grid .st-button {
    width: auto !important;
    /* Override default full-width */
    flex: 0 0 auto !important;
    /* Allow sizing by content */
    margin: 0 0.25rem 0.5rem 0 !important;
    /* Compact margins, like pills */
    padding: 0.5rem 0.8rem !important;
    /* Adjust padding for pills */
    font-size: 0.8rem !important;
    border-radius: 20px !important;
}

body.embed-mode .quick-actions-grid .st-button:hover {
    transform: none !important;
    /* No translateY on hover */
    box-shadow: var(--shadow-sm) !important;
}

/* ==========================================================================
   UI OVERHAUL: WIDGET STYLE (Reference Image Matching)
   ========================================================================== */

/* 1. Deep Blue Header */
.top-bar {
    background: #005494 !important;
    /* AIV Corporate Blue */
    padding: 0.8rem 1.2rem !important;
}

.app-title {
    font-size: 1rem !important;
    font-weight: 600 !important;
}

/* 2. Welcome Section (Greeting) */
.welcome-container {
    padding: 1.2rem 1.2rem 0.5rem 1.2rem;
    background: white;
}

.welcome-header {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 4px;
}

.welcome-subtext {
    font-size: 0.9rem;
    color: var(--text-secondary);
    margin-left: 2px;
}

/* 3. Vertical Action Cards */
.action-card-list {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    padding: 0.5rem 1.2rem 1.2rem 1.2rem;
    /* FIXED: Removed max-height + overflow-y auto.
       These caused individual scrollbars on each card inside the iframe.
       The parent .chat-content-scroll-area handles all scrolling. */
    max-height: none;
    overflow-y: visible;
    padding-right: 1.2rem;
}

.action-card {
    display: flex;
    align-items: center;
    padding: 0.85rem;
    background: white;
    border: 1px solid var(--border-light);
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    text-align: left;
    /* Ensure text aligns left */
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.02);
}

.action-card:hover {
    border-color: var(--primary-blue);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
}

body.in-iframe .action-card:hover,
body.embed-mode .action-card:hover {
    transform: none;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
}

/* 4. Colored Icon Boxes */
.card-icon-box {
    width: 42px;
    height: 42px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
    margin-right: 1rem;
    flex-shrink: 0;
}

/* Icon Color Variants */
.icon-purple {
    background: #f3e8ff;
    color: #9333ea;
}

.icon-orange {
    background: #ffedd5;
    color: #ea580c;
}

.icon-yellow {
    background: #fef9c3;
    color: #ca8a04;
}

.icon-blue {
    background: #dbeafe;
    color: #2563eb;
}

/* 5. Card Text */
.card-content {
    display: flex;
    flex-direction: column;
    flex: 1;
    /* FIXED: Allows text to fill available space beside icon */
    min-width: 0;
    /* FIXED: Prevents flex child from overflowing and clipping text */
    overflow: hidden;
}

.card-title {
    font-weight: 600;
    font-size: 1rem;
    color: var(--text-primary);
    line-height: 1.2;
    white-space: nowrap;
    /* FIXED: Keep title on one line */
    overflow: hidden;
    /* FIXED: Hide overflow */
    text-overflow: ellipsis;
    /* FIXED: Show "..." instead of cutting off */
}

.card-desc {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-top: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* 6. Quick Action Chips (Bottom) */
.quick-links {
    display: flex;
    flex-wrap: wrap;
    /* FIXED: wrap onto next line instead of overflowing */
    gap: 8px;
    padding: 0 1.2rem 1rem 1.2rem;
    font-size: 0.8rem;
    color: var(--text-secondary);
    align-items: center;
    overflow: hidden;
    /* FIXED: never show a scrollbar */
    box-sizing: border-box;
    width: 100%;
    /* FIXED: constrain to parent width */
}

.chip-btn {
    background: transparent;
    outline: 2px solid #2c9caf;
    color: #2c9caf;
    border: none;
    border-radius: 12px;
    padding: 4px 10px;
    font-size: 0.75rem;
    cursor: pointer;
    position: relative;
    overflow: hidden;
    z-index: 1;
    transition: color 0.4s ease-in-out;
    flex-shrink: 0;
    /* FIXED: don't squash button text */
    white-space: nowrap;
}

.chip-btn::before {
    content: '';
    position: absolute;
    top: 0;
    left: -50%;
    width: 0;
    height: 100%;
    background-color: #2c9caf;
    transform: skewX(45deg);
    z-index: -1;
    transition: width 0.4s ease-in-out;
}

.chip-btn:hover {
    color: white;
}

.chip-btn:hover::before {
    width: 250%;
}

/* Report list search bar (Step 1 of 3) */
.report-search-wrap {
    max-width: 100%;
}

.report-search-input {
    width: 100%;
    max-width: 400px;
    padding: 0.5rem 0.75rem 0.5rem 2rem;
    font-size: 0.9rem;
    border: 1px solid var(--border-light, #e5e7eb);
    border-radius: 8px;
    background: var(--bg-secondary, #f9fafb) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='%239ca3af' viewBox='0 0 16 16'%3E%3Cpath d='M11.742 10.344a6.5 6.5 0 1 0-1.397 1.398h-.001c.03.04.062.078.098.115l3.85 3.85a1 1 0 0 0 1.415-1.414l-3.85-3.85a1.007 1.007 0 0 0-.115-.1zM12 6.5a5.5 5.5 0 1 1-11 0 5.5 5.5 0 0 1 11 0z'/%3E%3C/svg%3E") no-repeat 0.5rem center;
    color: var(--text-primary, #111);
    transition: border-color 0.2s, box-shadow 0.2s;
}

.report-search-input:focus {
    outline: none;
    border-color: var(--primary-blue, #3b82f6);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
}

.report-search-input::placeholder {
    color: var(--text-secondary, #6b7280);
}

/* Hide Chat History when in Menu Mode */
.chat-history.hidden {
    display: none;
}

/* ==========================================================================
   WIZARD UI STYLES (Report Section)
   ========================================================================== */

/* 1. Wizard Header (e.g., "Create Report: Step 1 of 3") */
.step-header {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 4px;
    padding: 0.5rem 0.5rem 0 0.5rem;
}

.step-icon {
    font-size: 1.2rem;
    color: var(--primary-blue);
    background: var(--bg-secondary);
    width: 32px;
    height: 32px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.step-title {
    font-size: 1rem;
    font-weight: 700;
    color: var(--text-primary);
}

.step-counter {
    font-weight: 400;
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.step-subtext {
    padding: 0 0.5rem 1rem 0.5rem;
    color: var(--text-secondary);
    font-size: 0.9rem;
}

/* 2. Helper Message (Purple Bubble) */
.helper-message {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    background: #f5f3ff;
    /* Very light purple */
    border: 1px solid #ddd6fe;
    border-radius: 12px;
    padding: 12px 16px;
    margin: 1.2rem 0.5rem 0.5rem 0.5rem;
    font-size: 0.85rem;
    color: #5b21b6;
    /* Deep purple text */
    line-height: 1.4;
}

.helper-message i {
    color: #7c3aed;
    margin-top: 2px;
}

/* Safety: Ensure cards are always clickable */
.action-card {
    cursor: pointer !important;
    position: relative;
    z-index: 10;
    /* Lifts it above any potential background layers */
    user-select: none;
    /* Prevents text highlighting when clicking */
}

/* Ensure the widget area itself doesn't block clicks */
.widget-area {
    pointer-events: auto !important;
}

/* Styling for the Quick Action Buttons with Sliding Hover Effect */
.uiverse-button {
    margin-top: 0.5em;
    padding: 0.5em 1em;
    /* FIXED: tighter padding so buttons fit */
    border: none;
    border-radius: 5px;
    font-weight: bold;
    letter-spacing: 1px;
    /* FIXED: reduced letter-spacing saves width */
    text-transform: uppercase;
    cursor: pointer;
    color: #2c9caf;
    transition: all 1000ms;
    font-size: 11px;
    /* FIXED: slightly smaller */
    position: relative;
    overflow: hidden;
    outline: 2px solid #2c9caf;
    background: transparent;
    margin-left: 6px;
    /* FIXED: less margin */
    white-space: nowrap;
    flex-shrink: 0;
}

.uiverse-button:hover {
    color: #ffffff;
    transform: scale(1.1);
    outline: 2px solid #70bdca;
    box-shadow: 4px 5px 17px -4px #268391;
}

.uiverse-button::before {
    content: "";
    position: absolute;
    left: -50px;
    top: 0;
    width: 0;
    height: 100%;
    background-color: #2c9caf;
    transform: skewX(45deg);
    z-index: -1;
    transition: width 1000ms;
}

.uiverse-button:hover::before {
    width: 250%;
}


/* ==========================================================================
   IFRAME / EMBED COMPATIBILITY  ★ MASTER SECTION ★
   Covers both body.in-iframe (JS-detected) and body.embed-mode (param-detected).
   These rules override everything above for a seamless embedded experience.

   ROOT PROBLEM: dvh/vh units = browser window height, NOT iframe height.
                 max-width breakpoints expand the container outside the frame.
                 position:fixed is relative to browser viewport, not iframe.
   SOLUTION:     Use % everywhere. Flex chain with min-height:0 at every level.
   ========================================================================== */

/* ── 1. Lock html/body to the iframe boundaries ─────────────────────────── */
html {
    height: 100%;
    max-height: 100%;
    overflow: hidden;
}

body {
    height: 100%;
    max-height: 100%;
    overflow: hidden;
}

/* ── 2. App layout: column flex, 100% of frame ──────────────────────────── */
.app-layout {
    height: 100%;
    max-height: 100%;
    min-height: 0;
    overflow: hidden;
    flex-direction: column;
    /* column so nav-strip + main stack vertically */
}

/* ── 3. Main container: fill everything below the nav strip ─────────────── */
.main-container {
    max-width: 100% !important;
    width: 100% !important;
    margin: 0 !important;
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    height: 100%;
    box-shadow: none !important;
    border-radius: 0 !important;
    background: var(--bg-primary, #ffffff) !important;
    overflow: hidden;
}

/* Override every responsive max-width rule */
@media (min-width: 768px) {
    .main-container {
        max-width: 100% !important;
    }
}

@media (min-width: 1200px) {
    .main-container {
        max-width: 100% !important;
    }
}

/* ── 4. Sidebar: hide — no room in the embedded popup ───────────────────── */
.sidebar {
    display: none !important;
}

/* ── 5. The scroll area must have min-height:0 to actually scroll ────────── */
.chat-content-scroll-area {
    flex: 1;
    min-height: 0 !important;
    /* Without this, it expands beyond the frame */
    overflow-y: auto !important;
    overflow-x: hidden !important;
    padding: 0.65rem 0.85rem !important;
    gap: 0.65rem !important;
    background: var(--bg-secondary, #f8fafc) !important;
}

/* ── 6. Chat input: always at the bottom, never pushed off-screen ────────── */
.chat-input-wrapper {
    flex-shrink: 0 !important;
    padding: 0.5rem 0.75rem !important;
    background: white !important;
    border-top: 1px solid var(--border-light) !important;
    box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.06) !important;
    margin-top: 0 !important;
    /* Never push with margin-top:auto */
}

/* ── 7. Quick actions: single-column in narrow view ─────────────────────── */
.quick-actions-grid {
    grid-template-columns: 1fr !important;
}

/* ── 8. Prevent Angular Material CSS resets from leaking in ─────────────── */
.app-layout *,
.app-layout *::before,
.app-layout *::after {
    box-sizing: border-box;
}

/* ── 9. No element should expand beyond the frame width ─────────────────── */
.app-layout * {
    max-width: 100% !important;
}

/* Exception: tables need their own x-scroll container */
.data-table-container {
    overflow-x: auto !important;
    max-width: 100% !important;
}

.data-table {
    max-width: none !important;
    /* Table itself can be wider, container scrolls */
}

/* ── 10. Remove list inner scrollbars (parent handles scrolling) ─────────── */
.list-container {
    max-height: none !important;
    overflow-y: visible !important;
}

.action-card-list {
    max-height: none !important;
    overflow-y: visible !important;
}

/* ── 11. Message sizing for narrow containers ───────────────────────────── */
.message {
    max-width: calc(100% - 50px) !important;
    overflow-wrap: break-word !important;
    word-break: break-word !important;
}

.message-content,
.bubble-container {
    min-width: 0 !important;
    overflow-wrap: break-word !important;
    word-break: break-word !important;
    white-space: normal !important;
    overflow: visible !important;
}

.message code {
    white-space: pre-wrap !important;
    word-break: break-all !important;
    overflow-x: hidden !important;
    display: block !important;
}

/* ─────────────────────────────────────────────────────────────────────────
   BODY.IN-IFRAME  — JS class added when running inside <iframe>
   Hides the standalone top-bar; shows the compact iframe-nav-strip instead.
   ─────────────────────────────────────────────────────────────────────── */

/* Hide full standalone header in iframe */
body.in-iframe .top-bar {
    display: none !important;
}

/* Mic button is hidden by default in iframe (cross-origin permissions issue) */
body.in-iframe #mic-btn {
    display: none;
}

/* Re-show mic only when mic permission is confirmed */
body.in-iframe.mic-allowed #mic-btn {
    display: flex !important;
}

/* Compact input when mic is hidden */
body.in-iframe:not(.mic-allowed) .chat-input-box {
    gap: 0.4rem;
}

/* ─────────────────────────────────────────────────────────────────────────
   BODY.EMBED-MODE  — JS class added via ?embed=true URL param
   Same as in-iframe but the top-bar is also hidden.
   ─────────────────────────────────────────────────────────────────────── */
body.embed-mode .sidebar,
body.embed-mode .top-bar,
body.embed-mode .quick-actions-grid-top-hidden,
body.embed-mode .divider.top-divider-hidden {
    display: none !important;
}

/* Compact messages in embed/iframe */
body.in-iframe .message,
body.embed-mode .message {
    padding: 0.55rem 0.75rem !important;
    font-size: 0.86rem !important;
    line-height: 1.4 !important;
    box-shadow: var(--shadow-sm) !important;
}

body.in-iframe .message .avatar,
body.embed-mode .message .avatar {
    width: 28px !important;
    height: 28px !important;
    font-size: 0.9rem !important;
    flex-shrink: 0;
}

body.in-iframe .timestamp,
body.embed-mode .timestamp {
    font-size: 0.65rem !important;
    margin-top: 0.25rem !important;
}

/* Compact form elements */
body.in-iframe .form-section h3,
body.embed-mode .form-section h3 {
    font-size: 0.95rem !important;
    margin-bottom: 0.5rem !important;
}

body.in-iframe input[type="text"],
body.in-iframe input[type="password"],
body.in-iframe select,
body.in-iframe textarea,
body.embed-mode input[type="text"],
body.embed-mode input[type="password"],
body.embed-mode select,
body.embed-mode textarea {
    padding: 0.45rem 0.7rem !important;
    font-size: 0.82rem !important;
    margin-bottom: 0.6rem !important;
}

/* Compact buttons */
body.in-iframe .st-button,
body.embed-mode .st-button {
    padding: 0.45rem 0.75rem !important;
    font-size: 0.82rem !important;
    border-radius: 14px !important;
    box-shadow: var(--shadow-sm) !important;
}

body.in-iframe .st-button:hover,
body.embed-mode .st-button:hover {
    transform: none !important;
    /* No float-up animation in tight spaces */
}

/* Compact chat input elements */
body.in-iframe #user-input,
body.embed-mode #user-input {
    padding: 0.5rem 0.85rem !important;
    font-size: 0.86rem !important;
    border-radius: 20px !important;
    margin-bottom: 0 !important;
}

body.in-iframe #send-btn,
body.in-iframe #mic-btn,
body.embed-mode #send-btn,
body.embed-mode #mic-btn {
    width: 36px !important;
    height: 36px !important;
    box-shadow: var(--shadow-sm) !important;
}

/* Monaco editor compact */
body.in-iframe #monaco-container,
body.embed-mode #monaco-container {
    height: 120px !important;
    margin-bottom: 0.5rem !important;
}

/* DB grid: single column */
body.in-iframe .db-tables-grid,
body.embed-mode .db-tables-grid {
    grid-template-columns: 1fr !important;
    gap: 0.5rem !important;
}

/* File uploader compact */
body.in-iframe .file-uploader,
body.embed-mode .file-uploader {
    padding: 0.85rem !important;
    margin-bottom: 0.5rem !important;
}

body.in-iframe .file-uploader i,
body.embed-mode .file-uploader i {
    font-size: 1.75rem !important;
    margin-bottom: 0.35rem !important;
}

/* Faster, subtler animations in embedded context */
body.in-iframe .message,
body.embed-mode .message {
    animation: fadeInUp 0.25s ease-out !important;
}

/* ==========================================================================
   IFRAME NAV STRIP/* ==========================================================================
   IFRAME NAV STRIP
   Provides Back + Main Menu buttons inside the chat area when the HTML is
   embedded in an Angular iframe (which already has its own title header).
   ========================================================================== */

/* Hidden by default — only shown in iframe/embed mode */
#iframe-nav-strip {
    display: none;
}

/*
 * IFRAME DETECTION via CSS:
 * When this page is loaded inside an <iframe>, the Angular host applies a
 * fixed pixel height to the iframe element. We detect the "small viewport"
 * by checking max-height: 700px (iframe popup is ~600px tall, standalone
 * browser is always taller). Adjust the breakpoint if your iframe is taller.
 *
 * Alternatively, you can add class="in-iframe" to <body> from JavaScript:
 *   if (window.self !== window.top) document.body.classList.add('in-iframe');
 * and use body.in-iframe rules instead.
 */

/* Show the nav strip + hide top-bar when inside iframe */
body.in-iframe .top-bar {
    display: none !important;
}

body.in-iframe #iframe-nav-strip {
    display: flex !important;
    align-items: center;
    gap: 0.5rem;
    padding: 0.35rem 0.75rem;
    background: #005494;
    flex-shrink: 0 !important;
    /* NEVER allow this to grow/shrink — fixed header */
    min-height: 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.15);
    justify-content: flex-end;
    width: 100%;
}

body.in-iframe #iframe-nav-strip .nav-btn {
    background: rgba(255, 255, 255, 0.15) !important;
    border: 1px solid rgba(255, 255, 255, 0.3) !important;
    color: white !important;
    padding: 4px 10px !important;
    font-size: 0.75rem !important;
    border-radius: 12px !important;
    flex-shrink: 0;
}

body.in-iframe #iframe-nav-strip .nav-btn:hover {
    background: rgba(255, 255, 255, 0.28) !important;
}