/* ========================================
   LUMINA - FIXED CHAT STRUCTURE
   ======================================== */

/* ========== LANDING PAGE (Keep as is) ========== */

#view-landing {
    background: #f9fafb !important;
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
}

#view-landing::before,
.orb,
.badge,
.card-group,
.feature-card,
.features-list,
.gradient-text {
    display: none !important;
}

.landing-content {
    position: relative;
    z-index: 1;
    max-width: 48rem !important;
    width: 100%;
    padding: 0 !important;
}

.landing-content h1 {
    font-size: 3.75rem !important;
    line-height: 1 !important;
    color: #111827 !important;
    background: none !important;
    -webkit-text-fill-color: initial !important;
    animation: none !important;
    margin-bottom: 1rem !important;
    font-weight: 700 !important;
    letter-spacing: -0.025em !important;
    text-align: center !important;
}

.landing-content h1::after {
    display: none !important;
}

.landing-content .subtitle {
    color: #4b5563 !important;
    font-size: 1.25rem !important;
    animation: none !important;
    margin-bottom: 4rem !important;
    font-weight: 400 !important;
    line-height: 1.75rem !important;
    text-align: center !important;
}

.action-cards {
    display: grid !important;
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 1rem !important;
    max-width: 42rem !important;
    margin: 0 auto !important;
}

.action-card {
    background: #ffffff !important;
    border: 1px solid #e5e7eb !important;
    border-radius: 0.75rem !important;
    padding: 2rem !important;
    cursor: pointer !important;
    transition: all 0.2s ease !important;
    text-align: left !important;
    font-family: var(--font-body) !important;
    box-shadow: none !important;
}

.action-card::before {
    display: none !important;
}

.action-card:hover {
    background: #f9fafb !important;
    border-color: #d1d5db !important;
    transform: none !important;
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05) !important;
}

.action-card-featured {
    background: #ffffff !important;
    border: 1px solid #e5e7eb !important;
}

.action-card-featured:hover {
    background: #f9fafb !important;
    border-color: #d1d5db !important;
}

.action-card-featured .card-title,
.action-card-featured .card-desc {
    color: inherit !important;
}

.card-content {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.card-title {
    font-size: 1.25rem !important;
    font-weight: 600 !important;
    color: #111827 !important;
    margin-bottom: 0.5rem !important;
    line-height: 1.75rem !important;
}

.card-title::before {
    content: '✨';
    display: block;
    font-size: 2rem;
    margin-bottom: 1rem;
}

.action-card:nth-child(2) .card-title::before {
    content: '📄';
}

.card-desc {
    font-size: 0.875rem !important;
    color: #4b5563 !important;
    line-height: 1.25rem !important;
}

/* ========== FIXED CHAT LAYOUT ========== */

.app-header {
    display: none !important;
}

#view-chat {
    padding-top: 0 !important;
    background: linear-gradient(to bottom right, #f9fafb 0%, #f3f4f6 100%) !important;
    display: flex !important;
    flex-direction: column !important;
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    /* Use specific edges instead of inset for broader support */
    height: 100% !important;
    /* Fallback */
    height: 100dvh !important;
    width: 100% !important;
    z-index: 9999 !important;
    /* Ensure on top */
}

.chat-header-bar {
    display: none !important;
}

/* Floating back button */
.floating-back-btn {
    position: fixed;
    top: 1.5rem;
    left: 1.5rem;
    /* Move to left side which is more intuitive for 'Back' */
    z-index: 1000;
    background: white;
    border: 1px solid #e5e7eb;
    padding: 0.5rem 1rem;
    border-radius: 0.5rem;
    font-size: 0.875rem;
    cursor: pointer;
    color: #4b5563;
    font-weight: 500;
    transition: all 0.2s ease;
    box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1);
    font-family: var(--font-body);
}

