/* ── Mobile / compact layout overrides ── */

.mobile-experience-banner {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
    justify-content: space-between;
    gap: 0.5rem 0.75rem;
    margin: 0 0 0.75rem;
    padding: 0.65rem 0.85rem;
    border: 1px solid color-mix(in srgb, var(--accent-primary) 45%, var(--border-primary));
    background: color-mix(in srgb, var(--accent-primary) 8%, var(--background-primary));
    border-radius: 0.35rem;
    font-size: var(--font-size-controls);
    line-height: 1.45;
    color: var(--text-secondary);
}

.mobile-experience-banner[hidden] {
    display: none !important;
}

.mobile-experience-banner-text {
    margin: 0;
    flex: 1 1 14rem;
}

.mobile-experience-banner-text a {
    color: var(--accent-primary);
    font-weight: var(--font-weight-semibold);
}

.mobile-experience-banner-actions {
    display: flex;
    flex-shrink: 0;
    align-items: center;
    gap: 0.35rem;
}

.mobile-experience-banner-dismiss {
    border: 1px solid var(--border-primary);
    background: var(--background-secondary);
    color: var(--text-secondary);
    width: 2rem;
    height: 2rem;
    border-radius: 0.25rem;
    cursor: pointer;
    font-size: 1.25rem;
    line-height: 1;
    padding: 0;
}

.mobile-experience-banner-dismiss:hover {
    color: var(--text-primary);
}

/* ── Dashboard: footer — search + add bookmark on mobile ── */
body[data-mobile-layout="true"] #finders-button,
body[data-mobile-layout="true"] #commands-button,
body[data-mobile-layout="true"] #recent-bookmarks-button,
body[data-mobile-layout="true"] #help-button,
body[data-mobile-layout="true"] .btn-group-secondary {
    display: none !important;
}

body[data-mobile-layout="true"] #quick-add-toolbar-btn {
    display: flex !important;
    order: -1;
    flex: 1 1 auto;
    min-height: 44px;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

body[data-mobile-layout="true"] .button-container {
    justify-content: center;
    width: calc(100% - 2rem);
    flex-wrap: wrap;
    row-gap: 0.35rem;
}

body[data-mobile-layout="true"] .btn-group-primary {
    justify-content: center;
    width: 100%;
    gap: 0.5rem;
}

body[data-mobile-layout="true"] #search-button {
    flex: 1 1 auto;
    max-width: none;
    min-height: 44px;
}

/* Dashboard: single column on phone — ignore columnsPerRow / packed layout */
@media (max-width: 767px) {
    body[data-dashboard-stack-categories="true"] .dashboard-grid,
    .dashboard-grid.columns-2,
    .dashboard-grid.columns-3,
    .dashboard-grid.columns-4,
    .dashboard-grid.columns-5,
    .dashboard-grid.columns-6 {
        display: grid !important;
        grid-template-columns: 1fr !important;
    }

    body[data-dashboard-stack-categories="true"] .dashboard-grid.packed-columns,
    .dashboard-grid.packed-columns {
        display: flex !important;
        flex-direction: column !important;
        flex-wrap: nowrap !important;
    }

    body[data-dashboard-stack-categories="true"] .dashboard-grid.packed-columns .dashboard-column,
    .dashboard-grid.packed-columns .dashboard-column {
        flex: 1 1 100% !important;
        max-width: 100% !important;
        width: 100% !important;
    }
}

/* Search mode tabs visible on mobile (override search.css ≤479px hide) */
body[data-mobile-layout="true"] .search-mode-tabs {
    display: flex !important;
}

body[data-mobile-layout="true"] .search-mode-tab {
    min-height: 44px;
    flex: 1 1 0;
}

/* Header simplification */
body[data-mobile-layout="true"] .health-link,
body[data-mobile-layout="true"] #page-navigation,
body[data-mobile-layout="true"] #whats-new-btn,
body[data-mobile-layout="true"] #dashboard-tag-cloud-wrap,
body[data-mobile-layout="true"] #status-loading-indicator {
    display: none !important;
}

/* Header: Pages + config only — touch-friendly targets */
body[data-mobile-layout="true"] .header-actions {
    gap: 0.5rem;
    flex-shrink: 0;
}

body[data-mobile-layout="true"] #page-overview-header-btn {
    min-height: 44px;
    min-width: 44px;
    padding: 0.55rem 0.9rem;
    font-size: var(--font-size-controls);
    font-weight: var(--font-weight-semibold);
    text-transform: capitalize;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

body[data-mobile-layout="true"] .config-link a {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 44px;
    min-width: 44px;
    padding: 0.55rem 0.9rem;
    border: 1px solid color-mix(in srgb, var(--text-secondary) 35%, transparent);
    border-radius: 2px;
    text-transform: capitalize;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

body[data-mobile-layout="true"] .config-link a:active,
body[data-mobile-layout="true"] #page-overview-header-btn:active {
    background: color-mix(in srgb, var(--accent-primary) 10%, transparent);
    color: var(--text-primary);
    border-color: var(--text-primary);
}

