/* Mobile and narrow-viewport adaptations for the shared app shell and feature surfaces. */

@media (max-width: 1000px) {
    .sidebar {
        width: 176px;
    }

    .main-content {
        margin-left: 176px;
    }

    .content,
    .topbar {
        padding-right: 24px;
        padding-left: 24px;
    }

    .location-form {
        grid-template-columns: 1fr 1.5fr;
    }

    .location-form .color-field,
    .location-form .settings-primary-button {
        justify-self: start;
    }

    .edit-location-form {
        grid-template-columns: 1fr 1.5fr;
    }

    .runtime-status-grid {
        grid-template-columns: 1fr;
    }

    .trash-item {
        grid-template-columns: auto minmax(0, 1fr) auto;
    }

    .trash-item-detail {
        display: none;
    }

    .trash-item-detail.expiry {
        display: flex;
    }
}

/* Dense Gallery stays photo-forward on phones instead of inheriting card breakpoints. */
@media (max-width: 760px) {
    body[data-view="gallery"] .file-collection {
        grid-template-columns: repeat(3, minmax(0, 1fr));
        gap: 3px;
        touch-action: pan-y;
    }

    body[data-view="gallery"][data-gallery-density="2"] .file-collection {
        --gallery-tile-radius: 8px;
        --gallery-folder-preview-padding: 8px;
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    body[data-view="gallery"][data-gallery-density="5"] .file-collection {
        --gallery-tile-radius: 3px;
        --gallery-folder-preview-padding: 4px;
        --gallery-folder-preview-gap: 2px;
        grid-template-columns: repeat(5, minmax(0, 1fr));
    }

    body[data-view="gallery"][data-gallery-density="7"] .file-collection {
        --gallery-tile-radius: 2px;
        --gallery-folder-preview-padding: 3px;
        --gallery-folder-preview-gap: 1px;
        grid-template-columns: repeat(7, minmax(0, 1fr));
    }

    body[data-view="gallery"][data-gallery-density="9"] .file-collection {
        --gallery-tile-radius: 1px;
        --gallery-folder-preview-padding: 2px;
        --gallery-folder-preview-gap: 1px;
        grid-template-columns: repeat(9, minmax(0, 1fr));
    }

    body[data-view="gallery"].gallery-density-compositing .file-browser-content {
        overflow-anchor: none;
    }

    /* The semantic collection keeps one stable layout while two overscanned paint planes own
       direct manipulation. The DOM reflows only once, hidden, at the snapped handoff. */
    body[data-view="gallery"].gallery-density-compositing .file-collection {
        opacity: 0;
        pointer-events: none;
        transition: none;
    }

    body[data-view="gallery"].gallery-density-compositing.gallery-density-handoff .file-collection {
        opacity: 1;
        transition: opacity .1s linear;
    }

    .gallery-pinch-compositor {
        position: fixed;
        z-index: 24;
        overflow: hidden;
        pointer-events: none;
        opacity: 1;
        contain: strict;
        isolation: isolate;
        transition: opacity .1s linear;
    }

    .gallery-pinch-compositor.is-handing-off {
        opacity: 0;
    }

    .gallery-pinch-compositor-plane {
        position: absolute;
        top: 0;
        left: 0;
        width: 0;
        height: 0;
        opacity: 1;
        transform-origin: 0 0;
        will-change: transform, opacity;
        contain: style;
    }

    .gallery-pinch-compositor-canvas {
        position: absolute;
        display: block;
        max-width: none;
        pointer-events: none;
    }

    body[data-view="gallery"] .file-visual {
        height: auto;
    }

    body[data-view="gallery"] .folder-preview-grid {
        grid-template-rows: repeat(3, minmax(0, 1fr));
        gap: 3px;
    }

    body[data-view="gallery"] .folder-preview-grid > img:nth-child(n+7) {
        display: block;
    }

    body[data-view="gallery"] .folder-preview-grid > span:nth-child(n+7) {
        display: grid;
    }
}

@media (max-width: 760px) and (prefers-reduced-motion: reduce) {
    body[data-view="gallery"].gallery-density-compositing.gallery-density-handoff .file-collection,
    .gallery-pinch-compositor,
    .file-browser-context,
    .file-browser-context-inner,
    .file-browser-toolbar {
        transition: none !important;
    }
}

@media (max-width: 760px) {
    body.notes-editor-active {
        --note-visual-viewport-top: 0px;
        --note-keyboard-inset: 0px;
        overflow: hidden;
        overscroll-behavior: none;
    }

    .login-page {
        height: 100vh;
        height: 100dvh;
        min-height: 100dvh;
        max-height: 100dvh;
        padding: 0;
        overflow: hidden;
        overscroll-behavior: none;
        background: #fff;
    }

    .login-page .app-version-badge {
        bottom: max(54px, calc(env(safe-area-inset-bottom) + 42px));
        width: max-content;
        max-width: calc(100% - 48px);
    }

    .login-shell {
        height: 100%;
        min-height: 0;
        max-height: 100%;
        grid-template-columns: 1fr;
        border: 0;
        border-radius: 0;
        box-shadow: none;
    }

    .login-panel {
        width: 100%;
        max-width: 420px;
        padding: clamp(28px, 5.6dvh, 40px) 27px;
    }

    .brand-mark-large {
        width: 48px;
        height: 48px;
        margin-bottom: clamp(22px, 4.8dvh, 34px);
    }

    .login-copy {
        margin: 14px 0 clamp(20px, 4.2dvh, 28px);
        line-height: 1.5;
    }

    .login-form > input:not([type="hidden"]),
    .password-field input,
    .primary-button {
        height: 50px;
    }

    @supports selector(html:has(body.login-page)) {
        html:has(body.login-page) {
            height: 100%;
            overflow: hidden;
        }
    }

    @media (max-height: 680px) {
        .login-page .app-version-badge {
            bottom: max(36px, calc(env(safe-area-inset-bottom) + 28px));
        }

        .login-panel {
            padding: clamp(18px, 4dvh, 26px) 24px;
        }

        .brand-mark-large {
            width: 44px;
            height: 44px;
            margin-bottom: clamp(16px, 3.4dvh, 22px);
        }

        .login-panel h1 {
            font-size: 31px;
        }

        .login-copy {
            margin: 10px 0 16px;
            font-size: 14px;
            line-height: 1.42;
        }

        .login-form {
            gap: 8px;
        }

        .login-form > input:not([type="hidden"]),
        .password-field input,
        .primary-button {
            height: 46px;
        }

        .primary-button {
            margin-top: 4px;
        }

        .remember-login {
            padding: 4px 2px;
        }

        .remember-login small {
            font-size: 9px;
            line-height: 1.25;
        }
    }

    .login-art {
        display: none;
    }

    input:not([type="checkbox"]):not([type="radio"]):not([type="file"]):not(.note-title-input),
    select,
    textarea {
        font-size: 16px !important;
    }

    .share-invite-form,
    .share-invite-item,
    .share-collaborator-row {
        grid-template-columns: 1fr;
    }

    .share-invite-actions,
    .share-inline-form {
        width: 100%;
        flex-wrap: wrap;
        justify-content: flex-start;
    }

    .share-inline-form select {
        min-width: 150px;
        flex: 1 1 150px;
    }

    .sidebar {
        z-index: 180;
        width: min(290px, 84vw);
        height: 100dvh;
        min-height: 100dvh;
        max-height: 100dvh;
        transform: translateX(-102%);
        transition: transform .25s ease;
        touch-action: pan-y pinch-zoom;
        will-change: transform;
    }

    .sidebar-top {
        --sidebar-brand-size: 42px;
    }

    .brand-icon {
        width: 42px;
        height: 42px;
    }

    .sidebar-scrim {
        position: fixed;
        z-index: 160;
        inset: 0;
        opacity: 0;
        background: rgba(15, 17, 27, .42);
        backdrop-filter: blur(2px);
        transition: opacity .25s ease;
    }

    body.sidebar-open,
    body.sidebar-closing {
        overflow: hidden;
    }

    body.sidebar-open .sidebar {
        transform: translateX(0);
    }

    body.sidebar-open .sidebar-scrim {
        display: block;
        opacity: 1;
    }

    body.sidebar-closing .sidebar-scrim {
        display: block;
        opacity: 0;
    }

    body.sidebar-open.sidebar-dragging .sidebar {
        transform: translate3d(var(--sidebar-drag-x, 0px), 0, 0);
        transition: none;
    }

    body.sidebar-open.sidebar-dragging .sidebar-scrim {
        opacity: var(--sidebar-scrim-opacity, 1);
        transition: none;
    }

    body.sidebar-open .notes-bottom-actionbar {
        opacity: 0;
        pointer-events: none;
        transform: translateY(12px);
    }

    body.sidebar-open .notes-bottom-actionbar > * {
        pointer-events: none;
    }

    body.app-shell-keyboard-focus:has(.notes-list-page) .notes-bottom-actionbar {
        bottom: max(
            calc(var(--app-keyboard-inset, 0px) + 10px),
            calc(env(safe-area-inset-bottom) + 14px)
        );
    }

    .main-content {
        margin-left: 0;
    }

    body:has(.notes-list-page),
    body:has(.file-browser-content),
    body:has(.settings-content),
    body:has(.inbox-content),
    body:has(.trash-content),
    body:has(.expenses-content),
    body:has(.messages-content) {
        overflow: hidden;
    }

    body:has(.notes-list-page) .main-content,
    body:has(.file-browser-content) .main-content,
    body:has(.settings-content) .main-content,
    body:has(.inbox-content) .main-content,
    body:has(.trash-content) .main-content,
    body:has(.expenses-content) .main-content,
    body:has(.messages-content) .main-content {
        position: fixed;
        inset: 0;
        display: grid;
        width: 100%;
        height: 100dvh;
        min-height: 0;
        grid-template-rows: 68px minmax(0, 1fr);
        overflow: hidden;
    }

    body.app-shell-keyboard-focus:has(.notes-list-page) .main-content,
    body.app-shell-keyboard-focus:has(.file-browser-content) .main-content,
    body.app-shell-keyboard-focus:has(.settings-content) .main-content,
    body.app-shell-keyboard-focus:has(.inbox-content) .main-content,
    body.app-shell-keyboard-focus:has(.trash-content) .main-content,
    body.app-shell-keyboard-focus:has(.expenses-content) .main-content,
    body.app-shell-keyboard-focus:has(.messages-content) .main-content {
        top: var(--app-visual-viewport-top, 0px);
        bottom: auto;
        height: var(--app-visual-viewport-height, 100dvh);
    }

    .topbar {
        height: 68px;
        padding: 0 16px;
        gap: 9px;
    }

    body:has(.notes-list-page) .topbar,
    body:has(.file-browser-content) .topbar,
    body:has(.settings-content) .topbar,
    body:has(.inbox-content) .topbar,
    body:has(.trash-content) .topbar,
    body:has(.expenses-content) .topbar,
    body:has(.messages-content) .topbar {
        position: relative;
        top: auto;
    }

    .app-notification-stack {
        top: calc(100% + 10px);
        right: 12px;
        left: 12px;
        width: auto;
    }

    .app-notification {
        min-height: 56px;
        grid-template-columns: 28px minmax(0, 1fr) 28px;
        border-radius: 14px;
    }

    .app-notification-icon {
        width: 28px;
        height: 28px;
    }

    .menu-button {
        display: grid;
        flex: 0 0 auto;
    }

    .search-box {
        width: 100%;
        padding-right: 8px;
    }

    .search-scope-dropdown .ui-dropdown-toggle {
        min-width: 94px;
        padding: 0 6px;
        font-size: 11px;
    }

    .search-scope-dropdown .ui-dropdown-menu {
        position: fixed;
        top: 62px;
        right: 12px;
        width: min(210px, calc(100vw - 24px));
    }

    .search-box kbd,
    .privacy-pill {
        display: none;
    }

    .topbar-actions {
        position: static;
        margin-left: auto;
        flex: 0 0 auto;
    }

    .notes-editor-topbar .topbar-actions {
        margin-left: 0;
    }
    body.notes-editor-active .main-content {
        position: fixed;
        top: var(--note-visual-viewport-top, 0px);
        left: 0;
        display: grid;
        width: 100%;
        height: 100dvh;
        min-height: 0;
        grid-template-rows: 68px minmax(0, 1fr);
        overflow: hidden;
    }


    .topbar-note-actions {
        gap: 7px;
    }

    .notes-editor-topbar .note-back-button {
        order: 1;
    }

    .notes-editor-topbar .note-editor-app-label {
        order: 2;
    }

    .notes-editor-topbar .note-undo-button {
        order: 3;
    }

    .notes-editor-topbar .note-redo-button {
        order: 4;
    }

    .notes-editor-topbar .note-editor-menu {
        order: 5;
    }

    .note-find-panel {
        top: calc(env(safe-area-inset-top) + 74px);
        right: max(12px, env(safe-area-inset-right));
        left: max(12px, env(safe-area-inset-left));
        width: auto;
        padding: 7px;
        gap: 6px;
        border-radius: 16px;
    }

    .note-find-count {
        min-width: 48px;
        font-size: 11px;
    }

    .note-find-icon-button {
        width: 36px;
        height: 36px;
        border-radius: 12px;
    }

    .topbar-note-actions .note-nav-button,
    .topbar-note-nav .note-nav-button {
        width: 40px;
        height: 40px;
        border-radius: 13px;
    }

    .notes-editor-topbar .privacy-pill {
        display: none;
    }

    body.notes-editor-active .content {
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        padding-top: 0;
        padding-bottom: calc(88px + var(--note-keyboard-inset));
    }

    .content {
        padding: 20px 16px 40px;
    }

    .notes-heading {
        align-items: stretch;
        flex-direction: column;
    }

    .note-create-form {
        min-width: 0;
        align-items: stretch;
        flex-direction: column;
    }

    .note-create-form .settings-primary-button {
        width: 100%;
    }

    .notes-layout {
        grid-template-columns: 1fr;
    }

    .notes-list-panel {
        position: static;
    }

    .notes-list {
        display: grid;
        margin: 0;
        padding: 0;
        gap: 9px;
    }

    .notes-list-page {
        min-height: 0;
        overflow-x: hidden;
        overflow-y: auto;
        overscroll-behavior-y: auto;
        touch-action: pan-y;
        -webkit-overflow-scrolling: touch;
        -webkit-touch-callout: none;
        -webkit-user-select: none;
        user-select: none;
    }

    .file-browser-content {
        display: flex;
        min-height: 0;
        padding-top: 7px;
        padding-bottom: 0;
        flex-direction: column;
        overflow-x: hidden;
        overflow-y: auto;
        overflow-anchor: none;
        overscroll-behavior-y: auto;
        touch-action: pan-y;
        -webkit-overflow-scrolling: touch;
    }

    .file-browser-content > :not(.file-table-shell) {
        flex: 0 0 auto;
    }

    /* Context, toolbar, and files share one native touch scroller. The results reserve a
       viewport below the sticky toolbar, so short folders can still slide the context away. */
    .file-browser-content > .file-table-shell {
        min-height: calc(100% - 52px);
        padding-bottom: max(40px, env(safe-area-inset-bottom));
        flex: 0 0 auto;
        overflow: visible;
    }

    .settings-content,
    .inbox-content,
    .trash-content,
    .expenses-content,
    .messages-content {
        min-height: 0;
        overflow-x: hidden;
        overflow-y: auto;
        overscroll-behavior-y: auto;
        touch-action: pan-x pan-y;
        -webkit-overflow-scrolling: touch;
    }

    .notes-list-page input,
    .notes-list-page textarea {
        -webkit-touch-callout: default;
        -webkit-user-select: text;
        user-select: text;
    }

    .note-card {
        min-height: 84px;
        padding: 0;
        grid-template-columns: minmax(0, 1fr) auto;
        gap: 9px;
        overflow: visible;
        border: 0;
        background: transparent;
        touch-action: pan-y pinch-zoom;
        -webkit-touch-callout: none;
        -webkit-user-drag: none;
        -webkit-user-select: none;
        user-select: none;
    }

    .note-card *,
    .note-card-main {
        -webkit-touch-callout: none;
        -webkit-user-drag: none;
        -webkit-user-select: none;
        user-select: none;
    }

    .note-card.active {
        border-color: transparent;
        background: transparent;
        box-shadow: none;
    }

    .note-card:has(.note-card-menu[open]) {
        overflow: visible;
    }

    .note-card-swipe-content {
        min-height: 84px;
        padding: 9px 10px;
        grid-template-columns: minmax(0, 1fr) auto;
        gap: 9px;
        border: 1px solid var(--line);
        border-radius: 18px;
        background:
            linear-gradient(135deg, color-mix(in srgb, var(--note-accent) 8%, transparent), transparent 55%),
            color-mix(in srgb, var(--surface) 94%, var(--canvas));
        touch-action: pan-y pinch-zoom;
        transform: translate3d(var(--note-card-swipe-x), 0, 0);
        transition:
            transform var(--note-card-swipe-duration, .22s) cubic-bezier(.2, .9, .22, 1),
            border-color .18s ease,
            background .18s ease,
            box-shadow .18s ease;
    }

    .note-card.active .note-card-swipe-content {
        border-color: color-mix(in srgb, var(--note-accent) 38%, var(--line));
        background:
            linear-gradient(135deg, color-mix(in srgb, var(--note-accent) 14%, transparent), transparent 58%),
            color-mix(in srgb, var(--surface) 96%, var(--canvas));
        box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--note-accent) 30%, transparent);
    }

    .note-card.note-card-swiping .note-card-swipe-content {
        transition: none;
    }

    .note-card.note-card-swiping .note-card-swipe-content,
    .note-card.note-card-settling .note-card-swipe-content,
    .note-card.swipe-open .note-card-swipe-content {
        will-change: transform;
    }

    .note-card.swipe-open,
    .note-card.note-card-swiping,
    .note-card.note-card-settling {
        z-index: 8;
    }

    .note-card-primary-actions {
        transition:
            opacity .1s ease,
            transform .1s ease,
            visibility 0s linear 0s;
    }

    .note-card.swipe-face-controls-locked .note-card-primary-actions {
        opacity: 0;
        visibility: hidden;
        pointer-events: none;
        transform: translateX(5px) scale(.96);
        transition:
            opacity .08s ease,
            transform .08s ease,
            visibility 0s linear .08s;
    }

    .note-card-reorder-handle {
        display: none !important;
    }

    .note-card.note-card-order-dragging {
        overflow: visible;
        transform: scale(1.025);
        user-select: none;
        -webkit-user-select: none;
        -webkit-touch-callout: none;
    }

    .note-card.note-card-order-dragging::after {
        position: absolute;
        z-index: 10;
        inset: 0;
        content: "";
        touch-action: none;
    }

    .note-card.note-card-order-dragging .note-card-swipe-content {
        border-color: color-mix(in srgb, var(--note-accent) 44%, var(--line));
        box-shadow: 0 16px 36px rgba(5, 8, 20, .26);
        transition: none;
    }

    .note-card.note-card-order-dragging .note-card-actions,
    .note-card.note-card-order-dragging .note-card-swipe-actions,
    .note-card.note-card-order-dragging .note-card-menu {
        display: none !important;
    }

    .notes-list.note-list-reordering .note-card:not(.note-card-order-dragging) .note-card-swipe-content {
        opacity: .66;
    }

    .notes-list.note-list-reordering .note-card:not(.note-card-order-dragging)::after {
        position: absolute;
        z-index: 10;
        inset: 0;
        content: "";
        touch-action: none;
    }

    .notes-list.note-list-reordering .note-card:not(.note-card-order-dragging) .note-card-swipe-actions {
        display: none !important;
    }

    .note-card-swipe-actions {
        position: absolute;
        inset: 0 0 0 auto;
        z-index: 1;
        display: grid;
        width: var(--note-card-swipe-width);
        grid-template-columns: repeat(2, minmax(0, 1fr));
        overflow: hidden;
        border-radius: 18px;
        opacity: 0;
        pointer-events: none;
        visibility: hidden;
    }

    .note-card-swipe-actions-single {
        width: 64px;
        grid-template-columns: minmax(0, 1fr);
    }

    .note-card-swipe-actions-wide {
        width: 192px;
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }

    .note-card.swipe-open .note-card-swipe-actions,
    .note-card.note-card-swiping .note-card-swipe-actions,
    .note-card.note-card-settling .note-card-swipe-actions {
        opacity: 1;
        visibility: visible;
    }

    .note-card.swipe-open:not(.note-card-swiping):not(.note-card-settling) .note-card-swipe-actions {
        pointer-events: auto;
    }

    .note-card-swipe-form {
        display: flex;
        min-width: 0;
    }

    .note-card-swipe-action {
        display: grid;
        width: 100%;
        min-width: 0;
        min-height: 84px;
        padding: 0 8px;
        place-items: center;
        align-content: center;
        gap: 6px;
        color: #f8fbff;
        border: 0;
        font: inherit;
        font-size: 10px;
        font-weight: 900;
        letter-spacing: .01em;
        cursor: pointer;
        touch-action: manipulation;
    }

    .note-card-swipe-action svg {
        width: 20px;
        height: 20px;
    }

    .note-card-swipe-share-action {
        background:
            linear-gradient(145deg, rgba(85, 125, 255, .96), rgba(39, 83, 206, .96));
        box-shadow: inset 1px 0 0 rgba(255, 255, 255, .12);
    }

    .note-card-swipe-archive-action {
        background:
            linear-gradient(145deg, rgba(116, 127, 148, .97), rgba(68, 78, 99, .98));
        box-shadow: inset 1px 0 0 rgba(255, 255, 255, .12);
    }

    .note-card-swipe-delete-action {
        background:
            linear-gradient(145deg, rgba(255, 75, 105, .98), rgba(161, 25, 54, .98));
    }

    .note-card-swipe-action:active,
    .note-card-swipe-action.is-pressing {
        filter: brightness(1.08);
    }

    .note-card-desktop-action,
    .note-card-desktop-action-form {
        display: none;
    }

    .note-card-main {
        grid-template-columns: 48px minmax(0, 1fr);
        gap: 10px;
    }

    .note-card-icon {
        width: 48px;
        height: 48px;
        border-radius: 14px;
    }

    .note-card-icon > svg {
        width: 23px;
        height: 23px;
    }

    .note-card-copy strong {
        font-size: 13px;
    }

    .note-card-copy small {
        font-size: 10px;
        -webkit-line-clamp: 2;
    }

    .note-card-meta {
        gap: 4px;
        font-size: 9px;
    }

    .note-card-actions {
        gap: 5px;
        justify-content: end;
        padding-left: 0;
    }

    .notes-list.note-list-reordering {
        user-select: none;
        -webkit-user-select: none;
    }

    .note-card-action {
        width: 38px;
        height: 38px;
        border-radius: 11px;
    }

    .note-card-action svg {
        width: 17px;
        height: 17px;
    }

    .note-editor-card,
    .note-share-card {
        padding: 15px;
        border-radius: 18px;
    }

    .note-editor-top {
        align-items: stretch;
        flex-direction: column;
    }

    .note-status-stack {
        justify-items: start;
    }

    .note-title-input {
        font-size: 28px;
    }

    .notes-editor-page .note-title-input {
        order: 1;
        margin-top: 0;
        padding-right: 0;
        font-size: clamp(20px, 8vw, 42px);
        line-height: 1.06;
        overflow-wrap: anywhere;
    }

    .note-editor-meta {
        position: static;
        order: 0;
        justify-self: end;
        max-width: 100%;
        gap: 7px;
    }

    .note-editor-meta > i {
        width: 5px;
        height: 5px;
        box-shadow: 0 0 0 3px rgba(101, 119, 255, .1);
    }

    .notes-editor-page .note-save-status {
        font-size: 11px;
    }

    .note-editor-shell {
        padding: 10px 24px 104px;
        background: transparent;
        border: 0;
        border-radius: 0;
    }

    .note-editor-surface,
    html[data-theme="dark"] .note-editor-shell,
    html[data-theme="dark"] .note-editor-surface {
        background: transparent;
    }

    .note-editor-surface {
        padding: 0;
        border-radius: 0;
    }

    .notes-editor-page .note-editor {
        order: 2;
        padding: 4px 0 32px;
    }

    body.notes-editor-active .note-editor-shell {
        padding-bottom: calc(104px + var(--note-keyboard-inset));
    }

    body.notes-editor-active .note-floating-toolbar {
        bottom: max(
            calc(var(--note-keyboard-inset) + 10px),
            calc(env(safe-area-inset-bottom) + 10px)
        );
        opacity: 0;
        pointer-events: none;
        transform: translateY(14px);
        transition: opacity .22s ease, transform .22s ease, bottom .18s ease;
    }

    body.notes-editor-active.note-editor-focused .note-floating-toolbar,
    body.notes-editor-active.note-keyboard-open .note-floating-toolbar {
        opacity: 1;
        pointer-events: auto;
        transform: translateY(0);
    }

    .note-floating-toolbar .note-toolbar-toggle {
        display: grid;
    }

    .note-floating-toolbar.note-toolbar-expanded .note-toolbar-toggle {
        display: none;
    }

    .note-floating-toolbar:not(.note-toolbar-expanded) {
        right: max(16px, env(safe-area-inset-right));
        left: auto;
        width: 52px;
        min-height: 52px;
        margin: 0;
        padding: 4px;
        justify-content: center;
        gap: 0;
        border-color: color-mix(in srgb, var(--line) 72%, transparent);
        background: color-mix(in srgb, var(--surface) 58%, transparent);
        box-shadow: 0 12px 34px rgba(20, 23, 35, .16);
        backdrop-filter: blur(15px);
    }

    .note-floating-toolbar:not(.note-toolbar-expanded) > :not(.note-toolbar-toggle) {
        display: none;
    }

    .note-floating-toolbar:not(.note-toolbar-expanded) .note-toolbar-toggle {
        width: 42px;
        min-width: 42px;
        height: 42px;
        padding: 0;
        color: color-mix(in srgb, var(--ink) 76%, transparent);
        background: color-mix(in srgb, var(--surface) 32%, transparent);
    }

    .note-editor {
        min-height: 320px;
        padding: 16px;
        border-radius: 15px;
    }

    .note-toolbar {
        overflow-x: auto;
        flex-wrap: nowrap;
    }

    .settings-content {
        padding-top: 25px;
    }

    .trash-heading {
        align-items: stretch;
        flex-direction: column;
    }

    .trash-summary {
        text-align: left;
    }

    .trash-admin-filter {
        width: 100%;
    }

    .trash-admin-filter-row {
        align-items: stretch;
    }

    .trash-admin-filter .settings-secondary-button {
        flex: 0 0 auto;
    }

    .trash-item {
        grid-template-columns: auto minmax(0, 1fr);
        align-items: start;
    }

    .trash-item-info {
        padding-right: 112px;
    }

    .trash-item-actions {
        grid-column: 1 / -1;
        justify-content: stretch;
        flex-wrap: wrap;
    }

    .trash-item-actions > *,
    .trash-item-actions button,
    .trash-item-actions a {
        flex: 1;
    }

    .settings-panel {
        padding: 17px;
        border-radius: 17px;
    }

    .settings-agent-token {
        align-items: stretch;
        flex-direction: column;
    }

    .settings-agent-token .settings-primary-button,
    .settings-agent-actions,
    .settings-agent-actions form,
    .settings-agent-actions button {
        width: 100%;
    }

    .settings-agent-meta {
        grid-template-columns: 1fr;
    }

    .settings-agent-card > summary {
        align-items: center;
    }

    .settings-agent-card > summary .location-status {
        display: none;
    }

    .location-form,
    .edit-location-form,
    .profile-details-form,
    .language-form,
    .hidden-code-form,
    .admin-view-form,
    .user-create-form,
    .user-account-fields {
        grid-template-columns: 1fr;
    }

    .profile-details-form .settings-primary-button,
    .language-form .settings-primary-button,
    .hidden-code-form .settings-primary-button,
    .admin-view-form .settings-secondary-button,
    .location-form .settings-primary-button {
        width: 100%;
    }

    .admin-view-current {
        align-items: stretch;
        flex-direction: column;
    }

    .admin-view-current .settings-secondary-button {
        width: 100%;
    }

    .profile-image-settings {
        grid-template-columns: auto minmax(0, 1fr);
        align-items: center;
    }

    .profile-image-remove-form {
        grid-column: 1 / -1;
    }

    .profile-color-form {
        align-items: stretch;
        flex-direction: column;
    }

    .profile-color-status {
        min-height: 14px;
        text-align: left;
    }

    .profile-image-upload-form {
        align-items: center;
    }

    .profile-image-remove-form .settings-danger-button {
        width: 100%;
    }

    .user-create-form .settings-primary-button,
    .managed-user-actions > * {
        width: 100%;
    }

    .managed-user-actions {
        align-items: stretch;
        flex-direction: column;
    }

    .managed-location {
        align-items: start;
    }

    .managed-location-info > div {
        align-items: start;
        flex-wrap: wrap;
    }

    .editable-location .managed-location-icon {
        display: none;
    }

    .edit-location-heading {
        display: flex;
    }

    .managed-location-actions {
        grid-column: auto;
        justify-content: stretch;
    }

    .managed-location-actions button {
        flex: 1;
    }

    .selection-toolbar {
        align-items: stretch;
        flex-direction: column;
    }

    .selection-actions {
        display: grid;
        grid-template-columns: 1fr 1fr;
    }

    .selection-actions > *,
    .selection-actions button {
        width: 100%;
    }

    .selection-actions [data-select-cancel] {
        grid-column: 1 / -1;
    }

    .theme-options {
        grid-template-columns: 1fr;
    }

    .runtime-cache-footer {
        align-items: stretch;
        flex-direction: column;
    }

    .runtime-cache-footer .settings-secondary-button {
        width: 100%;
    }

    .thumbnail-generator {
        grid-template-columns: 1fr;
    }

    .thumbnail-generator .settings-primary-button {
        width: 100%;
    }

    .thumbnail-auto-form {
        align-items: stretch;
        flex-direction: column;
    }

    .thumbnail-auto-form .settings-secondary-button,
    .preference-action .settings-secondary-button {
        width: 100%;
    }

    .preference-action {
        align-items: stretch;
        flex-direction: column;
    }

    .folder-heading {
        margin-top: 10px;
        align-items: center;
        gap: 12px;
    }

    .file-browser-context .breadcrumbs {
        min-height: 20px;
    }

    .folder-heading h1 {
        font-size: clamp(25px, 7.2vw, 30px);
        line-height: 1.08;
        overflow-wrap: anywhere;
    }

    .folder-actions {
        flex-wrap: nowrap;
        align-items: center;
        justify-content: flex-end;
        gap: 8px;
    }

    .upload-button span,
    .folder-button span {
        display: none;
    }

    .upload-button,
    .folder-button {
        width: 44px;
        height: 44px;
        padding: 0;
        justify-content: center;
    }

    .file-browser-toolbar {
        position: sticky;
        z-index: 22;
        top: 0;
        margin: 14px 0 0;
        padding: 0 0 12px;
        align-items: center;
        flex-direction: row;
        gap: 8px;
        background: var(--canvas);
        touch-action: pan-y;
    }

    .file-browser-toolbar::before {
        position: absolute;
        z-index: -1;
        right: 0;
        bottom: 100%;
        left: 0;
        height: 7px;
        content: "";
        background: var(--canvas);
        pointer-events: none;
    }

    .file-browser-toolbar .view-switcher {
        flex: 0 0 auto;
        padding: 2px;
    }

    .file-browser-toolbar .view-switcher button {
        width: 42px;
        height: 42px;
    }

    .file-browser-context .folder-actions-expanded {
        display: none;
    }

    .file-toolbar-menus {
        margin-left: auto;
        gap: 7px;
    }

    .file-browser-toolbar .file-sort-menu .sort-dropdown .file-sort-menu-toggle,
    .file-filter-menu-toggle {
        width: 44px;
        min-width: 44px;
        height: 44px;
        border-radius: 12px;
    }

    .file-sort-menu-panel,
    .file-filter-menu-panel {
        width: min(238px, calc(100vw - 32px));
    }

    .file-compact-folder-actions {
        display: flex;
        align-items: center;
        gap: 7px;
        pointer-events: auto;
    }

    .folder-actions .folder-action-menu > .folder-action-menu-toggle {
        width: 44px;
    }

    .folder-actions .folder-action-menu > .folder-action-menu-panel > button,
    .folder-actions .folder-action-menu > .folder-action-menu-panel > form > button {
        min-height: 44px;
    }

    .folder-share-grid {
        grid-template-columns: 1fr;
    }

    .file-collection {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 10px;
    }

    .file-visual {
        height: 112px;
    }

    .file-visual.preview-folder {
        padding: 9px;
        border-radius: 10px;
    }

    .folder-preview-grid {
        grid-template-rows: repeat(2, minmax(0, 1fr));
        gap: 5px;
        border-radius: 7px;
    }

    .folder-preview-grid > :nth-child(n+7) {
        display: none;
    }

    .folder-preview-grid img,
    .folder-preview-grid > span {
        border-radius: 3px;
    }

    .file-actions {
        z-index: 9;
        top: auto;
        right: 6px;
        bottom: 6px;
        display: block;
        opacity: 1;
    }

    .file-card:has(.file-action-menu.open) {
        z-index: 18;
        overflow: visible;
    }

    .file-action-menu {
        position: relative;
        display: block;
    }

    .file-action-menu > .file-action-menu-toggle {
        display: grid;
        width: 38px;
        height: 38px;
        color: var(--ink);
        border-color: color-mix(in srgb, var(--line) 76%, transparent);
        border-radius: 11px;
        background: color-mix(in srgb, var(--surface) 91%, transparent);
        box-shadow: 0 8px 22px rgba(20, 24, 39, .14);
        backdrop-filter: blur(12px);
    }

    .file-action-menu > .file-action-menu-toggle svg {
        width: 18px;
        height: 18px;
        stroke-width: 3.2;
    }

    .file-action-menu.open > .file-action-menu-toggle {
        color: var(--accent);
        border-color: color-mix(in srgb, var(--accent) 34%, var(--line));
        background: color-mix(in srgb, var(--accent) 10%, var(--surface));
    }

    .file-action-menu:not(.open) > .file-action-menu-panel {
        display: none;
    }

    .file-actions .file-action-menu-panel {
        position: absolute;
        right: 0;
        bottom: calc(100% + 8px);
        display: grid;
        min-width: 174px;
        max-width: calc(100vw - 32px);
        padding: 6px;
        gap: 2px;
        border: 1px solid var(--line);
        border-radius: 14px;
        background: var(--surface);
        box-shadow: 0 18px 46px rgba(15, 18, 31, .24);
    }

    .file-actions .file-action-menu-panel > a,
    .file-actions .file-action-menu-panel > button,
    .file-actions .file-action-menu-panel > form > button,
    .file-actions .file-action-menu-panel > .file-visibility-picker > summary {
        display: flex;
        width: 100%;
        height: 42px;
        padding: 0 10px;
        justify-content: flex-start;
        gap: 10px;
        color: var(--ink);
        border: 0;
        border-radius: 9px;
        background: transparent;
        box-shadow: none;
        font-size: 12px;
        font-weight: 750;
        white-space: nowrap;
    }

    .file-actions .file-action-menu-panel > a:active,
    .file-actions .file-action-menu-panel > button:active,
    .file-actions .file-action-menu-panel > form > button:active,
    .file-actions .file-action-menu-panel > .file-visibility-picker > summary:active {
        background: color-mix(in srgb, var(--accent) 10%, transparent);
    }

    .file-actions .file-action-menu-panel > form,
    .file-actions .file-action-menu-panel > .file-visibility-picker {
        width: 100%;
    }

    .file-actions .file-action-menu-panel > form > .file-action-danger {
        color: #a7475a;
    }

    .file-action-label {
        display: inline;
    }

    .file-action-menu-panel .file-visibility-menu {
        position: static;
        min-width: 0;
        margin: 2px 4px 4px;
        padding: 4px 0 0;
        border: 0;
        border-top: 1px solid var(--line);
        border-radius: 0;
        box-shadow: none;
    }

    .file-card:has(.file-action-menu) .file-meta {
        padding-right: 42px;
    }

    body[data-view="list"] .file-table-shell {
        max-height: none;
        overflow: visible;
        border: 0;
        border-radius: 0;
        background: transparent;
    }

    body[data-view="list"] .list-head {
        display: none;
    }

    body[data-view="list"] .file-collection {
        min-width: 0;
        gap: 7px;
    }

    body[data-view="list"] .file-card {
        min-height: 62px;
        padding: 6px 7px;
        grid-template-columns: minmax(0, 1fr) auto;
        gap: 6px;
        overflow: hidden;
        border: 1px solid var(--line);
        border-radius: 12px;
    }

    body[data-view="list"] .file-card:last-child {
        border-bottom: 1px solid var(--line);
    }

    body[data-view="list"] .file-open {
        gap: 8px;
    }

    body[data-view="list"] .file-visual {
        width: 46px;
        height: 46px;
        border-radius: 9px;
    }

    body[data-view="list"] .file-meta {
        min-width: 0;
    }

    body[data-view="list"] .file-meta strong,
    body[data-view="list"] .file-meta span {
        display: block;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    body[data-view="list"] .file-meta span {
        margin-top: 3px;
        color: var(--muted);
        font-size: 10px;
    }

    body[data-view="list"] .mobile-file-date {
        display: inline;
    }

    body[data-view="list"] .mobile-file-date::before {
        content: " | ";
    }

    body[data-view="list"] .list-type,
    body[data-view="list"] .list-size,
    body[data-view="list"] .list-date {
        display: none;
    }

    body[data-view="list"] .file-actions {
        justify-self: end;
    }

    body[data-view="list"] .file-action-menu > .file-action-menu-toggle {
        width: 38px;
        height: 38px;
    }

    .preview-dialog {
        width: 100vw;
        height: 100dvh;
        max-width: none;
        max-height: none;
        border: 0;
        border-radius: 0;
    }

    .preview-dialog[open] {
        display: block;
    }

    .preview-topbar {
        position: absolute;
        z-index: 4;
        top: 0;
        right: 0;
        left: 0;
        min-height: 64px;
        padding: calc(9px + env(safe-area-inset-top)) calc(10px + env(safe-area-inset-right)) 16px calc(14px + env(safe-area-inset-left));
        gap: 8px;
        border-bottom: 0;
        background: linear-gradient(180deg, rgba(8, 10, 16, .92), rgba(8, 10, 16, .55) 68%, transparent);
        transition: opacity .22s ease, transform .22s ease;
    }

    .preview-topbar > div:last-child {
        gap: 4px;
    }

    .preview-dialog.preview-pdf .preview-topbar {
        border-bottom: 1px solid rgba(255, 255, 255, .1);
        background: rgba(8, 10, 16, .82);
        backdrop-filter: blur(14px);
    }

    .preview-heading {
        display: grid;
        grid-template-columns: 42px minmax(0, 1fr);
        align-items: center;
        gap: 9px;
    }

    .preview-back {
        display: inline-grid;
        width: 42px;
        height: 42px;
        padding: 0;
        place-items: center;
        color: #fff;
        border: 1px solid rgba(255, 255, 255, .12);
        border-radius: 13px;
        background: rgba(255, 255, 255, .08);
        cursor: pointer;
    }

    .preview-back:hover,
    .preview-back:focus-visible {
        border-color: rgba(101, 119, 255, .48);
        background: rgba(255, 255, 255, .13);
        outline: none;
    }

    .preview-back svg {
        width: 18px;
        height: 18px;
        transform: rotate(180deg);
    }

    .preview-topbar .preview-close-button {
        display: none;
    }

    .preview-dialog.preview-pdf .preview-topbar > div:last-child {
        gap: 8px;
    }

    .preview-dialog.preview-pdf .preview-topbar [data-preview-copy] {
        display: none;
    }

    .preview-dialog.preview-pdf .preview-topbar [data-preview-trash] {
        display: inline-grid;
        width: 44px;
        height: 44px;
    }

    .preview-dialog.preview-pdf [data-preview-download] {
        width: 44px;
        height: 44px;
        background: rgba(255, 255, 255, .08);
    }

    .preview-download span {
        display: none;
    }

    .preview-download,
    .preview-topbar .icon-button {
        width: 38px;
        height: 38px;
        padding: 0;
        justify-content: center;
        border-radius: 11px;
    }

    .preview-stage {
        height: 100dvh;
        overscroll-behavior: none;
        touch-action: none;
    }

    .preview-media {
        inset: 0;
    }

    .preview-dialog.preview-video .preview-media {
        inset: 0 0 calc(58px + env(safe-area-inset-bottom));
    }

    .preview-dialog.preview-pdf .preview-stage,
    .preview-dialog.preview-pdf .preview-media {
        touch-action: pan-y pinch-zoom;
    }

    .preview-dialog.preview-pdf .preview-media {
        inset: calc(70px + env(safe-area-inset-top)) 0 0;
        overflow: hidden;
    }

    .preview-dialog.preview-pdf .preview-pdf-pages {
        padding: 10px max(8px, env(safe-area-inset-right)) calc(14px + env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
        gap: 10px;
    }

    .preview-swipe-neighbor {
        position: absolute;
        z-index: 1;
        inset: 0;
        display: grid;
        place-items: center;
        overflow: hidden;
        pointer-events: none;
        will-change: transform;
    }

    .preview-media img,
    .preview-media video,
    .preview-swipe-neighbor img,
    .preview-swipe-neighbor video {
        display: block;
        width: 100%;
        height: 100%;
        min-width: 0;
        min-height: 0;
        max-width: none;
        max-height: none;
        border-radius: 0;
        object-fit: contain;
        object-position: center;
        filter: none;
        touch-action: none;
    }

    .preview-media img,
    .preview-swipe-neighbor img {
        -webkit-user-drag: none;
        user-select: none;
    }

    .preview-dialog.preview-swiping .preview-media {
        will-change: transform;
    }

    .preview-nav {
        z-index: 4;
        width: 42px;
        height: 54px;
        border-radius: 14px;
        background: rgba(10, 12, 19, .48);
        transition: background .18s ease, opacity .22s ease, transform .22s ease;
    }

    .preview-nav-previous {
        left: max(8px, env(safe-area-inset-left));
    }

    .preview-nav-next {
        right: max(8px, env(safe-area-inset-right));
    }

    .preview-dialog.preview-controls-hidden .preview-topbar {
        opacity: 0;
        pointer-events: none;
        transform: translateY(-100%);
    }

    .preview-dialog.preview-controls-hidden .preview-nav {
        opacity: 0;
        pointer-events: none;
    }

    .preview-dialog.preview-controls-hidden .preview-nav-previous {
        transform: translate(-8px, -50%);
    }

    .preview-dialog.preview-controls-hidden .preview-nav-next {
        transform: translate(8px, -50%);
    }

    .upload-dialog {
        width: calc(100vw - 18px);
        border-radius: 18px;
    }

    .upload-dialog form {
        padding: 16px;
    }

    .upload-dropzone {
        min-height: 190px;
    }
}

@media (max-width: 390px) {
    .notes-list-tools {
        grid-template-columns: 1fr;
    }

    .note-filter-active-row {
        gap: 7px;
    }

    .note-active-filters {
        gap: 6px;
    }

    .note-active-filter,
    .note-filter-chip {
        min-height: 32px;
        padding: 0 9px;
        gap: 6px;
        font-size: 11px;
    }

    .note-filter-toggle {
        width: 50px;
        height: 36px;
    }

    .note-filter-panel {
        padding: 12px;
        border-radius: 17px;
    }

    .notes-bottom-actionbar {
        right: 10px;
        left: 10px;
        width: calc(100% - 20px);
        gap: 8px;
    }

    .bottom-search-field {
        height: 54px;
        padding: 0 14px;
    }

    .bottom-note-create-form .settings-primary-button {
        width: 54px;
        min-width: 54px;
        height: 54px;
    }

    .note-card {
        padding: 0;
    }

    .note-card-swipe-content {
        padding: 8px;
    }

    .note-card-actions {
        gap: 4px;
    }

    .note-card-action {
        width: 36px;
        height: 36px;
    }

    .note-floating-toolbar {
        left: max(10px, env(safe-area-inset-left));
        right: max(10px, env(safe-area-inset-right));
        width: min(360px, calc(100vw - 20px));
        min-height: 56px;
        padding: 6px;
        gap: 2px;
    }

    .note-floating-toolbar button {
        min-width: 42px;
        height: 42px;
        padding: 0 9px;
        font-size: 14px;
    }

    .note-floating-toolbar .note-color-toggle {
        gap: 5px;
    }

    .note-card-main {
        grid-template-columns: 44px minmax(0, 1fr);
    }

    .note-card-icon {
        width: 44px;
        height: 44px;
    }

    .file-collection {
        grid-template-columns: 1fr;
    }

    .file-visual {
        height: 155px;
    }
}
