/* ============================================
   Mobile Responsive Styles
   Sidebar Drawer Pattern for Small Screens
   ============================================ */

/* === Critical: Prevent FOUC (Flash of Unstyled Content) === */
/* Hide mobile-header-bar on desktop IMMEDIATELY (before JS) */
@media (min-width: 769px) {
    .mobile-header-bar {
        display: none !important;
    }
}

/* Hide home content until page ready - prevents layout shift */
body:not(.page-ready):not(.has-messages) .chatbox {
    opacity: 0 !important;
    visibility: hidden !important;
    transition: none !important;
}
body.page-ready:not(.has-messages) .chatbox {
    opacity: 1 !important;
    visibility: visible !important;
    transition: opacity 0.15s ease, visibility 0s;
}

/* === Global Keyframes for Weather/Time Icons === */
@-webkit-keyframes rain-fall {
    0% { transform: translateY(0); }
    100% { transform: translateY(3px); }
}
@keyframes rain-fall {
    0% { transform: translateY(0); }
    100% { transform: translateY(3px); }
}

@-webkit-keyframes snow-fall {
    0%, 100% { transform: translateY(0) rotate(0deg); }
    50% { transform: translateY(2px) rotate(180deg); }
}
@keyframes snow-fall {
    0%, 100% { transform: translateY(0) rotate(0deg); }
    50% { transform: translateY(2px) rotate(180deg); }
}

@-webkit-keyframes lightning-flash {
    0%, 90%, 100% { opacity: 1; }
    92%, 94%, 96% { opacity: 0.3; }
}
@keyframes lightning-flash {
    0%, 90%, 100% { opacity: 1; }
    92%, 94%, 96% { opacity: 0.3; }
}

@-webkit-keyframes fog-drift {
    0%, 100% { transform: translateX(0); opacity: 0.7; }
    50% { transform: translateX(2px); opacity: 0.9; }
}
@keyframes fog-drift {
    0%, 100% { transform: translateX(0); opacity: 0.7; }
    50% { transform: translateX(2px); opacity: 0.9; }
}

@-webkit-keyframes cloud-float {
    0%, 100% { transform: translateX(0); }
    50% { transform: translateX(2px); }
}
@keyframes cloud-float {
    0%, 100% { transform: translateX(0); }
    50% { transform: translateX(2px); }
}

/* === Global Keyframes for Time Icons === */
@-webkit-keyframes sun-glow {
    0%, 100% {
        -webkit-filter: drop-shadow(0 0 4px rgba(251, 191, 36, 0.4));
        filter: drop-shadow(0 0 4px rgba(251, 191, 36, 0.4));
    }
    50% {
        -webkit-filter: drop-shadow(0 0 12px rgba(251, 191, 36, 0.7));
        filter: drop-shadow(0 0 12px rgba(251, 191, 36, 0.7));
    }
}
@keyframes sun-glow {
    0%, 100% {
        -webkit-filter: drop-shadow(0 0 4px rgba(251, 191, 36, 0.4));
        filter: drop-shadow(0 0 4px rgba(251, 191, 36, 0.4));
    }
    50% {
        -webkit-filter: drop-shadow(0 0 12px rgba(251, 191, 36, 0.7));
        filter: drop-shadow(0 0 12px rgba(251, 191, 36, 0.7));
    }
}

@-webkit-keyframes sun-spin {
    from { -webkit-transform: rotate(0deg); transform: rotate(0deg); }
    to { -webkit-transform: rotate(360deg); transform: rotate(360deg); }
}
@keyframes sun-spin {
    from { -webkit-transform: rotate(0deg); transform: rotate(0deg); }
    to { -webkit-transform: rotate(360deg); transform: rotate(360deg); }
}

@-webkit-keyframes moon-glow {
    0%, 100% {
        -webkit-filter: drop-shadow(0 0 4px rgba(165, 180, 252, 0.3));
        filter: drop-shadow(0 0 4px rgba(165, 180, 252, 0.3));
    }
    50% {
        -webkit-filter: drop-shadow(0 0 10px rgba(165, 180, 252, 0.6));
        filter: drop-shadow(0 0 10px rgba(165, 180, 252, 0.6));
    }
}
@keyframes moon-glow {
    0%, 100% {
        -webkit-filter: drop-shadow(0 0 4px rgba(165, 180, 252, 0.3));
        filter: drop-shadow(0 0 4px rgba(165, 180, 252, 0.3));
    }
    50% {
        -webkit-filter: drop-shadow(0 0 10px rgba(165, 180, 252, 0.6));
        filter: drop-shadow(0 0 10px rgba(165, 180, 252, 0.6));
    }
}

/* Hide desktop elements on mobile IMMEDIATELY (before JS) */
@media (max-width: 768px) {
    .model-select-wrapper {
        display: none !important;
    }
    .toggle-button {
        display: none !important;
    }

    /* Options layout - vertical on small screens (before JS) */
    body:not(.has-messages) .options {
        display: flex !important;
        flex-direction: column !important;
        align-items: center !important;
        gap: 0 !important;
    }

    /* Greeting centered */
    body:not(.has-messages) .greeting-container {
        text-align: center !important;
    }
    body:not(.has-messages) .greeting-text {
        font-size: 1.25rem !important;
        color: #ffffff !important;
    }
}

/* ============================================
   DEVICE-CLASS BASED STYLES (DeviceDetector v2)
   These use body classes instead of media queries
   for capability-based styling
   ============================================ */

/* === CSS Variable Overrides for Mobile === */
body.device-phone,
body.device-tablet,
body.is-mobile,
body.viewport-mobile {
    --send-button-size: 32px;
    --mobile-header-height: 44px;
}

/* === Hover States - Only on devices with hover capability === */
body.no-hover *:hover {
    /* Disable hover effects on touch-only devices */
}

body.no-hover .btn:hover,
body.no-hover .button:hover,
body.no-hover button:hover {
    /* Prevent sticky hover on touch devices */
    background: inherit;
    transform: none;
}

/* === Tooltips - Hide on touch devices === */
body.no-hover [data-tooltip]::after,
body.no-hover [data-tooltip]::before,
body.no-hover .tooltip,
body.no-hover .toggle-tooltip {
    display: none !important;
    visibility: hidden !important;
    opacity: 0 !important;
}

/* === Touch Targets - Larger on touch devices === */
/* Using :where() for zero specificity - easily overridden by component styles */
:where(body.is-touch) button,
:where(body.is-touch) .btn,
:where(body.is-touch) [role="button"],
:where(body.is-touch) .clickable {
    min-height: 44px;
    min-width: 44px;
}


body.is-touch input[type="checkbox"],
body.is-touch input[type="radio"] {
    min-height: 24px;
    min-width: 24px;
}

/* === Reduced Motion - Respect user preference === */
body.prefers-reduced-motion *,
body.prefers-reduced-motion *::before,
body.prefers-reduced-motion *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
}

/* Exception: Keep thinking indicator pulsing even with reduced motion */
body.prefers-reduced-motion .thinking-indicator .thinking-dots span,
body.prefers-reduced-motion .simple-pulsing-dot .streaming-cursor,
body.prefers-reduced-motion .streaming-cursor {
    animation-duration: 1.5s !important;
    animation-iteration-count: infinite !important;
}

/* === Hybrid Devices (touch + mouse) === */
:where(body.is-hybrid) button,
:where(body.is-hybrid) .btn {
    /* Slightly larger than desktop, smaller than phone */
    min-height: 38px;
}

/* === Phone-specific === */
body.device-phone {
    /* Base phone adjustments */
    --composer-padding-x: 12px;
    --composer-padding-y: 10px;
}

/* Sidebar toggle button sizing for touch/mobile devices */
body.device-phone .sidebar-toggle-button,
body.device-tablet .sidebar-toggle-button,
body.is-touch .sidebar-toggle-button,
body.viewport-mobile .sidebar-toggle-button {
    width: 44px;
    height: 44px;
}

body.device-phone .sidebar-toggle-button svg,
body.device-tablet .sidebar-toggle-button svg,
body.is-touch .sidebar-toggle-button svg {
    width: 1.5rem !important;
    height: 1.5rem !important;
    min-width: 1.5rem !important;
    min-height: 1.5rem !important;
    flex-shrink: 0 !important;
}

/* Larger icon for viewport-mobile (resized desktop) */
body.viewport-mobile .sidebar-toggle-button svg {
    width: 1.75rem !important;
    height: 1.75rem !important;
}

/* === Tablet-specific === */
body.device-tablet {
    /* Tablet adjustments */
    --composer-padding-x: 16px;
    --composer-padding-y: 12px;
}

/* === Desktop/Laptop - Reset touch accommodations === */
body.device-desktop button,
body.device-desktop .btn,
body.device-laptop button,
body.device-laptop .btn {
    min-height: unset;
    min-width: unset;
}

/* === Safe Area Insets (notched phones) === */
body.device-phone,
body.device-tablet {
    --safe-area-top: env(safe-area-inset-top, 0px);
    --safe-area-bottom: env(safe-area-inset-bottom, 0px);
    --safe-area-left: env(safe-area-inset-left, 0px);
    --safe-area-right: env(safe-area-inset-right, 0px);
}

/* =============================================
   MOBILE HEADER BAR - ChatGPT Style
   Clean header with burger | model | ghost
   ============================================= */

/* Hide mobile header on desktop */
.mobile-header-bar {
    display: none;
}

/* Hide desktop temp-chat-launcher on mobile */
body.device-phone .temp-chat-launcher.desktop-only,
body.device-tablet .temp-chat-launcher.desktop-only,
body.is-mobile .temp-chat-launcher.desktop-only,
body.is-ios .temp-chat-launcher.desktop-only {
    display: none !important;
}

/* Hide old toggle button on mobile (using new header burger) */
body.device-phone .toggle-button,
body.device-tablet .toggle-button,
body.is-mobile .toggle-button,
body.is-ios .toggle-button {
    display: none !important;
}

/* Show mobile header bar on phones/tablets */
body.device-phone .mobile-header-bar,
body.device-tablet .mobile-header-bar,
body.is-mobile .mobile-header-bar,
body.is-ios .mobile-header-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--mobile-header-height);
    padding: 0 4px;
    padding-top: env(safe-area-inset-top, 0px);
    background: #000 !important;
    border-bottom: none;
    z-index: 9999 !important;
    box-sizing: content-box;
}

/* Burger menu button - ChatGPT Style */
.mobile-header-burger {
    position: relative;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    width: 44px;
    height: 44px;
    padding: 0;
    background: transparent;
    border: none;
    cursor: pointer;
    flex-shrink: 0;
    gap: 6px;
}

.mobile-header-burger:active {
    transform: scale(0.95);
}

/* Two clean lines - ChatGPT style */
.mobile-header-burger span {
    display: block;
    width: 22px;
    height: 2px;
    background: rgba(255, 255, 255, 0.85);
    border-radius: 1px;
}

/* Hide third line */
.mobile-header-burger span:nth-child(3) {
    display: none;
}

/* Model selector - centered */
body.device-phone .mobile-model-select,
body.device-tablet .mobile-model-select,
body.is-mobile .mobile-model-select,
body.is-ios .mobile-model-select {
    position: relative;
    top: auto;
    left: auto;
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 44px;
    max-height: 44px;
    padding: 0;
    
    background: transparent;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    overflow: visible;
    transition: background 0.15s ease;
    z-index: 1;
}

body.device-phone .mobile-model-select:active,
body.device-tablet .mobile-model-select:active,
body.is-mobile .mobile-model-select:active,
body.is-ios .mobile-model-select:active {
    background: rgba(255, 255, 255, 0.08);
}

body.device-phone .mobile-model-select.expanded,
body.device-tablet .mobile-model-select.expanded,
body.is-mobile .mobile-model-select.expanded,
body.is-ios .mobile-model-select.expanded {
    position: relative;
    background: rgba(40, 40, 40, 0.98);
    border-radius: 12px;
    z-index: 9999;
}

/* Dropdown options container */
body.device-phone .mobile-model-select .mobile-model-options,
body.device-tablet .mobile-model-select .mobile-model-options,
body.is-mobile .mobile-model-select .mobile-model-options,
body.is-ios .mobile-model-select .mobile-model-options {
    display: none;
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    min-width: 180px;
    max-height: 50vh;
    overflow-y: auto;
    background: rgba(40, 40, 40, 0.98);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
    margin-top: 8px;
    padding: 8px 0;
    flex-direction: column;
}

body.device-phone .mobile-model-select.expanded .mobile-model-options,
body.device-tablet .mobile-model-select.expanded .mobile-model-options,
body.is-mobile .mobile-model-select.expanded .mobile-model-options,
body.is-ios .mobile-model-select.expanded .mobile-model-options {
    display: flex;
}

/* Model header */
body.device-phone .mobile-model-header,
body.device-tablet .mobile-model-header,
body.is-mobile .mobile-model-header,
body.is-ios .mobile-model-header {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 0 12px;
    height: 36px;
    min-height: 36px;
    white-space: nowrap;
}

body.device-phone .mobile-model-name,
body.device-tablet .mobile-model-name,
body.is-mobile .mobile-model-name,
body.is-ios .mobile-model-name {
    font-size: 0.9rem;
    font-weight: 600;
    color: rgba(255, 255, 255, 0.9);
}

body.device-phone .mobile-model-arrow,
body.device-tablet .mobile-model-arrow,
body.is-mobile .mobile-model-arrow,
body.is-ios .mobile-model-arrow {
    color: rgba(255, 255, 255, 0.5);
    transition: transform 0.2s ease;
}

body.device-phone .mobile-model-select.expanded .mobile-model-arrow,
body.device-tablet .mobile-model-select.expanded .mobile-model-arrow,
body.is-mobile .mobile-model-select.expanded .mobile-model-arrow,
body.is-ios .mobile-model-select.expanded .mobile-model-arrow {
    transform: rotate(180deg);
}

/* Ghost button */
.mobile-header-ghost {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    padding: 0;
    
    background: transparent;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    color: rgba(255, 255, 255, 0.7);
    flex-shrink: 0;
    transition: background 0.15s ease, color 0.15s ease;
}

.mobile-header-ghost:active {
    background: transparent;
    color: rgba(255, 255, 255, 1);
}

/* Temp chat button - transparent on mobile devices */
body.device-phone .temp-chat-button,
body.device-tablet .temp-chat-button,
body.is-mobile .temp-chat-button,
body.is-ios .temp-chat-button {
    background: transparent !important;
    border: none !important;
    backdrop-filter: none !important;
    -webkit-backdrop-filter: none !important;
}

body.device-phone .temp-chat-button:hover,
body.device-tablet .temp-chat-button:hover,
body.is-mobile .temp-chat-button:hover,
body.is-ios .temp-chat-button:hover {
    background: transparent !important;
}

/* Hide toggle button in temp chat mode on mobile - use mobile header burger instead */
body.device-phone.temporary-chat-mode .toggle-button,
body.device-tablet.temporary-chat-mode .toggle-button,
body.is-mobile.temporary-chat-mode .toggle-button,
body.is-ios.temporary-chat-mode .toggle-button {
    display: none !important;
}

.mobile-header-ghost svg,
body.device-phone .mobile-header-ghost svg,
body.device-tablet .mobile-header-ghost svg,
body.is-mobile .mobile-header-ghost svg,
body.is-ios .mobile-header-ghost svg,
#temp-chat-button.mobile-header-ghost svg,
.mobile-header-bar .mobile-header-ghost svg,
.mobile-header-bar #temp-chat-button svg {
    width: 32px !important;
    height: 32px !important;
    min-width: 32px !important;
    min-height: 32px !important;
}

/* Spacer for guests (no ghost button) */
.mobile-header-spacer {
    width: 44px;
    height: 44px;
    flex-shrink: 0;
}

/* Hide when sidebar is open */
body.mobile-sidebar-open .mobile-header-bar {
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
}

/* Adjust content area for header bar */
body.device-phone .chat-area,
body.device-tablet .chat-area,
body.is-mobile .chat-area,
body.is-ios .chat-area {
    padding-top: 0 !important;
}

body.device-phone #chat-display,
body.device-tablet #chat-display,
body.is-mobile #chat-display,
body.is-ios #chat-display {
    padding-top: 0 !important;
}

/* Hide desktop model selector on mobile */
body.device-phone .model-select-wrapper,
body.device-tablet .model-select-wrapper,
body.is-mobile .model-select-wrapper,
body.is-ios .model-select-wrapper {
    display: none !important;
}

