/* =========================================================
   Mobile UI — responsive panel, tables, modals, landing
   Load after compact-ui.css
   ========================================================= */

/* ---------- Shell & navigation (≤900px) ---------- */
@media (max-width: 900px) {
    html,
    body {
        max-width: 100%;
        overflow-x: hidden;
    }

    body.sidebar-open {
        overflow: hidden;
        touch-action: none;
    }

    #mobileHeader {
        display: flex !important;
        align-items: center;
        gap: 10px;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        z-index: 120;
        min-height: 52px;
        padding: calc(8px + env(safe-area-inset-top, 0px)) 12px 8px;
        background: rgba(8, 13, 24, 0.94);
        backdrop-filter: blur(16px);
        border-bottom: 1px solid rgba(122, 145, 186, 0.22);
        box-shadow: 0 8px 28px rgba(0, 0, 0, 0.28);
    }

    html:not(.dark) #mobileHeader {
        background: rgba(255, 255, 255, 0.94);
        border-bottom-color: rgba(46, 72, 107, 0.14);
    }

    .mobile-menu-btn {
        flex-shrink: 0;
        width: 40px;
        height: 40px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        border-radius: 10px;
        border: 1px solid rgba(255, 255, 255, 0.12);
        background: rgba(255, 255, 255, 0.06);
        color: #eef4ff;
        cursor: pointer;
        -webkit-tap-highlight-color: transparent;
    }

    html:not(.dark) .mobile-menu-btn {
        border-color: rgba(46, 72, 107, 0.16);
        background: rgba(15, 127, 176, 0.06);
        color: #14253f;
    }

    .mobile-header-title {
        flex: 1;
        min-width: 0;
    }

    .mobile-header-title .kicker {
        font-size: 9px;
        letter-spacing: 0.2em;
        text-transform: uppercase;
        color: var(--muted, #9aa9bf);
        line-height: 1.2;
    }

    .mobile-header-title h2 {
        margin: 0;
        font-size: 0.95rem;
        font-weight: 700;
        color: var(--text, #e7edf8);
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        line-height: 1.2;
    }

    .mobile-header-actions {
        display: flex;
        gap: 6px;
        flex-shrink: 0;
    }

    .mobile-header-actions a,
    .mobile-header-actions button {
        width: 36px;
        height: 36px;
        padding: 0;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        border-radius: 10px;
        font-size: 14px;
        min-height: 0 !important;
        min-width: 0 !important;
    }

    #sidebarOverlay {
        position: fixed;
        inset: 0;
        z-index: 125;
        background: rgba(2, 6, 14, 0.62);
        backdrop-filter: blur(3px);
    }

    #sidebarOverlay:not(.hidden) {
        display: block !important;
    }

    .app-shell {
        display: block !important;
    }

    .app-sidebar {
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        bottom: 0 !important;
        width: min(88vw, 300px) !important;
        min-width: 0 !important;
        max-width: 300px !important;
        height: 100vh !important;
        height: 100dvh !important;
        transform: translateX(-110%) !important;
        transition: transform 0.24s ease !important;
        z-index: 130 !important;
        overflow-y: auto !important;
        overscroll-behavior: contain;
        padding-top: calc(10px + env(safe-area-inset-top, 0px)) !important;
        padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px)) !important;
        box-shadow: 24px 0 60px rgba(0, 0, 0, 0.45) !important;
    }

    .app-sidebar.sidebar-open,
    .app-sidebar.is-open {
        transform: translateX(0) !important;
    }

    .sidebar-close-btn {
        position: absolute;
        top: 8px;
        right: 8px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        width: 32px;
        height: 32px;
        border: 1px solid rgba(255, 255, 255, 0.12);
        border-radius: 8px;
        background: rgba(255, 255, 255, 0.05);
        color: var(--muted, #9aa9bf);
        font-size: 1.25rem;
        line-height: 1;
        cursor: pointer;
        z-index: 2;
    }

    .sidebar-brand {
        position: relative;
        padding-right: 42px !important;
    }

    .app-main {
        width: 100% !important;
        min-width: 0 !important;
        margin: 0 !important;
        padding: calc(60px + env(safe-area-inset-top, 0px)) 10px calc(12px + env(safe-area-inset-bottom, 0px)) !important;
        height: auto !important;
        overflow: visible !important;
    }

    .app-topbar,
    .wow-blueprint-topbar {
        position: relative !important;
        top: 0 !important;
        margin: 0 0 10px !important;
        padding: 10px 12px !important;
        flex-direction: column !important;
        align-items: stretch !important;
        gap: 8px !important;
        border-radius: 12px !important;
    }

    .topbar-identity {
        min-width: 0;
    }

    .topbar-title h1 {
        font-size: clamp(1rem, 4.5vw, 1.25rem) !important;
        white-space: normal !important;
        overflow-wrap: anywhere;
    }

    .topbar-title .kicker {
        white-space: normal !important;
        overflow-wrap: anywhere;
    }

    .topbar-actions {
        display: grid !important;
        grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
        gap: 6px !important;
        width: 100% !important;
    }

    .topbar-actions > * {
        width: 100% !important;
        justify-content: center !important;
        min-height: 40px !important;
    }

    .workspace-frame {
        margin: 0 !important;
        border-radius: 12px !important;
        overflow: hidden !important;
    }

    .workspace-content {
        padding: 10px !important;
        overflow-x: hidden !important;
    }
}

