/* ============================================================================
   Mobile Optimizations
   Mobile-first responsive styles for improved UX on small screens
   ============================================================================ */

/* iOS Safari safe-area support for iPhone notch and toolbar */
:root {
    /* Use safe-area-inset for iPhone notch/toolbar compatibility */
    --safe-area-inset-top: env(safe-area-inset-top, 0px);
    --safe-area-inset-bottom: env(safe-area-inset-bottom, 0px);
    --safe-area-inset-left: env(safe-area-inset-left, 0px);
    --safe-area-inset-right: env(safe-area-inset-right, 0px);

    /* Mobile viewport height - adapts to browser capabilities */
    --viewport-height: 100vh;
}

/* For browsers that support Small Viewport Height (better for mobile) */
@supports (height: 100svh) {
    :root {
        /* svh = smallest viewport height (when browser UI is fully expanded) */
        --viewport-height: 100svh;
    }
}

/* Mobile-specific media queries */
@media (max-width: 768px) {
    /* Make top banner sticky at the top */
    .top-banner {
        position: sticky;
        top: 0;
        z-index: 100;
        width: 100%;
    }

    /* Hide chat header to maximize chat space */
    .chat-header {
        display: none !important;
    }

    /* Hide prompt suggestions container on mobile */
    .suggestions-container {
        display: none !important;
    }

    /* Make assistant cards mobile-friendly */
    .assistant-card {
        min-width: 100%;
        flex-direction: column;
        gap: 10px;
        padding: 12px;
    }

    .assistant-profile-pic {
        width: 100%;
        height: auto;
        padding: 0;
        margin: 0 0 10px 0;
    }

    .assistant-content {
        padding: 0;
    }

    .assistants-grid {
        display: flex;
        flex-direction: column;
        gap: 10px;
    }

    /* Stretch message boxes to full width */
    .chat-container {
        width: 100%;
        /* Use CSS variable that adapts to browser capabilities */
        height: var(--viewport-height);
        border-radius: 0;
        margin: 0;
        box-shadow: none;
        display: flex;
        flex-direction: column;
    }

    .chat-body {
        padding: var(--spacing-sm);
        flex: 1;
        overflow-y: auto;
        /* Add padding to prevent content from being hidden behind sticky footer */
        /* Calculate: base footer height (80px) + safe-area-inset for iPhone toolbar */
        padding-bottom: calc(80px + var(--safe-area-inset-bottom));
    }

    #messages {
        padding: var(--spacing-sm);
        width: 100%;
    }

    /* Make chat footer sticky at the bottom */
    .chat-footer {
        position: sticky;
        bottom: 0;
        z-index: 99;
        width: 100%;
        background-color: var(--bg-footer-color);
        box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.1);
        /* Add padding for iPhone safe-area (toolbar) - ensures footer is always visible */
        padding-bottom: max(5px, var(--safe-area-inset-bottom));
        /* Add side padding for notched devices */
        padding-left: max(5px, var(--safe-area-inset-left));
        padding-right: max(5px, var(--safe-area-inset-right));
    }

    /* Maximize vertical space */
    .chat-interface {
        padding: 0;
        /* Use CSS variable that adapts to browser capabilities */
        height: var(--viewport-height);
        display: flex;
        flex-direction: column;
    }

    .main-container {
        /* Use CSS variable that adapts to browser capabilities */
        height: var(--viewport-height);
    }

    /* Adjust input area for mobile */
    .input-container {
        padding: 8px;
    }

    .chat-input-wrap {
        width: 100%;
    }

    /* Make buttons more touch-friendly */
    .submit-btn,
    .mic-btn,
    .stop-btn {
        width: 44px;
        height: 44px;
        font-size: 1.3em;
    }

    .submit-btn {
        right: 100px;
    }

    .mic-btn {
        right: 52px;
    }

    .stop-btn {
        right: 4px;
    }

    .chat-input {
        padding-right: 150px;
    }

    /* Adjust footer status for mobile */
    .chat-footer-status {
        font-size: 0.85em;
        padding: 4px 8px;
    }

    /* Hide status text on mobile */
    .ready-text {
        display: none;
    }

    /* Vertical toolbar - compact on mobile */
    .chat-action-toolbar:not(.hidden) {
        padding: 8px;
        gap: 8px;
    }

    .toolbar-action-btn {
        min-width: 56px;
        width: 56px;
        height: 56px;
        padding: 8px;
        border-radius: 50%;
    }

    .toolbar-btn-text {
        display: none;
    }

    .toolbar-btn-icon {
        font-size: 1.8em;
        margin: 0;
    }

    /* Hide non-essential UI elements */
    .user-info span {
        display: none;
    }

    /* Hide assistants panel on mobile - we show assistants in chat-body instead */
    .assistants-container {
        display: none !important;
    }

    /* Make assistant list more compact */
    .assistants-list {
        flex-direction: column;
    }

    .assistants-title {
        font-size: 1.1em;
        margin-bottom: var(--spacing-md);
    }

    /* Assistant description display on mobile (shown until first message) */
    .assistant-description-mobile {
        display: flex;
        align-items: center;
        justify-content: center;
        min-height: 300px;
        padding: var(--spacing-lg);
        text-align: center;
        /* Add bottom padding for safe-area to prevent content being hidden */
        padding-bottom: calc(var(--spacing-lg) + var(--safe-area-inset-bottom));
    }

    .assistant-description-content {
        max-width: 500px;
        background: var(--containerbackground);
        padding: var(--spacing-xl);
        border-radius: var(--radius-lg);
        box-shadow: var(--shadow-md);
    }

    .assistant-description-content h2 {
        color: var(--accent-color);
        font-size: 1.8em;
        margin-bottom: var(--spacing-md);
        font-weight: 600;
    }

    .assistant-description-content p {
        color: var(--text-color);
        font-size: 1.1em;
        line-height: 1.6;
        margin-bottom: var(--spacing-lg);
    }

    .suggested-prompts-mobile {
        margin-top: var(--spacing-lg);
        text-align: left;
    }

    .suggested-prompts-mobile h3 {
        color: var(--accent-color);
        font-size: 1.2em;
        margin-bottom: var(--spacing-sm);
        font-weight: 600;
    }

    .suggested-prompts-mobile ul {
        list-style: none;
        padding: 0;
        margin: 0;
    }

    .suggested-prompts-mobile li {
        background: var(--bg-secondary, #f8f9fa);
        padding: var(--spacing-sm);
        margin-bottom: var(--spacing-xs);
        border-radius: var(--radius-sm);
        font-size: 0.95em;
        color: var(--text-color);
        border-left: 3px solid var(--accent-color);
        cursor: pointer;
        transition: all 0.2s ease;
    }

    .suggested-prompts-mobile li:hover,
    .suggested-prompts-mobile li:active {
        background: var(--accent-color);
        color: white;
        transform: translateX(4px);
        box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
    }

    /* Assistants list display on mobile (shown on book load) */
    .assistants-list-mobile {
        padding: var(--spacing-md);
        /* Add bottom padding for safe-area to prevent list being cut off */
        padding-bottom: calc(var(--spacing-md) + var(--safe-area-inset-bottom));
    }

    .assistants-list-content {
        max-width: 600px;
        margin: 0 auto;
    }

    .assistants-list-content h2 {
        color: var(--accent-color);
        font-size: 1.8em;
        margin-bottom: var(--spacing-sm);
        font-weight: 600;
        text-align: center;
    }

    .assistants-list-subtitle {
        text-align: center;
        color: var(--text-color);
        font-size: 1.1em;
        margin-bottom: var(--spacing-lg);
        opacity: 0.8;
    }

    .assistants-list-items {
        display: flex;
        flex-direction: column;
        gap: var(--spacing-sm);
    }

    .assistant-list-item {
        display: flex;
        align-items: center;
        gap: var(--spacing-md);
        background: var(--containerbackground);
        padding: var(--spacing-md);
        border-radius: var(--radius-lg);
        box-shadow: var(--shadow-sm);
        cursor: pointer;
        transition: all 0.2s ease;
        border: 2px solid transparent;
    }

    .assistant-list-item:hover,
    .assistant-list-item:active {
        border-color: var(--accent-color);
        box-shadow: var(--shadow-md);
        transform: translateY(-2px);
    }

    .assistant-list-item-icon {
        width: 50px;
        height: 50px;
        min-width: 50px;
        border-radius: 50%;
        background: var(--accent-color);
        color: white;
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 1.5em;
        font-weight: 600;
    }

    .assistant-list-item-content {
        flex: 1;
        min-width: 0;
    }

    .assistant-list-item-content h3 {
        color: var(--accent-color);
        font-size: 1.2em;
        margin: 0 0 var(--spacing-xs) 0;
        font-weight: 600;
    }

    .assistant-list-item-content p {
        color: var(--text-color);
        font-size: 0.95em;
        margin: 0;
        line-height: 1.4;
        opacity: 0.8;
        overflow: hidden;
        text-overflow: ellipsis;
        display: -webkit-box;
        -webkit-line-clamp: 2;
        -webkit-box-orient: vertical;
    }
}

/* Extra small devices (phones in portrait mode) */
@media (max-width: 480px) {
    /* Further reduce padding to maximize space */
    .chat-body {
        padding: 4px;
    }

    #messages {
        padding: 4px;
    }

    .chat-footer {
        padding: 4px;
        /* Maintain safe-area padding on very small devices */
        padding-bottom: max(4px, var(--safe-area-inset-bottom));
    }

    /* Make text input more compact */
    .chat-input {
        font-size: 14px;
        padding: 8px;
    }

    /* Stack buttons vertically if needed */
    .input-container {
        gap: 4px;
    }

    /* Adjust assistant cards for very small screens */
    .assistant-card {
        padding: 8px;
    }

    .assistant-card h4 {
        font-size: 0.9em;
    }

    .assistant-card p {
        font-size: 0.8em;
    }
}

/* Hide mobile-only elements on desktop (screens larger than 768px) */
@media (min-width: 769px) {
    .assistant-description-mobile,
    .assistants-list-mobile {
        display: none !important;
    }
}