/* === Standalone/PWA Mode === */
body.is-standalone {
    /* PWA installed - adjust for no browser chrome */
    --header-height: calc(56px + env(safe-area-inset-top, 0px));
}

body.is-standalone .page-wrapper::before {
    height: var(--header-height);
    padding-top: env(safe-area-inset-top, 0px);
}

/* ============================================
   SIDEBAR DRAWER - Device Class Based
   Phone: Full drawer pattern
   Tablet: Can use drawer or collapsible
   ============================================ */

/* Phone sidebar - always drawer */
body.device-phone .left-sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: var(--mobile-sidebar-width, 280px) !important;
    height: 100vh;
    height: 100dvh;
    transform: translateX(-100%);
    z-index: var(--z-sidebar, 1000);
    box-shadow: none;
    visibility: hidden;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1), visibility 0s linear 0.3s;
    background: var(--sidebar-bg, #0b0b10);
    will-change: transform;
}

body.device-phone.mobile-sidebar-open .left-sidebar {
    transform: translateX(0);
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.5);
    visibility: visible;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1), visibility 0s linear 0s;
}

body.device-phone .content-wrapper {
    margin-left: 0 !important;
    width: 100% !important;
}

body.device-phone.mobile-sidebar-open {
    overflow: hidden;
}

/* Phone overlay backdrop */
body.device-phone .mobile-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    z-index: var(--z-overlay, 900);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

body.device-phone .mobile-overlay.active {
    opacity: 1;
    visibility: visible;
}

/* Tablet - can use either drawer or collapsible */
body.device-tablet .left-sidebar {
    width: var(--mobile-sidebar-width, 300px) !important;
}

body.device-tablet.is-landscape .left-sidebar {
    /* Tablet landscape might show sidebar */
    width: 280px !important;
}

/* Hide guest floating login on mobile devices */
body.device-phone .guest-floating-login,
body.device-tablet .guest-floating-login {
    display: none !important;
}

/* ============================================
   COMPOSER/INPUT - Device Class Based
   ============================================ */

/* Phone composer - fixed bottom, full width */
body.device-phone .chat-shell__composer {
    left: 0 !important;
    width: 100% !important;
    padding: var(--space-2) var(--space-3) calc(var(--space-2) + var(--safe-area-bottom, 0px));
}

body.device-phone .input-row {
    border-radius: 24px;
    padding: 8px 12px;
    background: var(--input-row-bg, #1a1a1a);
}

body.device-phone .chat-input {
    font-size: 16px !important; /* Prevents iOS zoom */
    min-height: 24px;
    max-height: 120px;
}

body.device-phone .chat-input::placeholder {
    font-size: 14px;
}

/* Tablet composer */
body.device-tablet .chat-shell__composer {
    left: 0 !important;
    width: 100% !important;
    max-width: 100%;
}

body.device-tablet .input-row {
    border-radius: 26px;
    padding: 10px 16px;
}

body.device-tablet .chat-input {
    font-size: 16px !important;
}

/* Touch devices - ensure no zoom on focus */
body.is-touch .chat-input,
body.is-touch textarea,
body.is-touch input[type="text"] {
    font-size: 16px !important;
    -webkit-text-size-adjust: 100%;
}

/* Hybrid devices - slightly smaller touch targets */
body.is-hybrid .send-button {
    width: 34px;
    height: 34px;
}

/* iOS specific fixes */
body.is-ios .chat-input {
    -webkit-appearance: none;
    -webkit-user-select: text;
}

body.is-ios.device-phone .chat-shell__composer {
    /* Account for iOS Safari bottom bar */
    padding-bottom: calc(var(--space-3) + env(safe-area-inset-bottom, 20px));
}

/* Android specific */
body.is-android .chat-input:focus {
    /* Android keyboard push fix */
    scroll-margin-bottom: 100px;
}

/* ============================================
   MESSAGES/CHAT DISPLAY - Device Class Based

   NOTE: Base .message padding/margin styles are defined in the
   "ChatGPT-Style Mobile Messages" media query section (~line 2520)
   which uses !important for the chat bubble layout.
   Device-class styles here handle behavioral/interaction aspects.
   ============================================ */

/* Message content typography */
body.device-phone .message-content {
    font-size: 15px;
    line-height: 1.5;
}

body.device-tablet .message-content {
    font-size: 15px;
}

/* Message action buttons */
body.device-phone .message-actions {
    gap: 4px;
}

body.device-phone .message-actions button {
    width: 32px;
    height: 32px;
    min-width: 32px;
}

/* Chat scroll region - THE ONLY scroll container on mobile */
body.device-phone #chat-scroll-region,
body.device-tablet #chat-scroll-region,
body.is-mobile #chat-scroll-region,
body.is-ios #chat-scroll-region {
    position: relative !important;
    overflow-y: scroll !important;
    overflow-x: hidden !important;
    -webkit-overflow-scrolling: touch !important;
    overscroll-behavior-y: contain;
    overscroll-behavior-x: none;
    height: 100% !important;
    flex: 1 1 auto !important;
    min-height: 0 !important;
}

/* Disable scroll on all parent containers - only #chat-scroll-region scrolls */
body.device-phone,
body.device-tablet,
body.is-mobile,
body.is-ios {
    overflow: hidden !important;
}

/* NOTE: .chat-shell__messages IS #chat-scroll-region - don't disable scroll on it */
/* Parent containers: hidden overflow, let scroll region handle all scrolling */
/* Also fix height for mobile viewport */
body.device-phone .chat-area,
body.device-tablet .chat-area,
body.is-mobile .chat-area,
body.is-ios .chat-area {
    overflow: hidden !important;
    height: 100vh !important;
    height: 100dvh !important; /* Preferred */
    max-height: 100vh !important;
    max-height: 100dvh !important; /* Preferred */
}

body.device-phone .content-wrapper,
body.device-tablet .content-wrapper,
body.is-mobile .content-wrapper,
body.is-ios .content-wrapper {
    overflow: hidden !important;
    min-height: 100vh !important;
    min-height: 100dvh !important; /* Preferred */
}

body.device-phone .chat-shell,
body.device-tablet .chat-shell,
body.is-mobile .chat-shell,
body.is-ios .chat-shell,
body.device-phone .chat-stage,
body.device-tablet .chat-stage,
body.is-mobile .chat-stage,
body.is-ios .chat-stage {
    overflow: hidden !important;
    height: 100% !important;
}

body.device-phone #chat-scroll-region,
body.device-phone .chat-display {
    padding: 0 8px;
    padding-bottom: calc(var(--composer-reserved-height, 80px) + var(--safe-area-bottom, 0px));
}

body.device-tablet #chat-scroll-region,
body.device-tablet .chat-display {
    padding: 0 16px;
    padding-bottom: calc(var(--composer-reserved-height, 100px) + var(--safe-area-bottom, 0px));
}

/* Touch devices - swipe to reveal actions */
body.is-touch .message {
    touch-action: pan-y;
}

/* No hover - always show critical actions */
body.no-hover .message .message-actions {
    opacity: 1;
}

body.no-hover .message .message-actions .secondary-action {
    /* Hide secondary actions, show on long-press */
    display: none;
}

/* ============================================
   BUTTONS/TOUCH TARGETS - Device Class Based
   ============================================ */

/* Touch devices - minimum 44px touch target (Apple HIG) */
:where(body.is-touch) .btn,
:where(body.is-touch) .button,
:where(body.is-touch) button:not(.inline-btn),
:where(body.is-touch) [role="button"] {
    min-height: 44px;
    min-width: 44px;
    padding: 10px 16px;
}

/* Options/suggestion buttons - preserve pill styling (higher specificity) */
body.is-touch .options button,
body.is-mobile .options button,
body.device-phone .options button,
body.device-tablet .options button {
    min-height: auto !important;
    min-width: auto !important;
    height: auto !important;
    width: auto !important;
    padding: 12px 20px !important;
}

/* Phone - even larger targets */
body.device-phone .action-btn,
body.device-phone .icon-btn {
    width: 44px;
    height: 44px;
}

body.device-phone .toggle-button {
    width: 48px;
    height: 48px;
}

/* Tablet targets */
body.device-tablet .action-btn,
body.device-tablet .icon-btn {
    width: 40px;
    height: 40px;
}

/* Hybrid - balanced targets */
:where(body.is-hybrid) .btn,
:where(body.is-hybrid) button {
    min-height: 38px;
}

/* Desktop/Laptop - normal targets */
:where(body.device-desktop) .btn,
:where(body.device-desktop) button,
:where(body.device-laptop) .btn,
:where(body.device-laptop) button {
    min-height: unset;
    min-width: unset;
}

/* === Composer buttons - Preserve original sizing === */
/* These override :where() rules above which have zero specificity */
.input-row button,
.textarea-container button,
.chat-shell__composer button,
.actions-menu button,
.actions-toggle,
.send-button {
    min-height: unset;
    min-width: unset;
    padding: 0;
}

/* === Close sidebar button - explicit sizing for all devices === */
.close-sidebar-btn,
.mobile-close-sidebar {
    width: 36px;
    height: 36px;
    min-width: 36px;
    min-height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    background: transparent;
    border-radius: 50%;
    cursor: pointer;
}

.close-sidebar-btn:hover,
.mobile-close-sidebar:hover {
    background: rgba(255, 255, 255, 0.1);
}

/* ============================================
   SCROLL-TO-BOTTOM BUTTON - Device Class Based
   ============================================ */

body.device-phone .scroll-to-bottom,
body.device-phone .arrow-down,
body.device-tablet .scroll-to-bottom,
body.device-tablet .arrow-down,
body.is-mobile .scroll-to-bottom,
body.is-mobile .arrow-down,
body.is-ios .scroll-to-bottom,
body.is-ios .arrow-down {
    position: fixed !important;
    width: 44px !important;
    height: 44px !important;
    bottom: calc(100px + env(safe-area-inset-bottom, 0px)) !important;
    left: 50% !important;
    right: auto !important;
    top: auto !important;
    transform: translateX(-50%) !important;
    border-radius: 50% !important;
    z-index: 9999 !important;
    background: rgba(40, 40, 40, 0.95) !important;
    border: 1px solid rgba(255, 255, 255, 0.2) !important;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3) !important;
    cursor: pointer !important;
    touch-action: manipulation !important;
    -webkit-tap-highlight-color: transparent !important;
    pointer-events: auto !important;
}

/* Show arrow when has messages */
body.device-phone.has-messages .arrow-down,
body.device-tablet.has-messages .arrow-down,
body.is-mobile.has-messages .arrow-down,
body.is-ios.has-messages .arrow-down {
    display: flex !important;
}

/* Hide when at bottom - uses body class from IntersectionObserver */
body.device-phone.at-scroll-bottom .arrow-down,
body.device-tablet.at-scroll-bottom .arrow-down,
body.is-mobile.at-scroll-bottom .arrow-down,
body.is-ios.at-scroll-bottom .arrow-down {
    display: none !important;
}

/* Down arrow bounce animation on mobile */
body.device-phone .arrow-down,
body.is-mobile .arrow-down,
body.is-ios .arrow-down {
    animation: downArrowBounce 0.6s ease-out;
}

@keyframes downArrowBounce {
    0% {
        transform: translateX(-50%) translateY(20px);
        opacity: 0;
    }
    50% {
        transform: translateX(-50%) translateY(-8px);
        opacity: 1;
    }
    70% {
        transform: translateX(-50%) translateY(4px);
    }
    100% {
        transform: translateX(-50%) translateY(0);
    }
}

/* ============================================
   Pull to Refresh
   ============================================ */
.pull-to-refresh {
    display: none;
}

/* --- CSS Variables --- */
:root {
    --header-height: 56px;
    --mobile-sidebar-width: 280px;
    --mobile-header-height: 56px;

    /* Z-Index Hierarchy (mobile)
       10-99:    Content elements
       100-199:  Fixed footer/composer
       200-499:  Fixed header bar
       500-899:  Header controls (toggle, model select)
       900-999:  Overlay backdrop
       1000-1099: Sidebar drawer
       1100+:    Modals and dropdowns
    */
    --z-composer: 100;
    --z-header-bar: 200;
    --z-header-controls: 500;
    --z-overlay: 900;
    --z-sidebar: 1000;
    --z-modal: 1100;
}

/* --- Top Bar Background (Desktop + Mobile) --- */
/* Creates a solid bar so scrolling content goes UNDER it */
.page-wrapper::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--header-height);
    background: var(--background-dark, #212121);
    z-index: var(--z-header-bar, 200);
    pointer-events: none;
}

/* Ensure header elements are above the bar */
.toggle-button {
    z-index: var(--z-header-controls, 500) !important;
}

.model-select-wrapper {
    z-index: var(--z-header-controls, 500) !important;
}

.temp-chat-launcher {
    z-index: var(--z-header-controls, 500) !important;
}