/* Page overview sheet — large tap targets for each page link */
body[data-mobile-layout="true"] .page-overview-overlay--mobile {
    align-items: flex-end;
    justify-content: stretch;
    padding: 0;
}

body[data-mobile-layout="true"] .page-overview-overlay--mobile .page-overview-panel {
    width: 100%;
    min-width: 0;
    max-width: none;
    max-height: min(82dvh, 640px);
    border-radius: 1rem 1rem 0 0;
    border-left: none;
    border-right: none;
    border-bottom: none;
}

body[data-mobile-layout="true"] .page-overview-overlay--mobile .page-overview-header {
    padding: 0.85rem 1rem;
    min-height: 3.25rem;
}

body[data-mobile-layout="true"] .page-overview-overlay--mobile .page-overview-close {
    width: 44px;
    height: 44px;
}

body[data-mobile-layout="true"] .page-overview-overlay--mobile .page-overview-list {
    padding: 0.25rem 0 calc(env(safe-area-inset-bottom, 0px) + 0.5rem);
}

body[data-mobile-layout="true"] .page-overview-overlay--mobile .page-overview-item + .page-overview-item {
    border-top: 1px solid var(--border-primary);
}

body[data-mobile-layout="true"] .page-overview-overlay--mobile .page-overview-link {
    min-height: 52px;
    padding: 0.9rem 1.15rem;
    gap: 0.75rem;
    font-size: calc(var(--font-size-controls) * 1.05);
}

body[data-mobile-layout="true"] .page-overview-overlay--mobile .page-overview-num {
    font-size: 0.95em;
}

body[data-mobile-layout="true"] .page-overview-overlay--mobile .page-overview-count {
    font-size: 0.95em;
    padding-left: 0.35rem;
}

/* Link preview cards — no hover on touch */
body[data-mobile-hide-previews="true"] .link-preview-card,
body[data-mobile-hide-previews="true"] .bookmark-preview-popup {
    display: none !important;
}

/* ── Config: tabs & general panels (phone only — tablets keep full config) ── */
body[data-phone-layout="true"] .tab-button:not([data-tab="general"]):not([data-tab="help"]):not([data-tab="colors"]),
body[data-phone-layout="true"] .config-keyboard-chip {
    display: none !important;
}

body[data-phone-layout="true"] [data-general-panel][data-mobile-panel-hidden="true"],
body[data-phone-layout="true"] #general-layer-toolbar,
body[data-phone-layout="true"] #general-layer-show-all,
body[data-phone-layout="true"] #general-advanced-nav-wrap {
    display: none !important;
}

/* Config General — touch-friendly theme & language selects */
body[data-mobile-layout="true"] .form-group--theme-select .custom-select-trigger,
body[data-mobile-layout="true"] .form-group:has(#language-select) .custom-select-trigger {
    min-height: 44px;
    padding: 0.65rem 0.85rem;
    touch-action: manipulation;
}

body[data-mobile-layout="true"] .custom-select-option {
    min-height: 44px;
    padding: 0.65rem 0.85rem;
    display: flex;
    align-items: center;
}

body[data-mobile-layout="true"] .form-group--theme-select label,
body[data-mobile-layout="true"] .form-group:has(#language-select) label {
    font-weight: var(--font-weight-semibold);
}

body[data-mobile-layout="true"] .general-keyboard-link-row {
    display: none !important;
}

/* Tips, search-flow hint, spotlights — desktop discoverability only */
body[data-mobile-layout="true"] .button-hint,
body[data-mobile-layout="true"] .search-flow-hint,
body[data-mobile-layout="true"] .feature-spotlight {
    display: none !important;
}

/* Toasts above the mobile search footer */
body[data-mobile-layout="true"] .app-notification {
    bottom: max(4.75rem, calc(env(safe-area-inset-bottom) + 3.75rem));
    max-width: min(420px, calc(100vw - 1.25rem));
}

/* ── Modals: mobile sheet ── */
@media (max-width: 768px), (max-width: 991px) and (orientation: portrait) {
    .modal-overlay.show .modal,
    .modal-overlay.show .modal.modal--mobile-sheet {
        width: 100% !important;
        max-width: none !important;
        margin: 0;
        border-radius: 0;
        min-height: min(100dvh, 100vh);
        max-height: min(100dvh, 100vh);
    }

    .modal-overlay.show .modal .modal-body {
        max-height: calc(100dvh - 9rem);
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }

    .modal-overlay.show .modal .modal-actions {
        flex-direction: column;
        align-items: stretch;
        gap: 0.5rem;
    }

    .modal-overlay.show .modal .modal-button {
        min-height: 44px;
        width: 100%;
        justify-content: center;
    }

    .shortcut-search .search-container {
        max-height: calc(100dvh - 2rem);
    }
}
