:root {
    --ewer-sidebar-width: 272px;
    --ewer-sidebar-collapsed: 78px;
    --ewer-topbar-height: 68px;
}

.ewer-topbar {
    min-height: var(--ewer-topbar-height);
    border-bottom: 1px solid var(--border-color);
    box-shadow: var(--shadow-sm);
}

.ewer-topbar .navbar-content {
    width: 100%; max-width: none; min-height: var(--ewer-topbar-height); padding: 0 1rem !important;
    display: flex !important; flex-direction: row !important; align-items: center !important; gap: .75rem !important;
}
.ewer-topbar .navbar-brand {
    display: flex; align-items: center; min-width: 0; width: auto !important; flex: 0 1 auto;
    justify-content: flex-start !important;
}
.topbar-logo { width: 42px; height: 42px; object-fit: cover; border-radius: 10px; margin: 0 .65rem; }
.topbar-brand-copy { min-width: 0; }
.topbar-title { font-weight: 700; line-height: 1.1; white-space: nowrap; }
.topbar-subtitle { font-size: .7rem; opacity: .75; white-space: nowrap; }
.topbar-actions {
    margin: 0 0 0 auto !important; padding: 0 !important; width: auto !important; flex: 0 0 auto !important;
    display: flex !important; flex-direction: row !important; align-items: center !important; justify-content: flex-end !important;
    gap: .45rem !important; border: 0 !important; background: transparent !important;
}
.topbar-actions .nav-icon-btn, .topbar-actions .navbar-link {
    position: relative; width: 40px !important; height: 40px !important; min-width: 40px !important; padding: 0 !important;
    display: inline-flex !important; align-items: center !important; justify-content: center !important;
    border-radius: 11px !important; border: 1px solid var(--border-color) !important;
    background: var(--card-bg) !important; color: var(--text-primary) !important; box-shadow: none !important;
    font-size: 1rem !important; text-transform: none !important; transition: background-color .18s ease, color .18s ease, border-color .18s ease, transform .18s ease !important;
}
.topbar-actions .nav-icon-btn:hover, .topbar-actions .navbar-link:hover,
.topbar-actions .nav-icon-btn:focus-visible, .topbar-actions .navbar-link:focus-visible {
    background: var(--bg-secondary) !important; color: var(--primary-color) !important;
    border-color: rgba(37, 99, 235, .35) !important;
    transform: translateY(-1px);
}
.topbar-actions .navbar-link.active { background: rgba(37,99,235,.11) !important; color: var(--primary-color) !important; }
.topbar-actions .hidden { display: none !important; }
.topbar-action-label {
    position: absolute !important; width: 1px !important; height: 1px !important; padding: 0 !important; margin: -1px !important;
    overflow: hidden !important; clip: rect(0, 0, 0, 0) !important; white-space: nowrap !important; border: 0 !important;
}
.topbar-notification { position: relative; }
.topbar-notification .notification-dropdown {
    top: calc(100% + 10px) !important; right: 0 !important; bottom: auto !important; left: auto !important;
    width: min(360px, calc(100vw - 2rem)) !important; margin: 0 !important;
    background: var(--card-bg) !important; color: var(--text-primary) !important;
    border: 1px solid var(--border-color) !important; border-radius: 12px !important; box-shadow: var(--shadow-lg) !important;
}
.topbar-notification .notification-badge {
    top: -6px !important; right: -6px !important; z-index: 2; border-color: var(--card-bg) !important;
}