@media (min-width: 901px) {
    #mobileHeader,
    .sidebar-close-btn {
        display: none !important;
    }
}

/* ---------- Section content ---------- */
@media (max-width: 900px) {
    /* Stat cards: 2 columns on phone, full width for 3rd */
    .workspace-content .grid.grid-cols-1.md\:grid-cols-3 {
        grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
        gap: 0.5rem !important;
    }

    .workspace-content .grid.grid-cols-1.md\:grid-cols-3 > :last-child:nth-child(3n),
    .workspace-content .grid.grid-cols-1.md\:grid-cols-3 > :last-child:nth-child(odd):last-child {
        grid-column: 1 / -1;
    }

    .workspace-content .grid.grid-cols-2.md\:grid-cols-4 {
        grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
        gap: 0.5rem !important;
    }

    /* Version / category tabs — horizontal scroll */
    .workspace-content .flex.space-x-1,
    .workspace-content .flex.space-x-1.mb-6 {
        display: flex !important;
        flex-wrap: nowrap !important;
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        gap: 4px !important;
        margin-bottom: 0.65rem !important;
        padding-bottom: 2px;
    }

    .workspace-content .flex.space-x-1::-webkit-scrollbar {
        display: none;
    }

    .workspace-content .flex.space-x-1 a {
        flex-shrink: 0;
        white-space: nowrap;
        padding: 0.4rem 0.75rem !important;
        font-size: 0.72rem !important;
    }

    /* Section panel header + toolbar */
    .workspace-content .bg-\[\#161b28\] > .p-4.border-b.flex,
    .workspace-content .bg-\[\#161b28\].border > .p-4.border-b.flex {
        flex-direction: column !important;
        align-items: stretch !important;
        gap: 8px !important;
    }

    .workspace-content .bg-\[\#161b28\] > .p-4.border-b.flex h3,
    .workspace-content .bg-\[\#161b28\].border > .p-4.border-b.flex h3 {
        font-size: 0.78rem !important;
    }

    .workspace-content .bg-\[\#161b28\] > .p-4.border-b.flex h3 span,
    .workspace-content .bg-\[\#161b28\].border > .p-4.border-b.flex h3 span {
        display: block;
        margin-left: 0 !important;
        margin-top: 2px;
    }

    .workspace-content .bg-\[\#161b28\] > .p-4.border-b.flex > .flex,
    .workspace-content .bg-\[\#161b28\].border > .p-4.border-b.flex > .flex {
        display: grid !important;
        grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
        gap: 6px !important;
        width: 100% !important;
    }

    .workspace-content .bg-\[\#161b28\] > .p-4.border-b.flex > .flex button,
    .workspace-content .bg-\[\#161b28\].border > .p-4.border-b.flex > .flex button {
        width: 100% !important;
        min-height: 40px !important;
        padding: 0.45rem 0.5rem !important;
        font-size: 0.68rem !important;
        white-space: normal !important;
        line-height: 1.2 !important;
        text-align: center;
    }

    /* Scrollable tables */
    .workspace-content .overflow-x-auto {
        position: relative;
        -webkit-overflow-scrolling: touch;
        max-width: 100%;
    }

    .workspace-content .overflow-x-auto::after {
        content: "";
        position: absolute;
        top: 0;
        right: 0;
        bottom: 0;
        width: 28px;
        pointer-events: none;
        background: linear-gradient(to left, rgba(11, 18, 32, 0.85), transparent);
    }

    .workspace-content table {
        min-width: 640px;
    }

    .workspace-content .overflow-x-auto.max-h-\[540px\] {
        max-height: min(55vh, 460px) !important;
    }

    /* Pagination */
    .workspace-content .flex.justify-between.items-center,
    .workspace-content .flex.items-center.justify-between {
        flex-direction: column !important;
        align-items: stretch !important;
        gap: 8px !important;
    }

    .workspace-content .flex.justify-between.items-center .flex.gap-2,
    .workspace-content .flex.items-center.justify-between .flex.gap-2 {
        justify-content: center;
        flex-wrap: wrap;
    }
}

@media (max-width: 520px) {
    .app-main {
        padding-left: 8px !important;
        padding-right: 8px !important;
    }

    .topbar-actions {
        grid-template-columns: 1fr !important;
    }

    .workspace-content .grid.grid-cols-1.md\:grid-cols-3,
    .workspace-content .grid.grid-cols-2.md\:grid-cols-4 {
        grid-template-columns: 1fr !important;
    }

    .workspace-content .bg-\[\#161b28\] > .p-4.border-b.flex > .flex,
    .workspace-content .bg-\[\#161b28\].border > .p-4.border-b.flex > .flex {
        grid-template-columns: 1fr !important;
    }

    .workspace-content table {
        min-width: 580px;
        font-size: 11px !important;
    }
}

/* ---------- Modals & drawers ---------- */
@media (max-width: 900px) {
    .fixed.inset-0,
    [id$="Modal"],
    #editorModal,
    #tutEditorModal {
        padding: 8px !important;
        align-items: flex-start !important;
    }

    .fixed.inset-0 .relative,
    .fixed.inset-0 > div,
    [id$="Modal"] > div,
    #editorModal > div,
    #tutEditorModal > div {
        width: 100% !important;
        max-width: 100% !important;
        max-height: calc(100dvh - 16px) !important;
        overflow: auto !important;
        border-radius: 14px !important;
        margin: 0 !important;
    }

    .panel-drawer,
    .panel-fullscreen {
        border-radius: 0 !important;
        max-width: 100vw !important;
    }

    .modal-action-row,
    .editor-actions,
    .editor-bottom-actions,
    .quest-modal-actions {
        display: flex !important;
        flex-wrap: wrap !important;
        justify-content: center !important;
        gap: 8px !important;
    }

    .modal-action-row button,
    .modal-action-row a,
    .editor-actions button,
    .editor-bottom-actions button {
        flex: 1 1 calc(50% - 8px) !important;
        min-height: 44px !important;
        max-width: none !important;
    }
}

@media (max-width: 520px) {
    .modal-action-row button,
    .modal-action-row a,
    .editor-actions button,
    .editor-bottom-actions button {
        flex: 1 1 100% !important;
    }
}

/* ---------- Home / guest landing ---------- */
@media (max-width: 768px) {
    .guest-tools-page .max-w-7xl {
        padding-left: 0.75rem !important;
        padding-right: 0.75rem !important;
    }

    .guest-tools-page .flex.flex-col.md\:flex-row {
        align-items: stretch !important;
        text-align: center;
    }

    .guest-tools-page .flex.flex-col.md\:flex-row .absolute {
        width: 100% !important;
        height: 3px !important;
        top: 0 !important;
        left: 0 !important;
        bottom: auto !important;
    }

    .guest-tools-page .flex.gap-2.mt-4,
    .guest-tools-page .flex.gap-4.mt-6 {
        width: 100%;
        flex-direction: column;
        margin-top: 0.75rem !important;
    }

    .guest-tools-page .flex.gap-2.mt-4 a,
    .guest-tools-page .flex.gap-4.mt-6 a {
        width: 100%;
        text-align: center;
        min-height: 44px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }

    .guest-tools-page .grid.grid-cols-1.md\:grid-cols-2.lg\:grid-cols-4 {
        grid-template-columns: 1fr !important;
    }

    .guest-tools-page .card-hover .h-40 {
        height: 8.5rem !important;
    }

    .guest-tools-page .px-5.py-4 {
        padding: 0.85rem 1rem !important;
    }

    .guest-tools-page .flex.justify-between.text-\[10px\] {
        flex-direction: column;
        align-items: flex-start;
        gap: 4px;
    }

    .guest-quest-cat-tabs {
        grid-template-columns: 1fr !important;
    }
}

@media (max-width: 768px) {
    .guest-shell {
        padding: 0.75rem !important;
        min-height: 100dvh;
    }

    .auth-hero-grid {
        grid-template-columns: 1fr !important;
        gap: 1rem !important;
        padding: 0 !important;
    }

    .auth-hero {
        display: none !important;
    }

    .login-box {
        width: 100% !important;
        max-width: 100% !important;
        padding: 1.25rem !important;
        border-radius: 14px !important;
    }

    .btn-login,
    .btn-discord {
        min-height: 44px !important;
        width: 100% !important;
    }
}

/* ---------- Touch targets ---------- */
@media (max-width: 900px) and (pointer: coarse) {
    .sidebar-nav a,
    .sidebar-action-link,
    .user-card,
    button,
    .topbar-actions a,
    .topbar-actions button {
        min-height: 44px;
    }

    .mobile-menu-btn {
        width: 44px;
        height: 44px;
    }
}
