/* VoriTools 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;
    }
}

/* Phone tap targets and legibility, measured on the live site at 390x844:
 * the header toggle was 35x30 px, footer links 13-18 px tall, the back-to-top
 * button and the small copy buttons around 25 px, and the footer copy sat at
 * 11 px.  Everything below is scoped to the phone breakpoint so the desktop
 * layout is untouched. */
@media (max-width: 767px) {
    .navbar-toggle {
        min-width: 44px;
        min-height: 44px;
    }

    .navbar-brand {
        display: inline-flex;
        min-height: 44px;
        align-items: center;
    }

    #footer a {
        display: inline-flex;
        min-height: 34px;
        padding: 3px 4px;
        align-items: center;
        font-size: 12px;
    }

    #footer,
    #footer span {
        font-size: 12px;
    }

    .kiv-footer-policy,
    .kiv-footer-languages {
        display: inline-flex;
        flex-wrap: wrap;
        align-items: center;
    }

    .gotop {
        width: 44px;
        height: 44px;
    }

    .kiv-reference-copy,
    button[class*="copy"],
    [class*="copy-btn"] {
        min-width: 34px;
        min-height: 34px;
    }
}

/* Second pass, same breakpoint: the category strip link ("View category: …"),
 * the home featured chips and the 10 px meta labels were still under the
 * 34 px / 12 px bar measured at 390x844.  Superseded by the third pass,
 * which re-declares the same selectors with the specificity the cascade
 * actually needs. */
/* Third pass.  The label rules below lost the cascade to more specific
 * desktop rules measured on the live pages (e.g. `.kiv-ui .kiv-locale-code`
 * at 10 px beat `.kiv-locale-code` at 12 px), so they are re-declared on the
 * shell element and given an explicit floor.  The home page labels were the
 * other leftovers found by the live sweep: the featured eyebrow/tag text was
 * 8-11 px and the search suggestion chips 11.5 px at 390x844. */
@media (max-width: 767px) {
    .kiv-category-route a,
    .kiv-home-featured-link {
        display: inline-flex;
        min-height: 34px;
        align-items: center;
    }

    html body .kiv-locale-code,
    html body .kiv-tool-library-eyebrow,
    html body .kiv-shell-section-title,
    html body .kiv-shell-result-meta,
    html body .kiv-shell-footnote,
    html body.kiv-ui-home .kiv-home-featured-eyebrow,
    html body.kiv-ui-home .kiv-home-catalog-eyebrow,
    html body.kiv-ui-home .kiv-home-featured-tag,
    html body.kiv-ui-home .kiv-home-featured-card.is-spotlight .kiv-home-featured-tag,
    html body.kiv-ui-home .kiv-home-search-suggestions button {
        font-size: 12px !important;
    }

    html body.kiv-ui-home .kiv-home-search::after {
        font-size: 12px;
        letter-spacing: .06em;
    }
}