.profile-menu-wrapper { position: relative; }
.profile-menu {
    min-width: 210px; right: 0; left: auto; top: calc(100% + 10px); padding: .9rem;
    border-radius: 12px; background: var(--card-bg); color: var(--text-primary);
    border: 1px solid var(--border-color); box-shadow: var(--shadow-lg); opacity: 0;
    visibility: hidden; transform: translateY(-6px); transition: .18s ease; text-align: left;
}
.profile-menu.active { opacity: 1; visibility: visible; transform: translateY(0); }
.profile-name { font-weight: 700; }
.profile-role { font-size: .75rem; color: var(--text-muted); margin-top: .15rem; }
.profile-logout { width: 100%; margin-top: .75rem; padding: .55rem .65rem; border: 0; border-radius: 8px; cursor: pointer; text-align: left; color: #dc2626; background: rgba(220,38,38,.08); }

.app-shell { display: flex; min-height: calc(100vh - var(--ewer-topbar-height)); position: relative; }
.app-sidebar {
    width: var(--ewer-sidebar-width); flex: 0 0 var(--ewer-sidebar-width); height: calc(100vh - var(--ewer-topbar-height));
    position: sticky; top: var(--ewer-topbar-height); background: var(--card-bg); border-right: 1px solid var(--border-color);
    transition: width .22s ease, flex-basis .22s ease, transform .22s ease; z-index: 1000; overflow: hidden;
}
.sidebar-scroll { height: 100%; overflow-y: auto; padding: .85rem .7rem 1.25rem; }
.app-main { min-width: 0; flex: 1; }
.app-main > .container { max-width: none; }

.sidebar-section { margin-bottom: .65rem; }
.sidebar-section-toggle {
    width: 100%; border: 0; background: transparent; color: var(--text-muted); display: flex; align-items: center;
    justify-content: space-between; padding: .55rem .7rem; cursor: pointer; font-size: .69rem; font-weight: 800;
    letter-spacing: .08em; text-transform: uppercase;
}
.sidebar-section-toggle i { font-size: .65rem; transition: transform .2s ease; }
.sidebar-section.is-closed .sidebar-section-toggle i { transform: rotate(-90deg); }
.sidebar-section.is-closed .sidebar-section-items { display: none; }
.sidebar-section-items { display: grid; gap: .25rem; }
.app-sidebar .navbar-link, .sidebar-action {
    width: 100%; min-height: 42px; display: flex !important; align-items: center; gap: .8rem; padding: .65rem .8rem !important;
    border: 0 !important; border-radius: 9px !important; background: transparent !important; box-shadow: none !important;
    color: var(--text-secondary) !important; text-decoration: none; font-size: .88rem; font-weight: 550; cursor: pointer; text-align: left;
}
.app-sidebar .navbar-link i, .sidebar-action i { width: 20px; flex: 0 0 20px; text-align: center; font-size: .95rem; }
.app-sidebar .navbar-link:hover, .sidebar-action:hover { background: var(--bg-secondary) !important; color: var(--primary-color) !important; }
.app-sidebar .navbar-link.active { background: rgba(37,99,235,.11) !important; color: var(--primary-color) !important; font-weight: 700; }
.app-sidebar .navbar-link.hidden { display: none !important; }
.app-shell.sidebar-collapsed .app-sidebar { width: var(--ewer-sidebar-collapsed); flex-basis: var(--ewer-sidebar-collapsed); }
.app-shell.sidebar-collapsed .sidebar-section-title,
.app-shell.sidebar-collapsed .sidebar-section-toggle i,
.app-shell.sidebar-collapsed .app-sidebar .navbar-link span,
.app-shell.sidebar-collapsed .sidebar-action span:not(.notification-badge) { display: none; }
.app-shell.sidebar-collapsed .sidebar-section-toggle { height: 18px; padding: .25rem; }
.app-shell.sidebar-collapsed .app-sidebar .navbar-link,
.app-shell.sidebar-collapsed .sidebar-action { justify-content: center; padding: .65rem !important; }
.app-shell.sidebar-collapsed .app-sidebar .navbar-link i,
.app-shell.sidebar-collapsed .sidebar-action i { width: auto; flex-basis: auto; font-size: 1.05rem; }

.sidebar-overlay { display: none; }
@media (max-width: 1024px) {
    .app-sidebar { position: fixed; left: 0; top: var(--ewer-topbar-height); transform: translateX(-102%); box-shadow: var(--shadow-lg); width: var(--ewer-sidebar-width) !important; }
    .app-shell.sidebar-mobile-open .app-sidebar { transform: translateX(0); }
    .sidebar-overlay { position: fixed; inset: var(--ewer-topbar-height) 0 0; background: rgba(15,23,42,.45); z-index: 999; }
    .app-shell.sidebar-mobile-open .sidebar-overlay { display: block; }
    .app-shell.sidebar-collapsed .sidebar-section-title,
    .app-shell.sidebar-collapsed .sidebar-section-toggle i,
    .app-shell.sidebar-collapsed .app-sidebar .navbar-link span,
    .app-shell.sidebar-collapsed .sidebar-action span:not(.notification-badge) { display: initial; }
    .app-shell.sidebar-collapsed .app-sidebar .navbar-link,
    .app-shell.sidebar-collapsed .sidebar-action { justify-content: flex-start; }
}
@media (max-width: 760px) {
    .ewer-topbar .navbar-content { padding: 0 .55rem !important; gap: .35rem !important; }
    .topbar-actions { gap: .28rem !important; }
    .topbar-actions .nav-icon-btn, .topbar-actions .navbar-link {
        width: 36px !important; height: 36px !important; min-width: 36px !important; border-radius: 10px !important;
    }
    .topbar-subtitle { display: none; }
    .topbar-logo { width: 38px; height: 38px; margin-left: .35rem; margin-right: .45rem; }
}
@media (max-width: 480px) {
    .topbar-title { font-size: .86rem; }
    .topbar-brand-copy { max-width: 86px; overflow: hidden; }
    .topbar-actions .nav-icon-btn, .topbar-actions .navbar-link {
        width: 34px !important; height: 34px !important; min-width: 34px !important;
    }
    .topbar-actions { gap: .2rem !important; }
    .topbar-notification .notification-dropdown { right: -88px !important; width: min(340px, calc(100vw - 1rem)) !important; }
}

/* ============================================================================
   RESPONSIVE TABLE FIT — SIDEBAR-AWARE, NO PAGE OVERFLOW
   Keeps desktop tables inside the available main-content width and changes
   them to accessible stacked records on narrow screens.
   ============================================================================ */

/* Flex children must be allowed to shrink when the sidebar is visible. */
.app-main {
    width: calc(100% - var(--ewer-sidebar-width));
    max-width: calc(100% - var(--ewer-sidebar-width));
    min-width: 0;
    overflow-x: clip;
}

.app-shell.sidebar-collapsed .app-main {
    width: calc(100% - var(--ewer-sidebar-collapsed));
    max-width: calc(100% - var(--ewer-sidebar-collapsed));
}

.app-main > .container,
.app-main .view,
.app-main .card,
.app-main .card-body,
.app-main .table-container {
    width: 100%;
    min-width: 0;
    max-width: 100%;
    box-sizing: border-box;
}

.app-main > .container {
    padding-left: clamp(.85rem, 1.5vw, 1.5rem);
    padding-right: clamp(.85rem, 1.5vw, 1.5rem);
}

/* Search/filter rows can wrap before they force the page wider. */
.app-main .flex-between {
    min-width: 0;
    gap: .75rem;
    flex-wrap: wrap;
}

.app-main .flex-between > .flex {
    min-width: 0;
    flex: 1 1 460px;
    flex-wrap: wrap;
}

.app-main .flex-between > .form-input,
.app-main .flex-between > input.form-input {
    flex: 1 1 220px;
    min-width: 180px;
}

.app-main .flex-between select.form-select {
    min-width: 145px;
    max-width: 100%;
    flex: 1 1 160px;
}

/* Desktop and laptop: fit the complete table inside its card. */
.app-main .table-container {
    overflow-x: hidden !important;
    overflow-y: visible;
}

.app-main .table-container > table.table {
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
    table-layout: fixed;
}

.app-main .table th,
.app-main .table td {
    min-width: 0;
    max-width: 100%;
    padding: clamp(.48rem, .72vw, .82rem);
    font-size: clamp(.72rem, .76vw, .875rem);
    line-height: 1.35;
    vertical-align: middle;
    white-space: normal !important;
    overflow-wrap: anywhere;
    word-break: normal;
}

.app-main .table th {
    font-size: clamp(.66rem, .68vw, .75rem);
}

.app-main .table td[style*="white-space"] {
    white-space: normal !important;
}

.app-main .table td > div[style*="display: flex"],
.app-main .table .action-row {
    min-width: 0;
    display: flex !important;
    flex-wrap: wrap !important;
    align-items: center;
    gap: .35rem !important;
}

.app-main .table .btn,
.app-main .table .btn-sm {
    max-width: 100%;
    min-width: 0;
    padding: .38rem .62rem;
    font-size: .75rem;
    line-height: 1.15;
    white-space: normal;
}

.app-main .table .badge {
    max-width: 100%;
    white-space: normal;
    overflow-wrap: anywhere;
    text-align: center;
    line-height: 1.25;
}

/* Purpose-built width budgets for the busiest operational tables. */
#casesTable th:nth-child(1), #casesTable td:nth-child(1) { width: 14%; }
#casesTable th:nth-child(2), #casesTable td:nth-child(2) { width: 16%; }
#casesTable th:nth-child(3), #casesTable td:nth-child(3) { width: 12%; }
#casesTable th:nth-child(4), #casesTable td:nth-child(4) { width: 11%; }
#casesTable th:nth-child(5), #casesTable td:nth-child(5) { width: 8%; }
#casesTable th:nth-child(6), #casesTable td:nth-child(6) { width: 9%; }
#casesTable th:nth-child(7), #casesTable td:nth-child(7) { width: 11%; }
#casesTable th:nth-child(8), #casesTable td:nth-child(8) { width: 9%; }
#casesTable th:nth-child(9), #casesTable td:nth-child(9) { width: 10%; }

#incidentsTable th:nth-child(1), #incidentsTable td:nth-child(1) { width: 13%; }
#incidentsTable th:nth-child(2), #incidentsTable td:nth-child(2) { width: 15%; }
#incidentsTable th:nth-child(3), #incidentsTable td:nth-child(3) { width: 18%; }
#incidentsTable th:nth-child(4), #incidentsTable td:nth-child(4) { width: 12%; }
#incidentsTable th:nth-child(5), #incidentsTable td:nth-child(5) { width: 10%; }
#incidentsTable th:nth-child(6), #incidentsTable td:nth-child(6) { width: 8%; }
#incidentsTable th:nth-child(7), #incidentsTable td:nth-child(7) { width: 10%; }
#incidentsTable th:nth-child(8), #incidentsTable td:nth-child(8) { width: 14%; }

#risksTable th:nth-child(1), #risksTable td:nth-child(1) { width: 13%; }
#risksTable th:nth-child(2), #risksTable td:nth-child(2) { width: 13%; }
#risksTable th:nth-child(3), #risksTable td:nth-child(3) { width: 12%; }
#risksTable th:nth-child(4), #risksTable td:nth-child(4) { width: 8%; }
#risksTable th:nth-child(5), #risksTable td:nth-child(5) { width: 9%; }
#risksTable th:nth-child(6), #risksTable td:nth-child(6) { width: 10%; }
#risksTable th:nth-child(7), #risksTable td:nth-child(7) { width: 11%; }
#risksTable th:nth-child(8), #risksTable td:nth-child(8) { width: 9%; }
#risksTable th:nth-child(9), #risksTable td:nth-child(9) { width: 15%; }

/* Small laptops: use the whole viewport and make the sidebar an overlay. */
@media (max-width: 1180px) {
    .app-main,
    .app-shell.sidebar-collapsed .app-main {
        width: 100%;
        max-width: 100%;
    }

    .app-sidebar {
        position: fixed;
        left: 0;
        top: var(--ewer-topbar-height);
        transform: translateX(-102%);
        box-shadow: var(--shadow-lg);
        width: var(--ewer-sidebar-width) !important;
        flex-basis: var(--ewer-sidebar-width) !important;
    }

    .app-shell.sidebar-mobile-open .app-sidebar {
        transform: translateX(0);
    }

    .app-shell.sidebar-mobile-open .sidebar-overlay {
        display: block;
    }
}

/* Tablet and mobile: stacked records, no horizontal scrolling. */
@media (max-width: 820px) {
    .app-main > .container {
        padding: .75rem;
    }

    .app-main .card {
        padding: 1rem;
    }

    .app-main .card-header {
        align-items: flex-start;
        gap: .75rem;
        flex-wrap: wrap;
    }

    .app-main .card-actions {
        margin-left: auto;
        flex-wrap: wrap;
    }

    .app-main .table-container {
        border: 0 !important;
        border-radius: 0 !important;
        overflow: visible !important;
        background: transparent !important;
    }

    .app-main .table-container > table.table,
    .app-main .table-container > table.table tbody,
    .app-main .table-container > table.table tr,
    .app-main .table-container > table.table td {
        display: block;
        width: 100% !important;
        max-width: 100% !important;
    }

    .app-main .table-container > table.table {
        background: transparent;
    }

    .app-main .table-container > table.table thead {
        position: absolute;
        width: 1px;
        height: 1px;
        overflow: hidden;
        clip: rect(0 0 0 0);
        clip-path: inset(50%);
        white-space: nowrap;
    }

    .app-main .table-container > table.table tbody {
        display: grid;
        gap: .85rem;
    }

    .app-main .table-container > table.table tbody tr {
        overflow: hidden;
        border: 1px solid var(--border-color);
        border-radius: 12px;
        background: var(--bg-white);
        box-shadow: var(--shadow-sm);
    }

    .app-main .table-container > table.table tbody tr:hover {
        background: var(--bg-white);
    }

    .app-main .table-container > table.table tbody td {
        display: grid;
        grid-template-columns: minmax(105px, 38%) minmax(0, 1fr);
        gap: .75rem;
        align-items: center;
        padding: .68rem .78rem;
        border-top: 1px solid var(--border-color);
        text-align: left;
        font-size: .82rem;
    }

    .app-main .table-container > table.table tbody td:first-child {
        border-top: 0;
    }

    .app-main .table-container > table.table tbody td::before {
        content: attr(data-label);
        color: var(--text-secondary);
        font-size: .68rem;
        font-weight: 750;
        letter-spacing: .045em;
        line-height: 1.25;
        text-transform: uppercase;
    }

    .app-main .table-container > table.table tbody td[data-label=""]::before {
        display: none;
    }

    .app-main .table-container > table.table tbody td[colspan] {
        display: block;
        text-align: center;
    }

    .app-main .table-container > table.table tbody td[colspan]::before {
        display: none;
    }

    .app-main .table td > div[style*="display: flex"],
    .app-main .table .action-row {
        justify-content: flex-start;
    }
}

@media (max-width: 520px) {
    .app-main .table-container > table.table tbody td {
        grid-template-columns: 1fr;
        gap: .3rem;
    }

    .app-main .flex-between > .flex,
    .app-main .flex-between > .form-input,
    .app-main .flex-between > input.form-input,
    .app-main .flex-between select.form-select {
        width: 100% !important;
        min-width: 100%;
        flex-basis: 100%;
    }

    .app-main .card-actions,
    .app-main .card-actions .btn {
        width: 100%;
    }
}

/* ============================================================================
   GOVERNMENT-GRADE RESPONSIVE DATA TABLES — v1.3
   Whole words, aligned data, readable actions, and zero page-level overflow.
   ============================================================================ */

.app-main,
.app-main > .container,
.app-main .view,
.app-main .card,
.app-main .card-body,
.app-main .table-container,
.ati-content-grid,
.ati-content-grid > * {
    min-width: 0;
    max-width: 100%;
    box-sizing: border-box;
}

.app-main .table-container {
    width: 100%;
    overflow-x: hidden !important;
    overflow-y: visible;
    border-radius: 12px;
}

.app-main .professional-data-table {
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
    table-layout: auto !important;
    border-collapse: collapse;
}

/* Never split official labels, headers, badges, identifiers, or button text. */
.app-main .professional-data-table th,
.app-main .professional-data-table td {
    min-width: 0;
    max-width: none;
    padding: clamp(.62rem, .82vw, .95rem);
    font-size: clamp(.76rem, .78vw, .9rem);
    line-height: 1.42;
    vertical-align: middle;
    white-space: normal !important;
    overflow-wrap: normal !important;
    word-break: normal !important;
    hyphens: none !important;
}

.app-main .professional-data-table th {
    color: var(--text-primary);
    font-size: clamp(.69rem, .7vw, .79rem);
    font-weight: 750;
    letter-spacing: .035em;
    text-transform: uppercase;
    word-break: keep-all !important;
}

.app-main .professional-data-table .record-id-cell,
.app-main .professional-data-table .record-id-cell strong {
    white-space: nowrap !important;
    overflow-wrap: normal !important;
    word-break: keep-all !important;
}

.app-main .professional-data-table .table-title-cell,
.app-main .professional-data-table .table-description-cell {
    min-width: 8.5rem;
    color: var(--text-primary);
}

.app-main .professional-data-table .table-date-cell {
    min-width: 6.3rem;
    white-space: normal !important;
    font-variant-numeric: tabular-nums;
}

.app-main .professional-data-table .badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: auto;
    max-width: 100%;
    padding: .42rem .62rem;
    line-height: 1.25;
    text-align: center;
    white-space: normal !important;
    overflow-wrap: normal !important;
    word-break: keep-all !important;
    hyphens: none !important;
}

