/**
 * Smartphone / small-device layout fixes.
 * Loaded after style.css. Prefer stacking and wrapping over horizontal squeeze.
 */

.courses-org-selector {
    max-width: 400px;
}

@media (max-width: 767px) {
    /*
     * Overlay drawer width (phones). The red topbar logo strip is sized
     * separately below so it does not steal space from bell / menu / name.
     */
    :root {
        --mobile-nav-width: min(300px, 78vw);
    }

    .page-topbar .logo-area,
    .page-topbar.sidebar_shift .logo-area {
        width: auto !important;
        max-width: 128px !important;
        flex: 0 0 auto;
        justify-content: flex-start;
        box-sizing: border-box;
        padding: 0 8px 0 10px;
        min-height: 60px;
        background-image: none !important;
    }

    .page-topbar .logo-area .logo-area-link {
        display: flex !important;
        align-items: center;
        justify-content: flex-start;
        width: auto !important;
        min-height: 60px !important;
        padding: 0;
    }

    .page-topbar .logo-area .topbar-mobile-brand-mark {
        display: block;
        max-height: 28px;
        width: auto;
        max-width: 110px;
        height: auto;
        object-fit: contain;
    }

    .page-topbar .logo-area.logo-area-fr .topbar-mobile-brand-mark {
        max-height: 26px;
        max-width: 110px;
    }

    .courses-org-selector {
        max-width: 100% !important;
        width: 100%;
    }

    /* Allow readable page titles and action buttons without float overlap */
    .page-title {
        display: flex;
        flex-direction: column;
        align-items: stretch;
        gap: 0.5rem;
    }

    .page-title .float-left,
    .page-title .float-right {
        float: none !important;
        width: 100%;
        max-width: 100%;
    }

    .page-title h1,
    .page-title h1.title {
        font-size: 1.35rem;
        line-height: 1.25;
        margin-bottom: 0.25rem;
        word-break: break-word;
    }

    .page-title .float-right {
        display: flex;
        flex-wrap: wrap;
        gap: 0.4rem;
    }

    .page-title .float-right > .btn,
    .page-title .float-right > a.btn,
    .page-title .float-right > button.btn {
        flex: 1 1 auto;
        margin: 0 !important;
        text-align: center;
    }

    /* Panel headers: absolute .actions overlap titles when many buttons */
    section.box > header.panel_header,
    section.box header.panel_header {
        height: auto !important;
        min-height: 0;
        padding-bottom: 0.5rem;
        overflow: visible;
    }

    section.box header.panel_header .title,
    section.box header .title.float-left {
        float: none !important;
        display: block;
        width: 100%;
        max-width: 100%;
        padding-right: 15px;
        white-space: normal;
        line-height: 1.35;
        word-break: break-word;
    }

    section.box .actions.panel_actions,
    section.box .actions {
        position: static !important;
        float: none !important;
        right: auto;
        top: auto;
        margin: 0;
        padding: 0 15px 12px;
        line-height: normal;
        display: flex;
        flex-wrap: wrap;
        gap: 0.35rem;
        align-items: center;
    }

    section.box .actions .btn {
        margin: 0;
    }

    /* Tighten content padding on phones */
    section .content-body {
        padding: 14px 12px;
    }

    .main-wrapper {
        padding-left: 8px;
        padding-right: 8px;
    }

    /* Org selector and similar selects fill the viewport */
    .courses-org-selector,
    select.courses-org-selector {
        max-width: 100% !important;
        width: 100%;
    }

    /* Horizontally scrollable tab strips */
    ul.nav.nav-tabs {
        display: flex;
        flex-wrap: nowrap;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        gap: 0;
        margin-bottom: 0.75rem !important;
        padding-bottom: 2px;
    }

    ul.nav.nav-tabs .nav-item {
        flex: 0 0 auto;
        white-space: nowrap;
    }

    ul.nav.nav-tabs .nav-link {
        padding: 0.55rem 0.85rem;
    }

    /* Search / filter input groups stack instead of overflowing */
    .people-search-form.input-group,
    form.people-search-form .input-group,
    .people-search-form {
        display: flex;
        flex-direction: column;
        align-items: stretch;
        width: 100%;
    }

    .people-search-form > .input-group-prepend,
    .people-search-form > .input-group-append,
    .people-search-form > .custom-select,
    .people-search-form > .form-control,
    .people-search-form > .btn {
        width: 100%;
        max-width: 100%;
        margin: 0 0 0.4rem;
    }

    .people-search-form .input-group-prepend,
    .people-search-form .input-group-append {
        display: block;
    }

    .people-search-form .input-group-text,
    .people-search-form .custom-select,
    .people-search-form .form-control,
    .people-search-form input.form-control,
    .people-search-form .btn {
        width: 100% !important;
        max-width: 100%;
        border-radius: 0.25rem !important;
    }

    /* Tables: keep horizontal scroll; enlarge tap targets in action cells */
    .table-responsive {
        margin-bottom: 0.5rem;
        -webkit-overflow-scrolling: touch;
    }

    .table td .btn-link,
    .table td a.btn-link,
    .table td button.btn-link {
        display: inline-block;
        padding: 0.4rem 0.15rem !important;
        margin: 0.1rem 0.35rem 0.1rem 0;
        min-height: 36px;
        line-height: 1.3;
        vertical-align: middle;
    }

    /* Hide "|" separators between action links (text nodes inherit font-size: 0) */
    .table td[data-priority="6"],
    .table td.people-actions-cell {
        font-size: 0;
        line-height: 0;
    }

    .table td[data-priority="6"] > *,
    .table td.people-actions-cell > * {
        font-size: 0.875rem;
        line-height: 1.35;
        display: block;
        margin: 0.2rem 0;
        width: 100%;
        text-align: left;
    }

    .table td[data-priority="6"] form,
    .table td.people-actions-cell form {
        display: block;
        margin: 0.2rem 0;
    }

    .table td[data-priority="6"] .btn-link,
    .table td.people-actions-cell .btn-link {
        display: block;
        width: 100%;
        margin: 0;
        padding: 0.45rem 0 !important;
        min-height: 40px;
    }

    .table td.people-actions-cell .btn,
    .table td.people-actions-cell form {
        display: block;
        width: 100%;
        margin: 0.25rem 0 !important;
    }

    .table td.people-actions-cell form.d-inline {
        display: block !important;
    }

    /* Modals nearly full-bleed on phones */
    .modal-dialog {
        margin: 0.5rem;
        max-width: calc(100% - 1rem);
    }

    .modal-dialog.modal-lg,
    .modal-dialog.modal-xl {
        max-width: calc(100% - 1rem);
    }

    .modal-body {
        padding: 0.85rem;
    }

    /* Quick-eval sticky header stacks controls */
    .sticky-eval-header {
        padding: 10px 12px !important;
        top: 60px;
    }

    .sticky-eval-header > .d-flex {
        flex-direction: column !important;
        align-items: stretch !important;
        gap: 0.75rem;
    }

    .sticky-eval-header .d-flex.align-items-center {
        flex-wrap: wrap;
        gap: 0.4rem;
        justify-content: flex-start !important;
    }

    .sticky-eval-header h4 {
        font-size: 1.05rem;
        line-height: 1.3;
        word-break: break-word;
    }

    .sticky-eval-header #performance-level,
    .sticky-eval-header select.form-control,
    .sticky-eval-header select.form-control-sm {
        width: 100% !important;
        max-width: 100%;
    }

    .sticky-eval-header .btn,
    .sticky-eval-header a.btn {
        margin: 0 !important;
        flex: 1 1 auto;
    }

    .sticky-eval-header .quick-pick-group {
        width: 100%;
    }

    .sticky-eval-header .quick-pick-btn {
        min-height: 40px;
        font-size: 13px;
        padding: 10px 6px;
    }

    /* Forms: full-width controls where squeezed */
    .form-inline {
        flex-direction: column;
        align-items: stretch !important;
    }

    .form-inline .form-control,
    .form-inline .btn {
        width: 100%;
        margin: 0 0 0.4rem;
    }

    /* Checklist classlist toolbar already flex-wraps; ensure buttons don't overflow */
    .classlist-view-toolbar .btn,
    .classlist-bulk-actions .btn {
        flex: 1 1 auto;
        text-align: center;
        white-space: normal;
    }

    /* Alerts and buttons: comfortable touch */
    .btn-sm {
        min-height: 36px;
        padding-top: 0.35rem;
        padding-bottom: 0.35rem;
    }

    .alert {
        word-break: break-word;
    }

    /* Avoid fixed-width inline styles blowing out the viewport */
    .content-body input.form-control[style*="width"],
    .content-body select.form-control[style*="width"],
    .content-body .form-control[style*="width:70%"],
    .content-body .form-control[style*="width: 70%"] {
        width: 100% !important;
        max-width: 100%;
    }

    /*
     * Overlay drawer rules live in the 1024px block below (covers phones too).
     * Do not set .page-sidebar { width: 0 } here — see the incident comment there.
     */
    #main-content,
    #main-content.sidebar_shift,
    #main-content.chat_shift {
        margin-left: 0 !important;
        margin-right: 0 !important;
    }
}

