/* Shared user, guest and wiki layouts. Admin layouts do not load this file. */

.pwa-install-notice {
    display: none;
}

@media (display-mode: browser) and (max-width: 767.98px) {
    .pwa-install-notice:not([hidden]) {
        display: block;
    }

    html[data-ui="minimal-dark"] .dashboard-page > .container > .pwa-install-notice {
        /* Match the news order so the notice follows it in document order. */
        order: -3;
    }

    .pwa-install-notice summary {
        display: flex;
        align-items: center;
        justify-content: center;
        gap: .5rem;
        list-style: none;
        min-height: 44px;
    }

    .pwa-install-notice summary::-webkit-details-marker {
        display: none;
    }
}

@media (display-mode: standalone) {
    :is([data-app-sidebar], [data-app-offcanvas-nav]) a[href="/admin"] {
        display: none !important;
    }
}

/* Bound nested settings grids to the space inside their cards. */
body:not([data-admin-shell-page]) .user-settings-stack,
body:not([data-admin-shell-page]) .user-settings-section {
    grid-template-columns: minmax(0, 1fr);
    min-width: 0;
}

body:not([data-admin-shell-page]) .user-settings-stack > *,
body:not([data-admin-shell-page]) .user-settings-section > *,
body:not([data-admin-shell-page]) .user-settings-form-grid > *,
body:not([data-admin-shell-page]) .user-settings-section-header > div {
    min-width: 0;
    max-width: 100%;
}

body:not([data-admin-shell-page]) .user-settings-section-header {
    overflow-wrap: anywhere;
}

/* The available map width also depends on the desktop sidebar. */
body:not([data-admin-shell-page]) .map-toolbar-grid-dynamic,
body:not([data-admin-shell-page]) .map-toolbar-grid-off-map {
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 18rem), 1fr));
}

body:not([data-admin-shell-page]) .map-toolbar .map-zoom-control {
    grid-template-columns: repeat(auto-fit, minmax(2.35rem, 1fr));
    min-width: 0;
    width: 100%;
    max-width: 22rem;
}

body:not([data-admin-shell-page]) .map-toolbar-switches .form-check {
    min-width: 0;
    max-width: 100%;
}

body:not([data-admin-shell-page]) .map-toolbar-switches .form-check-label {
    min-width: 0;
    overflow-wrap: anywhere;
}

body.wiki-site:not([data-admin-shell-page]) .wiki-card {
    min-width: 0;
    overflow-wrap: anywhere;
}

@media (max-width: 575.98px) {
    /* Filters stay side by side; actions get their own full-width row. */
    .notification-filter-controls,
    .notification-filter-actions {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .notification-filter-actions {
        grid-column: 1 / -1;
    }

    .notification-filter-controls select {
        font-size: 16px;
    }

    .notification-history-page :is(.notification-filter-controls, .notification-row-actions) :is(.form-select, .btn) {
        min-height: 44px;
        touch-action: manipulation;
    }

    .notification-row-actions .btn {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        gap: .35rem;
        flex: 1 1 8rem;
        width: auto;
    }

    body:not([data-admin-shell-page]) #navbar > .container-fluid {
        flex-wrap: wrap;
        row-gap: .35rem;
    }

    body:not([data-admin-shell-page]) .ds-topbar-actions {
        flex-wrap: wrap;
        min-width: 0;
        max-width: 100%;
        margin-left: auto;
    }

    body:not([data-admin-shell-page]) .user-settings-risk-zone {
        flex-wrap: wrap;
    }
}