.app-main .professional-data-table .table-actions-cell {
    min-width: 7.6rem;
}

.app-main .professional-data-table .table-actions {
    display: flex !important;
    flex-wrap: wrap !important;
    align-items: center;
    justify-content: flex-start;
    gap: .45rem !important;
    min-width: 0;
}

.app-main .professional-data-table .table-actions .btn,
.app-main .professional-data-table .table-actions .btn-sm {
    flex: 0 0 auto;
    min-width: 4.8rem;
    max-width: 100%;
    padding: .5rem .72rem;
    line-height: 1.1;
    font-size: .78rem;
    white-space: nowrap !important;
    overflow-wrap: normal !important;
    word-break: keep-all !important;
    hyphens: none !important;
}

/* Practical width budgets: enough room for full words without oversized columns. */
#casesTable th:nth-child(1), #casesTable td:nth-child(1) { width: 10%; }
#casesTable th:nth-child(2), #casesTable td:nth-child(2) { width: 16%; }
#casesTable th:nth-child(3), #casesTable td:nth-child(3) { width: 12%; }
#casesTable th:nth-child(4), #casesTable td:nth-child(4) { width: 11%; }
#casesTable th:nth-child(5), #casesTable td:nth-child(5) { width: 8%; }
#casesTable th:nth-child(6), #casesTable td:nth-child(6) { width: 9%; }
#casesTable th:nth-child(7), #casesTable td:nth-child(7) { width: 11%; }
#casesTable th:nth-child(8), #casesTable td:nth-child(8) { width: 9%; }
#casesTable th:nth-child(9), #casesTable td:nth-child(9) { width: 14%; }