/* Mobile breakpoint: 768px and below */
@media (max-width: 768px) {

    /* --- Touch-action for faster tap response --- */
    button,
    a,
    input,
    textarea,
    select,
    [role="button"],
    .clickable,
    .chat-tab,
    .sidebar-action-btn,
    .sidebar-toggle-button,
    .submit-btn,
    .social-btn,
    .toggle-button,
    .model-select {
        touch-action: manipulation;
        -webkit-tap-highlight-color: transparent;
    }

    /* Hide tab action dots on mobile - use long-press orbit menu instead */
    .tab-actions-toggle,
    .tab-actions {
        display: none !important;
    }

    /* Mobile uses its own header height variable */
    .page-wrapper::before {
        height: var(--mobile-header-height);
    }

    /* --- Hide Guest Floating Login on Mobile --- */
    /* Mobile uses drawer pattern, not collapsed sidebar */
    body .guest-floating-login,
    body .guest-floating-login.visible,
    .page-wrapper .guest-floating-login,
    .page-wrapper .guest-floating-login.visible {
        display: none;
        visibility: hidden;
    }

    /* --- Mobile Overlay/Backdrop --- */
    .mobile-overlay {
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.6);
        backdrop-filter: blur(4px);
        -webkit-backdrop-filter: blur(4px);
        z-index: var(--z-overlay, 900);
        opacity: 0;
        visibility: hidden;
        transition: opacity 0.3s ease, visibility 0.3s ease;
    }

    .mobile-overlay.active {
        opacity: 1;
        visibility: visible;
    }

    /* --- Left Sidebar as Drawer --- */
    .left-sidebar {
        position: fixed;
        top: 0;
        left: 0;
        width: var(--mobile-sidebar-width) !important;
        height: 100vh;
        height: 100dvh; /* Dynamic viewport height for mobile */
        transform: translateX(-100%);
        transition: none; /* No transition on initial load */
        z-index: var(--z-sidebar, 1000);
        box-shadow: none;
        min-height: 0; /* Allow flex shrinking */
        visibility: hidden; /* Hidden until opened */
    }

    /* Enable transitions only after page is ready */
    body.mobile-ready .left-sidebar {
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1), visibility 0s linear 0.3s;
    }

    /* Sidebar open state on mobile */
    body.mobile-sidebar-open .left-sidebar {
        transform: translateX(0);
        box-shadow: 4px 0 24px rgba(0, 0, 0, 0.5);
        pointer-events: auto;
        overflow-y: auto;
        overflow-x: hidden;
        -webkit-overflow-scrolling: touch;
        visibility: visible;
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1), visibility 0s linear 0s;
    }

    /* Override the collapsed state on mobile - we use drawer instead */
    body.sidebar-collapsed .left-sidebar {
        width: var(--mobile-sidebar-width) !important;
        transform: translateX(-100%);
    }

    body.sidebar-collapsed.mobile-sidebar-open .left-sidebar {
        transform: translateX(0);
    }

    /* --- Content Wrapper Adjustments --- */
    .content-wrapper {
        margin-left: 0 !important;
        width: 100% !important;
        transition: none;
    }

    /* Prevent scrolling when sidebar is open */
    body.mobile-sidebar-open {
        overflow: hidden;
    }

    body.mobile-sidebar-open .content-wrapper {
        pointer-events: none;
    }

    /* --- Toggle Button as Hamburger Menu --- */
    .toggle-button {
        position: fixed;
        top: 12px;
        left: 12px;
        transform: none;
        z-index: 1100;
        width: 40px;
        height: 40px;
        background: rgba(30, 30, 30, 0.9);
        border-radius: 12px;
        border: 1px solid rgba(255, 255, 255, 0.1);
        backdrop-filter: blur(8px);
        -webkit-backdrop-filter: blur(8px);
    }

    /* Hide toggle when sidebar is open */
    body.mobile-sidebar-open .toggle-button {
        opacity: 0;
        pointer-events: none;
    }

    /* Hide model selector and temp chat when sidebar is open */
    body.mobile-sidebar-open .model-select-wrapper,
    body.mobile-sidebar-open .mobile-model-select,
    body.mobile-sidebar-open .temp-chat-launcher {
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.2s ease;
    }

    /* Hamburger icon lines */
    .toggle-button::before,
    .toggle-button::after {
        width: 18px;
        height: 2px;
        left: 50%;
        border-radius: 2px;
    }

    .toggle-button::before {
        transform: translate(-50%, -5px);
    }

    .toggle-button::after {
        transform: translate(-50%, 5px);
    }

    /* Add middle line for hamburger */
    .toggle-button .hamburger-line {
        position: absolute;
        width: 18px;
        height: 2px;
        background-color: var(--line-color, rgb(110, 110, 110));
        border-radius: 2px;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);
        transition: opacity 0.2s ease;
    }

    .toggle-button:hover .hamburger-line,
    .toggle-button:hover::before,
    .toggle-button:hover::after {
        background-color: var(--line-color-hover, #fff);
    }

    /* --- Sidebar Toggle Button on Mobile --- */
    .sidebar-toggle-button {
        position: relative;
        z-index: 10;
    }

    /* Hide ALL tooltips on mobile - not needed for touch */
    [data-tooltip]::after,
    [data-tooltip]::before,
    .tooltip,
    .toggle-tooltip {
        display: none;
        content: none;
        visibility: hidden;
        opacity: 0;
    }

    /* --- Sidebar Header Adjustments --- */
    /* Override collapsed styling - keep horizontal on mobile */
    .sidebar-header,
    body.sidebar-collapsed .left-sidebar .sidebar-header {
        display: flex;
        flex-direction: row;
        align-items: center;
        justify-content: space-between;
        padding: 1rem 0.5rem;
        padding-right: 0.5rem;
    }

    /* --- Sidebar Content Scroll --- */
    .sidebar-content {
        max-height: calc(100vh - 140px);
        max-height: calc(100dvh - 140px);
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }

    /* --- Input Container Full Width --- */
    .input-container {
        left: 0 !important;
        right: 0 !important;
        width: 100% !important;
        padding-left: 12px;
        padding-right: 12px;
    }

    /* --- Chat Input Mobile Styles (moved from styles.css) --- */
    .chat-input {
        font-size: var(--mobile-composer-font-size);
        padding: 0 var(--composer-text-pad-right) 0 var(--mobile-composer-padding-x);
    }

    /* --- Composer Position (moved from styles.css) --- */
    .chat-shell__composer {
        left: 0;
        width: 100%;
    }

    /* --- Temp Chat Launcher (moved from styles.css) --- */
    body.artifact-panel-open .temp-chat-launcher {
        opacity: 0;
        pointer-events: none;
    }

    /* --- Conversation Panel (moved from styles.css) --- */
    .conversation-panel {
        padding: var(--space-4);
        border-radius: 1rem;
    }

    /* --- Guest Elements (moved from styles.css) --- */
    .guest-banner {
        padding: 0.5rem 0.75rem;
        gap: 0.5rem;
        border-radius: 16px;
    }

    .guest-banner-text {
        font-size: 0.8rem;
    }

    .guest-banner-btn {
        padding: 0.4rem 0.75rem;
        font-size: 0.75rem;
    }

    .guest-modal-content {
        padding: 1.75rem;
        margin: 0;
    }

    .guest-modal-header::before {
        width: 48px;
        height: 48px;
        background-size: 24px;
    }

    .guest-modal-title {
        font-size: 1.125rem;
    }

    .guest-modal-body p {
        font-size: 0.875rem;
    }

    .guest-modal-features {
        grid-template-columns: 1fr;
        gap: 0.5rem;
    }

    .guest-modal-features li {
        padding: 0.625rem 0.75rem;
        font-size: 0.8125rem;
    }

    .guest-modal-btn {
        padding: 0.75rem 1.25rem;
        font-size: 0.875rem;
    }

    /* --- Greeting Text (moved from styles.css) --- */
    .greeting-container {
        padding: 0 0.5rem 0.15rem;
    }

    .greeting-text {
        font-size: 1.35rem;
    }

    /* --- Model Select Position --- */
    .model-select-wrapper {
        left: 60px !important;
        right: auto !important;
    }

    /* --- Chat Area Adjustments --- */
    .container.chat-area {
        padding-top: calc(var(--mobile-header-height) + env(safe-area-inset-top, 0px));
    }

    /* --- Hide Sidebar Text in Collapsed Mode --- */
    .sidebar-action-text,
    .sidebar-header h1,
    .tab-name,
    .section-header,
    .sidebar-empty-state,
    .load-more-button {
        display: block !important;
        opacity: 1 !important;
    }

    /* --- Touch-Friendly Tap Targets --- */
    .chat-tab,
    .sidebar-action-btn,
    .sidebar-toggle-button {
        min-height: 44px;
    }

    .tab-actions-toggle {
        width: 40px;
        height: 40px;
    }

    /* --- Swipe Indicator --- */
    .swipe-indicator {
        display: none;
        position: fixed;
        top: 50%;
        left: 0;
        transform: translateY(-50%);
        width: 4px;
        height: 60px;
        background: rgba(255, 255, 255, 0.15);
        border-radius: 0 4px 4px 0;
        z-index: 998;
        pointer-events: none;
    }

    body:not(.mobile-sidebar-open) .swipe-indicator {
        display: block;
    }
}

/* Extra small devices (phones, 480px and down) */
@media (max-width: 480px) {
    :root {
        --mobile-sidebar-width: 85vw;
    }

    .left-sidebar {
        width: var(--mobile-sidebar-width) !important;
        max-width: 320px;
    }

    .toggle-button {
        top: 8px;
        left: 8px;
        width: 40px;
        height: 40px;
    }

    .model-select-wrapper {
        left: 52px !important;
    }

    .mobile-close-sidebar {
        top: 8px;
        right: 8px;
    }

    /* --- Greeting Text 480px (moved from styles.css) --- */
    .greeting-container {
        padding: 0 0.5rem 0.1rem;
    }

    .greeting-text {
        font-size: 1.2rem;
    }

    /* --- Input Container 480px (moved from styles.css) --- */
    .input-container {
        padding-left: var(--space-2);
        padding-right: var(--space-2);
    }
}

/* Landscape orientation on mobile */
@media (max-width: 768px) and (orientation: landscape) {
    .left-sidebar {
        width: 260px !important;
    }

    .sidebar-content {
        max-height: calc(100vh - 100px);
        max-height: calc(100dvh - 100px);
    }
}

/* Safe area insets for notched devices */
@supports (padding: max(0px, env(safe-area-inset-top))) {
    @media (max-width: 768px) {
        .left-sidebar {
            padding-top: max(12px, env(safe-area-inset-top));
            padding-bottom: max(12px, env(safe-area-inset-bottom));
            padding-left: max(0px, env(safe-area-inset-left));
        }

        .toggle-button {
            top: max(12px, env(safe-area-inset-top));
            left: max(12px, env(safe-area-inset-left));
        }

        .input-container {
            padding-bottom: max(12px, env(safe-area-inset-bottom));
        }
    }
}

/* Reduced motion preference */
@media (prefers-reduced-motion: reduce) {
    .left-sidebar,
    .mobile-overlay,
    .toggle-button {
        transition-duration: 0.1s;
    }
}

/* ============================================
   Hide Scrollbar - MOBILE ONLY (Keep Scroll Functionality)
   ============================================ */

@media screen and (max-width: 768px) {
    /* Hide scrollbar but KEEP scrolling working */
    html,
    body,
    .chat-area,
    .chat-shell__messages,
    .content-wrapper,
    .sidebar-content,
    .chat-stage,
    .chat-shell,
    #chat-display,
    .conversation-panel {
        scrollbar-width: none;         /* Firefox */
        -ms-overflow-style: none;      /* IE/Edge */
    }

    html::-webkit-scrollbar,
    body::-webkit-scrollbar,
    .chat-area::-webkit-scrollbar,
    .chat-shell__messages::-webkit-scrollbar,
    .content-wrapper::-webkit-scrollbar,
    .sidebar-content::-webkit-scrollbar,
    .chat-stage::-webkit-scrollbar,
    .chat-shell::-webkit-scrollbar,
    #chat-display::-webkit-scrollbar,
    .conversation-panel::-webkit-scrollbar {
        display: none;                 /* Chrome/Safari/Opera */
        width: 0;
        height: 0;
    }

    /* ONLY #chat-scroll-region scrolls on mobile */
    /* NOTE: .chat-shell__messages IS #chat-scroll-region - don't disable scroll */
    .chat-area,
    .content-wrapper,
    .chat-shell,
    .chat-stage {
        overflow: hidden !important;
    }

    #chat-scroll-region {
        overflow-y: scroll !important;
        -webkit-overflow-scrolling: touch !important;
    }
}

/* ============================================
   Home Page / Options Buttons Mobile Styles
   Floating Chips Near Input Design
   ============================================ */

@media (max-width: 1024px) {
    /* Override CSS variables for black theme on mobile */
    :root,
    body {
        --background-dark: #000;
        --background-darker: #000;
        --card-bg: rgba(20, 20, 20, 0.9);
        --card-bg-hover: rgba(30, 30, 30, 0.95);
        --input-row-bg: #000;
        --input-row-bg-focus: #000;
    }

    body, html {
        background: #000;
        background-color: #000;
    }

    /* Header area */
    .chat-shell__header,
    .temp-composer-header,
    .toggle-button,
    .model-select-wrapper,
    .model-select-wrapper .model-select {
        background: transparent;
        background-color: transparent;
    }

    /* Input container */
    .chat-shell__input,
    .input-container,
    .chat-input-wrapper,
    .message-input-container,
    .composer-container,
    .chat-shell__composer {
        background: #000;
        background-color: #000;
        border: none;
    }

    /* Remove all borders on mobile */
    .chatbox,
    .conversation-panel,
    .chat-shell__messages,
    .chat-area,
    .content-wrapper,
    .chat-stage,
    .chat-shell,
    .input-container,
    .chat-shell__composer,
    .options {
        background: #000;
        background-color: #000;
        border: none;
        border-top: none;
        border-bottom: none;
        box-shadow: none;
        outline: none;
    }

    /* Input row - no border on mobile */
    .input-row,
    .input-row:focus-within {
        border: none !important;
    }

    /* ::after - keep normal, uses --background-dark */

    /* Home page - allow natural layout */
    body:not(.has-messages) .chat-area {
        overflow: hidden;
        height: 100vh;
        height: 100dvh;
    }

    body:not(.has-messages) .content-wrapper {
        overflow: hidden;
        height: 100vh;
        height: 100dvh;
    }

    body:not(.has-messages) .chat-stage {
        padding: 1rem;
        padding-top: calc(var(--mobile-header-height) + env(safe-area-inset-top, 0px));
        padding-bottom: 0;
        height: calc(100vh - var(--mobile-header-height) - env(safe-area-inset-top, 0px));
        height: calc(100dvh - var(--mobile-header-height) - env(safe-area-inset-top, 0px));
        display: flex;
        flex-direction: column;
        justify-content: flex-start;
        align-items: center;
        overflow: hidden;
    }

    body:not(.has-messages) .chat-shell {
        flex: 1 1 auto;
        width: 100%;
        max-width: 100%;
        height: auto;
        overflow: visible;
        display: flex;
        flex-direction: column;
    }

    body:not(.has-messages) .chat-shell__extras {
        width: 100%;
        padding: 0 1rem;
        overflow: visible;
    }

    /* Chatbox - container for fixed elements */
    body:not(.has-messages) .chatbox {
        display: block;
        width: 100%;
        height: 100%;
        position: relative;
    }

    /* Greeting container - fixed from start */
    body:not(.has-messages) .greeting-container {
        position: fixed;
        top: 16%;
        left: 0;
        right: 0;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        text-align: center;
        padding: 0 0.5rem;
        z-index: 10;
        background: #000;
    }

    /* Logo container */
    body:not(.has-messages) .logo-container {
        width: 2.75rem;
        height: 2.75rem;
        margin: 0 auto 0.75rem;
    }

    /* Greeting text */
    body:not(.has-messages) .greeting-text {
        font-size: 1.25rem;
        line-height: 1.3;
        text-align: center;
        color: #ffffff;
        position: relative;
    }

    /* Time-based icon container */
    body:not(.has-messages) .greeting-container .time-icon {
        display: inline-block;
        width: 28px;
        height: 28px;
        margin-right: 8px;
        vertical-align: middle;
        position: relative;
        top: -2px;
    }

    /* Sun icon (morning/afternoon) */
    body:not(.has-messages) .greeting-container .time-icon.sun {
        color: #fbbf24;
        animation: sun-glow 3s ease-in-out infinite;
    }

    @keyframes sun-glow {
        0%, 100% {
            filter: drop-shadow(0 0 4px rgba(251, 191, 36, 0.4));
        }
        50% {
            filter: drop-shadow(0 0 12px rgba(251, 191, 36, 0.7));
        }
    }

    /* Sun rays animation */
    body:not(.has-messages) .greeting-container .time-icon.sun svg {
        animation: sun-spin 20s linear infinite;
    }

    @keyframes sun-spin {
        from { transform: rotate(0deg); }
        to { transform: rotate(360deg); }
    }

    /* Moon icon (evening/night) */
    body:not(.has-messages) .greeting-container .time-icon.moon {
        color: #a5b4fc;
        animation: moon-glow 4s ease-in-out infinite;
    }

    @keyframes moon-glow {
        0%, 100% {
            filter: drop-shadow(0 0 4px rgba(165, 180, 252, 0.3));
        }
        50% {
            filter: drop-shadow(0 0 10px rgba(165, 180, 252, 0.6));
        }
    }

    /* Stars around moon */
    body:not(.has-messages) .greeting-container .time-icon.moon::before,
    body:not(.has-messages) .greeting-container .time-icon.moon::after {
        content: '✦';
        position: absolute;
        font-size: 8px;
        color: rgba(255, 255, 255, 0.6);
        animation: twinkle 2s ease-in-out infinite;
    }

    body:not(.has-messages) .greeting-container .time-icon.moon::before {
        top: -4px;
        right: -2px;
        animation-delay: 0s;
    }

    body:not(.has-messages) .greeting-container .time-icon.moon::after {
        bottom: 2px;
        left: -4px;
        font-size: 6px;
        animation-delay: 1s;
    }

    @keyframes twinkle {
        0%, 100% { opacity: 0.3; transform: scale(0.8); }
        50% { opacity: 1; transform: scale(1.2); }
    }

    /* Typewriter cursor effect */
    .greeting-text.typewriter-active .greeting-typed-text::after {
        content: '|';
        animation: blink-cursor 0.7s step-end infinite;
        margin-left: 2px;
        color: #ffffff;
    }

    @keyframes blink-cursor {
        0%, 100% { opacity: 1; }
        50% { opacity: 0; }
    }

    /* Greeting typed text inline */
    .greeting-text .greeting-typed-text {
        display: inline;
    }

    /* Hide arrow down on home mobile */
    body:not(.has-messages) .arrow-down {
        display: none !important;
    }

    /* =============================================
       MOBILE OPTIONS - Minimal with Icons
       Clean vertical list with icons
       ============================================= */
    body:not(.has-messages) .options {
        position: fixed;
        top: 30%;
        left: 0;
        right: 0;
        bottom: 90px;
        display: flex;
        flex-direction: column;
        align-items: center;
        gap: 0;
        padding: 0 20px;
        padding-bottom: 20px;
        max-width: 100%;
        width: 100%;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }

    /* Show all options on mobile */
    .options button:nth-child(n) {
        display: flex !important;
    }

    /* Hide More button */
    .options .more-button {
        display: none !important;
    }

    /* Enhanced button cards */
    .options button {
        width: 100%;
        max-width: 340px;
        height: auto;
        min-height: unset;
        padding: 14px 16px;
        border-radius: 14px;
        background: rgba(255, 255, 255, 0.03) !important;
        border: none !important;
        color: rgba(255, 255, 255, 0.8);
        font-size: 15px;
        font-weight: 400;
        display: flex;
        flex-direction: row;
        align-items: center;
        justify-content: flex-start;
        gap: 14px;
        white-space: normal;
        text-align: left;
        -webkit-tap-highlight-color: transparent;
        transition: all 0.2s ease;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15) !important;
        margin-bottom: 10px;
    }

    .options button:active {
        background: rgba(59, 130, 246, 0.1) !important;
        border-color: rgba(59, 130, 246, 0.3) !important;
        transform: scale(0.98);
    }

    /* Icon with blue accent */
    .options button .option-icon {
        display: flex !important;
        align-items: center;
        justify-content: center;
        width: 40px;
        height: 40px;
        min-width: 40px;
        border-radius: 12px;
        padding: 0;
        margin: 0;
        /* Default subtle style */
        background: transparent;
        border: none;
    }

    .options button .option-icon svg {
        width: 18px;
        height: 18px;
        stroke-width: 2;
        /* Default subtle */
        color: rgba(255, 255, 255, 0.6);
    }

    /* Hide subtitle */
    .options button .subtitle {
        display: none !important;
    }

    /* Text styling */
    .options button .option-content {
        display: flex;
        flex: 1;
    }

    .options button .button-text {
        display: inline;
        font-size: 15px;
        font-weight: 400;
        color: inherit;
        line-height: 1.4;
    }

    /* === Chat with messages - ONLY #chat-scroll-region scrolls === */
    body.has-messages .chat-area {
        overflow: hidden !important;
        height: 100%;
    }

    /* Hide options when there are messages */
    body.has-messages .options {
        display: none !important;
    }

    /* Parent containers - hidden overflow, let scroll region handle it */
    body.has-messages .content-wrapper {
        overflow: hidden !important;
    }

    body.has-messages .chat-stage {
        padding: 1rem;
        padding-top: calc(var(--mobile-header-height) + env(safe-area-inset-top, 0px));
        min-height: calc(100vh - var(--mobile-header-height) - env(safe-area-inset-top, 0px));
        min-height: calc(100dvh - var(--mobile-header-height) - env(safe-area-inset-top, 0px));
        height: 100%;
        overflow: hidden !important;
    }

    /* Ensure fixed header elements stay visible when has-messages */
    body.has-messages .toggle-button {
        position: fixed !important;
        z-index: 1100 !important;
    }

    body.has-messages .model-select-wrapper {
        position: fixed !important;
        z-index: 1000 !important;
    }

    body.has-messages .temp-chat-launcher {
        position: fixed !important;
        z-index: 1000 !important;
    }

    /* Chat shell messages area (IS #chat-scroll-region - preserve scroll!) */
    .chat-shell__messages {
        padding-bottom: calc(var(--space-4) + var(--composer-reserved-height, 150px));
        /* overflow-y: auto is set via #chat-scroll-region rule */
    }

    /* Conversation panel - inside scroll region, no separate scroll */
    .conversation-panel {
        padding: 1rem;
    }

    /* Body never scrolls on mobile - only #chat-scroll-region */
    body.has-messages:not(.mobile-sidebar-open) {
        overflow: hidden !important;
    }
}

