:root {
    --app-touch-target: 2.75rem;
    --app-sidebar-width: 18rem;
    --app-focus-ring: #f59e0b;
    --app-shell-edge: 0.75rem;
    --app-language-switch-height: 3.375rem;
    --app-header-utility-reserve: 7rem;
    --app-z-utility: 2000;
}

html {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

body {
    min-width: 20rem;
}

main {
    min-width: 0;
}

.app-language-switch {
    position: fixed;
    top: max(var(--app-shell-edge), env(safe-area-inset-top));
    right: max(var(--app-shell-edge), env(safe-area-inset-right));
    z-index: var(--app-z-utility);
}

.app-language-switch a[aria-current="true"] {
    forced-color-adjust: none;
}

.app-page-refresh {
    min-height: var(--app-touch-target);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.45rem;
    padding-inline: 0.85rem;
    font-size: 0.78rem;
    font-weight: 800;
    white-space: nowrap;
}

.app-page-refresh > [aria-hidden="true"] {
    font-size: 1.15rem;
    line-height: 1;
}

/*
 * The language switch is global while page actions belong to each page header.
 * Reserve a shared utility lane so the two controls can never occupy the same
 * hit area on desktop. At zoomed/narrow widths the mobile top-bar spacing below
 * takes over instead.
 */
@media (min-width: 1024px) {
    .flex.min-h-screen > main > header:first-child,
    .incident-center-main > .incident-center-page-header {
        min-height: var(--app-language-switch-height);
        padding-right: var(--app-header-utility-reserve);
    }
}

.app-sidebar {
    flex: 0 0 var(--app-sidebar-width);
    width: var(--app-sidebar-width);
}

.app-sidebar-brand-row {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 0.75rem;
}

.app-sidebar-toggle,
.app-sidebar-close,
.app-sidebar-backdrop {
    display: none;
}

.app-sidebar a,
.app-language-switch a {
    min-height: var(--app-touch-target);
    display: inline-flex;
    align-items: center;
}

.app-sidebar a {
    width: 100%;
}

.app-sidebar :focus-visible,
.app-sidebar-toggle:focus-visible,
.app-language-switch a:focus-visible,
.app-table-scroll:focus-visible {
    outline: 3px solid var(--app-focus-ring);
    outline-offset: 3px;
}

.app-table-scroll {
    max-width: 100%;
    overflow-x: auto;
    overscroll-behavior-inline: contain;
    -webkit-overflow-scrolling: touch;
}

.app-table-scroll > table {
    margin: 0;
}

@media (max-width: 1023px) {
    body.app-sidebar-open {
        overflow: hidden;
    }

    .app-sidebar-toggle {
        position: fixed;
        top: 0.75rem;
        left: 0.75rem;
        z-index: 6100;
        min-width: 5.5rem;
        min-height: var(--app-touch-target);
        display: inline-flex;
        align-items: center;
        justify-content: center;
        gap: 0.55rem;
        padding: 0.55rem 0.8rem;
        color: #fff;
        font-size: 0.78rem;
        font-weight: 900;
        line-height: 1;
        background: #0f172a;
        border: 2px solid rgba(255, 255, 255, 0.9);
        border-radius: 0.8rem;
        box-shadow: 0 8px 24px rgba(15, 23, 42, 0.28);
        cursor: pointer;
    }

    .app-sidebar-toggle__icon {
        width: 1.15rem;
        display: grid;
        gap: 0.2rem;
    }

    .app-sidebar-toggle__icon span {
        display: block;
        height: 2px;
        background: currentColor;
        border-radius: 999px;
    }

    .app-sidebar-backdrop {
        position: fixed;
        inset: 0;
        z-index: 6050;
        display: block;
        visibility: hidden;
        opacity: 0;
        background: rgba(15, 23, 42, 0.68);
        backdrop-filter: blur(2px);
        transition: opacity 180ms ease, visibility 180ms ease;
    }

    .app-sidebar {
        position: fixed !important;
        inset: 0 auto 0 0;
        z-index: 6150;
        width: min(var(--app-sidebar-width), calc(100vw - 3rem));
        height: 100dvh !important;
        max-height: 100dvh;
        overflow-y: auto;
        overscroll-behavior: contain;
        visibility: hidden;
        transform: translateX(-105%);
        box-shadow: 20px 0 55px rgba(15, 23, 42, 0.35);
        transition: transform 180ms ease, visibility 180ms ease;
    }

    body.app-sidebar-open .app-sidebar {
        visibility: visible;
        transform: translateX(0);
    }

    body.app-sidebar-open .app-sidebar-backdrop {
        visibility: visible;
        opacity: 1;
    }

    .app-sidebar-close {
        flex: 0 0 auto;
        width: var(--app-touch-target);
        height: var(--app-touch-target);
        display: inline-flex;
        align-items: center;
        justify-content: center;
        color: #fff;
        font-size: 1.75rem;
        line-height: 1;
        background: #1e293b;
        border: 1px solid #475569;
        border-radius: 0.75rem;
        cursor: pointer;
    }

    .app-language-switch a {
        min-width: var(--app-touch-target);
        justify-content: center;
    }

    .flex.min-h-screen > main,
    .incident-center-layout > main {
        width: 100%;
        min-height: 100dvh;
    }

    .flex.min-h-screen > main[class*="p-8"] {
        padding: 4.75rem 1rem 1.25rem !important;
    }

    body > .ml-64 {
        margin-left: 0 !important;
        padding: 4.75rem 1rem 1.25rem !important;
    }

    #map-controls-overlay {
        top: 4.5rem !important;
        left: 0.75rem !important;
        width: min(20rem, calc(100vw - 1.5rem)) !important;
    }

    main table {
        min-width: 44rem;
    }

    main th,
    main td {
        font-size: max(0.75rem, 12px);
    }

    main :is(button, input, select, textarea),
    [role="dialog"] :is(button, input, select, textarea) {
        min-height: var(--app-touch-target);
    }

    main :is(input, select, textarea),
    [role="dialog"] :is(input, select, textarea) {
        font-size: 1rem;
    }

    main :is([class~="text-[8px]"], [class~="text-[9px]"], [class~="text-[10px]"], [class~="text-[11px]"]) {
        font-size: 0.75rem !important;
        line-height: 1.35;
    }

    [role="dialog"] {
        width: min(100%, calc(100vw - 1rem));
        max-width: calc(100vw - 1rem);
        max-height: calc(100dvh - 1rem);
    }
}