#incidentsTable th:nth-child(1), #incidentsTable td:nth-child(1) { width: 12%; }
#incidentsTable th:nth-child(2), #incidentsTable td:nth-child(2) { width: 17%; }
#incidentsTable th:nth-child(3), #incidentsTable td:nth-child(3) { width: 19%; }
#incidentsTable th:nth-child(4), #incidentsTable td:nth-child(4) { width: 12%; }
#incidentsTable th:nth-child(5), #incidentsTable td:nth-child(5) { width: 10%; }
#incidentsTable th:nth-child(6), #incidentsTable td:nth-child(6) { width: 8%; }
#incidentsTable th:nth-child(7), #incidentsTable td:nth-child(7) { width: 9%; }
#incidentsTable th:nth-child(8), #incidentsTable td:nth-child(8) { width: 13%; }

#risksTable th:nth-child(1), #risksTable td:nth-child(1) { width: 11%; }
#risksTable th:nth-child(2), #risksTable td:nth-child(2) { width: 13%; }
#risksTable th:nth-child(3), #risksTable td:nth-child(3) { width: 13%; }
#risksTable th:nth-child(4), #risksTable td:nth-child(4) { width: 8%; }
#risksTable th:nth-child(5), #risksTable td:nth-child(5) { width: 9%; }
#risksTable th:nth-child(6), #risksTable td:nth-child(6) { width: 10%; }
#risksTable th:nth-child(7), #risksTable td:nth-child(7) { width: 11%; }
#risksTable th:nth-child(8), #risksTable td:nth-child(8) { width: 9%; }
#risksTable th:nth-child(9), #risksTable td:nth-child(9) { width: 16%; }