@media (max-width: 480px) {
    body:not(.has-messages) .chat-stage {
        padding: 0.75rem;
        padding-top: calc(var(--mobile-header-height) + env(safe-area-inset-top, 0px));
    }

    body:not(.has-messages) .options {
        bottom: calc(65px + env(safe-area-inset-bottom, 0px)) !important;
        padding: 0.4rem 8px !important;
        gap: 6px !important;
    }

    body:not(.has-messages) .options button {
        min-height: 32px !important;
        max-height: 32px !important;
        padding: 0 12px !important;
        font-size: 0.78rem !important;
        border-radius: 16px !important;
    }

    body:not(.has-messages) .options button .option-icon {
        width: 36px !important;
        height: 36px !important;
        min-width: 36px !important;
        display: flex !important;
        align-items: center;
        justify-content: center;
        border-radius: 10px !important;
    }

    /* Daytime - golden/warm icons */
    body:not(.has-messages).is-daytime .options button .option-icon {
        background: transparent !important;
        border: none !important;
    }

    body:not(.has-messages).is-daytime .options button .option-icon svg {
        width: 18px !important;
        height: 18px !important;
        color: rgba(255, 255, 255, 0.6) !important;
    }

    /* Nighttime - blue/cool icons */
    body:not(.has-messages).is-nighttime .options button .option-icon {
        background: transparent !important;
        border: none !important;
    }

    body:not(.has-messages).is-nighttime .options button .option-icon svg {
        width: 18px !important;
        height: 18px !important;
        color: #3b82f6 !important;
    }

    body:not(.has-messages) .logo-container {
        width: 2.5rem;
        height: 2.5rem;
        margin-bottom: 0.5rem;
    }
}

/* Landscape mode - smaller chips */
@media (max-width: 768px) and (orientation: landscape) {
    body:not(.has-messages) .options {
        bottom: calc(55px + env(safe-area-inset-bottom, 0px)) !important;
        padding: 0.35rem 10px !important;
        gap: 6px !important;
    }

    body:not(.has-messages) .options button {
        min-height: 28px !important;
        max-height: 28px !important;
        padding: 0 10px !important;
        font-size: 0.72rem !important;
        border-radius: 14px !important;
    }

    body:not(.has-messages) .logo-container {
        width: 2rem;
        height: 2rem;
        margin-bottom: 0.25rem;
    }
}

/* ============================================
   Incognito / Temp Chat Mobile Styles
   ============================================ */

@media (max-width: 768px) {
    /* =============================================
       UNIFIED MOBILE HEADER - Consistent styling
       All header elements: 40px height, same top position
       ============================================= */

    /* Temp chat launcher - matches toggle button style */
    .temp-chat-launcher {
        position: fixed;
        top: 12px;
        right: 12px;
        z-index: 1100;
    }

    body.right-sidebar-open .temp-chat-launcher {
        right: 12px;
    }

    .temp-chat-button {
        width: 40px;
        height: 40px;
        padding: 0;
        display: flex;
        align-items: center;
        justify-content: center;
        background: transparent;
        border-radius: 12px;
        border: none;
    }

    .temp-chat-button:hover {
        transform: none;
        background: transparent;
    }

    .temp-chat-icon {
        width: 28px;
        height: 28px;
    }

    .temp-chat-icon svg {
        width: 28px;
        height: 28px;
    }

    /* Hide tooltip on mobile - use touch feedback instead */
    .temp-chat-button::after {
        display: none;
    }

    /* Centered input container for temp chat */
    body.temporary-chat-centered .input-container {
        position: fixed;
        top: 45%;
        left: 50% !important;
        right: auto !important;
        width: calc(100% - 2rem) !important;
        max-width: 500px;
        transform: translate(-50%, -50%);
        padding: 0 1rem;
        z-index: 1500;
        pointer-events: auto;
    }

    body.temporary-chat-centered .input-row {
        width: 100%;
        border-radius: 1rem;
        pointer-events: auto;
    }

    body.temporary-chat-centered .chat-input,
    body.temporary-chat-centered .textarea-container,
    body.temporary-chat-centered textarea {
        pointer-events: auto !important;
        -webkit-user-select: text;
        user-select: text;
        touch-action: manipulation;
    }

    body.temporary-chat-centered .attachment-preview-tray {
        margin: 0 auto 0.5rem;
    }

    /* Temp composer header */
    body.temporary-chat-centered .temp-composer-header {
        padding: 0.5rem 0.75rem;
        font-size: 0.85rem;
    }

    /* Hide sidebar toggle in temp chat mode on mobile - use mobile header burger instead */
    body.temporary-chat-mode .toggle-button {
        display: none !important;
    }

    /* Ensure content is interactive in temp chat mode */
    body.temporary-chat-mode .content-wrapper {
        pointer-events: auto;
    }

    /* Adjust model select position in temp mode */
    body.temporary-chat-mode .model-select-wrapper {
        left: 12px !important;
        top: 12px !important;
    }
}

@media (max-width: 480px) {
    /* Temp chat launcher sizing now in unified 480px breakpoint below */

    body.temporary-chat-centered .input-container {
        width: calc(100% - 1.5rem) !important;
        padding: 0 0.75rem;
    }

    body.temporary-chat-centered .temp-composer-header {
        font-size: 0.8rem;
    }
}

/* ============================================
   File Preview / Thumbnail Mobile Styles
   ============================================ */

@media (max-width: 768px) {
    /* File preview container in input area */
    .file-preview-container {
        min-width: 7rem;
        max-width: 10rem;
        min-height: 3rem;
        padding: 0.25rem 0.4rem;
        padding-right: 1.2rem;
        margin-right: 0.2rem;
        margin-bottom: 0.15rem;
    }

    .file-preview-container .file-name {
        font-size: 0.7rem;
    }

    .file-preview-container .file-size {
        font-size: 0.6rem;
    }

    .file-preview-container .file-icon {
        font-size: 1.4rem;
    }

    .file-preview-container .close-button {
        width: 18px;
        height: 18px;
        font-size: 10px;
    }

    /* File preview cards in messages */
    .file-preview-card {
        width: clamp(100px, 28vw, 130px);
    }

    .file-preview-card__thumb {
        height: 70px;
    }

    .file-preview-card__icon {
        font-size: 2rem;
    }

    .file-preview-card__info {
        padding: 0.4rem 0.5rem;
    }

    .file-preview-card__name {
        font-size: 0.7rem;
    }

    .file-preview-card__meta {
        font-size: 0.6rem;
    }

    .file-preview-card__ext {
        font-size: 0.55rem;
        padding: 0.1rem 0.3rem;
    }

    /* File preview modal */
    .file-preview-modal__container {
        width: 95vw;
        max-width: none;
        max-height: 90vh;
        margin: 1rem;
    }

    .file-preview-modal__header {
        padding: 0.75rem;
        flex-wrap: wrap;
        gap: 0.5rem;
    }

    .file-preview-modal__title {
        font-size: 0.9rem;
    }

    .file-preview-modal__actions {
        width: 100%;
        justify-content: flex-end;
    }

    .file-preview-modal__content {
        padding: 0.5rem;
    }

    .file-preview-modal__image {
        max-height: 50vh;
    }

    /* Image previews in messages */
    .message-image-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 0.35rem;
    }

    .message-image-item {
        max-height: 150px;
    }

    /* Upload area adjustments */
    .upload-progress-container {
        gap: 0.25rem;
    }

    .upload-progress-status {
        font-size: 0.6rem;
    }

    .upload-progress-percent {
        font-size: 0.6rem;
    }
}

@media (max-width: 480px) {
    /* Extra small screens */
    .file-preview-container {
        min-width: 6rem;
        max-width: 8.5rem;
        min-height: 2.8rem;
    }

    .file-preview-card {
        width: clamp(90px, 40vw, 120px);
    }

    .file-preview-card__thumb {
        height: 60px;
    }

    .file-preview-card__icon {
        font-size: 1.6rem;
    }

    .message-image-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .message-image-item {
        max-height: 120px;
    }
}

/* ============================================
   Modal & Dropdown Mobile Positioning
   ============================================ */

@media (max-width: 768px) {
    /* === Delete/Confirm Modal === */
    .modal-overlay {
        padding: 1rem;
        align-items: center;
        justify-content: center;
    }

    .modal-content {
        width: calc(100% - 2rem);
        max-width: 320px;
        padding: 1.25rem;
        margin: auto;
    }

    .modal-content h2 {
        font-size: 1.1rem;
    }

    .modal-content p {
        font-size: 0.9rem;
    }

    .modal-actions {
        flex-direction: column;
        gap: 0.5rem;
    }

    .modal-actions .btn-cancel,
    .modal-actions .btn-delete {
        width: 100%;
        padding: 0.75rem 1rem;
    }

    /* === Model Select Dropdown - ChatGPT Style === */
    .model-select-wrapper {
        position: fixed !important;
        top: 12px !important;
        left: 60px !important;
        right: auto !important;
        z-index: 1000 !important;
    }

    .model-select {
        font-size: 0.8rem !important;
        padding: 0.4rem 0.5rem !important;
        background: transparent !important;
        border: none !important;
        color: rgba(255, 255, 255, 0.7) !important;
    }

    .model-select:hover,
    .model-select:active {
        background: rgba(255, 255, 255, 0.08) !important;
        color: #fff !important;
    }

    .model-select-content {
        position: fixed !important;
        top: 50px !important;
        bottom: auto !important;
        left: 12px !important;
        right: 12px !important;
        transform: none !important;
        width: auto !important;
        max-width: none !important;
        max-height: 60vh !important;
        overflow-y: auto !important;
        background: #2f2f2f !important;
        border: none !important;
        border-radius: 12px !important;
    }

    .model-select-content.active {
        transform: none !important;
    }

    .model-option {
        padding: 14px 16px !important;
        font-size: 0.9rem !important;
        min-height: 48px !important;
    }

    .model-meta {
        padding-left: 0 !important;
    }

    /* === Profile Dropdown in Sidebar === */
    .sidebar-footer .dropdown-container {
        position: fixed;
        bottom: auto;
        top: auto;
        left: 50%;
        transform: translateX(-50%);
        width: calc(100% - 2rem);
        max-width: 280px;
        z-index: 2000;
    }

    .sidebar-footer .dropdown-menu {
        width: 100%;
    }

    /* === Artifact Switcher Dropdown === */
    .artifact-switcher-dropdown {
        position: fixed;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%) !important;
        width: calc(100% - 2rem);
        max-width: 320px;
        max-height: 70vh;
        overflow-y: auto;
    }

    .artifact-switcher-dropdown.is-open {
        transform: translate(-50%, -50%) !important;
    }

    .artifact-switcher-dropdown__item {
        padding: 0.85rem 1rem;
    }

    /* === History Search Modal === */
    .history-search-dialog {
        width: calc(100% - 1.5rem);
        max-width: none;
        max-height: 85vh;
        margin: 0.75rem;
    }

    .history-search-input {
        padding: 0.65rem 0.85rem;
    }

    .history-search-input input {
        font-size: 1rem; /* Prevent zoom on iOS */
    }

    .history-search-result {
        padding: 0.65rem;
    }

    /* === Images Gallery Modal === */
    .images-gallery-dialog {
        width: calc(100% - 1rem);
        max-width: none;
        max-height: 90vh;
        padding: 1rem;
        margin: 0.5rem;
    }

    .images-gallery-header h2 {
        font-size: 1.2rem;
    }

    .images-gallery-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 0.4rem;
    }

    .images-gallery-cta {
        flex-direction: column;
        text-align: center;
        gap: 0.75rem;
    }

    /* === Image Preview Modal === */
    .images-preview-dialog {
        width: calc(100% - 1rem);
        max-width: none;
        padding: 1rem;
    }

    .images-preview-canvas img {
        max-height: 50vh;
    }

    /* === Tab Actions Dropdown (Button Group) === */
    .button-group {
        position: fixed;
        top: auto;
        bottom: 20%;
        left: 50%;
        transform: translateX(-50%);
        width: calc(100% - 3rem);
        max-width: 220px;
        z-index: 2000;
    }

    .button-group.button-group-visible {
        transform: translateX(-50%) scale(1);
    }

    .chat-btn {
        padding: 0.65rem 0.75rem;
        font-size: 0.9rem;
    }

    /* === Toast Notifications === */
    .toast {
        left: 50%;
        right: auto;
        transform: translateX(-50%);
        width: calc(100% - 2rem);
        max-width: 400px;
        bottom: 6rem;
    }
}

@media (max-width: 480px) {
    .modal-content {
        padding: 1rem;
    }

    .model-select-content {
        max-width: 260px;
    }

    .images-gallery-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .history-search-dialog {
        max-height: 80vh;
    }

    .button-group {
        max-width: 200px;
    }

    .toast {
        bottom: 5rem;
        font-size: 0.75rem;
    }
}

/* ============================================
   Mobile Model Selector - Options dropdown
   (Header bar handles main positioning)
   ============================================ */

/* Hidden on desktop */
.mobile-model-select {
    display: none;
}

