/* ============================================
   MOBILE LAYOUT — AskTheFounders
   "One page, two layouts"
   
   This file contains ALL mobile-specific styles.
   Desktop styles live in styles.css (no mobile overrides there).
   Breakpoints:
     768px  = tablet / large phone
     480px  = phone
     380px  = small phone
   ============================================ */

/* ============================================
   1. TABLET & LARGE PHONE (≤ 768px)
   ============================================ */

@media (max-width: 768px) {

    /* --- Sidebar --- */
    .sidebar {
        width: 280px;
    }

    .sidebar-toggle {
        padding: 0 4px;
        height: 38px;
    }

    .sidebar-toggle svg {
        width: 14px;
        height: 14px;
    }

    .sidebar-toggle-label {
        display: none;
    }

    /* --- Spacing Overrides --- */
    :root {
        --space-xl: 1.5rem;
        --space-2xl: 1.5rem;
        --space-3xl: 2rem;
    }

    /* --- Container iOS fix --- */
    .container {
        padding: 3.5rem 0 5rem;
        padding-bottom: calc(5rem + env(safe-area-inset-bottom, 0px));
    }

    .container.chatting {
        padding-top: 0 !important;
    }

    /* --- Hero: vertically center between pills and input --- */
    .centered-content {
        margin-top: auto;
        margin-bottom: auto;
        transform: none;
        padding-top: 0;
    }

    /* --- Chatting Mode: sticky header that blends with page background --- */
    .container.chatting .centered-content {
        position: sticky !important;
        top: 0 !important;
        z-index: 40 !important;
        margin-top: 0;
        margin-bottom: 0;
        transform: none;
        padding: max(2.5rem, calc(env(safe-area-inset-top) + 1.75rem)) var(--space-md) 0.75rem;
        background: rgba(13, 17, 26, 0.92) !important;
        backdrop-filter: blur(24px) !important;
        -webkit-backdrop-filter: blur(24px) !important;
        box-shadow: none !important;
        width: 100% !important;
        flex-direction: column-reverse !important; /* Seal on top, text below */
        gap: 0.4rem !important;
    }

    /* Soft gradient fade at bottom edge of header */
    .container.chatting .centered-content::after {
        content: '' !important;
        position: absolute !important;
        left: 0 !important;
        right: 0 !important;
        bottom: -30px !important;
        height: 30px !important;
        background: linear-gradient(to bottom, rgba(13, 17, 26, 0.92), transparent) !important;
        pointer-events: none !important;
        z-index: -1 !important;
    }

    /* --- Logo: responsive sizing so it never overlaps buttons --- */
    .title-logo {
        max-width: clamp(140px, 28vw, 220px) !important;
    }
    .container.chatting .title-logo {
        max-width: clamp(90px, 22vw, 140px) !important;
    }

    /* --- Hide avatar in chat mode — keep only text logo --- */
    .container.chatting .avatar-container {
        display: none !important;
    }

    .title-text {
        font-size: 2rem;
    }

    .container.chatting .title-text {
        font-size: 1.2rem;
    }

    .avatar-container {
        margin-bottom: var(--space-md);
    }

    .container.chatting .avatar-container {
        margin-bottom: var(--space-xs);
    }

    .container.chatting .avatar {
        width: 50px;
        height: 50px;
    }

    /* --- Messages: enough top padding to clear sticky header --- */
    .messages {
        padding: 140px var(--space-md) 160px var(--space-md);
        mask-image: linear-gradient(to bottom,
                transparent 0px,
                black 20px,
                black calc(100% - 100px),
                transparent 100%);
        -webkit-mask-image: linear-gradient(to bottom,
                transparent 0px,
                black 20px,
                black calc(100% - 80px),
                transparent 100%);
    }

    .message {
        max-width: 92%;
        padding: var(--space-sm) var(--space-md);
        font-size: calc(0.77rem * var(--zoom-scale));
    }

    /* --- Input Area: sits cleanly above AI disclaimer --- */
    .input-area {
        bottom: 3.5rem !important;
        bottom: calc(3.5rem + env(safe-area-inset-bottom, 0px)) !important;
        width: calc(100% - var(--space-md) * 2);
        z-index: 60 !important;
    }

    /* --- File Preview Chips: Sit above the mobile input area --- */
    .file-preview-container {
        bottom: calc(3.5rem + 65px + env(safe-area-inset-bottom, 0px)) !important;
        width: calc(100% - var(--space-md) * 2);
        max-width: 100%;
        padding: 4px 0 0;
    }

    .input-pill {
        padding: 0.75rem 1rem !important;
        border-radius: 24px !important;
        background: rgba(18, 24, 38, 0.98) !important;
        box-shadow: 0 2px 20px rgba(0, 0, 0, 0.6) !important;
    }

    .message-input {
        font-size: 16px !important;
        min-height: 24px !important;
    }

    .message-input::placeholder {
        color: rgba(160, 170, 195, 0.9) !important;
    }

    .send-button {
        width: 34px;
        height: 34px;
    }

    /* --- Search Toggle --- */
    .search-toggle {
        opacity: 1 !important;
        width: 38px;
        height: 38px;
        background: rgba(255, 255, 255, 0.06);
        border-radius: 50%;
    }

    .search-toggle svg {
        width: 20px;
        height: 20px;
    }

    /* --- AI Disclaimer: shrink on mobile to not cover input --- */
    .ai-disclaimer {
        z-index: 40 !important;
        padding: 0.3rem 0.75rem !important;
        padding-bottom: calc(0.3rem + env(safe-area-inset-bottom, 0px)) !important;
    }

    /* --- Typing Indicator: Shrink for mobile --- */
    .typing-indicator {
        bottom: calc(var(--space-md) + 70px);
        padding: 8px 14px !important;
    }
    .thinking-label {
        font-size: 11px !important;
    }
    .thinking-dots span {
        width: 6px !important;
        height: 6px !important;
    }

    /* --- Zoom Controls: Move above input, let desktop styles handle shape --- */
    .zoom-controls {
        display: flex !important;
        bottom: 9rem !important; /* High above input area */
        right: var(--space-md) !important;
        z-index: 70 !important;
    }

    /* --- User Greeting --- */
    .user-greeting {
        top: 0.65rem;
        right: 0.75rem;
        padding: 0.35rem 0.65rem;
        gap: 0.4rem;
    }

    .user-greeting-text {
        font-size: 0.72rem;
    }

    .sign-out-btn {
        width: 24px;
        height: 24px;
    }

    .sign-out-btn svg {
        width: 13px;
        height: 13px;
    }

    /* --- Top Left Actions (Feedback + Share Chat) --- */
    .top-left-actions {
        top: 0.65rem;
        left: 0.75rem;
        flex-direction: row !important;
        gap: 0.35rem;
    }

    .feedback-btn {
        padding: 0.35rem 0.65rem;
        font-size: 0.72rem;
        gap: 0.35rem;
    }

    .feedback-btn svg {
        width: 12px;
        height: 12px;
    }

    .share-chat-btn {
        padding: 0.35rem 0.65rem;
        font-size: 0.72rem;
        gap: 0.35rem;
    }

    .share-chat-btn svg {
        width: 12px;
        height: 12px;
    }

    /* --- Message Action Buttons --- */
    .msg-actions {
        gap: 1px;
        margin-top: 0.4rem;
        padding-top: 0.35rem;
    }

    .msg-action-btn {
        padding: 3px 7px;
        font-size: 0.65rem;
        gap: 3px;
    }

    .msg-action-icon svg {
        width: 12px;
        height: 12px;
    }

    /* --- Intro Text --- */
    .intro-text {
        font-size: 0.88rem;
        padding: 0 var(--space-md);
    }

    /* --- AI Disclaimer --- */
    .ai-disclaimer {
        padding: 0.45rem 0.75rem;
        padding-bottom: calc(0.45rem + env(safe-area-inset-bottom, 0px));
    }

    .ai-disclaimer-text {
        font-size: 0.62rem;
    }
}


