/* ==========================================
   18. 手機版響應式校準 (@media max-width: 768px)
   ========================================== */
@media (max-width: 768px) {
    :root {
        --modal-bar-height: 64px;
    }

    body {
        height: 100dvh;
        min-height: 100dvh;
        display: flex;
        overflow: hidden;
    }

    main {
        overflow-y: auto;
        height: 100dvh;
        min-height: 100dvh;
        margin-left: 0;
        width: 100%;
        -webkit-overflow-scrolling: touch;
    }

    html:has(#editor-modal.active, #full-editor-modal.active) {
        position: fixed !important;
        inset: 0 !important;
        width: 100% !important;
        /* stylelint-disable-next-line declaration-block-no-duplicate-properties */
        height: 100% !important;
        height: 100dvh !important;
        overflow: hidden !important;
        overscroll-behavior: none !important;
    }

    body:has(#editor-modal.active, #full-editor-modal.active) {
        position: fixed !important;
        inset: 0 !important;
        width: 100% !important;
        /* stylelint-disable-next-line declaration-block-no-duplicate-properties */
        height: 100% !important;
        height: 100dvh !important;
        overflow: hidden !important;
        overscroll-behavior: none !important;
    }

    body:has(#editor-modal.active, #full-editor-modal.active) main {
        overflow-y: hidden;
        height: var(--editor-rest-height, 100dvh);
        min-height: var(--editor-rest-height, 100dvh);
    }

    #text-toolbar {
        display: none !important;
    }

    textarea {
        height: auto;
        font-size: 14pt;
    }

    #editor-modal {
        overscroll-behavior: contain;
        width: 90% !important;
        max-width: 400px !important;
        height: min(536px, calc(100dvh - 2 * (var(--modal-bar-height) + 24px)));
        max-height: min(536px, calc(100dvh - 2 * (var(--modal-bar-height) + 24px)));
        padding: 24px 20px !important;
    }

    .editor-external-top-bar {
        border-radius: 16px !important;
        padding: 7px !important;
    }

    .editor-external-top-bar.active.keyboard-hidden,
    .editor-external-bottom-bar.active.keyboard-hidden {
        opacity: 0;
        pointer-events: none;
        transition: transform 0.2s ease, opacity 0.18s ease;
    }

    .editor-external-top-bar.active.keyboard-hidden {
        transform: translateY(-32px);
    }

    .editor-external-bottom-bar.active.keyboard-hidden {
        transform: translateY(32px);
    }

    .category-popover-item.active,
    .category-popover-item:active,
    .context-item.active,
    .context-item:active,
    #chapter-popover .chapter-item:is(.active, :active),
    #chapter-popover .chapter-popover-header[data-action]:active {
        background: var(--menu-selection-bg) !important;
    }

    .category-popover-item.danger:active,
    .context-item.danger:active {
        background: var(--menu-danger-selection-bg) !important;
    }

    @media (hover: hover) {

        .category-popover-item:hover:not(.danger),
        .context-item:hover:not(.danger),
        .floating-avatar-menu-item:hover:not(.danger),
        #chapter-popover .chapter-item:hover,
        #chapter-popover .chapter-popover-header[data-action]:hover {
            background: var(--menu-selection-bg) !important;
        }

        .category-popover-item.danger:hover,
        .context-item.danger:hover,
        .floating-avatar-menu-item.danger:hover {
            background: var(--menu-danger-selection-bg) !important;
        }
    }

    #editor-external-top-bar #unified-type-selector {
        border-radius: 11px !important;
    }

    #editor-external-top-bar #unified-type-selector .segment-slider::before {
        border-radius: 11px !important;
    }

    #editor-external-top-bar #unified-type-selector .segment-btn {
        font-size: 19px !important;
        gap: 5px !important;
    }

    .editor-edit-header {
        padding: 0 13px !important;
    }

    .editor-modal-title {
        font-size: 20px !important;
    }

    .editor-external-bottom-bar {
        border-radius: 16px !important;
        padding: 0 8px !important;
        gap: 8px !important;
    }

    .editor-external-bottom-bar .btn-primary {
        height: 44px !important;
        border-radius: 11px !important;
        font-size: 15px !important;
    }

    #category-modal {
        width: 90% !important;
        max-width: 400px !important;
        height: min(536px, calc(100dvh - 198px));
        max-height: min(536px, calc(100dvh - 198px));
        padding: 28px 20px !important;
    }

    .category-external-top-bar {
        height: 64px !important;
        border-radius: 16px !important;
        padding: 0 8px !important;
    }

    .category-external-bottom-bar {
        height: 94px !important;
        border-radius: 16px !important;
        padding: 8px !important;
        gap: 8px !important;
    }

    .btn-add-category-item {
        flex: 1 !important;
        width: auto !important;
        min-width: 0 !important;
        height: 100% !important;
        border-radius: 11px !important;
        padding: 0 !important;
    }

    .category-bottom-right-actions {
        gap: 6px !important;
    }

    .category-bottom-right-actions .btn-primary {
        height: 36px !important;
        min-height: 36px !important;
        border-radius: 11px !important;
        font-size: 14px !important;
    }

    #sort-modal {
        width: 90% !important;
        max-width: 400px !important;
        height: min(536px, calc(100dvh - 2 * (var(--modal-bar-height) + 24px)));
        max-height: min(536px, calc(100dvh - 2 * (var(--modal-bar-height) + 24px)));
        padding: 28px 20px !important;
    }

    .sort-carousel-wrapper {
        width: calc(100% + 40px) !important;
        margin-left: -20px !important;
        margin-right: -20px !important;
        padding-left: 20px !important;
        padding-right: 20px !important;
    }

    .sort-external-top-bar {
        border-radius: 16px !important;
        padding: 0 8px !important;
    }

    .sort-path-segment {
        height: 50px !important;
        border-radius: 11px !important;
        padding: 0 4px !important;
    }

    .sort-path-title {
        font-size: 16px !important;
    }

    .sort-path-segment.has-value .sort-path-title {
        transform: translate3d(0, -10px, 0) scale(0.76) !important;
    }

    .sort-path-value {
        font-size: 15px !important;
    }

    .sort-path-segment.has-value .sort-path-value {
        transform: translate3d(0, 9px, 0) scale(1) !important;
    }

    .sort-external-bottom-bar {
        border-radius: 16px !important;
        padding: 0 8px !important;
        gap: 8px !important;
    }

    .sort-external-bottom-bar .btn-primary {
        height: 44px !important;
        border-radius: 11px !important;
        font-size: 14px !important;
    }

    .sort-drag-ghost {
        transform: none !important;
    }

    #bookmark-form-container:not(.mode-note) {
        flex: 1 !important;
        height: 100% !important;
        min-height: 0 !important;
        max-height: none !important;
        justify-content: safe center !important;
    }

    #bookmark-form-container.mode-note {
        flex: 1 !important;
        height: 100% !important;
        min-height: 0 !important;
        max-height: none !important;
        justify-content: flex-start !important;
    }

    #reminder-form-container {
        flex: 1 !important;
        height: 100% !important;
        min-height: 0 !important;
        max-height: none !important;
        justify-content: flex-start !important;
        padding-top: 0 !important;
    }

    #reminder-form-container #reminder-content {
        flex: 1 !important;
        height: auto !important;
        min-height: 100px !important;
        max-height: none !important;
    }

    #bookmark-form-container.mode-note #bookmark-content {
        flex: 1 !important;
        height: auto !important;
        min-height: 100px !important;
        max-height: none !important;
    }

    .editor-modal-timestamp {
        font-size: 13.5px !important;
        margin-top: 10px !important;
        transform: translateY(10px) !important;
    }

    .date-ui-display {
        min-height: 50px !important;
        height: auto !important;
        padding: 10px 14px !important;
        font-size: 16px !important;
        box-sizing: border-box;
    }

    .reminder-date-row {
        font-size: 15px;
        gap: 6px;
    }

    .reminder-date-single {
        font-size: 16px;
        gap: 6px;
    }

    .reminder-modal-checkbox {
        width: 52px;
        height: 40px;
        min-width: 52px;
        min-height: 40px;
        border-radius: 11px;
    }

    .editor-edit-actions .action-delete-btn {
        width: 40px;
        height: 40px;
        min-width: 40px;
        min-height: 40px;
        border-radius: 11px;
    }

    .text-toolbar .animated-action-btn {
        width: 44px;
        height: 44px;
    }

}