/*
 * Tablets (and landscape phones up to the theme's 1025px collapse): same overlay
 * drawer as phones. The 60px icon rail otherwise steals width from tables.
 */
@media (max-width: 1024px) {
    :root {
        --mobile-nav-width: min(300px, 78vw);
    }

    /*
     * Overlay drawer — not a persistent mini icon rail overlapping content.
     *
     * Past incident (staging organization-view after PR #480): closed-state
     * `width: 0` plus `transform: translateX(-100%)` is a no-op, because
     * translate percentages are of the element's own width (100% of 0 is 0).
     * Ultra Admin also sets `.page-sidebar.collapseit { overflow: visible
     * !important; position: absolute !important }` and `.wraplist { width:
     * 60px }`, so the 60px icon rail (Me/Club/Admin hats wrapping, labels
     * like "Fil", white icons with no text) stayed on screen. Keep a real
     * drawer width so the translate leaves the viewport, beat overflow and
     * position with !important, and force wraplist to the full drawer width.
     */
    .page-sidebar,
    .page-sidebar.collapseit,
    .page-sidebar.chat_shift {
        width: var(--mobile-nav-width) !important;
        max-width: var(--mobile-nav-width);
        min-width: 0;
        margin-left: 0 !important;
        left: 0;
        position: fixed !important;
        z-index: 3000;
        transform: translateX(-100%);
        overflow: hidden !important;
        pointer-events: none;
        box-shadow: none;
        visibility: hidden;
    }

    .page-sidebar.collapseit #main-menu-wrapper,
    .page-sidebar.chat_shift #main-menu-wrapper {
        overflow: hidden !important;
    }

    .page-sidebar.collapseit .wraplist,
    .page-sidebar.chat_shift .wraplist,
    .page-sidebar .wraplist {
        width: 100% !important;
        max-width: 100% !important;
    }

    .page-sidebar.expandit {
        width: var(--mobile-nav-width) !important;
        transform: none;
        pointer-events: auto;
        visibility: visible;
        overflow-x: hidden !important;
        overflow-y: auto !important;
        box-shadow: 4px 0 18px rgba(0, 0, 0, 0.28);
        -webkit-overflow-scrolling: touch;
    }

    /* Theme hides .title/.arrow in the 60px rail; the overlay drawer needs labels. */
    .page-sidebar.expandit .wraplist li .title,
    .page-sidebar.expandit .wraplist li .arrow {
        display: inline-block !important;
    }

    .page-sidebar.expandit .menu-hat-switch {
        display: flex;
        flex-wrap: nowrap;
        align-items: stretch;
    }

    .page-sidebar.expandit .menu-hat-btn {
        white-space: nowrap;
        min-width: 0;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .page-sidebar.expandit .menu-hat-club-name {
        white-space: normal;
        overflow: visible;
        text-overflow: unset;
    }

    #main-content,
    #main-content.sidebar_shift,
    #main-content.chat_shift {
        margin-left: 0 !important;
        margin-right: 0 !important;
    }

    .page-sidebar-backdrop {
        display: none;
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.45);
        z-index: 2999;
    }

    .page-sidebar.expandit + .page-sidebar-backdrop {
        display: block;
    }
}