.floating-back-btn:hover {
    background: #f9fafb;
    border-color: #d1d5db;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}

/* Paper Panel - Hide for cleaner layout */
aside {
    display: none !important;
}

/* Chat Layout Structure */
.chat-layout {
    display: flex !important;
    flex-direction: column !important;
    height: 100% !important;
    flex: 1 !important;
    overflow: hidden !important;
    /* Critical for inner scrolling */
}

/* Chat Messages Area - Takes available space */
/* Chat Messages Area */
.chat-messages {
    flex: 1 1 auto !important;
    /* Allow growing and shrinking */
    overflow-y: auto !important;
    overflow-x: hidden !important;
    min-height: 0 !important;
    /* Critical for Safari flex nesting */
    max-width: 56rem !important;
    margin: 0 auto !important;
    width: 100% !important;
    padding: 1.5rem !important;
    /* Standard padding, header handles the top gap */
    background: transparent !important;
    display: flex !important;
    flex-direction: column !important;
    gap: 1.5rem !important;
    -webkit-overflow-scrolling: touch !important;
    /* Smooth scroll */
}

/* User Query - Compact Pill */
.message.user {
    display: flex !important;
    justify-content: flex-start !important;
}

.message.user .bubble {
    display: inline-flex !important;
    align-items: center !important;
    gap: 0.75rem !important;
    padding: 0.75rem 1.25rem !important;
    background: linear-gradient(to right, #eff6ff 0%, #e0e7ff 100%) !important;
    border: 1px solid #dbeafe !important;
    border-radius: 1rem !important;
    color: #111827 !important;
    font-size: 0.9375rem !important;
    font-weight: 500 !important;
    line-height: 1.5 !important;
    box-shadow: none !important;
    max-width: fit-content !important;
    width: auto !important;
}

.message.user .bubble::before {
    content: '';
    display: inline-block;
    width: 0.375rem;
    height: 0.375rem;
    background: #3b82f6;
    border-radius: 50%;
    flex-shrink: 0;
}

/* Assistant Response Card */
.message.assistant {
    display: block !important;
    width: 100% !important;
}

.message.assistant .bubble {
    max-width: 100% !important;
    width: 100% !important;
    background: white !important;
    border: 1px solid #e5e7eb !important;
    border-radius: 1rem !important;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06) !important;
    overflow: hidden !important;
    padding: 1.5rem 2rem !important;
    color: #1f2937 !important;
    font-size: 0.9375rem !important;
    line-height: 1.7 !important;
}

/* Headings in response */
.bubble h1,
.bubble h2,
.bubble h3 {
    font-weight: 600 !important;
    color: #111827 !important;
    margin-top: 1.5rem !important;
    margin-bottom: 0.75rem !important;
}

.bubble h1 {
    font-size: 1.125rem !important;
}

.bubble h2 {
    font-size: 1.0625rem !important;
}

.bubble h3 {
    font-size: 1rem !important;
}

/* Paragraphs */
.bubble p {
    margin: 0.75rem 0 !important;
}

/* Lists */
.bubble ul,
.bubble ol {
    margin: 1rem 0 !important;
    padding-left: 1.25rem !important;
    border-left: 2px solid #dbeafe !important;
    color: #374151 !important;
}

.bubble li {
    margin: 0.375rem 0 !important;
    line-height: 1.6 !important;
}

/* Code */
.bubble code {
    background: #f3f4f6 !important;
    padding: 0.125rem 0.375rem !important;
    border-radius: 0.25rem !important;
    font-family: 'Courier New', monospace !important;
    font-size: 0.875em !important;
    color: #1f2937 !important;
}

.bubble pre {
    background: #f9fafb !important;
    padding: 1rem !important;
    border-radius: 0.5rem !important;
    border: 1px solid #e5e7eb !important;
    overflow-x: auto !important;
    margin: 1rem 0 !important;
}

.bubble pre code {
    background: transparent !important;
    padding: 0 !important;
}

/* Tables */
.bubble .md-table {
    width: 100% !important;
    border-collapse: collapse !important;
    margin: 1rem 0 !important;
    font-size: 0.875rem !important;
}

.bubble .md-table th,
.bubble .md-table td {
    padding: 0.75rem !important;
    text-align: left !important;
    border: 1px solid #e5e7eb !important;
}

.bubble .md-table th {
    background: #f9fafb !important;
    font-weight: 600 !important;
}

/* Message Actions */
.message-actions {
    display: flex !important;
    align-items: center !important;
    gap: 0.5rem !important;
    margin-top: 1rem !important;
    padding-top: 1rem !important;
    border-top: 1px solid #f3f4f6 !important;
    opacity: 0 !important;
    transition: opacity 0.2s ease !important;
}

.bubble:hover .message-actions {
    opacity: 1 !important;
}

.action-btn {
    display: inline-flex !important;
    align-items: center !important;
    gap: 0.5rem !important;
    padding: 0.5rem 0.875rem !important;
    background: white !important;
    border: 1px solid #e5e7eb !important;
    border-radius: 0.5rem !important;
    font-size: 0.875rem !important;
    font-weight: 500 !important;
    color: #374151 !important;
    cursor: pointer !important;
    transition: all 0.2s ease !important;
}

.action-btn:hover {
    background: #f9fafb !important;
    border-color: #d1d5db !important;
}

.action-btn svg {
    width: 1rem !important;
    height: 1rem !important;
}

/* System Welcome */
.message.system-welcome .bubble {
    background: transparent !important;
    border: 1px dashed #d1d5db !important;
    color: #6b7280 !important;
    font-style: italic !important;
    text-align: center !important;
    padding: 1rem !important;
    max-width: 500px !important;
    margin: 0 auto !important;
    box-shadow: none !important;
}

/* Input Area - Compact and Fixed */
.chat-input-area {
    flex-shrink: 0 !important;
    border-top: 1px solid #e5e7eb !important;
    background: white !important;
    padding: 1rem 1.5rem !important;
    padding-bottom: max(1rem, env(safe-area-inset-bottom)) !important;
    /* Safe area for iPhone */
}

.input-wrapper {
    max-width: 56rem !important;
    margin: 0 auto !important;
    position: relative !important;
}

.input-wrapper textarea {
    width: 100% !important;
    background: #f9fafb !important;
    border: 1px solid #e5e7eb !important;
    border-radius: 0.75rem !important;
    font-size: 0.9375rem !important;
    padding: 0.75rem 3rem 0.75rem 1rem !important;
    resize: none !important;
    max-height: 120px !important;
    min-height: 48px !important;
    line-height: 1.5 !important;
}

.input-wrapper textarea:focus {
    border-color: #3b82f6 !important;
    background: white !important;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1) !important;
    outline: none !important;
}

