/* Shared mobile layout for Storage Admin + App */

:root {
    --mobile-break: 768px;
    --mobile-break-sm: 480px;
    --mobile-nav-width: min(300px, 92vw);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --safe-top: env(safe-area-inset-top, 0px);
}

.hide-mobile { display: revert; }
.show-mobile-only { display: none !important; }

.mobile-nav-toggle {
    display: none;
    align-items: center;
    justify-content: center;
    width: 44px;
    min-width: 44px;
    height: 100%;
    padding: 0;
    border: none;
    border-right: 1px solid var(--border);
    background: transparent;
    color: var(--text);
    flex-shrink: 0;
}
.mobile-nav-toggle:hover { background: var(--row-hover); filter: none; }
.mobile-nav-icon {
    display: block;
    width: 18px;
    height: 2px;
    background: currentColor;
    position: relative;
}
.mobile-nav-icon::before,
.mobile-nav-icon::after {
    content: '';
    position: absolute;
    left: 0;
    width: 100%;
    height: 2px;
    background: currentColor;
}
.mobile-nav-icon::before { top: -6px; }
.mobile-nav-icon::after { top: 6px; }

.mobile-panel-title {
    display: none;
    align-items: center;
    padding: 0 10px;
    font-size: 13px;
    font-weight: 600;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.mobile-nav-backdrop {
    position: fixed;
    inset: 0;
    z-index: 200;
    background: var(--modal-overlay, rgba(0, 0, 0, 0.55));
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s ease, visibility 0.2s;
}
.mobile-nav-backdrop.is-open {
    opacity: 1;
    visibility: visible;
}

.mobile-nav-drawer {
    position: fixed;
    top: 0;
    left: 0;
    z-index: 210;
    width: var(--mobile-nav-width);
    max-width: 100%;
    height: 100%;
    height: 100dvh;
    padding-top: var(--safe-top);
    padding-bottom: var(--safe-bottom);
    background: var(--surface-raised);
    border-right: 1px solid var(--border-strong);
    transform: translateX(-105%);
    transition: transform 0.22s ease;
    display: flex;
    flex-direction: column;
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.18);
}
.mobile-nav-drawer.is-open { transform: translateX(0); }

.mobile-nav-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
    font-weight: 600;
    font-size: 13px;
    flex-shrink: 0;
}
.mobile-nav-header .btn { padding: 6px 10px; font-size: 12px; min-height: 32px; }

.mobile-nav-list {
    display: flex;
    flex-direction: column;
    padding: 8px;
    gap: 2px;
    overflow: auto;
    flex: 1;
    min-height: 0;
}
.mobile-nav-footer {
    flex-shrink: 0;
    padding: 8px;
    border-top: 1px solid var(--border);
}
.mobile-nav-section {
    margin: 10px 0 4px;
    padding: 0 10px;
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--muted);
}
.mobile-nav-section:first-child { margin-top: 2px; }
.mobile-nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    text-align: left;
    padding: 11px 12px;
    border: none;
    background: transparent;
    color: var(--text);
    font-size: 14px;
    font-weight: 500;
    border-radius: 0;
    min-height: 44px;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}
.mobile-nav-item:hover { background: var(--row-hover); filter: none; }
.mobile-nav-item.active {
    background: var(--accent-dim);
    color: var(--text);
    box-shadow: inset 3px 0 0 var(--accent);
}

.mobile-search-bar {
    display: none;
    padding: 6px 10px;
    background: var(--surface-raised);
    border-bottom: 1px solid var(--border);
}
.mobile-search-bar .search-field {
    max-width: none;
    width: 100%;
    height: 34px;
}
.mobile-search-bar .search-field input {
    line-height: 34px;
    font-size: 16px;
}

.mobile-action-bar {
    display: none;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 120;
    padding: 4px 6px calc(4px + var(--safe-bottom));
    background: var(--surface-raised);
    border-top: 1px solid var(--border-strong);
    gap: 4px;
}
.mobile-action-bar.is-hidden { display: none !important; }
.mobile-action-btn {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1px;
    min-height: 44px;
    padding: 4px 2px;
    font-size: 11px;
    line-height: 1.15;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}
.mobile-action-btn--primary {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}
.mobile-action-glyph {
    font-size: 16px;
    line-height: 1;
    font-weight: 600;
}
.mobile-action-label {
    font-size: 10px;
    font-weight: 500;
    letter-spacing: 0.01em;
}