/* Model options list styling */
@media (max-width: 768px) {
    .mobile-model-select.guest-disabled {
        display: none !important;
    }

    /* Option items styling */
    .mobile-model-option {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 8px;
        padding: 12px 16px;
        color: rgba(255, 255, 255, 0.9);
        font-size: 0.9rem;
        font-weight: 500;
        transition: background 0.1s ease;
        cursor: pointer;
        white-space: nowrap;
        min-height: 44px;
    }

    .mobile-model-option:active {
        background: rgba(255, 255, 255, 0.1);
    }

    .mobile-model-option.selected {
        color: rgba(255, 255, 255, 0.9);
    }

    .mobile-model-option.selected::after {
        content: '✓';
        font-size: 0.8rem;
        color: rgba(255, 255, 255, 0.6);
    }

    .mobile-model-option-note {
        display: none;
    }
}

@media (max-width: 480px) {
    /* Smaller phones: adjust model options */
    .mobile-model-option {
        padding: 10px 12px;
        font-size: 0.85rem;
        min-height: 40px;
    }
}

/* ============================================
   Mobile Chat Message Alignment
   User messages right, AI messages left
   Clean, compact, readable layout
   ============================================ */

@media (max-width: 768px) {
    /* Override composer reserved height for mobile */
    :root {
        --composer-reserved-height: 70px;
    }

    /* Chat stage - proper spacing from header */
    body.has-messages .chat-stage {
        padding-top: calc(var(--mobile-header-height) + env(safe-area-inset-top, 0px));
        padding-left: 0.5rem;
        padding-right: 0.5rem;
        gap: 0;
    }

    /* Chat shell - reduce gap and don't expand */
    body.has-messages .chat-shell {
        gap: 0;
        flex: 0 0 auto;
        min-height: 0;
    }

    /* Messages container - proper bottom padding for input */
    body.has-messages .chat-shell__messages {
        padding-bottom: calc(var(--space-4, 1rem) + var(--composer-reserved-height, 150px)) !important;
        gap: 0.5rem;
    }

    /* Conversation panel - clean padding */
    body.has-messages .conversation-panel {
        padding: 0.5rem;
        gap: 0.5rem;
    }

    /* Chat display - clean vertical layout */
    #chat-display {
        padding: 0.5rem;
        display: flex;
        flex-direction: column;
        gap: 0.75rem;
    }

    /* NOTE: Message styles moved to "ChatGPT-Style Mobile Messages" section below */

    /* Code blocks on mobile */
    .message .text-message pre {
        font-size: 0.8rem;
        padding: 0.75rem;
        border-radius: 10px;
        margin: 0.5rem 0;
        overflow-x: auto;
    }

    .message .text-message code {
        font-size: 0.8rem;
    }

    /* Lists on mobile */
    .message.ai-message .text-message ul,
    .message.ai-message .text-message ol {
        padding-left: 1.25rem;
        margin: 0.5rem 0;
    }

    .message.ai-message .text-message li {
        margin-bottom: 0.3rem;
    }

    /* Attachments alignment */
    .message.user-message .message-attachments {
        justify-content: flex-end;
    }

    .message.ai-message .message-attachments {
        justify-content: flex-start;
    }

    /* Image attachments - constrain width */
    .message .attachment-card.image-attachment {
        max-width: 280px;
    }

    /* Note: Message footer styles moved to Enhanced Mobile Chat section below */
}

/* Guest mode placeholder - smaller text on mobile */
@media (max-width: 768px) {
    .chat-input::placeholder {
        font-size: 0.85rem;
    }

    /* iOS zoom fix - 16px minimum prevents auto-zoom on focus */
    .chat-input,
    textarea.chat-input {
        font-size: 16px !important;
    }

    /* Note: Action button styles moved to Enhanced Mobile Chat section below */

    /* Smaller tooltips on mobile - show on tap (except action buttons) */
    [data-tooltip]::after,
    .edit-button[data-tooltip]::after,
    .copy-message-button[data-tooltip]::after {
        font-size: 10px !important;
        padding: 3px 6px !important;
        border-radius: 3px !important;
        white-space: nowrap !important;
        transform: translateX(-50%) scale(1) !important;
    }

    /* Action button tooltips are hidden on mobile to avoid stray dots */
    .action-btn::after {
        display: none !important;
        content: none !important;
    }

    /* Remove any arrow/dot from tooltips */
    .action-btn::before,
    [data-tooltip]::before,
    .edit-button::before,
    .copy-message-button::before {
        display: none !important;
        content: none !important;
        visibility: hidden !important;
        opacity: 0 !important;
    }

    .tooltip,
    .toggle-tooltip,
    .theme-toggle__tooltip {
        font-size: 0.7rem !important;
        padding: 4px 8px !important;
        max-width: 120px !important;
        border-radius: 4px !important;
    }

    /* Hide tooltip arrows on mobile */
    .tooltip::before,
    .toggle-tooltip::before,
    .theme-toggle__tooltip::before,
    .theme-toggle__tooltip::after {
        display: none !important;
    }

    /* Safe area support for footer/composer */
    .chat-shell__composer {
        padding-bottom: calc(var(--space-3) + env(safe-area-inset-bottom, 0px));
    }

    /* Ensure input container respects safe area */
    .input-container {
        padding-bottom: env(safe-area-inset-bottom, 0px);
    }
}

/* Extra small screens */
@media (max-width: 480px) {
    :root {
        --composer-reserved-height: 65px;
    }

    .chat-input::placeholder {
        font-size: 0.75rem;
    }

    /* FIXED: Keep header offset on extra small screens */
    body.has-messages .chat-stage {
        padding-top: calc(var(--mobile-header-height) + env(safe-area-inset-top, 0px));
        padding-left: 0.35rem;
        padding-right: 0.35rem;
    }

    body.has-messages .chat-shell__messages {
        padding-bottom: calc(var(--space-4, 1rem) + var(--composer-reserved-height, 150px)) !important;
    }

    body.has-messages .conversation-panel {
        padding: 0.25rem;
    }

    #chat-display {
        padding: 0.15rem 0.35rem;
    }

    .message.user-message .message-content {
        max-width: 88%;
    }

    .message.ai-message .message-content {
        max-width: 95%;
    }
}

/* Desktop: Hide mobile-only elements */
@media (min-width: 769px) {
    .mobile-overlay,
    .swipe-indicator,
    .hamburger-line {
        display: none !important;
    }
}

/* ============================================
   Long-Press Context Menu for Mobile Sessions
   (Styles in context-menu.css)
   ============================================ */

/* Legacy swipe classes - hidden */
.swipe-delete-action {
    display: none !important;
}

/* ============================================
   Enhanced Mobile Chat Window Styles
   Full chat experience optimized for touch
   ============================================ */

