/* Memo Cloud plugin / theme integration. */

/*
 * Theme 1.1.13: one width contract for the whole app.
 * The app must always use the real width of its parent. Individual panes may
 * scroll their own content, but no desktop child may enlarge the page itself.
 */
.mct-app-page .mct-app-main,
.mct-app-page .mc-shell {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    box-sizing: border-box;
}

/* Plugin 1.3.4 historically uses max-width:none!important on these roots.
 * Override it here so the theme wrapper is the single source of truth for app width. */
.mct-app-page .mct-app-main > #mc-auth-root,
.mct-app-page .mct-app-main > #mc-app-root,
.mct-app-page #mc-app-root {
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
    box-sizing: border-box;
}

.mct-app-main > #mc-auth-root,
.mct-app-main > #mc-app-root {
    height: 100%;
    min-height: 720px;
}

.mct-app-page.mc-body {
    margin: 0;
    overflow-y: auto;
}

.mct-app-page .mc-shell {
    height: 100%;
    min-height: 720px;
    position: relative;
}

.mct-app-page.mc-page-settings .mct-app-main > #mc-app-root,
.mct-app-page.mc-page-plan .mct-app-main > #mc-app-root,
.mct-app-page.mc-page-settings .mc-shell,
.mct-app-page.mc-page-plan .mc-shell {
    min-height: 800px;
}

/* The site logo is owned by the WordPress theme header. */
.mct-app-page .mc-logo-wrap {
    display: none !important;
}

.mct-app-page .mc-global-search {
    grid-column: auto !important;
    border-left: 0;
}

.mct-app-page .mc-auth-page {
    width: 100%;
    min-height: 100%;
    height: 100%;
    padding: 24px;
}

.mct-app-page .mc-auth-logo {
    display: none;
}

.mct-app-page .mc-auth-box h1:first-child {
    margin-top: 0;
}