/*
 * Keyboard open (class set by mobile-viewport.js from visualViewport).
 * iOS does not shrink the layout viewport, so max-height media queries never
 * fire — this class is what actually frees the remaining strip in landscape.
 */
html.keyboard-open .page-topbar {
    display: none !important;
}

html.keyboard-open .page-sidebar,
html.keyboard-open .page-sidebar.expandit,
html.keyboard-open .page-sidebar.collapseit {
    display: none !important;
}

html.keyboard-open .main-wrapper,
html.keyboard-open .wrapper.main-wrapper {
    margin-top: 0 !important;
    padding-top: 8px;
}

html.keyboard-open #main-content,
html.keyboard-open #main-content.sidebar_shift,
html.keyboard-open #main-content.chat_shift {
    margin-left: 0 !important;
    margin-right: 0 !important;
}

html.keyboard-open .sticky-eval-header {
    top: 0;
}

/* Slightly larger phones / small tablets in portrait */
@media (max-width: 991px) {
    .page-title h1 {
        font-size: 1.5rem;
    }

    section.box .actions.panel_actions {
        max-width: 100%;
    }
}

/*
 * Guest login (and forgot-password / create-account pages that share login_page).
 * .btn-red is referenced by the login form but was never defined, so Sign In
 * rendered as Bootstrap's default grey button.
 */
body.login_page:not(.login-new) .btn-red {
    background-color: #c62828;
    border-color: #b71c1c;
    color: #fff;
    font-family: inherit;
    font-weight: 600;
    font-size: 16px;
    letter-spacing: 0.02em;
    line-height: 1.2;
    min-height: 48px;
    padding: 12px 16px;
    border-radius: 8px;
}