@media (max-width: 768px) {

    /* === Fixed Bottom Input Container === */
    .chat-shell__composer .input-container {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        width: 100%;
        max-width: 100%;
        margin: 0;
        padding: 8px 16px;
        padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px));
        background: linear-gradient(to top, #212121 85%, transparent);
        z-index: 100;
        box-sizing: border-box;
    }

    /* === Input Row - Full width flex container === */
    .chat-shell__composer .input-container .input-row,
    .chat-shell__composer .input-container .input-row.composer-expanded {
        width: 100% !important;
        max-width: 100% !important;
        margin: 0;
        padding: 0;
        background: transparent;
        border: none;
        display: flex !important;
        flex-direction: row !important;
        align-items: flex-end !important;
        gap: 8px !important;
        box-sizing: border-box;
    }

    /* === Inner pill wrapper (textarea + buttons) === */
    .chat-shell__composer .input-row > .textarea-container {
        flex: 1 1 auto !important;
        min-width: 0;
        max-width: none !important;
        display: flex;
        align-items: flex-end;
        gap: 4px;
        padding: 3px 3px 3px 12px;
        border-radius: 20px;
        min-height: 38px;
        background: #2f2f2f;
        border: 1px solid rgba(255, 255, 255, 0.08);
        order: 1 !important;
    }

    /* === + Button - Flexbox positioning (NOT absolute) === */
    footer.chat-shell__composer .input-container .input-row .actions-menu,
    footer.chat-shell__composer .input-container .input-row.composer-expanded .actions-menu {
        position: static !important;
        flex-shrink: 0 !important;
        order: 2 !important;
        margin: 0 !important;
        margin-bottom: 3px !important; /* Align with buttons inside pill */
        align-self: flex-end !important;
    }

    .chat-shell__composer .input-row > .textarea-container:focus-within {
        border-color: rgba(255, 255, 255, 0.15);
        background: #333;
    }

    /* === Send Button - Inside the pill === */
    .chat-shell__composer .textarea-container .send-button {
        width: 32px;
        height: 32px;
        min-width: 32px;
        min-height: 32px;
        border-radius: 50%;
        padding: 0;
        align-items: center;
        justify-content: center;
        background: #ffffff;
        border: none;
        flex-shrink: 0;
        touch-action: manipulation;
        -webkit-tap-highlight-color: transparent;
        transition: all 0.15s ease;
    }

    .chat-shell__composer .textarea-container .send-button:active {
        transform: scale(0.95);
        background: #e5e5e5;
    }

    .chat-shell__composer .textarea-container .send-button i {
        font-size: 13px;
        color: #000000;
    }

    /* === Textarea Chat Input - iOS Compatibility === */
    .chat-shell__composer .input-row textarea.chat-input,
    .chat-shell__composer textarea.chat-input,
    textarea.chat-input,
    #prompt {
        font-size: 16px !important; /* Prevents iOS zoom */
        -webkit-appearance: none;
        appearance: none;
        /* iOS text editing support */
        -webkit-user-select: text !important;
        user-select: text !important;
        -webkit-user-modify: read-write-plaintext-only !important;
        /* Touch handling */
        touch-action: manipulation;
        -webkit-tap-highlight-color: transparent;
        /* Critical: ensure input receives events */
        pointer-events: auto !important;
        opacity: 1 !important;
        visibility: visible !important;
        /* Prevent iOS text resize */
        -webkit-text-size-adjust: 100%;
        text-size-adjust: 100%;
        /* Ensure proper stacking */
        position: relative;
        z-index: 1;
        /* iOS-specific: prevent transform issues */
        transform: translateZ(0);
        -webkit-transform: translateZ(0);
    }

    /* Ensure input is interactive when focused */
    .chat-shell__composer textarea.chat-input:focus,
    textarea.chat-input:focus,
    #prompt:focus {
        -webkit-user-select: text !important;
        user-select: text !important;
        -webkit-user-modify: read-write-plaintext-only !important;
        caret-color: #ffffff !important;
        outline: none;
        /* Ensure visibility on focus */
        opacity: 1 !important;
        pointer-events: auto !important;
    }

    /* iOS: Ensure textarea container doesn't block touches */
    .textarea-container {
        pointer-events: auto !important;
        touch-action: manipulation;
    }

    .chat-shell__composer .input-row textarea.chat-input::placeholder {
        color: rgba(255, 255, 255, 0.5);
        font-size: 13px;
        line-height: 30px; /* Same as textarea for alignment */
    }

    /* === Microphone button === */
    .chat-shell__composer .textarea-container .microphone-button {
        width: 32px;
        height: 32px;
        min-width: 32px;
        min-height: 32px;
        flex-shrink: 0;
        border-radius: 50%;
        align-items: center;
        justify-content: center;
        background: transparent;
        border: none;
        color: rgba(255, 255, 255, 0.6);
        touch-action: manipulation;
    }

    /* === Voice mode button === */
    .chat-shell__composer .textarea-container .voice-mode-button {
        width: 32px;
        height: 32px;
        min-width: 32px;
        min-height: 32px;
        flex-shrink: 0;
        border-radius: 50%;
        align-items: center;
        justify-content: center;
        background: transparent;
        border: none;
        color: rgba(255, 255, 255, 0.6);
        touch-action: manipulation;
    }

    /* Voice bars - grey color like mic icon */
    .chat-shell__composer .textarea-container .voice-mode-button .voice-bar {
        background: rgba(255, 255, 255, 0.6);
    }

    /* === Edit Textarea - Prevents iOS Zoom === */
    .message .edit-textarea {
        font-size: 16px;
        line-height: 1.5;
        padding: 12px 16px 50px;
        min-height: 70px;
    }

    .message .edit-textarea:focus {
        font-size: 16px;
    }

    /* Edit mode buttons */
    .message .button-container {
        bottom: 8px;
        right: 8px;
    }

    .message .cancel-button,
    .message .save-button {
        padding: 8px 16px;
        font-size: 14px;
        min-height: 36px;
        touch-action: manipulation;
    }

    /* === Actions Menu (+ button) - Separate from pill === */
    .chat-shell__composer .input-row .actions-menu {
        flex-shrink: 0;
        position: relative;
    }

    .chat-shell__composer .input-row .actions-toggle,
    .chat-shell__composer .input-row .actions-menu > button {
        width: 38px;
        height: 38px;
        min-width: 38px;
        min-height: 38px;
        border-radius: 19px; /* Match pill curvature */
        padding: 0;
        display: flex;
        align-items: center;
        justify-content: center;
        background: #2f2f2f;
        border: 1px solid rgba(255, 255, 255, 0.08);
        color: rgba(255, 255, 255, 0.7);
        touch-action: manipulation;
        -webkit-tap-highlight-color: transparent;
        transition: all 0.15s ease;
    }

    .chat-shell__composer .input-row .actions-toggle:active,
    .chat-shell__composer .input-row .actions-menu > button:active {
        background: #3a3a3a;
        transform: scale(0.95);
    }

    .chat-shell__composer .input-row .actions-toggle svg {
        width: 16px;
        height: 16px;
        stroke-width: 2;
    }

    /* === Chat Area - NO scroll here, only #chat-scroll-region scrolls === */
    .chat-shell .chat-area,
    .chat-shell .container.chat-area {
        padding-bottom: calc(80px + env(safe-area-inset-bottom, 0px));
        overflow: hidden !important;
    }

    /* === Messages Display === */
    #chat-display {
        padding: 0.5rem !important;
        padding-bottom: calc(100px + env(safe-area-inset-bottom, 0px)) !important;
        display: flex !important;
        flex-direction: column !important;
        gap: 0.75rem !important;
    }

    /* =============================================
       ChatGPT-Style Mobile Messages
       Clean, minimal, perfectly aligned
       ============================================= */

    /* === BASE MESSAGE RESET === */
    .message {
        width: 100% !important;
        padding: 0 !important;
        margin: 0 !important;
        display: flex !important;
        flex-direction: column !important;
    }

    /* Hide all message headers on mobile */
    .message .message-header {
        display: none !important;
        height: 0 !important;
        padding: 0 !important;
        margin: 0 !important;
    }

    /* === USER MESSAGE - Right aligned bubble === */
    .message.user-message {
        align-items: flex-end !important;
        padding: 0 12px !important;
    }

    .message.user-message .message-content {
        display: flex !important;
        flex-direction: column !important;
        align-items: flex-end !important;
        max-width: 85% !important;
        width: auto !important;
        margin: 0 !important;
        padding: 0 !important;
        gap: 0 !important;
    }

    .message.user-message .text-message-container {
        display: flex !important;
        flex-direction: column !important;
        align-items: flex-end !important;
        width: auto !important;
        max-width: 100% !important;
        margin: 0 !important;
        padding: 0 !important;
    }

    .message.user-message .text-message {
        background: #2f2f2f !important;
        color: #ececec !important;
        border-radius: 20px 20px 4px 20px !important;
        padding: 10px 14px !important;
        font-size: 15px !important;
        line-height: 1.5 !important;
        width: auto !important;
        max-width: 100% !important;
        margin: 0 !important;
        word-wrap: break-word !important;
        overflow-wrap: break-word !important;
        box-shadow: none !important;
        border: none !important;
    }

    /* User message footer - HIDDEN on mobile, shown via long-press popup */
    .message.user-message .message-bubble-footer {
        display: none !important;
    }

    /* Prevent text selection during long-press (but allow inputs) */
    body.no-select,
    body.no-select *:not(input):not(textarea):not([contenteditable="true"]) {
        -webkit-user-select: none !important;
        user-select: none !important;
        -webkit-touch-callout: none !important;
    }

    /* Always allow text selection in inputs/textareas */
    body.no-select input,
    body.no-select textarea,
    body.no-select [contenteditable="true"] {
        -webkit-user-select: text !important;
        user-select: text !important;
        -webkit-touch-callout: default !important;
    }

    /* Long-press visual feedback */
    .message.user-message.holding .text-message {
        opacity: 0.7 !important;
        transform: scale(0.98) !important;
        transition: all 0.1s ease !important;
    }

    .message.user-message.action-active .text-message {
        box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.2) !important;
    }

    /* Message Actions Popup */
    .message-actions-overlay {
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.3);
        z-index: 9998;
        opacity: 0;
        visibility: hidden;
        transition: opacity 0.15s ease, visibility 0.15s ease;
    }

    .message-actions-overlay.visible {
        opacity: 1;
        visibility: visible;
    }

    .message-actions-popup {
        position: fixed;
        z-index: 9999;
        background: #3a3a3a;
        border-radius: 12px;
        padding: 6px;
        display: flex;
        flex-direction: row;
        gap: 2px;
        box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
        opacity: 0;
        visibility: hidden;
        transform: scale(0.9);
        transition: all 0.15s ease;
    }

    .message-actions-popup.visible {
        opacity: 1;
        visibility: visible;
        transform: scale(1);
    }

    .message-action-item {
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 4px;
        padding: 10px 16px;
        background: transparent;
        border: none;
        border-radius: 8px;
        color: rgba(255, 255, 255, 0.9);
        cursor: pointer;
        touch-action: manipulation;
        -webkit-tap-highlight-color: transparent;
    }

    .message-action-item:active {
        background: rgba(255, 255, 255, 0.1);
    }

    .message-action-item i {
        font-size: 16px;
        color: rgba(255, 255, 255, 0.8);
    }

    .message-action-item span {
        font-size: 11px;
        font-weight: 500;
        color: rgba(255, 255, 255, 0.7);
    }

    /* === AI MESSAGE - Left aligned, full width, no bubble === */
    .message.ai-message {
        align-items: flex-start !important;
        padding: 0 12px !important;
    }

    .message.ai-message .message-content {
        display: flex !important;
        flex-direction: column !important;
        align-items: flex-start !important;
        width: 100% !important;
        max-width: 100% !important;
        margin: 0 !important;
        padding: 0 !important;
        gap: 0 !important;
    }

    .message.ai-message .text-message-container {
        width: 100% !important;
        max-width: 100% !important;
        margin: 0 !important;
        padding: 0 !important;
    }

    .message.ai-message .text-message {
        background: transparent !important;
        color: #d1d5db !important;
        padding: 0 !important;
        margin: 0 !important;
        font-size: 15px !important;
        line-height: 1.6 !important;
        width: 100% !important;
        border: none !important;
        box-shadow: none !important;
    }

    /* AI message text formatting */
    .message.ai-message .text-message p {
        margin: 0 0 12px 0 !important;
    }

    .message.ai-message .text-message p:last-child {
        margin-bottom: 0 !important;
    }

    .message.ai-message .text-message h1,
    .message.ai-message .text-message h2,
    .message.ai-message .text-message h3 {
        margin: 16px 0 8px 0 !important;
        font-weight: 600 !important;
    }

    .message.ai-message .text-message h1:first-child,
    .message.ai-message .text-message h2:first-child,
    .message.ai-message .text-message h3:first-child {
        margin-top: 0 !important;
    }

    .message.ai-message .text-message ul,
    .message.ai-message .text-message ol {
        margin: 8px 0 !important;
        padding-left: 20px !important;
    }

    .message.ai-message .text-message li {
        margin-bottom: 4px !important;
    }

    .message.ai-message .text-message strong {
        font-weight: 600 !important;
        color: #fff !important;
    }

    /* AI message footer */
    .message.ai-message .message-bubble-footer {
        display: flex !important;
        flex-direction: row !important;
        justify-content: flex-start !important;
        align-items: center !important;
        gap: 4px !important;
        margin: 8px 0 0 0 !important;
        padding: 0 !important;
        width: auto !important;
    }

    /* === ACTION BUTTONS - Small, subtle === */
    .message.user-message .edit-button,
    .message.user-message .copy-message-button {
        width: 24px !important;
        height: 24px !important;
        min-width: 24px !important;
        min-height: 24px !important;
        padding: 0 !important;
        margin: 0 !important;
        background: transparent !important;
        border: none !important;
        border-radius: 4px !important;
        opacity: 0.4 !important;
        display: inline-flex !important;
        align-items: center !important;
        justify-content: center !important;
        cursor: pointer !important;
        touch-action: manipulation !important;
        -webkit-tap-highlight-color: transparent !important;
    }

    .message.user-message .edit-button i,
    .message.user-message .copy-message-button i {
        font-size: 10px !important;
        color: rgba(255, 255, 255, 0.6) !important;
    }

    .message.user-message .edit-button:active,
    .message.user-message .copy-message-button:active {
        opacity: 1 !important;
        background: rgba(255, 255, 255, 0.1) !important;
    }

    /* AI message action buttons */
    .message.ai-message .action-btn,
    .message.ai-message .edit-button,
    .message.ai-message .copy-message-button {
        width: 28px !important;
        height: 28px !important;
        min-width: 28px !important;
        min-height: 28px !important;
        padding: 0 !important;
        margin: 0 !important;
        background: transparent !important;
        border: none !important;
        border-radius: 6px !important;
        opacity: 0.5 !important;
        display: inline-flex !important;
        align-items: center !important;
        justify-content: center !important;
        cursor: pointer !important;
        touch-action: manipulation !important;
        -webkit-tap-highlight-color: transparent !important;
    }

    .message.ai-message .action-btn i,
    .message.ai-message .edit-button i,
    .message.ai-message .copy-message-button i {
        font-size: 12px !important;
        color: rgba(255, 255, 255, 0.6) !important;
    }

    .message.ai-message .action-btn:active,
    .message.ai-message .edit-button:active,
    .message.ai-message .copy-message-button:active {
        opacity: 1 !important;
        background: rgba(255, 255, 255, 0.1) !important;
    }

    /* === Three Dots More Menu - Mobile === */
    .action-more-wrapper {
        position: relative;
    }

    .action-more-menu {
        position: absolute !important;
        bottom: calc(100% + 8px) !important;
        left: 50% !important;
        top: auto !important;
        transform: translateX(-50%) !important;
        right: auto !important;
        min-width: 180px;
        background: #252525 !important;
        border: 1px solid rgba(255, 255, 255, 0.12) !important;
        border-radius: 12px !important;
        box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4) !important;
        padding: 6px 0 !important;
        z-index: 10000 !important;
    }

    .action-more-menu.open {
        display: flex !important;
        animation: mobileMenuSlideUp 0.15s ease-out;
    }

    @keyframes mobileMenuSlideUp {
        from {
            opacity: 0;
            transform: translateX(-50%) translateY(8px);
        }
        to {
            opacity: 1;
            transform: translateX(-50%) translateY(0);
        }
    }

    .action-more-menu button {
        padding: 12px 16px !important;
        font-size: 14px !important;
        color: rgba(255, 255, 255, 0.9) !important;
        display: flex !important;
        align-items: center !important;
        gap: 10px !important;
        background: transparent !important;
        border: none !important;
        width: 100% !important;
        text-align: left !important;
        touch-action: manipulation;
        -webkit-tap-highlight-color: transparent;
    }

    .action-more-menu button:active {
        background: rgba(255, 255, 255, 0.1) !important;
    }

    .action-more-menu button svg {
        width: 18px !important;
        height: 18px !important;
        flex-shrink: 0;
    }

    /* Make the three dots button easier to tap */
    .action-more-button,
    .action-more-wrapper .action-btn {
        min-width: 36px !important;
        min-height: 36px !important;
        padding: 8px !important;
    }

    /* === ATTACHMENTS === */
    .message.user-message .message-attachments {
        display: flex !important;
        flex-wrap: wrap !important;
        justify-content: flex-end !important;
        gap: 6px !important;
        margin-top: 6px !important;
        width: auto !important;
        max-width: 100% !important;
    }

    .message.ai-message .message-attachments {
        display: flex !important;
        flex-wrap: wrap !important;
        justify-content: flex-start !important;
        gap: 8px !important;
        margin-top: 8px !important;
        width: 100% !important;
    }

    /* === Code Blocks - Horizontal Scroll === */
    .message .text-message pre,
    .code-block-wrapper {
        margin: 0.5rem -0.5rem !important;
        border-radius: 10px !important;
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch !important;
    }

    .message .text-message pre code {
        font-size: 13px !important;
        line-height: 1.5 !important;
        white-space: pre !important;
        word-break: normal !important;
    }

    /* Code block header */
    .code-block-header {
        padding: 0.5rem 0.75rem !important;
        position: sticky !important;
        top: 0 !important;
        z-index: 1 !important;
    }

    .code-block-copy {
        padding: 0.4rem 0.6rem !important;
        min-height: 32px !important;
        touch-action: manipulation !important;
    }

    /* === Lists in Messages === */
    .message.ai-message .text-message ul,
    .message.ai-message .text-message ol {
        padding-left: 1.25rem !important;
        margin: 0.5rem 0 !important;
    }

    .message.ai-message .text-message li {
        margin-bottom: 0.35rem !important;
        min-height: 28px !important;
        padding: 0.1rem 0 !important;
    }

    /* === Tables - Scrollable === */
    .message .text-message table {
        display: block !important;
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch !important;
        margin: 0.75rem 0 !important;
        font-size: 13px !important;
    }

    .message .text-message th,
    .message .text-message td {
        padding: 0.5rem 0.75rem !important;
        white-space: nowrap !important;
    }

    /* === Blockquotes === */
    .message .text-message blockquote {
        margin: 0.75rem 0 !important;
        padding: 0.65rem 0.85rem !important;
        font-size: 14px !important;
    }

    /* === Inline Code === */
    .message .text-message code:not(pre code) {
        font-size: 13px !important;
        padding: 0.15rem 0.35rem !important;
        border-radius: 4px !important;
    }

    /* === Links - Touch Targets === */
    .message .text-message a {
        padding: 0.1rem 0 !important;
        display: inline !important;
    }

    /* === Image Attachments === */
    .message .attachment-card.image-attachment {
        max-width: 100% !important;
    }

    .message .attachment-card.image-attachment .attachment-thumb {
        max-width: 280px !important;
        width: 100% !important;
        height: auto !important;
        aspect-ratio: auto !important;
    }

    /* === File Attachments === */
    .message .file-preview-card {
        width: calc(50% - 0.25rem) !important;
        max-width: 150px !important;
    }

    /* === Action Buttons on Messages === */
    .message-bubble-footer {
        opacity: 1 !important;
        visibility: visible !important;
    }

    /* User message buttons - smaller, compact */
    .message.user-message .edit-button,
    .message.user-message .copy-message-button {
        width: 26px !important;
        height: 26px !important;
        min-width: 26px !important;
        min-height: 26px !important;
        padding: 0 !important;
        opacity: 0.5 !important;
        display: inline-flex !important;
        align-items: center !important;
        justify-content: center !important;
        border-radius: 6px !important;
        background: transparent !important;
        border: none !important;
        touch-action: manipulation !important;
        -webkit-tap-highlight-color: transparent !important;
    }

    .message.user-message .edit-button i,
    .message.user-message .copy-message-button i {
        font-size: 11px !important;
        color: rgba(255, 255, 255, 0.7) !important;
    }

    .message.user-message .edit-button:active,
    .message.user-message .copy-message-button:active {
        opacity: 1 !important;
        background: rgba(255, 255, 255, 0.1) !important;
    }

    /* AI message buttons - slightly larger */
    .message.ai-message .action-btn,
    .message.ai-message .edit-button,
    .message.ai-message .copy-message-button {
        width: 30px !important;
        height: 30px !important;
        min-width: 30px !important;
        min-height: 30px !important;
        opacity: 0.6 !important;
        display: inline-flex !important;
        align-items: center !important;
        justify-content: center !important;
        border-radius: 6px !important;
        touch-action: manipulation !important;
        -webkit-tap-highlight-color: transparent !important;
    }

    .message.ai-message .action-btn:active,
    .message.ai-message .edit-button:active,
    .message.ai-message .copy-message-button:active {
        opacity: 1 !important;
        background: rgba(255, 255, 255, 0.1) !important;
    }

    /* === Stop/Regenerate Buttons === */
    .stop-btn,
    .regenerate-btn {
        min-height: 40px !important;
        min-width: 100px !important;
        padding: 0.5rem 1rem !important;
        font-size: 14px !important;
        border-radius: 20px !important;
        touch-action: manipulation !important;
    }

    /* === Typing Indicator === */
    .typing-indicator,
    .ai-typing {
        padding: 0.5rem !important;
        font-size: 14px !important;
    }

    /* === Scroll to Bottom Button === */
    .scroll-to-bottom,
    .arrow-down {
        width: 40px !important;
        height: 40px !important;
        bottom: calc(90px + env(safe-area-inset-bottom, 0px)) !important;
        right: 12px !important;
        border-radius: 50% !important;
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3) !important;
        touch-action: manipulation !important;
    }

    /* === Voice Input Button === */
    .voice-input-btn {
        width: 36px !important;
        height: 36px !important;
        min-width: 36px !important;
        touch-action: manipulation !important;
    }

    /* === Online Search Toggle === */
    .online-search-toggle {
        min-height: 36px !important;
        padding: 0.4rem 0.75rem !important;
        font-size: 13px !important;
        touch-action: manipulation !important;
    }

    /* === Attachment Preview in Input === */
    .attachment-preview-tray {
        max-height: 100px !important;
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch !important;
        gap: 0.5rem !important;
        padding: 0.5rem 0 !important;
    }

    .attachment-preview-tray .file-preview-container {
        min-width: 80px !important;
        max-width: 100px !important;
        flex-shrink: 0 !important;
    }
}

/* === Extra Small Screens (< 480px) === */
@media (max-width: 480px) {
    .input-container {
        padding: 6px 8px !important;
        padding-bottom: calc(6px + env(safe-area-inset-bottom, 0px)) !important;
    }

    .input-row {
        padding: 8px 10px !important;
        border-radius: 22px !important;
        min-height: 44px !important;
        border: none !important;
    }

    .submit-btn {
        width: 36px !important;
        height: 36px !important;
        min-width: 36px !important;
        min-height: 36px !important;
    }

    .submit-btn svg,
    .submit-btn i {
        width: 16px !important;
        height: 16px !important;
    }

    .actions-menu button,
    .add-action-btn {
        width: 32px !important;
        height: 32px !important;
        min-width: 32px !important;
        min-height: 32px !important;
    }

    /* Extra small screen message adjustments */
    .message.user-message {
        padding: 0 8px !important;
    }

    .message.ai-message {
        padding: 0 8px !important;
    }

    .message.user-message .message-content {
        max-width: 90% !important;
    }

    .message.user-message .text-message {
        padding: 8px 12px !important;
        font-size: 14px !important;
        border-radius: 18px 18px 4px 18px !important;
    }

    .message.ai-message .text-message {
        font-size: 14px !important;
    }

    /* Extra small - tighter footer buttons */
    .message.user-message .message-bubble-footer {
        gap: 1px !important;
        margin-top: 1px !important;
    }

    .message.user-message .edit-button,
    .message.user-message .copy-message-button {
        width: 22px !important;
        height: 22px !important;
        min-width: 22px !important;
        min-height: 22px !important;
    }

    .message.user-message .edit-button i,
    .message.user-message .copy-message-button i {
        font-size: 9px !important;
    }

    .message .text-message pre code {
        font-size: 12px !important;
    }

    #chat-display {
        padding: 0.35rem !important;
        gap: 0.5rem !important;
    }

    .scroll-to-bottom,
    .arrow-down {
        width: 36px !important;
        height: 36px !important;
        bottom: calc(80px + env(safe-area-inset-bottom, 0px)) !important;
        right: 8px !important;
    }
}

/* === Landscape Mode Adjustments === */
@media (max-width: 768px) and (orientation: landscape) {
    .input-container {
        padding: 6px 16px !important;
    }

    .chat-area {
        padding-bottom: 70px !important;
    }

    #chat-display {
        padding-bottom: 80px !important;
    }

    .scroll-to-bottom,
    .arrow-down {
        bottom: 75px !important;
    }
}

/* === Fix blur flash on resize - disable backdrop-filter on mobile sidebar === */
@media (max-width: 768px) {
    .left-sidebar {
        backdrop-filter: none !important;
        -webkit-backdrop-filter: none !important;
        background-color: rgba(5, 5, 10, 0.98) !important; /* Solid bg instead of blur */
    }

    /* Fix caret visibility - ensure it's visible against dark backgrounds */
    textarea.chat-input,
    .chat-input,
    #prompt {
        caret-color: #ffffff !important;
    }

    /* Ensure caret is visible when input has light theme */
    .light-mode textarea.chat-input,
    .light-mode .chat-input,
    .light-mode #prompt {
        caret-color: #000000 !important;
    }
}