/* ============================================
   2. PHONE (≤ 480px)
   ============================================ */

@media (max-width: 480px) {

    /* --- Container --- */
    .container {
        padding: 3rem 0 4.5rem;
        padding-bottom: calc(4.5rem + env(safe-area-inset-bottom, 0px));
    }

    .container.chatting {
        padding-top: 0 !important;
    }

    /* --- Chatting Mode: sticky header that blends with page background --- */
    .container.chatting .centered-content {
        position: sticky !important;
        top: 0 !important;
        z-index: 40 !important;
        margin-top: 0;
        margin-bottom: 0;
        transform: none;
        padding: max(2.5rem, calc(env(safe-area-inset-top) + 1.75rem)) var(--space-sm) 0.75rem;
        background: rgba(13, 17, 26, 0.92) !important;
        backdrop-filter: blur(24px) !important;
        -webkit-backdrop-filter: blur(24px) !important;
        box-shadow: none !important;
        width: 100% !important;
        flex-direction: column-reverse !important; /* Seal on top, text below */
        gap: 0.35rem !important;
    }

    /* Soft gradient fade at bottom edge of header */
    .container.chatting .centered-content::after {
        content: '' !important;
        position: absolute !important;
        left: 0 !important;
        right: 0 !important;
        bottom: -30px !important;
        height: 30px !important;
        background: linear-gradient(to bottom, rgba(13, 17, 26, 0.92), transparent) !important;
        pointer-events: none !important;
        z-index: -1 !important;
    }

    /* --- Logo: responsive sizing for phones --- */
    .title-logo {
        max-width: clamp(120px, 35vw, 180px) !important;
    }
    .container.chatting .title-logo {
        max-width: clamp(80px, 22vw, 120px) !important;
    }

    /* --- Hide avatar in chat mode — keep only text logo --- */
    .container.chatting .avatar-container {
        display: none !important;
    }

    .title-text {
        font-size: 1.8rem;
    }

    .container.chatting .title-text {
        font-size: 1.1rem;
    }

    .container.chatting .header {
        margin-bottom: var(--space-xs);
    }

    /* --- Messages: enough top padding to clear sticky header --- */
    .messages {
        padding: 120px var(--space-sm) 150px var(--space-sm);
        mask-image: linear-gradient(to bottom,
                transparent 0px,
                black 20px,
                black calc(100% - 90px),
                transparent 100%);
        -webkit-mask-image: linear-gradient(to bottom,
                transparent 0px,
                black 20px,
                black calc(100% - 70px),
                transparent 100%);
    }

    .message {
        max-width: 95%;
        padding: var(--space-sm) var(--space-md);
        font-size: calc(0.72rem * var(--zoom-scale));
        border-radius: 14px;
    }

    /* --- Input --- */
    .input-area {
        bottom: 3.2rem !important;
        bottom: calc(3.2rem + env(safe-area-inset-bottom, 0px)) !important;
        width: calc(100% - var(--space-sm) * 2);
    }

    /* --- File Preview Chips: Sit above the mobile input area --- */
    .file-preview-container {
        bottom: calc(3.2rem + 65px + env(safe-area-inset-bottom, 0px)) !important;
        width: calc(100% - var(--space-sm) * 2);
        max-width: 100%;
        padding: 4px 0 0;
    }

    .input-pill {
        padding: 0.65rem 0.85rem !important;
        border-radius: 22px !important;
    }

    .message-input {
        font-size: 16px !important;
        /* Must be ≥16px to prevent iOS auto-zoom on focus */
        min-height: 22px !important;
    }

    .send-button {
        width: 30px;
        height: 30px;
    }

    .send-button svg {
        width: 16px;
        height: 16px;
    }

    /* --- Typing Indicator: Shrink for mobile --- */
    .typing-indicator {
        bottom: calc(var(--space-sm) + 60px);
        padding: 6px 12px !important;
    }
    .thinking-label {
        font-size: 10px !important;
    }
    .thinking-dots span {
        width: 5px !important;
        height: 5px !important;
    }

    /* --- User Greeting --- */
    .user-greeting {
        top: 0.5rem;
        right: 0.5rem;
        padding: 0.3rem 0.55rem;
        gap: 0.3rem;
        max-width: 55%;
    }

    .user-greeting-text {
        font-size: 0.65rem;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .user-name {
        max-width: 10ch;
        display: inline-block;
        overflow: hidden;
        text-overflow: ellipsis;
        vertical-align: bottom;
    }

    .sign-out-btn {
        width: 22px;
        height: 22px;
    }

    .sign-out-btn svg {
        width: 12px;
        height: 12px;
    }

    /* --- Top Left Actions --- */
    .top-left-actions {
        top: 0.5rem;
        left: 0.5rem;
        flex-direction: row !important;
        gap: 0.3rem;
    }

    .feedback-btn {
        padding: 0.3rem 0.55rem;
        font-size: 0.65rem;
        gap: 0.3rem;
    }

    .feedback-btn svg {
        width: 11px;
        height: 11px;
    }

    .share-chat-btn {
        padding: 0.3rem 0.55rem;
        font-size: 0.65rem;
        gap: 0.3rem;
    }

    .share-chat-btn svg {
        width: 11px;
        height: 11px;
    }

    /* --- Message Action Buttons: icon-only --- */
    .msg-action-btn {
        padding: 3px 5px;
        font-size: 0.6rem;
        gap: 2px;
    }

    .msg-action-label {
        display: none;
    }

    .msg-action-icon svg {
        width: 14px;
        height: 14px;
    }

    /* --- Share Chat Menu: bottom sheet --- */
    .share-chat-menu {
        max-width: 100%;
        border-radius: 18px 18px 0 0;
    }

    .share-chat-menu-header {
        padding: 1rem 1rem 0.5rem;
    }

    .share-chat-menu-header h3 {
        font-size: 0.95rem;
    }

    .share-chat-menu-body {
        padding: 0.4rem 0.5rem 0.75rem;
    }

    .share-chat-option {
        padding: 0.7rem 0.6rem;
        gap: 0.65rem;
    }

    .share-chat-option-icon {
        width: 34px;
        height: 34px;
        border-radius: 10px;
    }

    .share-chat-option-title {
        font-size: 0.82rem;
    }

    .share-chat-option-desc {
        font-size: 0.7rem;
    }

    /* --- Quote Popup --- */
    .quote-popup-content {
        max-width: calc(100% - 1.5rem);
        padding: 1rem;
    }

    .quote-popup-text {
        font-size: 0.82rem;
        padding: 0.6rem 0.75rem;
        max-height: 150px;
    }

    .quote-popup-btn {
        padding: 0.5rem 0.6rem;
        font-size: 0.75rem;
        border-radius: 10px;
        gap: 0.3rem;
    }

    /* --- Intro Text --- */
    .intro-text {
        font-size: 0.85rem;
        padding: 0 var(--space-md);
    }

    /* --- AI Disclaimer --- */
    .ai-disclaimer {
        padding: 0.4rem 0.5rem;
        padding-bottom: calc(0.4rem + env(safe-area-inset-bottom, 0px));
    }

    .ai-disclaimer-text {
        font-size: 0.58rem;
    }

    .ai-disclaimer-icon {
        width: 12px;
        height: 12px;
    }

    /* --- Feedback Modal --- */
    .feedback-modal {
        padding: 24px;
        border-radius: 16px;
        max-width: calc(100% - 16px);
    }

    .feedback-modal-title {
        font-size: var(--font-size-lg);
    }

    .feedback-field input,
    .feedback-field textarea {
        padding: 10px 14px;
        font-size: 16px;
        /* Prevent iOS auto-zoom */
        -webkit-appearance: none;
        appearance: none;
        border-radius: 8px;
    }

    .feedback-submit-btn {
        padding: 12px 20px;
        touch-action: manipulation;
    }
}


/* ============================================
   3. SMALL PHONE (≤ 380px)
   ============================================ */

@media (max-width: 380px) {

    .user-greeting {
        padding: 0.25rem 0.45rem;
        gap: 0.25rem;
    }

    .user-greeting-text {
        font-size: 0.6rem;
    }

    .user-name {
        max-width: 7ch;
    }

    .sign-out-btn {
        width: 20px;
        height: 20px;
    }

    .top-left-actions {
        flex-direction: row !important;
        gap: 0.2rem;
    }

    .feedback-btn {
        padding: 0.25rem 0.45rem;
        font-size: 0.6rem;
    }

    .share-chat-btn {
        padding: 0.25rem 0.45rem;
        font-size: 0.6rem;
    }
}