body.login_page:not(.login-new) .btn-red:hover,
body.login_page:not(.login-new) .btn-red:focus {
    background-color: #b71c1c;
    border-color: #9a1818;
    color: #fff;
}

body.login_page:not(.login-new) .login-lang {
    text-align: right;
    margin: 10px 0 16px;
}

body.login_page:not(.login-new) .login-lang a {
    color: #1a1a1a;
    font-weight: 600;
}

body.login_page:not(.login-new) .login-field {
    margin-bottom: 12px;
}

body.login_page:not(.login-new) .login-field label {
    display: block;
    margin-bottom: 4px;
    color: #1a1a1a;
}

body.login_page:not(.login-new) .login-password-wrap {
    position: relative;
    display: block;
    width: 100%;
}

body.login_page:not(.login-new) .login-password-wrap .input {
    width: 100%;
    padding-right: 44px;
    margin-bottom: 0;
}

body.login_page:not(.login-new) .login-toggle-password {
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    cursor: pointer;
    padding: 8px;
    line-height: 1;
}

body.login_page:not(.login-new) .login-toggle-password i {
    font-size: 18px;
    color: #555;
}

body.login_page:not(.login-new) .login-links {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
    margin: 4px 0 0;
}

body.login_page:not(.login-new) .login-links a {
    float: none;
}

@media (max-width: 767px) {
    /*
     * login-logo.jpg is 1024x504. Scale it to the column (a fixed 400px
     * min-width clipped the bilingual title on phones) and sit the form on
     * a card so labels stay readable over the sail photo.
     */
    body.login_page:not(.login-new) {
        background-attachment: scroll;
        background-position: center top;
        background-size: cover;
        padding-top: env(safe-area-inset-top);
        padding-bottom: env(safe-area-inset-bottom);
    }

    body.login_page:not(.login-new) .loginpage {
        padding: 0 16px 28px;
        max-width: 100%;
        box-sizing: border-box;
    }

    body.login_page:not(.login-new) .loginpage h1 {
        margin: 0;
    }

    body.login_page:not(.login-new) .loginpage h1 a {
        min-width: 0;
        min-height: 0;
        width: 100%;
        max-width: 100%;
        height: auto;
        aspect-ratio: 1024 / 504;
        background-size: contain;
        background-position: center top;
        box-sizing: border-box;
        border-radius: 0 0 10px 10px;
    }

    body.login_page:not(.login-new) .login-lang a {
        display: inline-block;
        padding: 8px 12px;
        background: #fff;
        border-radius: 6px;
        box-shadow: 0 1px 4px rgba(0, 0, 0, 0.12);
        text-decoration: none;
    }

    body.login_page:not(.login-new) .login-panel {
        background: #fff;
        border-radius: 12px;
        box-shadow: 0 8px 28px rgba(0, 0, 0, 0.16);
        padding: 18px 16px 16px;
        margin-top: 4px;
    }

    body.login_page:not(.login-new) .login-links a {
        display: inline-block;
        min-height: 44px;
        padding: 10px 0;
        font-size: 16px;
        line-height: 1.3;
    }

    body.login_page:not(.login-new) .loginpage form {
        margin-top: 0;
        margin-bottom: 8px;
        overflow: visible;
    }

    body.login_page:not(.login-new) .loginpage form .input,
    body.login_page:not(.login-new) .loginpage input[type=text],
    body.login_page:not(.login-new) .loginpage input[type=password] {
        font-size: 16px !important;
        line-height: 1.35;
        padding: 12px 14px;
        margin: 0 0 4px;
        border: 1px solid #c5c5c5 !important;
        border-radius: 8px;
        background: #fff;
        color: #1a1a1a;
    }

    body.login_page:not(.login-new) .loginpage form .input::placeholder,
    body.login_page:not(.login-new) .loginpage input::placeholder {
        color: #5c5c5c;
        opacity: 1;
        font-size: 13px;
    }

    body.login_page:not(.login-new) .loginpage form .input:focus,
    body.login_page:not(.login-new) .loginpage input:focus {
        background-color: #fff;
        border-color: #c62828 !important;
        outline: none;
        box-shadow: 0 0 0 3px rgba(198, 40, 40, 0.18);
    }

    body.login_page:not(.login-new) .loginpage #nav a,
    body.login_page:not(.login-new) .loginpage .login-links a,
    body.login_page:not(.login-new) .loginpage #nav a:hover,
    body.login_page:not(.login-new) .loginpage .login-links a:hover {
        color: #1565c0;
    }

    body.login_page:not(.login-new) .login-lang a,
    body.login_page:not(.login-new) .login-lang a:hover {
        color: #1a1a1a;
    }
}