@media (max-width: 639px) {
    :root {
        font-size: 16px;
    }

    .app-sidebar-toggle__label {
        position: absolute;
        width: 1px;
        height: 1px;
        padding: 0;
        margin: -1px;
        overflow: hidden;
        clip: rect(0, 0, 0, 0);
        white-space: nowrap;
        border: 0;
    }

    .app-sidebar-toggle {
        min-width: var(--app-touch-target);
        width: var(--app-touch-target);
        padding: 0;
    }

    .app-language-switch {
        top: max(var(--app-shell-edge), env(safe-area-inset-top)) !important;
        right: max(var(--app-shell-edge), env(safe-area-inset-right)) !important;
    }

    main h1,
    main h2 {
        overflow-wrap: anywhere;
    }

    [role="dialog"] {
        border-radius: 1rem !important;
    }
}

@media (prefers-reduced-motion: reduce) {
    .app-sidebar,
    .app-sidebar-backdrop {
        transition: none !important;
    }
}

@media (forced-colors: active) {
    .app-sidebar-toggle,
    .app-sidebar-close,
    .app-language-switch,
    .app-page-refresh {
        border: 2px solid ButtonText;
    }

    .app-language-switch a[aria-current="true"] {
        color: HighlightText;
        background: Highlight;
    }
}