/* === Mobile Thinking Indicator - ChatGPT Style Pulsing Dot === */
@media (max-width: 768px) {
    .thinking-indicator {
        background: transparent !important;
        padding: 12px 16px !important;
        margin: 4px 0 !important;
        gap: 0 !important;
    }

    /* Hide everything except the dots container */
    .thinking-indicator .thinking-tip,
    .thinking-indicator .thinking-text,
    .thinking-indicator .thinking-reasoning,
    .thinking-indicator .thinking-chevron {
        display: none !important;
    }

    /* Make header transparent but keep visible so dots inside show */
    .thinking-indicator .thinking-header {
        background: transparent !important;
        border: none !important;
        padding: 0 !important;
    }

    .thinking-indicator .thinking-content {
        gap: 0 !important;
    }

    /* Transform 3 dots into single pulsing dot */
    .thinking-indicator .thinking-dots {
        display: flex;
        align-items: center;
        justify-content: center;
        gap: 0;
    }

    .thinking-indicator .thinking-dots span {
        width: 12px;
        height: 12px;
        background: rgba(255, 255, 255, 0.85);
        border-radius: 50%;
        animation: chatgpt-pulse 1.5s ease-in-out infinite !important;
    }

    /* Hide 2nd and 3rd dots */
    .thinking-indicator .thinking-dots span:nth-child(2),
    .thinking-indicator .thinking-dots span:nth-child(3) {
        display: none !important;
    }

    /* Dark mode adjustment - same white dot */
    .dark-mode .thinking-indicator .thinking-dots span {
        background: rgba(255, 255, 255, 0.85);
    }
}

/* ChatGPT breathing/pulsing animation - outside media query for broader support */
@keyframes chatgpt-pulse {
    0%, 100% {
        transform: scale(1);
        opacity: 0.4;
    }
    50% {
        transform: scale(1.3);
        opacity: 1;
    }
}

/* === Mobile Streaming Text - ChatGPT Style Clean Fade === */
body.device-phone .stream-fade-in,
body.is-ios .stream-fade-in,
body.is-mobile .stream-fade-in {
    animation: streamFadeInMobile 0.2s ease-out forwards;
}

@keyframes streamFadeInMobile {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

/* ============================================
   TEXT SELECTION QUOTE - Mobile Enhancements
   ============================================ */

/* Mobile floating button - larger touch target, pill shape */
body.device-phone .text-selection-ask-btn,
body.device-tablet .text-selection-ask-btn,
body.is-mobile .text-selection-ask-btn,
body.is-ios .text-selection-ask-btn {
    padding: 12px 20px !important;
    font-size: 15px !important;
    border-radius: 28px !important;
    min-height: 44px !important;
    gap: 8px !important;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.5) !important;
    -webkit-tap-highlight-color: transparent !important;
    touch-action: manipulation !important;
}

body.device-phone .text-selection-ask-btn i,
body.device-tablet .text-selection-ask-btn i,
body.is-mobile .text-selection-ask-btn i,
body.is-ios .text-selection-ask-btn i {
    font-size: 14px !important;
}

/* Ensure button appears above any mobile UI (header is z-index 9999) */
body.device-phone .text-selection-ask-btn,
body.is-mobile .text-selection-ask-btn,
body.is-ios .text-selection-ask-btn {
    z-index: 10100 !important;
}

/* Quote indicator - inside input-row flex, matches pill width */
body.device-phone .input-row .quote-reply-indicator,
body.is-mobile .input-row .quote-reply-indicator,
body.is-ios .input-row .quote-reply-indicator {
    /* Same flex as pill */
    flex: 1 1 auto !important;
    order: 0 !important;
    /* Match pill styling */
    background: #2f2f2f !important;
    border: 1px solid rgba(255, 255, 255, 0.08) !important;
    border-bottom: none !important;
    border-radius: 20px 20px 0 0 !important;
    margin: 0 !important;
}

/* Pill connects below quote */
body.device-phone .input-row .quote-reply-indicator + .textarea-container,
body.is-mobile .input-row .quote-reply-indicator + .textarea-container,
body.is-ios .input-row .quote-reply-indicator + .textarea-container {
    border-radius: 0 0 20px 20px !important;
    border-top: none !important;
}

/* Make input-row wrap when quote present */
body.device-phone .input-row:has(.quote-reply-indicator),
body.is-mobile .input-row:has(.quote-reply-indicator),
body.is-ios .input-row:has(.quote-reply-indicator) {
    flex-wrap: wrap !important;
}

body.device-phone .quote-reply-content,
body.is-mobile .quote-reply-content,
body.is-ios .quote-reply-content {
    padding: 10px 14px !important;
}

body.device-phone .quote-reply-text,
body.is-mobile .quote-reply-text,
body.is-ios .quote-reply-text {
    font-size: 13px !important;
    -webkit-line-clamp: 2 !important;
}

body.device-phone .quote-reply-close,
body.is-mobile .quote-reply-close,
body.is-ios .quote-reply-close {
    width: 44px !important;
    min-width: 44px !important;
    -webkit-tap-highlight-color: transparent !important;
}

/* Improve text selection on mobile */
body.device-phone .ai-message,
body.device-phone .assistant-message,
body.device-phone [data-role="assistant"],
body.is-mobile .ai-message,
body.is-mobile .assistant-message,
body.is-mobile [data-role="assistant"],
body.is-ios .ai-message,
body.is-ios .assistant-message,
body.is-ios [data-role="assistant"] {
    -webkit-user-select: text !important;
    user-select: text !important;
}

/* Selection highlight color for AI messages on mobile */
body.device-phone .ai-message ::selection,
body.device-phone .assistant-message ::selection,
body.is-mobile .ai-message ::selection,
body.is-mobile .assistant-message ::selection,
body.is-ios .ai-message ::selection,
body.is-ios .assistant-message ::selection {
    background: rgba(100, 150, 255, 0.35) !important;
}

/* =============================================
   VIEWPORT-MOBILE LAYOUT (for resized desktop)
   These rules apply when body has 'viewport-mobile'
   class, which is set by DeviceDetector when:
   - Viewport width <= 768px AND
   - Device is NOT a real mobile (phone/tablet)
   ============================================= */

/* === HOME PAGE LAYOUT (no messages) === */

/* Disable scroll on home page - everything should fit */
body.viewport-mobile:not(.has-messages) #chat-scroll-region {
    overflow: hidden !important;
}

/* Chat stage - center content for home page */
body.viewport-mobile:not(.has-messages) .chat-stage {
    display: flex !important;
    flex-direction: column !important;
    justify-content: flex-start !important;
    align-items: center !important;
    overflow: hidden !important;
}

/* Chat shell - full width, centered */
body.viewport-mobile:not(.has-messages) .chat-shell {
    flex: 1 1 auto !important;
    width: 100% !important;
    max-width: 100% !important;
    display: flex !important;
    flex-direction: column !important;
    align-items: center !important;
}

/* Conversation panel - center, no extra padding */
body.viewport-mobile:not(.has-messages) .conversation-panel {
    width: 100% !important;
    display: flex !important;
    flex-direction: column !important;
    align-items: center !important;
    padding-top: 0 !important;
}

/* Chatbox - container for fixed elements */
body.viewport-mobile:not(.has-messages) .chatbox {
    display: block !important;
    width: 100% !important;
    height: 100% !important;
    position: relative !important;
}

/* Greeting container - fixed from start */
body.viewport-mobile:not(.has-messages) .greeting-container {
    position: fixed !important;
    top: 22% !important;
    left: 0 !important;
    right: 0 !important;
    display: flex !important;
    flex-direction: column !important;
    align-items: center !important;
    justify-content: center !important;
    text-align: center !important;
    padding: 0 0.5rem !important;
    z-index: 10 !important;
    background: #000 !important;
}

/* Hide empty elements between greeting and options */
body.viewport-mobile:not(.has-messages) #page-controls,
body.viewport-mobile:not(.has-messages) #chat-display {
    display: none !important;
}

/* Logo container */
body.viewport-mobile:not(.has-messages) .logo-container {
    width: 2.75rem !important;
    height: 2.75rem !important;
    margin: 0 auto 0.75rem !important;
}

/* Greeting text */
body.viewport-mobile:not(.has-messages) .greeting-text {
    font-size: 1.25rem !important;
    line-height: 1.3 !important;
    text-align: center !important;
    color: #ffffff !important;
}

/* Time icon for greeting */
body.viewport-mobile:not(.has-messages) .greeting-container .time-icon,
body.device-phone:not(.has-messages) .greeting-container .time-icon {
    display: inline-block;
    width: 28px;
    height: 28px;
    margin-right: 8px;
    vertical-align: middle;
    position: relative;
    top: -2px;
}

/* Sun icon with rotation */
body.viewport-mobile:not(.has-messages) .greeting-container .time-icon.sun,
body.device-phone:not(.has-messages) .greeting-container .time-icon.sun {
    color: #fbbf24;
    -webkit-animation: sun-glow 3s ease-in-out infinite;
    animation: sun-glow 3s ease-in-out infinite;
}

body.viewport-mobile:not(.has-messages) .greeting-container .time-icon.sun svg,
body.device-phone:not(.has-messages) .greeting-container .time-icon.sun svg {
    -webkit-animation: sun-spin 20s linear infinite;
    animation: sun-spin 20s linear infinite;
}

/* Moon icon with glow */
body.viewport-mobile:not(.has-messages) .greeting-container .time-icon.moon,
body.is-ios:not(.has-messages) .greeting-container .time-icon.moon {
    color: #a5b4fc;
    -webkit-animation: moon-glow 4s ease-in-out infinite;
    animation: moon-glow 4s ease-in-out infinite;
}

/* iOS specific - ensure animations work */
body.is-ios:not(.has-messages) .greeting-container .time-icon {
    display: inline-block !important;
    width: 28px !important;
    height: 28px !important;
    margin-right: 8px !important;
    vertical-align: middle !important;
    position: relative !important;
    top: -2px !important;
}

body.is-ios:not(.has-messages) .greeting-container .time-icon.sun {
    color: #fbbf24 !important;
    -webkit-animation: sun-glow 3s ease-in-out infinite !important;
    animation: sun-glow 3s ease-in-out infinite !important;
}

body.is-ios:not(.has-messages) .greeting-container .time-icon.sun svg {
    -webkit-animation: sun-spin 20s linear infinite !important;
    animation: sun-spin 20s linear infinite !important;
}

/* === Weather Icons === */
/* Base weather icon styles */
body.viewport-mobile:not(.has-messages) .greeting-container .weather-icon,
body.device-phone:not(.has-messages) .greeting-container .weather-icon,
body.is-ios:not(.has-messages) .greeting-container .weather-icon {
    display: inline-block;
    width: 28px;
    height: 28px;
    margin-right: 8px;
    vertical-align: middle;
    position: relative;
    top: -2px;
}

/* Weather icon SVG sizing */
body.viewport-mobile:not(.has-messages) .greeting-container .weather-icon svg,
body.device-phone:not(.has-messages) .greeting-container .weather-icon svg,
body.is-ios:not(.has-messages) .greeting-container .weather-icon svg {
    width: 28px !important;
    height: 28px !important;
}

/* Clear day - sun */
.weather-icon.weather-clear-day {
    color: #fbbf24;
    -webkit-animation: sun-glow 3s ease-in-out infinite;
    animation: sun-glow 3s ease-in-out infinite;
}

.weather-icon.weather-clear-day svg {
    -webkit-animation: sun-spin 20s linear infinite;
    animation: sun-spin 20s linear infinite;
}

/* Clear night - moon */
.weather-icon.weather-clear-night {
    color: #a5b4fc;
    -webkit-animation: moon-glow 4s ease-in-out infinite;
    animation: moon-glow 4s ease-in-out infinite;
}

/* Partly cloudy */
.weather-icon.weather-partly-cloudy-day {
    color: #fbbf24;
    -webkit-animation: sun-glow 3s ease-in-out infinite;
    animation: sun-glow 3s ease-in-out infinite;
}

.weather-icon.weather-partly-cloudy-night {
    color: #94a3b8;
}

/* Cloudy */
.weather-icon.weather-cloudy {
    color: #94a3b8;
    -webkit-animation: cloud-float 4s ease-in-out infinite;
    animation: cloud-float 4s ease-in-out infinite;
}

/* Fog */
.weather-icon.weather-fog {
    color: #94a3b8;
    -webkit-animation: fog-drift 5s ease-in-out infinite;
    animation: fog-drift 5s ease-in-out infinite;
}

/* Drizzle & Rain */
.weather-icon.weather-drizzle,
.weather-icon.weather-rain {
    color: #60a5fa;
}

/* Snow */
.weather-icon.weather-snow {
    color: #e0f2fe;
    -webkit-animation: snow-fall 2s ease-in-out infinite;
    animation: snow-fall 2s ease-in-out infinite;
}

/* Thunderstorm */
.weather-icon.weather-thunderstorm {
    color: #6b7280;
    -webkit-animation: lightning-flash 4s ease-in-out infinite;
    animation: lightning-flash 4s ease-in-out infinite;
}

/* === OPTIONS - Vertical list with icons === */
/* Hide options when there are messages */
body.viewport-mobile.has-messages .options {
    display: none !important;
}

body.viewport-mobile:not(.has-messages) .options {
    position: fixed !important;
    top: 30% !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 90px !important;
    display: flex !important;
    flex-direction: column !important;
    align-items: center !important;
    gap: 0 !important;
    padding: 0 20px !important;
    padding-bottom: 20px !important;
    max-width: 100% !important;
    width: 100% !important;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch !important;
}

/* Show all options */
body.viewport-mobile .options button:nth-child(n) {
    display: flex !important;
}

/* Hide More button */
body.viewport-mobile .options .more-button {
    display: none !important;
}

/* Option buttons - compact style */
body.viewport-mobile .options button {
    width: 100% !important;
    max-width: 340px !important;
    height: auto !important;
    min-height: unset !important;
    padding: 10px 12px !important;
    border-radius: 10px !important;
    background: transparent !important;
    border: none !important;
    color: rgba(255, 255, 255, 0.6) !important;
    font-size: 14px !important;
    font-weight: 400 !important;
    flex-direction: row !important;
    align-items: center !important;
    justify-content: flex-start !important;
    gap: 12px !important;
    box-shadow: none !important;
}

/* Icon styling - compact with time-based colors */
body.viewport-mobile .options button .option-icon {
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    width: 28px !important;
    height: 28px !important;
    min-width: 28px !important;
    border-radius: 8px !important;
    /* Default to golden (daytime) */
    background: transparent !important;
    border: none !important;
}

body.viewport-mobile .options button .option-icon svg {
    width: 14px !important;
    height: 14px !important;
    color: rgba(255, 255, 255, 0.6) !important;
}

/* Daytime - golden/warm icons */
body.viewport-mobile.is-daytime .options button .option-icon {
    background: transparent !important;
    border: none !important;
}

body.viewport-mobile.is-daytime .options button .option-icon svg {
    width: 14px !important;
    height: 14px !important;
    color: rgba(255, 255, 255, 0.6) !important;
}

/* Nighttime - blue/cool icons */
body.viewport-mobile.is-nighttime .options button .option-icon {
    background: transparent !important;
    border: none !important;
}

body.viewport-mobile.is-nighttime .options button .option-icon svg {
    width: 14px !important;
    height: 14px !important;
    color: #3b82f6 !important;
}

/* Hide subtitle */
body.viewport-mobile .options button .subtitle {
    display: none !important;
}

/* Text styling */
body.viewport-mobile .options button .button-text {
    font-size: 15px !important;
    font-weight: 400 !important;
    color: inherit !important;
}

/* Hide arrow down on home */
body.viewport-mobile:not(.has-messages) .arrow-down {
    display: none !important;
}

/* === GENERAL SMALL VIEWPORT === */

/* Sidebar as drawer */
body.viewport-mobile .left-sidebar {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    width: 280px !important;
    height: 100vh !important;
    height: 100dvh !important;
    z-index: 1000 !important;
    transform: translateX(-100%) !important;
    visibility: hidden;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1), visibility 0s linear 0.3s !important;
    background: var(--sidebar-bg, #0b0b10) !important;
    will-change: transform;
}

/* Show sidebar when open */
body.viewport-mobile.mobile-sidebar-open .left-sidebar {
    transform: translateX(0) !important;
    visibility: visible !important;
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.5) !important;
    overflow-y: auto !important;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1), visibility 0s linear 0s !important;
}