/* Theme 1.1.14: desktop width contract — the visible app always totals 100%. */
@media (min-width: 821px) {
    body.mct-app-page {
        grid-template-columns: minmax(0, 1fr);
        min-width: 0;
        max-width: 100%;
    }

    .mct-app-page .mct-site-header,
    .mct-app-page .mct-header-inner {
        width: 100%;
        max-width: 100%;
        min-width: 0;
        box-sizing: border-box;
    }

    .mct-app-page .mct-branding,
    .mct-app-page .mct-note-tabs,
    .mct-app-page .mct-header-actions {
        min-width: 0;
    }

    .mct-app-page .mct-note-tabs {
        flex: 1 1 0;
        max-width: 100%;
        overflow-x: auto;
        overflow-y: hidden;
    }

    .mct-app-page .mct-header-actions {
        flex: 0 0 auto;
    }

    body.mct-app-page.mc-body {
        width: 100%;
        max-width: 100%;
        overflow-x: auto;
    }

    .mct-app-page .mct-app-main,
    .mct-app-page #mc-app-root,
    .mct-app-page .mc-shell,
    .mct-app-page .mc-topbar,
    .mct-app-page .mc-layout,
    .mct-app-page .mc-pane,
    .mct-app-page .mc-editor-pane,
    .mct-app-page .mc-editor-workspace,
    .mct-app-page .mc-editor-wrap {
        width: 100%;
        max-width: 100%;
        min-width: 0;
        box-sizing: border-box;
    }

    .mct-app-page .mct-app-main {
        display: flex;
        overflow-x: visible;
        overflow-y: hidden;
    }

    /*
     * Folder 15.5% + note list 21% + editor 63.5% = exactly 100%.
     * These percentages match the established wide-PC layout while allowing all
     * three panes to shrink together instead of pushing the editor off-screen.
     */
    .mct-app-page .mc-layout {
        grid-template-columns: minmax(0, 15.5%) minmax(0, 21%) minmax(0, 63.5%);
    }

    .mct-app-page .mc-layout.mc-folders-collapsed {
        grid-template-columns: 48px minmax(0, 21%) minmax(0, 1fr);
    }

    .mct-app-page .mc-layout.mc-list-collapsed {
        grid-template-columns: minmax(0, 15.5%) 48px minmax(0, 1fr);
    }

    .mct-app-page .mc-layout.mc-folders-collapsed.mc-list-collapsed {
        grid-template-columns: 48px 48px minmax(0, 1fr);
    }

    /* Theme wrapper removes the plugin logo: search 36.5% + actions 63.5% = 100%. */
    .mct-app-page .mc-topbar,
    .mct-app-page .mc-shell:has(.mc-layout.mc-folders-collapsed) .mc-topbar,
    .mct-app-page .mc-shell:has(.mc-layout.mc-list-collapsed) .mc-topbar,
    .mct-app-page .mc-shell:has(.mc-layout.mc-folders-collapsed.mc-list-collapsed) .mc-topbar {
        grid-template-columns: minmax(0, 36.5%) minmax(0, 63.5%) !important;
        min-height: 64px;
        height: auto;
    }

    .mct-app-page .mc-global-search,
    .mct-app-page .mc-search-box,
    .mct-app-page .mc-topbar-right,
    .mct-app-page .mc-top-note-actions,
    .mct-app-page .mc-top-actions,
    .mct-app-page .mc-mode-toolbar,
    .mct-app-page .mc-mode-toolbar-label,
    .mct-app-page .mc-mode-toolbar-actions,
    .mct-app-page .mc-save-meta,
    .mct-app-page .mc-editor-actions {
        min-width: 0;
        max-width: 100%;
        box-sizing: border-box;
    }

    /*
     * Keep the note-input controls and utility controls in the same real row.
     * The previous 78% + 22% flex split exceeded 100% once gap/padding were added,
     * so the utility controls wrapped underneath even when there was enough PC width.
     */
    .mct-app-page .mc-topbar-right {
        display: grid;
        grid-template-columns: minmax(0, 1fr) auto;
        align-items: center;
        column-gap: 10px;
        row-gap: 4px;
        padding-top: 4px;
        padding-bottom: 4px;
    }

    .mct-app-page #mc-top-note-actions {
        display: flex;
        min-width: 0;
        max-width: 100%;
        flex-wrap: wrap;
        align-items: center;
        gap: 2px 10px;
    }

    .mct-app-page .mc-top-actions {
        display: flex;
        min-width: 0;
        max-width: 100%;
        flex-wrap: nowrap;
        align-items: center;
        justify-content: flex-end;
        justify-self: end;
        margin-left: 0;
    }

    /*
     * Theme 1.1.16: the save state and note commands are one desktop row.
     * The command group keeps its natural width; the update text owns the
     * remaining space and may truncate. Never wrap this toolbar into two rows.
     */
    .mct-app-page .mc-editor-pane {
        container-type: inline-size;
        container-name: mct-editor-pane;
    }

    .mct-app-page .mc-editor-toolbar {
        display: grid;
        grid-template-columns: minmax(0, 1fr) auto;
        align-items: center;
        column-gap: 10px;
        width: 100%;
        max-width: 100%;
        min-width: 0;
        height: 42px;
        min-height: 42px;
        flex: 0 0 42px;
        padding-top: 0;
        padding-bottom: 0;
        overflow: visible;
    }

    .mct-app-page .mc-save-meta {
        display: flex;
        min-width: 0;
        max-width: 100%;
        overflow: hidden;
        white-space: nowrap;
    }

    .mct-app-page .mc-save-meta #mc-save-status {
        flex: 0 0 auto;
    }

    .mct-app-page .mc-save-meta .mc-updated {
        min-width: 0;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .mct-app-page .mc-editor-actions {
        display: flex;
        min-width: 0;
        max-width: 100%;
        flex-wrap: nowrap;
        align-items: center;
        justify-content: flex-end;
        gap: 10px;
        margin-left: 0;
        overflow: visible;
        white-space: nowrap;
    }

    .mct-app-page .mc-editor-actions > .mc-editor-action {
        flex: 0 0 auto;
    }

    /* Keep one row even when the editor track itself becomes narrow. */
    @container mct-editor-pane (max-width: 900px) {
        .mc-editor-toolbar {
            column-gap: 6px;
            padding-left: 12px;
            padding-right: 12px;
        }
        .mc-save-meta .mc-updated {
            display: none;
        }
        .mc-editor-actions {
            gap: 6px;
        }
    }

    @container mct-editor-pane (max-width: 780px) {
        .mc-editor-toolbar {
            grid-template-columns: auto minmax(0, 1fr);
            column-gap: 4px;
            padding-left: 8px;
            padding-right: 8px;
        }
        .mc-save-meta {
            gap: 5px;
        }
        .mc-editor-actions {
            gap: 3px;
        }
        .mc-editor-actions > .mc-editor-action {
            position: relative;
            display: inline-flex;
            align-items: center;
            justify-content: center;
            flex: 0 0 28px;
            width: 28px;
            min-width: 28px;
            height: 30px;
            padding: 0;
        }
        .mc-editor-actions > .mc-editor-action > span {
            position: absolute;
            width: 1px;
            height: 1px;
            margin: -1px;
            padding: 0;
            overflow: hidden;
            clip: rect(0, 0, 0, 0);
            white-space: nowrap;
            border: 0;
        }
        .mc-editor-actions > .mc-editor-action svg {
            width: 15px;
            height: 15px;
        }
        #mc-history > small {
            display: none;
        }
    }

    /* The editor itself owns 100% of its grid track. */
    .mct-app-page .mc-editor-workspace > .mc-editor-wrap {
        flex: 1 1 82%;
        width: 82%;
        min-width: 0;
        max-width: 82%;
    }

    /* Attachments use a share of the editor track, never a fixed desktop pixel width. */
    .mct-app-page .mc-attachment-panel:not(.is-collapsed) {
        flex: 0 1 18%;
        width: 18%;
        min-width: 0;
        max-width: 18%;
    }

    .mct-app-page .mc-attachment-panel:not(.is-collapsed) .mc-attachment-inner {
        width: 100%;
        max-width: 100%;
        min-width: 0;
    }

    /* Markdown preview is also a percentage of the real editor track. */
    .mct-app-page .mc-editor-workspace.mc-has-markdown-preview > .mc-editor-wrap {
        flex: 0 1 65%;
        width: 65%;
        max-width: 65%;
    }

    .mct-app-page .mc-markdown-preview {
        flex: 0 1 35%;
        width: 35%;
        min-width: 0;
        max-width: 35%;
    }

    /* Special-mode toolbars may wrap, but must not set a page-level minimum width. */
    .mct-app-page .mc-handwriting-toolbar-label,
    .mct-app-page .mc-table-toolbar-label,
    .mct-app-page .mc-todo-toolbar-label,
    .mct-app-page .mc-handwriting-top-actions,
    .mct-app-page .mc-table-top-actions,
    .mct-app-page .mc-todo-top-actions {
        min-width: 0 !important;
        max-width: 100% !important;
        flex-wrap: wrap;
    }

    /* Intentional wide content scrolls locally, never through the page itself. */
    .mct-app-page .mc-table-editor-scroll,
    .mct-app-page .mc-table-import-preview-scroll,
    .mct-app-page .mc-revision-table-wrap,
    .mct-app-page .mc-code-block .mc-block-content,
    .mct-app-page .mc-markdown-preview pre {
        max-width: 100%;
        overflow-x: auto;
    }
}