#atiTable th:nth-child(1), #atiTable td:nth-child(1) { width: 12%; }
#atiTable th:nth-child(2), #atiTable td:nth-child(2) { width: 17%; }
#atiTable th:nth-child(3), #atiTable td:nth-child(3) { width: 13%; }
#atiTable th:nth-child(4), #atiTable td:nth-child(4) { width: 10%; }
#atiTable th:nth-child(5), #atiTable td:nth-child(5) { width: 11%; }
#atiTable th:nth-child(6), #atiTable td:nth-child(6) { width: 11%; }
#atiTable th:nth-child(7), #atiTable td:nth-child(7) { width: 10%; }
#atiTable th:nth-child(8), #atiTable td:nth-child(8) { width: 16%; }

/* A standard 1366/1440 laptop gets the full content width; sidebar becomes an overlay. */
@media (max-width: 1440px) {
    .app-main,
    .app-shell.sidebar-collapsed .app-main {
        width: 100%;
        max-width: 100%;
    }

    .app-sidebar {
        position: fixed;
        left: 0;
        top: var(--ewer-topbar-height);
        width: var(--ewer-sidebar-width) !important;
        flex-basis: var(--ewer-sidebar-width) !important;
        transform: translateX(-102%);
        box-shadow: var(--shadow-lg);
        z-index: 1200;
    }

    .app-shell.sidebar-mobile-open .app-sidebar {
        transform: translateX(0);
    }

    .app-shell.sidebar-mobile-open .sidebar-overlay {
        display: block;
    }
}

