/*
 * UI25 responsive layer: loaded last, so desktop styling elsewhere is untouched and everything here
 * only applies below the stated widths or on touch screens.
 *
 *   >900px   desktop: nothing in this file changes the layout
 *   <=900px  tablet:  static top bar, collapsible organization menu
 *   <=600px  phone:   tighter spacing, full-screen dialogs
 *   coarse pointer:   comfortable tap targets
 */

html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
img, svg, video, canvas { max-width: 100%; height: auto; }

/* The organization menu wrapper is invisible on desktop. */
.org-menu-summary { display: none; }

/*
 * Laptop widths (901-1500px). The top bar's brand, links, search and account area add up to more
 * than the screen, the links were allowed to shrink below their content, and "Administration"
 * ended up underneath the search box. Let the links keep their size, drop the redundant tagline
 * and make the search box give way.
 */
@media (min-width: 901px) and (max-width: 1500px) {
    .topbar { gap: 16px; }
    .brand { min-width: 0; }
    .brand span { display: none; }
    .global-nav { flex: 0 0 auto; }
    .toolbar-global-search { flex: 1 1 200px; min-width: 150px; max-width: 340px; }
}
@media (min-width: 901px) and (max-width: 1180px) {
    .user-profile-chip-label { display: none; }
}
/* Between 901 and 1020px even that is too tight: use the stacked layout the phone view uses. */
@media (min-width: 901px) and (max-width: 1020px) {
    .topbar { flex-wrap: wrap; align-items: center; padding: 10px 16px; position: static; }
    .global-nav { order: 3; flex: 1 1 100%; overflow-x: auto; }
    .toolbar-global-search { order: 2; flex: 1 1 100%; max-width: none; margin-left: 0; }
}

@media (max-width: 900px) {
    /* A sticky top bar that wraps to three rows would cover a quarter of a phone screen. */
    .topbar { position: static; }

    .org-sidebar { padding: 10px 12px; gap: 10px; }
    .org-switcher { margin-bottom: 0; }

    .org-menu-summary {
        display: flex;
        align-items: center;
        gap: 10px;
        min-height: 44px;
        padding: 0 14px;
        border: 1px solid var(--line);
        border-radius: 10px;
        background: var(--surface);
        color: var(--text);
        font-weight: 700;
        cursor: pointer;
        list-style: none;
        user-select: none;
    }
    .org-menu-summary::-webkit-details-marker { display: none; }
    .org-menu-current {
        margin-left: auto;
        max-width: 55%;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        color: var(--accent);
        font-size: 13px;
        font-weight: 600;
    }
    .org-menu-chevron { color: var(--muted); transition: transform .15s ease; }
    .org-menu[open] .org-menu-chevron { transform: rotate(180deg); }

    /* The list: two columns of full-size tap targets instead of one endless horizontal row. */
    .org-nav {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 6px;
        overflow: visible;
        padding: 10px 0 2px;
    }
    .org-nav a {
        min-height: 44px;
        white-space: normal;
        flex-shrink: 1;
        background: var(--surface);
        border: 1px solid var(--line);
    }
    .org-nav a.active { box-shadow: inset 3px 0 0 var(--accent); }
    .org-nav-separator { display: none; }
    .org-nav-group { grid-column: 1 / -1; }
    .org-nav-group > summary { min-height: 44px; display: flex; align-items: center; justify-content: space-between; }
    .org-nav-submenu { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; padding-top: 6px; }

    /* Long names (hostnames, file names, URLs) wrap instead of pushing the page wider than the screen. */
    main :where(h1, h2, h3, h4, p, li, dt, dd, small, strong, label, a, span, td, th, code) { overflow-wrap: anywhere; }

    /* The "+" menu opens from a button at the left edge, so anchor it there, not to the button's right edge. */
    .ui11-add-options { left: 0; right: auto; max-width: calc(100vw - 28px); }

    /* Later stylesheets re-declare these two-column layouts after their own narrow-screen rules. */
    .profile-layout { grid-template-columns: minmax(0, 1fr); }
    .document-view-heading-copy-line { width: auto; }
    .document-view-heading-copy-line h1 { white-space: normal; overflow-wrap: anywhere; }

    /* iOS zooms the page when a field under 16px is focused; keep forms at their real size. */
    input:not([type="checkbox"]):not([type="radio"]):not([type="range"]),
    select,
    textarea { font-size: 16px; }
}

@media (max-width: 600px) {
    .topbar { padding: 8px 12px; }
    .brand span { display: none; }

    /* Record pop-ups use the whole screen on a phone; dvh follows the browser's collapsing address bar. */
    .record-modal-dialog {
        width: 100vw;
        height: 100vh;
        height: 100dvh;
        max-width: 100vw;
        border-radius: 0;
        border-width: 0;
    }
    .record-modal-dialog-head { padding: 8px 12px 8px 16px; }

    /* Import / Export menus open from buttons near the left edge on a phone. */
    .ui16-export-panel { left: 0; right: auto; max-width: calc(100vw - 28px); }
}

@media (max-width: 380px) {
    .org-nav, .org-nav-submenu { grid-template-columns: 1fr; }
}

/* Touch screens: comfortable tap targets without changing the desktop look. */
@media (pointer: coarse) {
    .button, button.linkbtn, .top-link, .user-profile-chip,
    .density-menu-button, .favorites-toolbar-button,
    .toolbar-search-submit { min-height: 40px; }
    .top-link, .linkbtn { display: inline-flex; align-items: center; }
}