.btn-send {
    position: absolute !important;
    right: 0.5rem !important;
    top: 50% !important;
    transform: translateY(-50%) !important;
    background: #3b82f6 !important;
    width: 2rem !important;
    height: 2rem !important;
}

.btn-send:hover {
    background: #2563eb !important;
    transform: translateY(-50%) scale(1.05) !important;
}

/* Responsive */
@media (max-width: 768px) {
    .landing-content h1 {
        font-size: 3rem !important;
    }

    .action-cards {
        grid-template-columns: 1fr !important;
    }

    .chat-messages {
        padding: 1.5rem 1rem !important;
    }

    .message.assistant .bubble {
        padding: 1.25rem 1.5rem !important;
    }
}

@media (max-width: 640px) {

    /* Mobile Enhancements */
    .app-header {
        display: none !important;
    }

    .landing-content {
        padding: 0 1rem !important;
    }

    .landing-content h1 {
        font-size: 2.5rem !important;
        margin-bottom: 0.5rem !important;
    }

    .landing-content .subtitle {
        font-size: 1rem !important;
        margin-bottom: 2rem !important;
    }

    .action-cards {
        gap: 0.75rem !important;
    }

    .action-card {
        padding: 1.5rem !important;
    }

    .card-title {
        font-size: 1.125rem !important;
    }

    /* Mobile Header - Static Bar to prevent overlap */
    .chat-header-bar {
        display: flex !important;
        align-items: center !important;
        justify-content: space-between !important;
        height: 60px !important;
        background: white !important;
        border-bottom: 1px solid #e5e7eb !important;
        padding: 0 1rem !important;
        flex-shrink: 0 !important;
        width: 100% !important;
        z-index: 50 !important;
    }

    .chat-header-bar .btn-back {
        display: flex !important;
        /* Ensure visibility */
        font-size: 1rem !important;
        color: #4b5563 !important;
        padding: 0.5rem !important;
    }

    .floating-back-btn {
        display: none !important;
        /* Hide floating button on mobile */
    }

    /* Chat Area */
    .chat-messages {
        padding: 1rem !important;
        /* Reset extra padding since we have a header */
    }

    .message.user .bubble {
        max-width: 90% !important;
        font-size: 0.9rem !important;
    }

    .message.assistant .bubble {
        padding: 1rem 1.25rem !important;
        font-size: 0.95rem !important;
        border-width: 1px !important;
    }

    /* Input Area */
    .chat-input-area {
        padding: 0.75rem 1rem !important;
    }

    .input-wrapper textarea {
        padding: 0.75rem 2.5rem 0.75rem 0.75rem !important;
        font-size: 16px !important;
        /* Prevent iOS zoom */
        min-height: 44px !important;
    }

    .btn-send {
        width: 1.75rem !important;
        height: 1.75rem !important;
        right: 0.5rem !important;
    }

    /* Modal */
    .modal-card {
        margin: 1rem !important;
        padding: 1.5rem !important;
        max-height: 90vh !important;
        overflow-y: auto !important;
    }
}