/* ATI: do not squeeze the request table beside charts on normal laptop screens. */
@media (max-width: 1200px) {
    .ati-content-grid {
        grid-template-columns: minmax(0, 1fr) !important;
    }

    .ati-charts-column {
        display: grid !important;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 1rem !important;
    }

    .ati-table-card {
        width: 100%;
        min-width: 0;
    }

    .app-main .professional-data-table th,
    .app-main .professional-data-table td {
        padding: .62rem .55rem;
        font-size: .78rem;
    }

    .app-main .professional-data-table th {
        font-size: .68rem;
    }
}

/* Only genuinely narrow screens switch to labelled record cards. */
@media (max-width: 900px) {
    .app-main > .container {
        padding: .75rem;
    }

    .app-main .table-container {
        overflow: visible !important;
        border: 0 !important;
        background: transparent !important;
    }

    .app-main .professional-data-table,
    .app-main .professional-data-table tbody,
    .app-main .professional-data-table tr,
    .app-main .professional-data-table td {
        display: block;
        width: 100% !important;
        max-width: 100% !important;
    }

    .app-main .professional-data-table thead {
        position: absolute;
        width: 1px;
        height: 1px;
        padding: 0;
        margin: -1px;
        overflow: hidden;
        clip: rect(0, 0, 0, 0);
        clip-path: inset(50%);
        white-space: nowrap;
        border: 0;
    }

    .app-main .professional-data-table tbody {
        display: grid;
        gap: .9rem;
    }

    .app-main .professional-data-table tbody tr {
        overflow: hidden;
        border: 1px solid var(--border-color);
        border-radius: 14px;
        background: var(--bg-white);
        box-shadow: var(--shadow-sm);
    }

    .app-main .professional-data-table tbody td {
        display: grid;
        grid-template-columns: minmax(8rem, 32%) minmax(0, 1fr);
        gap: .8rem;
        align-items: start;
        min-width: 0 !important;
        padding: .72rem .85rem;
        border-top: 1px solid var(--border-color);
        text-align: left;
        font-size: .84rem;
    }

    .app-main .professional-data-table tbody td:first-child {
        border-top: 0;
    }

    .app-main .professional-data-table tbody td::before {
        content: attr(data-label);
        color: var(--text-secondary);
        font-size: .7rem;
        font-weight: 750;
        letter-spacing: .04em;
        line-height: 1.35;
        text-transform: uppercase;
        word-break: normal;
    }

    .app-main .professional-data-table tbody td[colspan] {
        display: block;
        text-align: center;
    }

    .app-main .professional-data-table tbody td[colspan]::before,
    .app-main .professional-data-table tbody td[data-label=""]::before {
        display: none;
    }

    .app-main .professional-data-table .table-actions {
        justify-content: flex-start;
    }

    .ati-charts-column {
        grid-template-columns: minmax(0, 1fr);
    }

    #atiView .stats-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    }
}

@media (max-width: 560px) {
    .app-main .professional-data-table tbody td {
        grid-template-columns: minmax(0, 1fr);
        gap: .3rem;
    }

    #atiView .stats-grid {
        grid-template-columns: minmax(0, 1fr) !important;
    }

    .app-main .professional-data-table .table-actions .btn,
    .app-main .professional-data-table .table-actions .btn-sm {
        min-width: 5.4rem;
    }
}

/* ============================================================================
   INCIDENT DESCRIPTION PREVIEW — v1.4
   Keeps operational tables concise. Full descriptions remain in the View modal.
   ============================================================================ */
.app-main .professional-data-table .table-text-preview {
    display: -webkit-box;
    overflow: hidden;
    white-space: normal !important;
    overflow-wrap: break-word !important;
    word-break: normal !important;
    hyphens: none !important;
    line-height: 1.45;
    text-overflow: ellipsis;
    -webkit-box-orient: vertical;
}

.app-main #incidentsTable .table-description-preview {
    -webkit-line-clamp: 3;
    line-clamp: 3;
    max-height: 4.35em;
}

.app-main #incidentsTable .table-description-cell {
    vertical-align: top;
}

@media (max-width: 760px) {
    .app-main #incidentsTable .table-description-preview {
        -webkit-line-clamp: 4;
        line-clamp: 4;
        max-height: 5.8em;
    }
}


/* ============================================================================
   COMPLETE OPERATIONAL TABLE FIT + ACTION RELIABILITY — v1.5
   Fixed column budgets prevent the final Actions column from being clipped.
   Whole words remain readable; action buttons stay fully visible and clickable.
   ============================================================================ */