.mobile-search-bar.is-hidden { display: none !important; }

.context-menu--sheet {
    z-index: 250;
    min-width: 0;
    border: none;
    border-top: 1px solid var(--border-strong);
    border-radius: 12px 12px 0 0;
    padding: 8px 8px calc(8px + var(--safe-bottom));
    box-shadow: 0 -8px 32px rgba(0, 0, 0, 0.22);
}
.context-menu--sheet button {
    min-height: 48px;
    padding: 12px 16px;
    font-size: 15px;
    border-radius: var(--radius, 0);
}

body.mobile-nav-open { overflow: hidden; }

@media (max-width: 768px) {
    .hide-mobile { display: none !important; }
    .show-mobile-only { display: flex !important; }

    .mobile-nav-toggle { display: flex; }
    .mobile-panel-title { display: flex; }

    #app:not(.hidden) {
        display: flex;
        flex-direction: column;
        height: 100dvh;
        max-height: 100dvh;
        overflow: hidden;
    }

    .app-header {
        flex: 0 0 auto;
        height: calc(var(--header-h, 36px) + var(--safe-top));
        min-height: calc(var(--header-h, 36px) + var(--safe-top));
        max-height: none;
        flex-wrap: nowrap;
        padding-top: var(--safe-top);
    }
    .app-brand {
        border-right: none;
        padding: 0 8px;
        font-size: 10px;
        display: none;
    }
    .mobile-brand-compact { display: none; }
    .app-toolbar-end {
        border-left: none;
        margin-left: auto;
        padding: 0 6px;
        gap: 4px;
    }
    .app-toolbar-end .app-user-label { display: none; }
    .app-toolbar-end button {
        min-height: 28px;
        height: 28px;
        padding: 2px 8px;
        font-size: 11px;
    }
    .app-header .theme-switch--compact {
        font-size: 9px;
    }
    #mobile-app-title {
        flex: 1;
        font-size: 15px;
        font-weight: 600;
        padding: 0 4px;
    }

    .tabs {
        flex-wrap: nowrap;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        padding: 0 8px;
    }
    #app:has(#mobile-nav-drawer) .tabs,
    #app:has(#mobile-app-drawer) .tabs {
        display: none;
    }

    .mobile-search-bar {
        display: block;
        flex: 0 0 auto;
    }
    .mobile-search-bar .search-field button {
        min-height: 34px;
        min-width: 64px;
        height: 100%;
        padding: 0 10px;
        font-size: 12px;
    }
    .mobile-search-bar .search-field input {
        min-height: 0;
        height: 100%;
        line-height: 34px;
        font-size: 16px;
    }

    .app-body {
        flex: 1 1 auto;
        min-height: 0;
        flex-direction: column;
        overflow: hidden;
    }

    .app-content {
        flex: 1;
        min-height: 0;
        overflow: auto;
        -webkit-overflow-scrolling: touch;
    }

    .settings-subnav {
        position: sticky;
        top: 0;
        z-index: 2;
        flex-wrap: nowrap;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
    }
    .settings-subnav::-webkit-scrollbar { display: none; }
    .settings-subnav-item {
        flex: 0 0 auto;
        text-align: center;
        padding: 10px 14px;
        min-height: 40px;
        white-space: nowrap;
    }
    .tabs::-webkit-scrollbar { display: none; }
    .tab {
        flex-shrink: 0;
        padding: 10px 12px;
    }

    .tab-panel {
        padding: 8px 8px 12px;
    }

    #tab-explorer.tab-panel:not(.hidden) {
        padding: 0;
        display: flex;
        flex-direction: column;
        min-height: 100%;
    }
    #tab-explorer .explorer-content {
        flex: 1;
        min-height: 0;
    }

    #upload-dropzone.dropzone { display: none; }

    #upload-progress.upload-panel,
    #download-progress.upload-panel,
    #extract-progress.upload-panel {
        position: fixed;
        left: 8px;
        right: 8px;
        bottom: calc(52px + var(--safe-bottom));
        z-index: 130;
        margin: 0;
        border-radius: 0;
        box-shadow: 0 4px 24px rgba(0, 0, 0, 0.2);
    }
    #download-progress.upload-panel { z-index: 131; }
    #extract-progress.upload-panel { z-index: 131; }

    #tab-explorer:has(#upload-progress:not(.hidden)) #extract-progress.upload-panel {
        bottom: calc(120px + var(--safe-bottom));
    }

    .explorer-bar {
        position: sticky;
        top: 0;
        z-index: 15;
        display: flex;
        flex-wrap: wrap;
        align-items: center;
        min-height: 0;
        background: var(--surface-raised);
        gap: 0;
    }
    .path-up-btn {
        order: 0;
        align-self: stretch;
        border-bottom: 1px solid var(--border);
        border-right: 1px solid var(--border);
        padding: 0 12px;
        min-height: 40px;
    }
    .path-bar {
        order: 0;
        width: auto;
        flex: 1 1 0;
        min-width: 0;
        border-bottom: 1px solid var(--border);
        padding: 2px 4px;
        min-height: 40px;
    }
    .folder-stats {
        display: none;
    }
    .sort-control {
        order: 2;
        border-left: none;
        border-bottom: 1px solid var(--border);
        padding: 4px 8px;
        flex: 1 1 40%;
        min-width: 0;
    }
    .sort-control label { display: none; }
    .sort-control select {
        max-width: 100%;
        width: 100%;
        min-height: 32px;
        height: 32px;
        font-size: 12px;
        padding: 2px 6px;
    }
    .tile-size-control {
        order: 3;
        border-left: none;
        border-bottom: 1px solid var(--border);
        padding: 4px 8px;
        flex: 1 1 30%;
        min-width: 0;
    }
    .tile-size-control label { display: none; }
    .tile-size-control select {
        width: 100%;
        min-height: 32px;
        height: 32px;
        font-size: 12px;
        padding: 2px 6px;
    }
    .view-toggle {
        order: 1;
        width: auto;
        flex: 0 0 auto;
        border-left: none;
        border-bottom: 1px solid var(--border);
        border-top: none;
    }
    .view-toggle button {
        flex: 0 0 auto;
        padding: 0 10px;
        min-height: 40px;
        font-size: 11px;
    }

    .explorer-content {
        min-height: 0;
        border-left: none;
        border-right: none;
    }

    .file-table thead { display: none; }
    .file-table .col-type,
    .file-table th.col-type,
    .file-table .col-size,
    .file-table th.col-size,
    .file-table .col-date,
    .file-table th.col-date,
    .file-table th.col-actions {
        display: none !important;
    }
    .file-table tbody td.col-actions {
        display: flex !important;
        align-items: center;
        flex-shrink: 0;
        width: auto;
        min-width: 0;
        padding: 0;
        border: none;
        height: auto;
    }
    .file-table tbody tr {
        display: flex;
        align-items: center;
        gap: 10px;
        padding: 8px 12px;
        border-bottom: 1px solid var(--border);
        min-height: 52px;
    }
    .file-table tbody tr:hover td { background: transparent; }
    .file-table tbody td.col-name,
    .file-table .col-name {
        max-width: none;
        width: auto;
    }
    .file-table tbody td.col-name {
        flex: 1;
        display: block;
        min-width: 0;
        height: auto;
        padding: 0;
        border: none;
    }
    .list-thumb {
        width: 40px;
        height: 40px;
    }
    .list-name {
        min-height: 40px;
        gap: 10px;
    }
    .list-name-text {
        font-size: 14px;
        line-height: 1.3;
    }

    .tile-grid {
        --tile-cell: 96px;
        --tile-icon: 52px;
        --tile-pad: 8px;
        padding: 4px;
        gap: 2px;
    }
    .tile {
        min-height: 96px;
        padding: 8px 4px;
    }
    .tile-name { font-size: 11px; }
    .tile-actions { opacity: 1; pointer-events: auto; }

    .file-name-label.is-truncated:hover .file-name-static {
        visibility: visible;
    }
    .file-name-label.is-truncated:hover .file-name-marquee {
        display: none;
    }
    .file-name-label.is-truncated:hover .file-name-marquee-inner {
        animation: none;
    }

    .row {
        flex-direction: column;
        align-items: stretch;
    }
    .row > h2,
    .row > h3.grow { width: 100%; }
    .row > button,
    .row > .btn { width: 100%; }

    .field {
        min-width: 0;
        width: 100%;
        max-width: none !important;
    }

    .grid.cols-2,
    .grid.cols-3,
    .grid.cols-4 {
        grid-template-columns: 1fr;
    }

    .surface,
    .admin-block {
        padding: 10px 12px;
    }

    .status { margin: 0 10px 8px; }

    .table-wrap {
        -webkit-overflow-scrolling: touch;
        border-radius: 0;
    }

    .tab-panel table:not(.file-table) {
        display: block;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    #app.has-mobile-actions .app-content,
    #app.has-mobile-actions main {
        padding-bottom: calc(52px + var(--safe-bottom));
    }

    .mobile-action-bar:not(.is-hidden) { display: flex; }

    .modal-box,
    .preview-modal {
        width: 100% !important;
        max-width: 100% !important;
        height: 100% !important;
        max-height: 100dvh !important;
        border-radius: 0 !important;
    }

    .viewer-box {
        width: 100% !important;
        max-height: 100dvh !important;
        height: 100dvh !important;
    }
    .viewer-head {
        padding: 8px 10px;
        padding-top: calc(8px + var(--safe-top));
        gap: 6px;
        grid-template-columns: auto minmax(0, 1fr) auto 6.5rem auto;
    }
    .viewer-nav-btn {
        min-width: 44px;
        min-height: 44px;
        padding: 8px;
        font-size: 18px;
    }
    #viewer-close {
        min-height: 44px;
        padding: 8px 12px;
    }
    .viewer-body {
        padding: 0;
        min-height: 0;
    }
    .viewer-body.viewer-body--swipe {
        touch-action: none;
    }
    .viewer-body.viewer-body--swipe img,
    .viewer-body.viewer-body--swipe video {
        touch-action: none;
    }
    .viewer-body img,
    .viewer-body video {
        max-height: 100%;
    }
    .viewer-body video {
        width: 100%;
        max-width: 100%;
    }
    .viewer-video-shell {
        width: 100%;
        max-height: 100%;
        border-radius: 0;
    }
    .viewer-video-shell > video {
        width: 100%;
        max-width: 100%;
    }
    .video-player-chrome {
        padding: 40px 10px max(10px, env(safe-area-inset-bottom, 0px));
    }
    .video-player-bigplay {
        width: 64px;
        height: 64px;
    }
    .video-player-btn {
        width: 40px;
        height: 40px;
    }
    .video-scrub {
        width: 100%;
        min-height: 28px;
        padding-top: 10px;
    }
    .video-scrub-rail {
        height: 8px;
    }
    .video-scrub-times {
        font-size: 12px;
    }
    .video-player-volume .video-player-vol {
        width: 56px;
        opacity: 1;
    }

    .modal-box h3,
    .modal-box .access-tabs button,
    .file-modal-tabs button {
        font-size: 14px;
    }
    .modal-box button,
    .access-add-form button {
        min-height: 44px;
    }
    .modal-box input,
    .modal-box select,
    .modal-box textarea {
        min-height: 44px;
        font-size: 16px;
    }
}