/* Overlay backdrop */
body.viewport-mobile .mobile-overlay {
    position: fixed !important;
    inset: 0 !important;
    background: rgba(0, 0, 0, 0.6) !important;
    z-index: 900 !important;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s cubic-bezier(0.4, 0, 0.2, 1), visibility 0.3s ease !important;
    will-change: opacity, visibility;
}

body.viewport-mobile .mobile-overlay.active {
    opacity: 1 !important;
    visibility: visible !important;
}

/* Hide desktop toggle button */
body.viewport-mobile .toggle-button {
    display: none !important;
}

/* Hide desktop model selector */
body.viewport-mobile .model-select-wrapper {
    display: none !important;
}

/* Hide desktop temp-chat-launcher */
body.viewport-mobile .temp-chat-launcher.desktop-only {
    display: none !important;
}

/* === MOBILE HEADER BAR === */
/* Adjust page-wrapper::before to match mobile header height */
body.viewport-mobile .page-wrapper::before {
    height: var(--mobile-header-height) !important;
}

/* Show mobile header bar for viewport-mobile */
body.viewport-mobile .mobile-header-bar {
    display: flex !important;
    align-items: center !important;
    justify-content: space-between !important;
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    height: var(--mobile-header-height) !important;
    padding: 0 4px !important;
    background: #000 !important;
    border-bottom: none !important;
    z-index: 9999 !important;
    box-sizing: content-box !important;
}

/* Show mobile model selector */
body.viewport-mobile .mobile-model-select:not(.guest-disabled) {
    display: inline-flex !important;
    flex-direction: column !important;
    align-items: center !important;
    justify-content: center !important;
    min-height: 44px !important;
    max-height: 44px !important;
    padding: 0 !important;
}

body.viewport-mobile .mobile-model-header {
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    gap: 6px !important;
    padding: 0 12px !important;
    height: 36px !important;
    min-height: 36px !important;
    white-space: nowrap !important;
}

body.viewport-mobile .mobile-model-name {
    font-size: 14px !important;
    font-weight: 500 !important;
    color: rgba(255, 255, 255, 0.9) !important;
}

body.viewport-mobile .mobile-model-arrow {
    width: 10px !important;
    height: 10px !important;
    color: rgba(255, 255, 255, 0.5) !important;
    transition: transform 0.2s ease !important;
}

/* Dropdown options - HIDDEN by default */
body.viewport-mobile .mobile-model-options {
    display: none !important;
    position: absolute !important;
    top: 100% !important;
    left: 50% !important;
    transform: translateX(-50%) !important;
    min-width: 180px !important;
    max-height: 50vh !important;
    overflow-y: auto !important;
    background: rgba(40, 40, 40, 0.98) !important;
    border: none !important;
    border-radius: 12px !important;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5) !important;
    margin-top: 8px !important;
    padding: 8px 0 !important;
    flex-direction: column !important;
    z-index: 10000 !important;
}

/* Show dropdown when expanded */
body.viewport-mobile .mobile-model-select.expanded .mobile-model-options {
    display: flex !important;
}

/* Expanded state styling */
body.viewport-mobile .mobile-model-select.expanded {
    position: relative !important;
    background: rgba(40, 40, 40, 0.98) !important;
    border-radius: 12px !important;
    z-index: 9999 !important;
}

body.viewport-mobile .mobile-model-select.expanded .mobile-model-arrow {
    transform: rotate(180deg) !important;
}

/* Individual model options */
body.viewport-mobile .mobile-model-option {
    display: flex !important;
    align-items: center !important;
    justify-content: space-between !important;
    padding: 12px 16px !important;
    color: rgba(255, 255, 255, 0.9) !important;
    font-size: 14px !important;
    cursor: pointer !important;
    transition: background 0.15s ease !important;
    white-space: nowrap !important;
}

body.viewport-mobile .mobile-model-option:hover {
    background: rgba(255, 255, 255, 0.08) !important;
}

body.viewport-mobile .mobile-model-option.selected {
    background: rgba(255, 255, 255, 0.05) !important;
}

body.viewport-mobile .mobile-model-option.selected::after {
    content: '✓' !important;
    color: #4CAF50 !important;
    font-size: 14px !important;
}

/* Ghost/incognito button in header */
body.viewport-mobile .mobile-header-ghost {
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    width: 44px !important;
    height: 44px !important;
}

/* Add padding to content for mobile header - only on content-wrapper, not chat-area (which is inside it) */
body.viewport-mobile .content-wrapper {
    padding-top: var(--mobile-header-height) !important;
}

body.viewport-mobile .chat-area {
    padding-top: 0 !important;
}

/* Hide desktop header - we use mobile-header-bar instead */
body.viewport-mobile .chat-shell__header {
    display: none !important;
}

/* Remove any lines/borders from composer area */
body.viewport-mobile .chat-shell__composer {
    border: none !important;
    border-top: none !important;
    box-shadow: none !important;
}

body.viewport-mobile .input-container {
    border: none !important;
    box-shadow: none !important;
    gap: 0.5rem !important;
}

body.viewport-mobile .input-container::before,
body.viewport-mobile .input-container::after {
    display: none !important;
}

/* Input area - match body background exactly */
body.viewport-mobile .chat-shell__composer,
body.viewport-mobile .input-container,
body.viewport-mobile .input-row,
body.viewport-mobile .input-row:focus-within,
body.device-phone .chat-shell__composer,
body.device-phone .input-container,
body.device-phone .input-row,
body.device-phone .input-row:focus-within,
body.device-tablet .chat-shell__composer,
body.device-tablet .input-container,
body.device-tablet .input-row,
body.device-tablet .input-row:focus-within,
body.is-mobile .chat-shell__composer,
body.is-mobile .input-container,
body.is-mobile .input-row,
body.is-mobile .input-row:focus-within {
    background: transparent !important;
    background-color: transparent !important;
    border: none !important;
    box-shadow: none !important;
}

/* Hide the ::after pseudo-element */
body.viewport-mobile .input-row::after,
body.device-phone .input-row::after,
body.device-tablet .input-row::after,
body.is-mobile .input-row::after {
    display: none !important;
}


/* Reduce top padding on conversation-panel so content scrolls closer to header */
body.viewport-mobile .conversation-panel {
    padding-top: 0.5rem !important;
}

/* === SCROLL FIX === */
/* Ensure scroll container works */
body.viewport-mobile #chat-scroll-region {
    flex: 1 1 auto !important;
    overflow-y: auto !important;
    overflow-x: hidden !important;
    -webkit-overflow-scrolling: touch !important;
}

body.viewport-mobile .chat-shell__messages {
    flex: 1 1 auto !important;
    overflow-y: auto !important;
    overflow-x: hidden !important;
}

/* Parent containers - proper overflow handling */
body.viewport-mobile .chat-area {
    height: 100vh !important;
    height: 100dvh !important;
    overflow: hidden !important;
}

body.viewport-mobile .content-wrapper {
    height: 100% !important;
    overflow: hidden !important;
}

body.viewport-mobile .chat-stage {
    height: 100% !important;
    overflow: hidden !important;
    display: flex !important;
    flex-direction: column !important;
}

body.viewport-mobile .chat-shell {
    flex: 1 1 auto !important;
    min-height: 0 !important;
    overflow: hidden !important;
    display: flex !important;
    flex-direction: column !important;
}

/* ============================================
   VIEWPORT-MOBILE: Desktop-like message actions
   Show edit/copy/pagination on hover, not long-press
   ============================================ */

/* Show message footer (contains edit/copy buttons) on viewport-mobile - hidden by default */
body.viewport-mobile .message.user-message .message-bubble-footer {
    display: flex !important;
    opacity: 0 !important;
    visibility: hidden !important;
    transition: opacity 0.15s ease, visibility 0.15s ease !important;
}

/* Show on hover */
body.viewport-mobile .message.user-message:hover .message-bubble-footer {
    opacity: 1 !important;
    visibility: visible !important;
}

/* Message actions - hidden by default, show on hover like desktop */
body.viewport-mobile .message .message-actions {
    opacity: 0 !important;
    visibility: hidden !important;
    transition: opacity 0.15s ease, visibility 0.15s ease !important;
}

body.viewport-mobile .message:hover .message-actions {
    opacity: 1 !important;
    visibility: visible !important;
}

/* Pagination controls - hidden by default, show on hover */
body.viewport-mobile .message .pagination-controls {
    display: flex !important;
    opacity: 0 !important;
    visibility: hidden !important;
    transition: opacity 0.15s ease, visibility 0.15s ease !important;
}

body.viewport-mobile .message:hover .pagination-controls {
    opacity: 1 !important;
    visibility: visible !important;
}

/* ============================================
   VIEWPORT-MOBILE: Enable tooltips (has hover)
   Exclude buttons that use ::after for other purposes
   ============================================ */

body.viewport-mobile [data-tooltip]:not(.voice-mode-button):not(.send-button):not(.actions-toggle)::after {
    display: block !important;
    content: attr(data-tooltip) !important;
    visibility: hidden !important;
    opacity: 0 !important;
    transition: opacity 0.15s ease, visibility 0.15s ease !important;
}

body.viewport-mobile [data-tooltip]:not(.voice-mode-button):not(.send-button):not(.actions-toggle):hover::after {
    visibility: visible !important;
    opacity: 1 !important;
}

body.viewport-mobile .tooltip,
body.viewport-mobile .toggle-tooltip {
    display: block !important;
    visibility: hidden !important;
    opacity: 0 !important;
    transition: opacity 0.15s ease, visibility 0.15s ease !important;
}

body.viewport-mobile *:hover > .tooltip,
body.viewport-mobile *:hover > .toggle-tooltip {
    visibility: visible !important;
    opacity: 1 !important;
}

/* ================================
   Mobile Notification Dot Styles
   ================================ */

/* Define keyframes for mobile (needed for some mobile browsers) */
@-webkit-keyframes mobile-notification-pulse {
    0%, 100% {
        opacity: 1;
        -webkit-transform: scale(1);
        transform: scale(1);
    }
    50% {
        opacity: 0.5;
        -webkit-transform: scale(1.3);
        transform: scale(1.3);
    }
}

@keyframes mobile-notification-pulse {
    0%, 100% {
        opacity: 1;
        transform: scale(1);
    }
    50% {
        opacity: 0.5;
        transform: scale(1.3);
    }
}

@media (max-width: 768px) {
    /* Ensure notification dot is visible on mobile - positioned on right side */
    .chat-tab .session-notification-dot {
        width: 8px;
        height: 8px;
        position: relative;
        flex-shrink: 0;
    }

    .chat-tab.has-notification .session-notification-dot {
        display: inline-block !important;
        background: #3b82f6 !important;
        border-radius: 50%;
        -webkit-animation: mobile-notification-pulse 1.5s ease-in-out infinite !important;
        animation: mobile-notification-pulse 1.5s ease-in-out infinite !important;
    }

    /* Ensure tab-content doesn't clip the dot */
    .chat-tab .tab-content {
        overflow: visible;
    }
}

/* ============================================
   MOBILE IMAGE RENDERING - Enhanced Loading
   Blur-up effect with smooth reveal
   ============================================ */

/* Image container with loading state */
.file-preview-card__thumb,
.image-preview-card,
.attachment-card.image-attachment {
    position: relative;
    overflow: hidden;
}

/* Loading skeleton before image loads */
.file-preview-card__thumb::before,
.image-preview-card::before {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(
        110deg,
        rgba(255, 255, 255, 0.03) 0%,
        rgba(255, 255, 255, 0.08) 40%,
        rgba(255, 255, 255, 0.03) 60%
    );
    background-size: 200% 100%;
    animation: mobile-img-shimmer 1.5s ease-in-out infinite;
    z-index: 1;
    opacity: 1;
    transition: opacity 0.3s ease;
    pointer-events: none;
    border-radius: inherit;
}

/* Hide shimmer when image is loaded */
.file-preview-card__thumb.loaded::before,
.image-preview-card.loaded::before {
    opacity: 0;
}

@keyframes mobile-img-shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* Mobile-specific image styling */
@media (max-width: 768px) {
    /* Full-width images on mobile */
    .image-preview-card {
        width: 100% !important;
        max-width: 100% !important;
        margin: 0.5rem 0;
        padding: 0.5rem;
        border-radius: 0.75rem;
    }

    /* Image loading states */
    .file-preview-card__thumb img,
    .image-preview-card img,
    .attachment-card.image-attachment img {
        opacity: 0;
        filter: blur(10px);
        transform: scale(1.02);
        transition:
            opacity 0.4s ease-out,
            filter 0.5s ease-out,
            transform 0.5s cubic-bezier(0.25, 0.46, 0.45, 0.94);
        will-change: opacity, filter, transform;
    }

    /* Loaded state - blur-up reveal */
    .file-preview-card__thumb img.loaded,
    .image-preview-card img.loaded,
    .attachment-card.image-attachment img.loaded {
        opacity: 1;
        filter: blur(0);
        transform: scale(1);
    }

    /* Touch feedback on images */
    .file-preview-card__thumb:active,
    .image-preview-card:active,
    .attachment-card.image-attachment:active {
        transform: scale(0.98);
        transition: transform 0.1s ease;
    }

    /* Image attachment cards */
    .message-attachments {
        width: 100%;
    }

    .file-preview-card {
        width: 100%;
        max-width: 100%;
    }

    .file-preview-card__thumb {
        aspect-ratio: 1 / 1;
        max-height: 300px;
        background: rgba(0, 0, 0, 0.3);
        border-radius: 0.5rem;
    }

    .file-preview-card__thumb img {
        width: 100%;
        height: 100%;
        object-fit: cover;
        border-radius: inherit;
    }

    /* AI Generated image badge styling */
    .image-preview-card__badge {
        font-size: 0.7rem;
        padding-bottom: 0.3rem;
    }

    /* Loading placeholder pulse */
    .image-placeholder {
        min-height: 200px;
        border-radius: 0.5rem;
    }

    /* Live-generated AI images (.chat-image) */
    .image-layer .chat-image {
        opacity: 0;
        filter: blur(12px);
        transform: scale(1.03);
        transition:
            opacity 0.5s ease-out,
            filter 0.6s ease-out,
            transform 0.6s cubic-bezier(0.25, 0.46, 0.45, 0.94);
        will-change: opacity, filter, transform;
        width: 100%;
        border-radius: 0.5rem;
    }

    .image-layer .chat-image.loaded {
        opacity: 1;
        filter: blur(0);
        transform: scale(1);
    }

    /* Image layer container */
    .image-layer {
        width: 100%;
        border-radius: 0.75rem;
        overflow: hidden;
    }

    .image-layer.revealed .image-placeholder {
        opacity: 0 !important;
        pointer-events: none;
    }


    /* Mobile weather badge - compact, no background, no shimmer */
    .weather-badge.weather-badge-mobile {
        display: inline-flex;
        align-items: center;
        gap: 4px;
        padding: 0;
        margin-left: 6px;
        vertical-align: middle;
        background: none !important;
        border: none !important;
        border-radius: 0 !important;
        overflow: visible !important;
    }

    /* Remove shimmer effect on mobile */
    .weather-badge.weather-badge-mobile::before {
        display: none !important;
        content: none !important;
    }

    /* Username wrapper with weather above/below */
    .weather-username-wrapper {
        display: inline-flex;
        flex-direction: column;
        align-items: center;
        vertical-align: middle;
        margin-left: 4px;
    }

    /* Icon+degrees above username */
    .weather-username-wrapper .weather-icon-wrapper {
        display: inline-flex;
        align-items: center;
        position: relative;
        overflow: visible !important;
        margin-bottom: -2px;
    }

    .weather-username-wrapper .weather-icon {
        width: 18px;
        height: 18px;
        overflow: visible !important;
    }

    .weather-username-wrapper .weather-icon svg {
        width: 14px;
        height: 14px;
    }

    /* Temperature next to icon */
    .weather-username-wrapper .weather-temp-badge {
        font-size: 0.5rem;
        font-weight: 600;
        color: rgba(255, 255, 255, 0.8);
        margin-left: 2px;
        line-height: 1;
    }

    /* City below */
    .weather-username-wrapper .weather-city {
        font-size: 0.45rem;
        font-weight: 500;
        color: rgba(255, 255, 255, 0.5);
        text-transform: uppercase;
        letter-spacing: 0.02em;
        line-height: 1;
        margin-top: -2px;
    }
}