@media (min-width: 901px) {
    .app-main .table-container {
        width: 100% !important;
        max-width: 100% !important;
        overflow-x: hidden !important;
        contain: inline-size;
    }

    .app-main .professional-data-table {
        width: 100% !important;
        max-width: 100% !important;
        min-width: 100% !important;
        table-layout: fixed !important;
    }

    .app-main .professional-data-table th,
    .app-main .professional-data-table td {
        min-width: 0 !important;
        max-width: 100% !important;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .app-main .professional-data-table .record-id-cell,
    .app-main .professional-data-table .record-id-cell strong {
        white-space: normal !important;
        overflow-wrap: normal !important;
        word-break: normal !important;
        hyphens: manual !important;
    }

    .app-main .professional-data-table .table-title-cell,
    .app-main .professional-data-table .table-description-cell,
    .app-main .professional-data-table .table-date-cell,
    .app-main .professional-data-table .table-actions-cell {
        min-width: 0 !important;
    }

    .app-main .professional-data-table .table-title-cell,
    .app-main .professional-data-table .table-description-cell {
        overflow-wrap: break-word !important;
        word-break: normal !important;
    }

    .app-main .professional-data-table .table-actions-cell {
        overflow: visible !important;
        padding-left: .55rem !important;
        padding-right: .55rem !important;
    }

    .app-main .professional-data-table .table-actions {
        width: 100%;
        display: grid !important;
        grid-template-columns: minmax(0, 1fr);
        align-items: stretch;
        gap: .45rem !important;
    }

    .app-main .professional-data-table .table-actions .btn,
    .app-main .professional-data-table .table-actions .btn-sm {
        width: 100%;
        min-width: 0 !important;
        max-width: 100% !important;
        padding: .52rem .45rem;
        overflow: visible !important;
        text-overflow: clip !important;
        white-space: nowrap !important;
        cursor: pointer;
        position: relative;
        z-index: 2;
    }

    /* Cases: 100% total. */
    #casesTable th:nth-child(1), #casesTable td:nth-child(1) { width: 12% !important; }
    #casesTable th:nth-child(2), #casesTable td:nth-child(2) { width: 17% !important; }
    #casesTable th:nth-child(3), #casesTable td:nth-child(3) { width: 11% !important; }
    #casesTable th:nth-child(4), #casesTable td:nth-child(4) { width: 10% !important; }
    #casesTable th:nth-child(5), #casesTable td:nth-child(5) { width: 8% !important; }
    #casesTable th:nth-child(6), #casesTable td:nth-child(6) { width: 9% !important; }
    #casesTable th:nth-child(7), #casesTable td:nth-child(7) { width: 11% !important; }
    #casesTable th:nth-child(8), #casesTable td:nth-child(8) { width: 10% !important; }
    #casesTable th:nth-child(9), #casesTable td:nth-child(9) { width: 12% !important; }

    /* Incidents: 100% total. */
    #incidentsTable th:nth-child(1), #incidentsTable td:nth-child(1) { width: 12% !important; }
    #incidentsTable th:nth-child(2), #incidentsTable td:nth-child(2) { width: 16% !important; }
    #incidentsTable th:nth-child(3), #incidentsTable td:nth-child(3) { width: 19% !important; }
    #incidentsTable th:nth-child(4), #incidentsTable td:nth-child(4) { width: 11% !important; }
    #incidentsTable th:nth-child(5), #incidentsTable td:nth-child(5) { width: 10% !important; }
    #incidentsTable th:nth-child(6), #incidentsTable td:nth-child(6) { width: 8% !important; }
    #incidentsTable th:nth-child(7), #incidentsTable td:nth-child(7) { width: 10% !important; }
    #incidentsTable th:nth-child(8), #incidentsTable td:nth-child(8) { width: 14% !important; }

    /* Risks: 100% total, with protected Actions column. */
    #risksTable th:nth-child(1), #risksTable td:nth-child(1) { width: 14% !important; }
    #risksTable th:nth-child(2), #risksTable td:nth-child(2) { width: 12% !important; }
    #risksTable th:nth-child(3), #risksTable td:nth-child(3) { width: 13% !important; }
    #risksTable th:nth-child(4), #risksTable td:nth-child(4) { width: 7% !important; }
    #risksTable th:nth-child(5), #risksTable td:nth-child(5) { width: 8% !important; }
    #risksTable th:nth-child(6), #risksTable td:nth-child(6) { width: 10% !important; }
    #risksTable th:nth-child(7), #risksTable td:nth-child(7) { width: 11% !important; }
    #risksTable th:nth-child(8), #risksTable td:nth-child(8) { width: 10% !important; }
    #risksTable th:nth-child(9), #risksTable td:nth-child(9) { width: 15% !important; }

    /* ATI: 100% total. */
    #atiTable th:nth-child(1), #atiTable td:nth-child(1) { width: 13% !important; }
    #atiTable th:nth-child(2), #atiTable td:nth-child(2) { width: 17% !important; }
    #atiTable th:nth-child(3), #atiTable td:nth-child(3) { width: 13% !important; }
    #atiTable th:nth-child(4), #atiTable td:nth-child(4) { width: 10% !important; }
    #atiTable th:nth-child(5), #atiTable td:nth-child(5) { width: 11% !important; }
    #atiTable th:nth-child(6), #atiTable td:nth-child(6) { width: 11% !important; }
    #atiTable th:nth-child(7), #atiTable td:nth-child(7) { width: 10% !important; }
    #atiTable th:nth-child(8), #atiTable td:nth-child(8) { width: 15% !important; }
}

@media (min-width: 901px) and (max-width: 1180px) {
    .app-main .professional-data-table th,
    .app-main .professional-data-table td {
        padding: .58rem .42rem !important;
        font-size: .75rem !important;
    }

    .app-main .professional-data-table th {
        font-size: .66rem !important;
        letter-spacing: .02em !important;
    }
}


/* ============================================================================
   CENTERED MODAL WORKSPACES + RELIABLE EDIT FORMS — v1.6
   All dialogs are viewport-centred and use one controlled internal scrollbar.
   ============================================================================ */
body.modal-open {
    overflow: hidden !important;
}

.modal-overlay {
    inset: 0 !important;
    width: auto !important;
    height: auto !important;
    padding: clamp(.75rem, 2vw, 1.75rem) !important;
    box-sizing: border-box !important;
    align-items: center !important;
    justify-content: center !important;
    overflow: auto !important;
    overscroll-behavior: contain;
}

.modal-overlay > .modal {
    width: min(100%, 46rem) !important;
    max-width: 46rem !important;
    max-height: calc(100dvh - clamp(1.5rem, 4vw, 3.5rem)) !important;
    margin: auto !important;
    padding: 0 !important;
    display: flex !important;
    flex-direction: column !important;
    overflow: hidden !important;
    box-sizing: border-box !important;
}

#newCaseModal > .modal,
#newIncidentModal > .modal,
#newRiskModal > .modal,
#atiModal > .modal,
#editUserModal > .modal,
#newUserModal > .modal {
    width: min(100%, 52rem) !important;
    max-width: 52rem !important;
}