@media (max-width: 820px) {
    .mct-app-page .mct-app-main > #mc-auth-root,
    .mct-app-page .mct-app-main > #mc-app-root,
    .mct-app-page .mc-shell,
    .mct-app-page.mc-page-settings .mct-app-main > #mc-app-root,
    .mct-app-page.mc-page-plan .mct-app-main > #mc-app-root,
    .mct-app-page.mc-page-settings .mc-shell,
    .mct-app-page.mc-page-plan .mc-shell {
        min-height: 640px;
    }

    .mct-app-page .mc-topbar,
    .mct-app-page .mc-shell:has(.mc-layout.mc-folders-collapsed) .mc-topbar,
    .mct-app-page .mc-shell:has(.mc-layout.mc-list-collapsed) .mc-topbar,
    .mct-app-page .mc-shell:has(.mc-layout.mc-folders-collapsed.mc-list-collapsed) .mc-topbar {
        grid-template-columns: minmax(0, 1fr) auto !important;
    }

    .mct-app-page .mc-global-search {
        grid-column: 1 !important;
    }

    .mct-app-page .mc-folders-pane,
    .mct-app-page .mc-notes-pane {
        position: absolute;
        top: 58px;
        bottom: 0;
    }

    .mct-app-page .mc-editor-pane {
        height: 100%;
        min-height: 0;
    }
}

/* Theme 1.1.4: keep plugin screens inside the real mobile viewport. */
.mct-app-page .mct-app-main,
.mct-app-page #mc-app-root,
.mct-app-page .mc-shell {
    min-width: 0;
    max-width: 100%;
}

@media (max-width: 820px) {
    .mct-app-page .mct-app-main,
    .mct-app-page .mct-app-main > #mc-auth-root,
    .mct-app-page .mct-app-main > #mc-app-root,
    .mct-app-page .mc-shell {
        width: 100%;
        max-width: 100%;
        min-width: 0;
        overflow-x: hidden;
    }
}

/* Theme 1.1.7: phone app pages use natural document scrolling. */
@media (max-width: 820px) {
    body.mct-app-page,
    body.mct-app-page.mc-body {
        display: block !important;
        min-height: 100dvh !important;
        height: auto !important;
        overflow-x: hidden !important;
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch;
    }

    .mct-app-page .mct-site-header {
        position: static !important;
    }

    .mct-app-page .mct-app-main,
    .mct-app-page.mc-page-settings .mct-app-main,
    .mct-app-page.mc-page-plan .mct-app-main {
        display: block !important;
        width: 100% !important;
        min-height: 0 !important;
        height: auto !important;
        overflow: visible !important;
    }

    .mct-app-page .mct-app-main > #mc-auth-root,
    .mct-app-page .mct-app-main > #mc-app-root,
    .mct-app-page #mc-app-root,
    .mct-app-page .mc-shell,
    .mct-app-page.mc-page-settings .mct-app-main > #mc-app-root,
    .mct-app-page.mc-page-plan .mct-app-main > #mc-app-root,
    .mct-app-page.mc-page-settings .mc-shell,
    .mct-app-page.mc-page-plan .mc-shell {
        width: 100% !important;
        max-width: 100% !important;
        min-width: 0 !important;
        min-height: 0 !important;
        height: auto !important;
        overflow: visible !important;
    }

    .mct-app-page .mc-shell {
        min-height: 100dvh !important;
    }

    .mct-app-page .mc-folders-pane,
    .mct-app-page .mc-notes-pane {
        position: fixed !important;
        top: 0 !important;
        bottom: 0 !important;
    }

    .mct-app-page .mc-editor-pane {
        height: auto !important;
        min-height: calc(100dvh - 58px) !important;
        overflow: visible !important;
    }
}
