/* KivTools phone geometry fixes
 *
 * Companion to the ui-* surfaces.  Desktop workbenches that were built as a
 * fixed column (or a fixed pixel height) are re-scoped to the phone viewport
 * here, so the page scrolls vertically only and every wide table gets its own
 * horizontal scroller.  Loaded on every route; every rule is viewport scoped.
 */

/* Special characters reference: the symbol rows are long unbreakable runs
 * that widen the document on every viewport. */
html[data-kiv-tool="tesufuhao"] .panel-body {
    overflow-wrap: anywhere;
    word-break: break-word;
}

@media (max-width: 767px) {
    /* Reference pages run their own scroll wrapper around each data table.
     * Make sure the wrapper, and not the document, is what scrolls. */
    .kiv-reference-table-scroll,
    body.kiv-contextual-nav-page .kiv-contextual-nav-root .table-responsive {
        max-width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        overscroll-behavior-inline: contain;
    }

    /* Tables that still sit directly in their column: give the table itself a
     * scroll box instead of letting the whole page slide sideways. */
    body.kiv-contextual-nav-page .kiv-contextual-nav-root .table {
        display: block;
        width: 100%;
        max-width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    /* Refresh tool: the preview frame is empty until a run starts, and an
     * empty 600px frame is the largest block on the phone screen. */
    iframe#frame:not([src]) {
        display: none;
    }

    iframe#frame {
        height: min(60vh, 420px) !important;
        min-height: 240px;
        padding: 0;
    }

    /* Side-by-side JSON editor: keep both panes usable but stop the fixed
     * 530px column from dominating a small screen. */
    #json-src {
        height: min(42vh, 300px) !important;
        max-height: min(42vh, 300px) !important;
    }

    #json-target {
        height: auto !important;
        min-height: min(42vh, 300px);
        max-height: min(60vh, 440px);
    }

    /* Legacy widget pages that fix their own width (calculator family). */
    html[data-kiv-tool="calculator"] .CalculatorWrap .CalculTable,
    html[data-kiv-tool="calculator"] .CalculatorWrap .ShowAreaWrap,
    html[data-kiv-tool="calculator"] .CalculatorWrap .ShowArea {
        width: 100% !important;
        max-width: 100% !important;
    }

    /* Rich text editors (KindEditor) are injected with a fixed 650px frame. */
    body.kiv-contextual-nav-page .kiv-contextual-nav-root .ke-container {
        width: 100% !important;
        max-width: 100% !important;
    }

    /* macOS app builder: the generated file chips stay on one line and push
     * the preview panel out of the viewport. */
    #mac-files {
        display: flex;
        max-width: 100%;
        flex-wrap: wrap;
        gap: 6px;
    }

    #mac-files .app-file-chip {
        max-width: 100%;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    /* Keyboard tester: the key map is a fixed 890px board, keep it pannable
     * inside the panel instead of pushing the document sideways. */
    html[data-kiv-tool="keyboardtest"] #anjian_test {
        width: 100% !important;
        max-width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    html[data-kiv-tool="keyboardtest"] #anjian_test_xia {
        width: 100% !important;
    }

    /* Data workbenches: the pipeline rail keeps every node on one row and the
     * nowrap labels widen the grid past the viewport. */
    .dw-pipeline {
        grid-template-columns: repeat(auto-fit, minmax(min(100%, 150px), 1fr));
    }

    .dw-pipeline-node {
        white-space: normal;
    }

    /* Analog clock widget: the dial is a fixed 400px circle. */
    html[data-kiv-tool="shizhong"] .box {
        width: 100% !important;
        padding-top: 24px !important;
        transform: none !important;
    }

    html[data-kiv-tool="shizhong"] .clock {
        zoom: .82;
    }

    /* Special characters reference: plain code tables without a Bootstrap
     * class still have to scroll in their column. */
    html[data-kiv-tool="tesufuhao"] .panel-body table {
        display: block;
        width: 100%;
        max-width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
}