@media (max-width: 767.98px) {
    body:not([data-admin-shell-page]) .map-toolbar-grid-dynamic,
    body:not([data-admin-shell-page]) .map-toolbar-grid-off-map {
        grid-template-columns: minmax(0, 1fr);
    }

    /* Keep the unit and removal action above the operator and value. */
    body:not([data-admin-shell-page]) #tab-recognition-pane .condition-item {
        display: grid !important;
        grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) 2.5rem;
        gap: .4rem;
        min-width: 0;
    }

    body:not([data-admin-shell-page]) #tab-recognition-pane .condition-item > img {
        grid-column: 1;
        grid-row: 1;
        margin: 0 !important;
    }

    body:not([data-admin-shell-page]) #tab-recognition-pane .condition-item > span {
        grid-column: 1 / 3;
        grid-row: 1;
        min-width: 0;
        margin: 0 !important;
        padding-left: 1.75rem;
        overflow-wrap: anywhere;
    }

    body:not([data-admin-shell-page]) #tab-recognition-pane .condition-item > .form-select {
        grid-column: 1;
        grid-row: 2;
        min-width: 0;
        width: 100%;
        margin: 0 !important;
    }

    body:not([data-admin-shell-page]) #tab-recognition-pane .condition-item > .form-control {
        grid-column: 2 / 4;
        grid-row: 2;
        min-width: 0;
        width: 100%;
    }

    body:not([data-admin-shell-page]) #tab-recognition-pane .condition-item > .btn-remove-unit {
        grid-column: 3;
        grid-row: 1;
        box-sizing: border-box;
        width: 2.5rem;
        height: 2.5rem;
        margin: 0 !important;
    }

    /* A wrapping footer must not set the minimum width of an empty table. */
    body:not([data-admin-shell-page]) .ds-attacks-page .dt-container {
        grid-template-columns: minmax(0, 1fr);
    }

    body:not([data-admin-shell-page]) .ds-attacks-page .dt-container,
    body:not([data-admin-shell-page]) .ds-attacks-page .ds-datatable-footer,
    body:not([data-admin-shell-page]) .ds-attacks-page .ds-datatable-footer > *,
    body:not([data-admin-shell-page]) .ds-attacks-page .dt-paging nav {
        min-width: 0;
        max-width: 100%;
    }

    body:not([data-admin-shell-page]) .ds-attacks-page .dt-paging .pagination {
        flex-wrap: wrap;
        row-gap: .35rem;
        max-width: 100%;
    }
}

@media (max-width: 520px) {
    body.wiki-site:not([data-admin-shell-page]) .wiki-card-grid {
        grid-template-columns: minmax(0, 1fr);
    }
}

/* One calm phone header; secondary actions live in a labelled drawer. */
body:not([data-admin-shell-page]) .ds-mobile-actions-toggle,
body:not([data-admin-shell-page]) .ds-mobile-action-label,
body:not([data-admin-shell-page]) .ds-mobile-alert {
    display: none;
}

body:not([data-admin-shell-page]) .ds-topbar-panel {
    min-width: 0;
    margin-left: auto;
}

