/*
 * RaASaAD Mobile Results Overhaul 2026
 *
 * Mobile is treated as a first-class product surface rather than a scaled
 * desktop layout. The existing desktop components remain untouched; this
 * layer owns viewport rhythm, touch targets, card hierarchy, chat docking,
 * safe-area handling and horizontal-overflow prevention below 760px.
 */

@media (max-width: 760px) {
    :root {
        --ra-mobile-gutter: 12px;
        --ra-mobile-radius: 18px;
        --ra-mobile-dock: 70px;
    }

    html,
    body {
        width: 100%;
        max-width: 100%;
        min-width: 320px;
        overflow-x: hidden !important;
        -webkit-text-size-adjust: 100%;
    }

    body {
        padding-bottom: calc(var(--ra-mobile-dock) + env(safe-area-inset-bottom));
    }

    .ra-app,
    .ra-main,
    .ra-container,
    .ra-layout,
    .ra-results-column,
    .result-list,
    .results-list,
    .ai-center,
    .ai-card,
    .ra-ai,
    .search-ai {
        min-width: 0;
        max-width: 100%;
    }

    .ra-container {
        width: 100%;
        padding-inline: var(--ra-mobile-gutter);
    }

    /* Header becomes two intentional rows: brand/actions, then search. */
    .ra-header {
        position: sticky;
        top: 0;
        z-index: 100;
    }

    .ra-header-inner {
        min-height: 0;
        display: grid;
        grid-template-columns: minmax(0, 1fr) auto;
        grid-template-areas:
            "brand actions"
            "search search";
        gap: 10px;
        padding: 10px 0 11px;
    }

    .ra-brand {
        grid-area: brand;
        min-width: 0;
    }

    .ra-brand-mark {
        width: 35px;
        height: 35px;
        border-radius: 11px;
    }

    .ra-brand-mark:before,
    .ra-brand-mark:after {
        width: 5px;
        height: 19px;
        left: 15px;
        top: 8px;
    }

    .ra-brand-mark span {
        width: 6px;
        height: 6px;
        left: 15px;
        top: 15px;
    }

    .ra-brand-name {
        font-size: 16px;
        letter-spacing: -.5px;
    }

    .ra-brand-sub {
        font-size: 8px;
        margin-top: 3px;
    }

    .ra-header-actions {
        grid-area: actions;
        align-self: center;
        gap: 6px;
    }

    .ra-chat-trigger,
    .ra-theme-trigger {
        width: 40px;
        height: 40px;
        min-width: 40px;
        padding: 0;
        border-radius: 12px;
    }

    .ra-chat-trigger b {
        display: none;
    }

    .ra-search {
        grid-area: search;
        width: 100%;
        max-width: none;
    }

    .ra-search-box {
        height: 48px;
        border-radius: 15px;
        padding: 3px 4px 3px 10px;
    }

    .ra-search-leading {
        width: 23px;
        font-size: 21px;
    }

    .ra-search-input {
        font-size: 13px;
        padding: 7px 4px;
    }

    .ra-tool-ghost {
        width: 36px;
        height: 36px;
        flex: 0 0 36px;
    }

    .ra-search-action {
        width: 38px;
        height: 38px;
        flex: 0 0 38px;
        border-radius: 11px;
    }

    /* Desktop category strip is replaced by the thumb-friendly dock. */
    .ra-nav {
        display: none;
    }

    .ra-main {
        padding: 14px 0 30px;
    }

    .ra-layout {
        display: block;
    }

    .ra-sidebar,
    .results-sidebar,
    .sidebar {
        display: none !important;
    }

    /* Search status */
    .search-status {
        display: grid;
        grid-template-columns: minmax(0, 1fr) auto;
        gap: 8px;
        align-items: center;
        margin: 0 1px 10px;
        font-size: 10px;
    }

    .status-text {
        min-width: 0;
        overflow-wrap: anywhere;
        line-height: 1.8;
    }

    .status-badge {
        padding: 4px 7px;
        font-size: 9px;
    }

    .suggestion-box {
        display: block;
        margin-bottom: 10px;
        padding: 10px 12px;
        border-radius: 14px;
        line-height: 1.9;
    }

    .suggestion-button {
        display: block;
        width: 100%;
        min-height: 36px;
        margin-top: 3px;
        padding: 5px 0;
        text-align: right;
        overflow-wrap: anywhere;
    }

    /* AI center: compact, readable, and no desktop-style giant padding. */
    .ai-center,
    .ai-card,
    .ra-ai,
    .search-ai {
        margin-bottom: 12px;
        padding: 16px;
        border-radius: var(--ra-mobile-radius);
    }

    .ai-center h1,
    .ai-center h2,
    .ai-card h2,
    .ra-ai h2 {
        font-size: 16px;
        line-height: 1.65;
        text-wrap: balance;
    }

    .ai-center p,
    .ai-card p {
        font-size: 11px;
        line-height: 1.9;
    }

    .conversation-flow {
        margin-top: 14px;
        gap: 9px;
    }

    .conversation-line {
        display: grid;
        grid-template-columns: 28px minmax(0, 1fr);
        gap: 8px;
        align-items: start;
    }

    .conversation-avatar {
        width: 28px;
        height: 28px;
        flex: 0 0 28px;
        display: grid;
        place-items: center;
        border-radius: 9px;
    }

    .conversation-message {
        min-width: 0;
        max-width: 100%;
        font-size: 11px;
        line-height: 1.9;
        overflow-wrap: anywhere;
        word-break: normal;
        unicode-bidi: plaintext;
    }

    .intent-chips,
    .ai-actions,
    .suggestions {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 7px;
        margin-top: 12px;
    }

    .intent-chip,
    .chat-suggestion,
    .suggestion-chip {
        min-height: 42px;
        padding: 8px 9px;
        border-radius: 12px;
        font-size: 10px;
        line-height: 1.65;
        text-align: center;
    }

    /* Result cards become compact editorial cards. */
    .result-list,
    .results-list {
        gap: 9px;
    }

    .result-card {
        width: 100%;
        min-width: 0;
        padding: 14px;
        border-radius: 16px;
        box-shadow: 0 4px 18px rgba(20, 40, 60, .045);
    }

    .result-card:hover {
        transform: none;
    }

    .result-content,
    .result-body {
        min-width: 0;
        width: 100%;
    }

    .result-domain-row {
        min-height: 20px;
        margin-bottom: 4px;
        gap: 6px;
    }

    .domain-favicon {
        width: 17px;
        height: 17px;
    }

    .result-domain,
    .result-url,
    .domain {
        min-width: 0;
        max-width: 62%;
        font-size: 9.5px;
    }

    .result-match {
        max-width: 38%;
        padding: 2px 6px;
        font-size: 8px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .result-title {
        margin-bottom: 5px;
        font-size: 15px;
        line-height: 1.65;
        overflow-wrap: anywhere;
        word-break: normal;
    }

    .result-description,
    .result-snippet,
    .snippet {
        margin-top: 4px;
        font-size: 11px;
        line-height: 1.95;
        -webkit-line-clamp: 4;
    }

    .result-image-wrap {
        float: none;
        width: 100%;
        height: auto;
        aspect-ratio: 16 / 9;
        margin: 0 0 11px;
        border-radius: 13px;
    }

    .result-image {
        object-fit: cover;
    }

    .result-actions {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 7px;
        margin-top: 11px;
    }

    .result-action,
    [data-result-action] {
        min-height: 40px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        padding: 7px 8px;
        border-radius: 11px;
        font-size: 10px;
        line-height: 1.5;
        text-align: center;
        white-space: normal;
    }

    /* Image search becomes a clean 2-column gallery. */
    .ra-image-discovery {
        padding: 13px;
        border-radius: 17px;
    }

    .ra-image-discovery-head {
        display: grid;
        grid-template-columns: minmax(0, 1fr) auto;
        gap: 8px;
        margin-bottom: 11px;
    }

    .ra-image-discovery h2 {
        font-size: 14px;
        line-height: 1.7;
    }

    .ra-image-discovery p {
        font-size: 9px;
        line-height: 1.8;
    }

    .ra-image-count {
        align-self: start;
        font-size: 8px;
        padding: 4px 7px;
    }

    .ra-image-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 8px;
    }

    .ra-image-card {
        border-radius: 12px;
    }

    .ra-image-media {
        aspect-ratio: 1 / 1;
    }

    .ra-image-card-body {
        padding: 8px;
    }

    .ra-image-source {
        font-size: 7.5px;
    }

    .ra-image-card h3 {
        font-size: 10px;
        line-height: 1.6;
    }

    .ra-image-card p {
        display: none;
    }

    .ra-image-actions {
        display: grid;
        gap: 3px;
        margin-top: 6px;
    }

    .ra-image-actions a {
        min-height: 30px;
        display: flex;
        align-items: center;
        justify-content: center;
        border-radius: 8px;
        background: var(--ra-primary-soft);
        font-size: 8px;
    }

    /* Empty/error states */
    .empty-state,
    .ra-image-empty {
        padding: 32px 16px;
        border-radius: 16px;
    }

    .empty-title,
    .ra-image-empty-title {
        font-size: 14px;
    }

    .empty-text,
    .ra-image-empty-text {
        font-size: 10px;
        line-height: 1.9;
    }

    /* Chat becomes a true mobile sheet, not a squeezed desktop popup. */
    .chat-panel {
        position: fixed !important;
        left: 8px !important;
        right: 8px !important;
        bottom: calc(8px + env(safe-area-inset-bottom)) !important;
        width: auto !important;
        max-width: none !important;
        height: min(78dvh, 680px);
        max-height: calc(100dvh - 16px - env(safe-area-inset-bottom));
        border-radius: 22px !important;
        overflow: hidden;
        display: flex;
        flex-direction: column;
        z-index: 300;
        box-shadow: 0 24px 70px rgba(0, 0, 0, .28);
    }

    .chat-header {
        min-height: 58px;
        padding: 10px 12px;
        flex: 0 0 auto;
    }

    .chat-title {
        min-width: 0;
        display: flex;
        align-items: center;
        gap: 8px;
    }

    .chat-name {
        font-size: 11px;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .chat-state {
        max-width: 100%;
        font-size: 8px;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .chat-orb {
        width: 31px;
        height: 31px;
        flex: 0 0 31px;
    }

    .chat-close {
        width: 38px;
        height: 38px;
        min-width: 38px;
        flex: 0 0 38px;
        border-radius: 11px;
    }

    .chat-messages {
        min-height: 0;
        max-height: none;
        flex: 1 1 auto;
        padding: 12px;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        overscroll-behavior: contain;
    }

    .chat-message {
        max-width: 92%;
        margin-bottom: 8px;
        padding: 9px 10px;
        border-radius: 13px;
        font-size: 10px;
        line-height: 1.9;
    }

    .chat-message-title {
        font-size: 10px;
        line-height: 1.7;
    }

    .chat-suggestions {
        display: grid;
        gap: 6px;
        margin-top: 8px;
    }

    .chat-suggestion {
        width: 100%;
        min-height: 38px;
        font-size: 9px;
        text-align: right;
    }

    .chat-search-context {
        flex: 0 0 auto;
        margin: 0 8px 7px;
        padding: 8px 9px;
        border-radius: 11px;
    }

    .chat-context-content strong {
        font-size: 9px;
    }

    .chat-input-area {
        flex: 0 0 auto;
        padding: 8px;
        padding-bottom: calc(8px + env(safe-area-inset-bottom));
    }

    .chat-input-row {
        gap: 6px;
    }

    .chat-input {
        min-height: 43px;
        max-height: 100px;
        padding: 9px 10px;
        font-size: 11px;
        line-height: 1.8;
        border-radius: 12px;
    }

    .chat-send {
        width: 43px;
        height: 43px;
        flex: 0 0 43px;
        border-radius: 12px;
    }

    .chat-input-hint {
        font-size: 7.5px;
        line-height: 1.7;
    }

    /* Bottom navigation: persistent, thumb-reachable and visually separate. */
    .ra-mobile-dock {
        position: fixed;
        left: 8px;
        right: 8px;
        bottom: calc(7px + env(safe-area-inset-bottom));
        z-index: 200;
        height: var(--ra-mobile-dock);
        padding: 7px;
        display: grid;
        grid-template-columns: repeat(4, minmax(0, 1fr));
        gap: 4px;
        border: 1px solid var(--ra-border);
        border-radius: 20px;
        background: color-mix(in srgb, var(--ra-surface) 92%, transparent);
        backdrop-filter: blur(22px);
        -webkit-backdrop-filter: blur(22px);
        box-shadow: 0 15px 45px rgba(20, 35, 55, .16);
    }

    .ra-mobile-dock-item {
        min-width: 0;
        min-height: 54px;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 2px;
        border: 0;
        border-radius: 14px;
        color: var(--ra-muted);
        background: transparent;
        font-size: 8px;
        font-weight: 750;
        line-height: 1.35;
    }

    .ra-mobile-dock-item span:first-child {
        font-size: 17px;
        line-height: 1;
    }

    .ra-mobile-dock-item.active {
        color: var(--ra-primary);
        background: var(--ra-primary-soft);
    }

    .ra-mobile-dock-item.ai {
        color: var(--ra-purple);
    }

    .ra-mobile-dock-item.ai.active {
        background: var(--ra-purple-soft);
    }
}

@media (max-width: 390px) {
    :root {
        --ra-mobile-gutter: 10px;
    }

    .ra-brand-sub {
        display: none;
    }

    .result-actions {
        grid-template-columns: 1fr 1fr;
    }

    .result-action,
    [data-result-action] {
        min-height: 38px;
        font-size: 9.5px;
    }

    .ra-mobile-dock {
        left: 6px;
        right: 6px;
        border-radius: 18px;
    }
}

@media (prefers-reduced-motion: reduce) {
    .ra-mobile-dock,
    .result-card,
    .intent-chip,
    .result-action {
        transition: none !important;
    }
}