@media (max-width: 480px) {
    body { font-size: 14px; }

    .login-card,
    #login-screen form {
        padding: 18px;
    }

    #login-screen input {
        min-height: 44px;
        font-size: 16px;
    }

    #login-screen button[type="submit"] {
        min-height: 48px;
        font-size: 16px;
    }

    .table-wrap table:not(.file-table) {
        min-width: 0;
        font-size: 12px;
    }

    .table-wrap thead {
        display: none;
    }

    .table-wrap tbody tr {
        display: block;
        border-bottom: 1px solid var(--border);
        padding: 8px 10px;
    }
    .table-wrap tbody tr:hover td {
        background: transparent;
    }
    .table-wrap tbody td {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 12px;
        height: auto;
        min-height: 28px;
        padding: 4px 0;
        border: none;
        text-align: right;
    }
    .table-wrap tbody td::before {
        content: attr(data-label);
        font-size: 10px;
        font-weight: 600;
        text-transform: uppercase;
        letter-spacing: 0.04em;
        color: var(--muted);
        text-align: left;
        flex: 1;
        min-width: 0;
    }
    .table-wrap tbody td[data-label=""]::before,
    .table-wrap tbody td:not([data-label])::before {
        content: none;
    }
    .table-wrap tbody td.col-actions {
        justify-content: flex-end;
        flex-wrap: nowrap;
        height: auto;
        min-height: 32px;
        white-space: nowrap;
    }
    .table-wrap tbody .table-actions > .btn,
    .table-wrap tbody .table-actions > button {
        width: auto;
        margin-right: 0;
    }
}

@media (prefers-reduced-motion: reduce) {
    .mobile-nav-backdrop,
    .mobile-nav-drawer {
        transition: none;
    }
}