@media (max-width: 767.98px) {
    body:not([data-admin-shell-page]) .ds-shell-header:has(.ds-topbar-panel) {
        backdrop-filter: none;
    }

    body:not([data-admin-shell-page]) .ds-shell-header:has(#appActionsOffcanvas:is(.show, .showing, .hiding)) {
        z-index: 1045;
    }

    body:not([data-admin-shell-page]) #navbar:has(.ds-topbar-panel) > .container-fluid {
        flex-wrap: nowrap;
        gap: .5rem;
        padding-inline: .75rem;
    }

    body:not([data-admin-shell-page]) #navbar:has(.ds-topbar-panel) .ds-brand {
        display: inline-flex;
        margin: 0;
    }

    body:not([data-admin-shell-page]) #navbar:has(.ds-topbar-panel) .ds-brand img {
        width: 2rem;
        height: 2rem !important;
    }

    body:not([data-admin-shell-page]) #navbar:has(.ds-topbar-panel) .ds-mobile-nav-toggle,
    body:not([data-admin-shell-page]) #navbar .ds-mobile-actions-toggle {
        min-width: 2.75rem;
        min-height: 2.75rem;
    }

    body:not([data-admin-shell-page]) #navbar .ds-mobile-actions-toggle {
        display: inline-flex;
        position: relative;
        gap: .4rem;
        width: auto;
        padding-inline: .65rem;
        margin-left: auto;
        font-size: .85rem;
        font-weight: 650;
    }

    body:not([data-admin-shell-page]) #navbar:has(.ds-topbar-panel) .ds-world-pill-link {
        min-height: 2.75rem;
        min-width: 0;
        flex: 0 1 auto;
    }

    body:not([data-admin-shell-page]) #navbar:has(#message-badge:not(.d-none), #notification-badge:not(.d-none)) .ds-mobile-alert {
        display: block;
        position: absolute;
        top: .2rem;
        right: .2rem;
        width: .55rem;
        height: .55rem;
        border-radius: 50%;
        background: var(--bs-danger);
        box-shadow: 0 0 0 2px var(--ds-surface);
    }

    body:not([data-admin-shell-page]) #navbar .ds-topbar-panel {
        --bs-offcanvas-width: min(23rem, 100vw);
        background: var(--ds-surface);
        color: var(--ds-text);
    }

    body:not([data-admin-shell-page]) #navbar .ds-topbar-panel .offcanvas-header {
        padding: 1rem;
        border-bottom: 1px solid var(--ds-border);
    }

    body:not([data-admin-shell-page]) #navbar .ds-topbar-panel .offcanvas-header .btn-close {
        box-sizing: border-box;
        width: 2.75rem;
        height: 2.75rem;
        padding: .85rem;
        margin: -.35rem -.35rem -.35rem auto;
    }

    body:not([data-admin-shell-page]) #navbar .ds-topbar-panel .offcanvas-body {
        padding: 1rem;
    }

    body:not([data-admin-shell-page]) #navbar .ds-topbar-panel .ds-topbar-actions {
        width: 100%;
        flex-direction: column !important;
        align-items: stretch !important;
        flex-wrap: nowrap;
        gap: .5rem;
    }

    body:not([data-admin-shell-page]) #navbar .ds-topbar-panel .nav-link,
    body:not([data-admin-shell-page]) #navbar .ds-topbar-panel .wiki-page-help,
    body:not([data-admin-shell-page]) #navbar .ds-topbar-panel .ds-theme-switch {
        display: flex;
        align-items: center;
        justify-content: flex-start;
        box-sizing: border-box;
        gap: .75rem;
        width: 100%;
        min-width: 0;
        min-height: 3rem;
        height: auto;
        padding: .75rem;
        border: 1px solid var(--ds-border) !important;
        border-radius: var(--radius-sm);
        color: var(--ds-text);
        font-size: .9rem;
        font-weight: 650;
        opacity: 1;
        white-space: normal;
    }

    body:not([data-admin-shell-page]) #navbar .ds-topbar-panel .wiki-page-help::after {
        content: attr(aria-label);
        font-size: .9rem;
        font-weight: 650;
    }

    body:not([data-admin-shell-page]) #navbar .ds-topbar-panel .wiki-page-help svg {
        flex-shrink: 0;
    }

    body:not([data-admin-shell-page]) #navbar .ds-topbar-panel .ds-mobile-action-label,
    body:not([data-admin-shell-page]) #navbar .ds-topbar-panel .ds-user-name {
        display: inline;
        white-space: normal;
        overflow-wrap: anywhere;
    }

    body:not([data-admin-shell-page]) #navbar .ds-topbar-panel .dropdown-toggle::after,
    body:not([data-admin-shell-page]) #navbar .ds-topbar-panel .ds-theme-switch-track {
        margin-left: auto;
        flex-shrink: 0;
    }

    body:not([data-admin-shell-page]) #navbar .ds-topbar-panel #message-badge,
    body:not([data-admin-shell-page]) #navbar .ds-topbar-panel #notification-badge {
        position: static !important;
        transform: none !important;
        margin-left: auto;
    }

    body:not([data-admin-shell-page]) #navbar .ds-topbar-panel .dropdown-menu {
        position: static !important;
        transform: none !important;
        width: 100%;
        min-width: 0;
        max-width: 100%;
        margin-top: .5rem !important;
    }

    body:not([data-admin-shell-page]) #navbar .ds-topbar-panel .ds-notification-menu > .border-bottom {
        flex-wrap: wrap;
        gap: .5rem !important;
    }
}

/* Keep compact desktop controls, but preserve readable mobile input text. */
@media (max-width: 767.98px) {
    body:not([data-admin-shell-page]) :is(.form-control, .form-select) { font-size: 1rem; }
    body:not([data-admin-shell-page]) .map-controls-disclosure > summary { display: list-item; min-height: 44px; padding-block: .5rem; cursor: pointer; }
    body:not([data-admin-shell-page]) .map-zoom-control .btn { min-height: 44px; }
}
@media (min-width: 768px) {
    body:not([data-admin-shell-page]) .map-controls-disclosure > summary { display: none; }
}
body:not([data-admin-shell-page]) .map-toolbar .map-zoom-control { grid-template-columns: repeat(auto-fit, minmax(3rem, 1fr)); gap: .35rem; }
body:not([data-admin-shell-page]) .map-zoom-control .btn { white-space: nowrap; padding-inline: .5rem; }
body:not([data-admin-shell-page]) .report-preview-frame { display: block; border: 0; width: 100%; height: min(70vh, 800px); min-height: 260px; }
