/*
 * Mobile layout for Satbayev AI chat.
 * Loaded only on /llm/ — safe to override .rms-* classes.
 */

/* Hidden until media query */
.su-chat-drawer-open,
.su-chat-drawer-close,
.su-chat-backdrop {
    display: none;
}

/* ============================================================
   PAGE SCROLL LOCK
   (This file is only loaded on /llm/ — safe to override rms-*)
   ============================================================ */
@media (max-width: 960.98px) {

    /* No page-level scroll — chat scrolls internally */
    html,
    body.rms-page {
        overflow: hidden !important;
        height: 100% !important;
    }

    /* Remove content padding and footer */
    .rms-content {
        padding: 0 !important;
        margin: 0 !important;
        overflow: visible !important;
        flex: none !important;
    }

    .rms-footer {
        display: none !important;
    }
}

/* ============================================================
   MOBILE LAYOUT  (≤ 960px)
   ============================================================ */
@media (max-width: 960.98px) {

    body.su-chat-drawer-is-open {
        overflow: hidden !important;
    }

    /*
     * Chat page: fixed below topbar (64px on mobile), fills to bottom.
     * position:fixed bypasses all parent-container height issues.
     */
    .su-chat-page {
        position: fixed !important;
        z-index: 10 !important;
        top: 64px !important;
        left: 0 !important;
        right: 0 !important;
        bottom: 0 !important;
        width: 100% !important;
        height: auto !important;
        min-height: 0 !important;
        overflow: hidden !important;
        background: #ffffff;
    }

    /* Main column fills the fixed chat page */
    .su-chat-main {
        display: flex !important;
        flex-direction: column !important;
        width: 100% !important;
        height: 100% !important;
        min-width: 0 !important;
        min-height: 0 !important;
        margin: 0 !important;
    }

    /* ── Header ── */
    .su-chat-header {
        flex: 0 0 auto !important;
        padding: 10px 12px 8px !important;
        border-bottom: 1px solid #e2e8f0;
        background: #ffffff;
    }

    /* Single horizontal row: [☰] [title] [⚙] [↗] */
    .su-chat-header-top {
        display: flex !important;
        flex-direction: row !important;
        align-items: center !important;
        gap: 8px !important;
        width: 100% !important;
    }

    .su-chat-header-copy {
        flex: 1 1 auto !important;
        min-width: 0 !important;
        text-align: left !important;
        align-items: flex-start !important;
    }

    .su-chat-header-title {
        margin: 0 !important;
        font-size: 16px !important;
        font-weight: 700 !important;
        line-height: 1.25 !important;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .su-chat-header-subtitle {
        display: none !important;
    }

    .su-chat-share-status {
        margin: 4px 0 0 !important;
        font-size: 12px !important;
    }

    /* ── Drawer open button ── */
    .su-chat-drawer-open {
        display: inline-flex;
        flex-shrink: 0;
        align-items: center;
        justify-content: center;
        width: 40px;
        height: 40px;
        border: 1px solid #dbe4ef;
        border-radius: 12px;
        background: #ffffff;
        color: #132848;
        font-size: 22px;
        cursor: pointer;
        transition: background 0.15s, border-color 0.15s;
    }

    .su-chat-drawer-open:hover,
    .su-chat-drawer-open:active {
        background: #f1f5f9;
        border-color: #b6c8de;
    }

    /* ── Settings button — icon only ── */
    .su-chat-settings-button {
        flex-shrink: 0 !important;
        width: 40px !important;
        height: 40px !important;
        padding: 0 !important;
        border-radius: 12px !important;
        justify-content: center !important;
    }

    .su-chat-settings-button span {
        display: none !important;
    }

    /* ── Share button — icon only ── */
    .su-chat-share-button {
        flex-shrink: 0 !important;
        width: 40px !important;
        height: 40px !important;
        padding: 0 !important;
        display: inline-flex !important;
        justify-content: center !important;
        align-items: center !important;
        border-radius: 12px !important;
    }

    .su-chat-share-button span {
        display: none !important;
    }

    /* Reset: desktop @640px sets width:100% on .chat-share-btn */
    .su-chat-settings-button.chat-share-btn,
    .su-chat-share-button.chat-share-btn {
        width: 40px !important;
        justify-content: center !important;
    }

    /* ── Settings dropdown ── */
    .su-chat-settings-dropdown {
        position: fixed !important;
        top: auto !important;
        right: 10px !important;
        left: 10px !important;
        width: auto !important;
        min-width: 0 !important;
        z-index: 1070 !important;
        border-radius: 16px !important;
        box-shadow: 0 8px 32px rgba(15, 23, 42, 0.18) !important;
    }

    .su-chat-model-select {
        font-size: 15px !important;
        padding: 10px 12px !important;
        height: 44px;
    }

    /* ── Messages ── */
    .su-chat-messages {
        flex: 1 1 auto !important;
        min-height: 0 !important;
        width: 100% !important;
        overflow-y: auto !important;
        overscroll-behavior: contain;
        padding: 14px 12px 20px !important;
        background: #ffffff;
    }

    /* Bubbles nearly full width */
    .su-chat-messages .message-bubble {
        max-width: 92% !important;
    }

    /* Tables: horizontal scroll instead of crushing columns */
    .su-chat-messages .chat-md-table {
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch;
    }

    .su-chat-messages .chat-md-table table {
        min-width: 440px;
    }

    /* Follow-up buttons: horizontal scroll */
    .su-chat-messages .chat-followup-buttons {
        flex-wrap: nowrap !important;
        overflow-x: auto !important;
        overflow-y: hidden !important;
        -webkit-overflow-scrolling: touch;
        padding-bottom: 4px !important;
        gap: 8px !important;
        scrollbar-width: none;
    }

    .su-chat-messages .chat-followup-buttons::-webkit-scrollbar {
        display: none;
    }

    .su-chat-messages .chat-followup-btn {
        flex-shrink: 0 !important;
        font-size: 13px !important;
        padding: 7px 13px !important;
        white-space: nowrap !important;
    }

    /* ── Input area ── */
    .su-chat-input-wrap {
        flex: 0 0 auto !important;
        position: relative !important;
        bottom: auto !important;
        width: 100% !important;
        padding: 8px 10px calc(8px + env(safe-area-inset-bottom)) !important;
        background: #ffffff;
        border-top: 1px solid #e8eef6;
    }

    .su-chat-form {
        display: flex !important;
        align-items: flex-end !important;
        gap: 8px !important;
        width: 100% !important;
        grid-template-columns: unset !important;
    }

    .su-chat-textarea {
        flex: 1 1 auto !important;
        min-width: 0 !important;
        max-height: 130px !important;
        font-size: 16px !important;
        line-height: 1.45 !important;
    }

    .su-chat-form-actions {
        display: flex !important;
        align-items: center !important;
        gap: 6px !important;
        flex: 0 0 auto !important;
        grid-template-columns: unset !important;
        width: auto !important;
    }

    .su-chat-send-button,
    .su-chat-stop-button {
        width: auto !important;
        flex-shrink: 0 !important;
        min-width: 44px !important;
        min-height: 44px !important;
    }

    /* ============================================================
       HISTORY DRAWER
       ============================================================ */

    .su-chat-drawer {
        display: flex !important;
        flex-direction: column !important;
        position: fixed !important;
        z-index: 1061 !important;
        top: 0 !important;
        bottom: 0 !important;
        left: 0 !important;
        width: min(86vw, 340px) !important;
        height: 100dvh !important;
        padding-bottom: env(safe-area-inset-bottom) !important;
        margin: 0 !important;
        background: #ffffff !important;
        border: 0 !important;
        border-radius: 0 20px 20px 0 !important;
        box-shadow: 12px 0 32px rgba(15, 23, 42, 0.16) !important;
        transform: translateX(-104%) !important;
        visibility: hidden !important;
        transition:
            transform 0.22s ease,
            visibility 0s linear 0.22s !important;
    }

    body.su-chat-drawer-is-open .su-chat-drawer {
        transform: translateX(0) !important;
        visibility: visible !important;
        transition:
            transform 0.22s ease,
            visibility 0s linear 0s !important;
    }

    .su-chat-drawer-header {
        display: flex !important;
        align-items: center !important;
        justify-content: space-between !important;
        flex: 0 0 auto !important;
        padding: calc(16px + env(safe-area-inset-top)) 14px 14px !important;
        border-bottom: 1px solid #e2e8f0;
    }

    .su-chat-drawer-title {
        margin: 0 !important;
        font-size: 18px !important;
        font-weight: 700 !important;
        color: #0f172a !important;
    }

    .su-chat-drawer-actions {
        display: flex !important;
        align-items: center !important;
        gap: 6px !important;
    }

    .su-chat-drawer-close {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        width: 38px;
        height: 38px;
        border: 1px solid #dbe4ef;
        border-radius: 12px;
        background: #ffffff;
        color: #334155;
        cursor: pointer;
        transition: background 0.15s;
    }

    .su-chat-drawer-close:hover {
        background: #f1f5f9;
    }

    .su-chat-history {
        flex: 1 1 auto !important;
        min-height: 0 !important;
        overflow-y: auto !important;
        padding: 10px !important;
        overscroll-behavior: contain;
    }

    /* Backdrop */
    .su-chat-backdrop {
        display: block;
        position: fixed;
        z-index: 1060;
        inset: 0;
        border: 0;
        padding: 0;
        background: rgba(15, 23, 42, 0.38);
        opacity: 0;
        visibility: hidden;
        pointer-events: none;
        transition:
            opacity 0.22s ease,
            visibility 0s linear 0.22s;
    }

    body.su-chat-drawer-is-open .su-chat-backdrop {
        opacity: 1;
        visibility: visible;
        pointer-events: auto;
        transition:
            opacity 0.22s ease,
            visibility 0s linear 0s;
    }

    /* Share dialog */
    .su-chat-share-dialog {
        width: calc(100% - 24px) !important;
        max-width: 420px !important;
        padding: 18px !important;
        border-radius: 18px !important;
    }
}

/* ============================================================
   SMALL PHONES  (≤ 420px)
   ============================================================ */
@media (max-width: 420px) {
    .su-chat-header {
        padding-left: 8px !important;
        padding-right: 8px !important;
    }

    .su-chat-messages {
        padding-left: 8px !important;
        padding-right: 8px !important;
    }

    .su-chat-messages .message-bubble {
        max-width: 96% !important;
    }

    .su-chat-header-title {
        font-size: 15px !important;
    }
}

/* ============================================================
   REDUCED MOTION
   ============================================================ */
@media (prefers-reduced-motion: reduce) {
    .su-chat-drawer,
    .su-chat-backdrop,
    .su-chat-drawer-open {
        transition: none !important;
    }
}