#caseDetailModal > .modal,
#incidentDetailModal > .modal,
#riskDetailModal > .modal,
#atiDetailModal > .modal {
    width: min(100%, 68rem) !important;
    max-width: 68rem !important;
}

.modal-overlay > .modal > .modal-header {
    flex: 0 0 auto;
    margin: 0 !important;
    padding: 1rem 1.25rem !important;
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-white);
    position: relative;
    z-index: 2;
}

.modal-overlay > .modal > form,
.modal-overlay > .modal > .modal-body {
    flex: 1 1 auto;
    min-height: 0;
    width: 100%;
    max-width: 100%;
    margin: 0 auto !important;
    padding: 1.25rem !important;
    overflow-x: hidden !important;
    overflow-y: auto !important;
    box-sizing: border-box !important;
}

#caseDetailContent.record-detail-layout {
    display: grid !important;
    grid-template-columns: minmax(0, 1fr) minmax(15rem, 18rem) !important;
    gap: 1.25rem !important;
    align-items: start !important;
}

.record-detail-main,
.record-detail-sidebar {
    min-width: 0;
}

.record-detail-main > .card,
.record-detail-sidebar > .card {
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
}

.record-detail-sidebar > .card {
    position: sticky;
    top: 0;
}

.modal-overlay .grid-2,
.modal-overlay .grid-3,
.modal-overlay .grid-4 {
    min-width: 0;
}

.modal-overlay .form-input,
.modal-overlay .form-select,
.modal-overlay .form-textarea {
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
}

@media (max-width: 900px) {
    #caseDetailContent.record-detail-layout {
        grid-template-columns: minmax(0, 1fr) !important;
    }

    .record-detail-sidebar > .card {
        position: static;
    }
}

@media (max-width: 640px) {
    .modal-overlay {
        padding: .5rem !important;
        align-items: stretch !important;
    }

    .modal-overlay > .modal {
        width: 100% !important;
        max-height: calc(100dvh - 1rem) !important;
        border-radius: .75rem !important;
    }

    .modal-overlay > .modal > .modal-header,
    .modal-overlay > .modal > form,
    .modal-overlay > .modal > .modal-body {
        padding: 1rem !important;
    }

    .modal-overlay .grid-2,
    .modal-overlay .grid-3,
    .modal-overlay .grid-4 {
        grid-template-columns: minmax(0, 1fr) !important;
    }
}


/* Location cascade and modal integrity repair */
.modal-overlay:not(.hidden) {
    position: fixed !important;
    inset: 0 !important;
    width: 100vw !important;
    height: 100vh !important;
    margin: 0 !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    padding: clamp(0.75rem, 2vw, 2rem) !important;
    z-index: 10000 !important;
}

.modal-overlay > .modal,
.modal-overlay > .modal-content {
    margin: 0 auto !important;
    max-height: calc(100vh - clamp(1.5rem, 4vw, 4rem)) !important;
    overflow: hidden !important;
}

.modal-body,
.modal-form-body,
.modal .form-body {
    min-width: 0;
}

#caseTown,
#incidentTown,
#riskTown,
#atiDistrict,
#atiTown {
    width: 100%;
    min-width: 0;
}

@media (max-width: 768px) {
    .modal-overlay:not(.hidden) {
        align-items: flex-start !important;
        padding: 0.5rem !important;
        overflow-y: auto !important;
    }
    .modal-overlay > .modal,
    .modal-overlay > .modal-content {
        width: 100% !important;
        max-width: 100% !important;
        max-height: calc(100vh - 1rem) !important;
    }
}
