/* =========================================================
   BRIGIF TP 88 SIADM — Responsive Layer
   Coding Pt-3
   Loaded after style.css and v3-game.css so it can safely
   improve layouts without changing application logic.
   ========================================================= */

html,
body {
    width: 100%;
    max-width: 100%;
    overflow-x: hidden;
}

img,
svg,
video,
canvas,
iframe {
    max-width: 100%;
}

.main-shell,
.main-inner,
.section-card,
.card,
.row > * {
    min-width: 0;
}

.main-inner img,
.main-inner video {
    height: auto;
}

/* Keep long text from forcing cards wider than the viewport. */
.main-inner p,
.main-inner h1,
.main-inner h2,
.main-inner h3,
.main-inner h4,
.main-inner h5,
.main-inner h6,
.main-inner .fw-semibold,
.main-inner .fw-bold {
    overflow-wrap: anywhere;
}

/* Tables fit inside their cards without a horizontal scrollbar. */
.table-wrap {
    width: 100%;
    max-width: 100%;
    overflow-x: hidden !important;
    overflow-y: visible;
}

.table-wrap .table {
    width: 100% !important;
    max-width: 100%;
    min-width: 0 !important;
    table-layout: fixed;
}

.table-wrap .table td,
.table-wrap .table th {
    vertical-align: middle;
    white-space: normal !important;
    overflow-wrap: anywhere;
    word-break: normal;
    min-width: 0 !important;
}

/* Utility classes from Bootstrap/project must not force table overflow. */
.table-wrap .text-nowrap,
.table-wrap .fw-semibold.text-nowrap {
    white-space: normal !important;
}

/* Keep numbering/action columns compact, leaving more room for content. */
.table-wrap .table th:first-child,
.table-wrap .table td:first-child {
    width: 52px;
}

.table-wrap .table th:last-child,
.table-wrap .table td:last-child {
    width: 72px;
    text-align: center;
}

.table-wrap .btn-ico {
    flex: 0 0 auto;
}

/* Responsive dropdowns/modal content. */
.topbar .dropdown-menu,
.main-inner .dropdown-menu {
    max-width: calc(100vw - 24px);
}

.modal-dialog {
    max-width: min(var(--bs-modal-width, 500px), calc(100vw - 24px));
}

.modal-content {
    max-height: calc(100vh - 24px);
}

.modal-body {
    overflow-y: auto;
}

/* Prevent wide controls from escaping their grid columns. */
.form-control,
.form-select,
.input-group,
.search-box,
textarea {
    max-width: 100%;
}

/* ---------- Tablet / collapsed sidebar ---------- */
@media (max-width: 991.98px) {
    body.sidebar-open {
        overflow: hidden;
    }

    .sidebar {
        width: min(82vw, 286px);
        max-width: 286px;
        z-index: 1060;
    }

    #sidebarBackdrop {
        position: fixed;
        inset: 0;
        z-index: 1050;
        background: rgba(13, 28, 20, .48);
        backdrop-filter: blur(2px);
    }

    #sidebarBackdrop.d-none {
        display: none !important;
    }

    #sidebarBackdrop.show {
        display: block !important;
        opacity: 1;
    }

    .main-shell {
        width: 100%;
        margin-left: 0 !important;
    }

    .topbar {
        padding: 10px 16px;
        gap: 10px;
    }

    .topbar .tt-wrap h1,
    .topbar h1 {
        font-size: 17px;
    }

    .topbar .sub {
        font-size: 11.5px;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .topbar > .toolbar {
        flex-wrap: nowrap;
        flex-shrink: 0;
        gap: 8px;
    }

    .main-inner {
        padding: 18px;
    }

    .app-footer {
        padding: 14px 18px;
    }

    .page-head {
        margin-bottom: 18px;
    }

    .page-head h2 {
        font-size: 22px;
    }

    .section-card .sc-head {
        padding: 15px 16px;
    }

    .section-card .sc-body {
        padding: 16px;
    }

    .quick-grid {
        grid-template-columns: repeat(auto-fit, minmax(135px, 1fr));
    }

    .pdf-box {
        min-height: 420px;
    }
}

/* ---------- Phone / portrait tablet ---------- */
@media (max-width: 767.98px) {
    .topbar {
        min-height: 62px;
        padding: 9px 12px;
    }

    .topbar .btn-ico {
        width: 38px;
        height: 38px;
        flex: 0 0 38px;
    }

    .topbar-icon {
        width: 38px;
        height: 38px;
        border-radius: 10px;
    }

    .user-menu .chip {
        padding: 3px;
        border-radius: 10px;
    }

    .user-menu .avatar {
        width: 32px;
        height: 32px;
        border-radius: 9px;
    }

    .main-inner {
        padding: 14px;
    }

    .app-footer {
        padding: 12px 14px;
        font-size: 11.5px;
    }

    .page-head {
        align-items: stretch;
        gap: 12px;
        margin-bottom: 16px;
    }

    .page-head > div:first-child {
        min-width: 0;
    }

    .page-head h2 {
        font-size: 20px;
        line-height: 1.25;
    }

    .page-head > .toolbar {
        width: 100%;
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 8px;
    }

    .page-head > .toolbar > .btn,
    .page-head > .toolbar > a,
    .page-head > .toolbar > button {
        width: 100%;
        min-height: 40px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        white-space: normal;
        text-align: center;
    }

    .section-card {
        margin-bottom: 16px;
        border-radius: 14px;
    }

    .section-card .sc-head {
        padding: 13px 14px;
        flex-wrap: wrap;
    }

    .section-card .sc-head h3 {
        font-size: 14.5px;
        min-width: 0;
    }

    .section-card .sc-head .sc-tools {
        width: 100%;
    }

    .section-card .sc-body {
        padding: 14px;
    }

    .stat-card {
        padding: 16px;
        gap: 12px;
    }

    .stat-icon {
        width: 48px;
        height: 48px;
        font-size: 21px;
    }

    .stat-card .val {
        font-size: 23px;
    }

    .quick-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 9px;
    }

    .quick-act {
        padding: 14px 9px;
    }

    .quick-act span {
        font-size: 12px;
    }

    .table-wrap .table {
        min-width: 0 !important;
        width: 100% !important;
        table-layout: fixed;
        font-size: 11.5px;
    }

    .table thead th,
    .table tbody td {
        padding: 8px 6px;
        line-height: 1.25;
    }

    .table thead th {
        font-size: 10px;
        letter-spacing: .01em;
    }

    .table-wrap .badge {
        white-space: normal;
        text-align: center;
        line-height: 1.2;
        padding: .34em .5em;
    }

    .empty-state {
        padding: 36px 16px;
    }

    .empty-state i {
        font-size: 38px;
    }

    .info-list li {
        flex-direction: column;
        gap: 3px;
    }

    .info-list .k {
        width: auto;
    }

    .pdf-box {
        min-height: 330px;
    }

    .modal-dialog,
    .modal-dialog-centered {
        margin: 12px auto;
        min-height: calc(100% - 24px);
    }

    .modal-header,
    .modal-body,
    .modal-footer {
        padding-left: 14px;
        padding-right: 14px;
    }

    .modal-footer {
        gap: 8px;
    }

    .pagination {
        flex-wrap: wrap;
        gap: 4px;
    }

    .pagination .page-link {
        border-radius: 8px;
    }

    /* Form action rows should wrap instead of overflowing. */
    .main-inner form .d-flex.justify-content-end,
    .main-inner .d-flex.justify-content-end.gap-2 {
        flex-wrap: wrap;
    }

    /* Login becomes a compact top-brand + form layout. */
    .auth-wrap {
        flex-direction: column;
        min-height: 100dvh;
    }

    .auth-info {
        flex: 0 0 auto;
        min-height: 0;
        padding: 20px 18px;
    }

    .auth-info > div:nth-child(2),
    .auth-info > div:last-child {
        display: none;
    }

    .auth-brand {
        gap: 11px;
    }

    .auth-brand .unit-emblem {
        width: 46px;
        height: 46px;
    }

    .auth-card {
        flex: 1 1 auto;
        align-items: flex-start;
        padding: 28px 18px 36px;
    }

    .auth-card .ac-inner {
        max-width: 520px;
        margin: 0 auto;
    }
}

/* ---------- Small phones ---------- */
@media (max-width: 575.98px) {
    .sidebar {
        width: min(88vw, 300px);
        max-width: 300px;
    }

    .sidebar .brand {
        padding: 16px 15px;
    }

    .side-nav {
        padding: 10px 8px;
    }

    .side-nav a {
        padding: 10px 11px;
        margin-left: 6px !important;
        margin-right: 6px !important;
    }

    .sidebar-foot {
        padding: 10px;
    }

    .topbar {
        gap: 7px;
    }

    .topbar .tt-wrap h1,
    .topbar h1 {
        font-size: 15px;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .topbar .sub {
        display: none;
    }

    .topbar > .toolbar {
        gap: 6px;
    }

    .main-inner {
        padding: 11px;
    }

    .breadcrumb {
        font-size: 11.5px;
        overflow-x: auto;
        flex-wrap: nowrap;
        white-space: nowrap;
        padding-bottom: 2px;
        scrollbar-width: none;
    }

    .breadcrumb::-webkit-scrollbar {
        display: none;
    }

    .page-head {
        flex-direction: column;
        align-items: stretch;
        margin-bottom: 13px;
    }

    .page-head h2 {
        font-size: 19px;
    }

    .page-head > .toolbar {
        grid-template-columns: 1fr;
    }

    /* Bootstrap col-6 filters are too cramped on narrow phones. */
    .main-inner form.row > .col-6,
    .main-inner form.row > [class*="col-6"] {
        flex: 0 0 100%;
        width: 100%;
        max-width: 100%;
    }

    .section-card .sc-head {
        align-items: flex-start;
    }

    .section-card .sc-head > .badge {
        align-self: flex-start;
    }

    .section-card .sc-body {
        padding: 12px;
    }

    .section-card .sc-head {
        padding: 12px;
    }

    .table-wrap .table {
        font-size: 10.5px;
    }

    .table-wrap .table thead th,
    .table-wrap .table tbody td {
        padding: 7px 4px;
    }

    .table-wrap .table th:first-child,
    .table-wrap .table td:first-child {
        width: 34px;
    }

    .table-wrap .table th:last-child,
    .table-wrap .table td:last-child {
        width: 46px;
    }

    .table-wrap .btn-ico {
        width: 28px;
        height: 28px;
        border-radius: 7px;
    }

    .main-inner form .col-12:last-child > .btn,
    .main-inner form .col-12:last-child > a.btn {
        width: 100%;
        margin: 0 0 7px !important;
    }

    .main-inner form .d-flex.justify-content-end > .btn,
    .main-inner form .d-flex.justify-content-end > a.btn {
        flex: 1 1 100%;
    }

    .quick-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .stat-card {
        min-height: 92px;
    }

    .table-wrap .table {
        min-width: 0 !important;
        width: 100% !important;
    }

    .table tbody td.wrap {
        min-width: 0 !important;
    }

    .modal-dialog {
        width: auto;
        max-width: none;
        margin: 8px;
    }

    .modal-dialog-centered {
        min-height: calc(100% - 16px);
    }

    .modal-footer {
        display: grid;
        grid-template-columns: 1fr 1fr;
    }

    .modal-footer > *,
    .modal-footer form,
    .modal-footer form .btn {
        width: 100%;
        margin: 0 !important;
    }

    .dropdown-menu {
        font-size: 13px;
    }

    .topbar .dropdown-menu {
        width: min(320px, calc(100vw - 16px)) !important;
    }

    .auth-card {
        padding: 24px 15px 30px;
    }

    .auth-card h2 {
        font-size: 22px;
    }
}

/* Very narrow phones: prioritize breathing room over two-column tiles. */
@media (max-width: 380px) {
    .quick-grid {
        grid-template-columns: 1fr;
    }

    .topbar {
        padding-left: 8px;
        padding-right: 8px;
    }

    .main-inner {
        padding: 8px;
    }

    .section-card {
        border-radius: 12px;
    }
}

/* Touch devices should not depend on hover movement. */
@media (hover: none) {
    .stat-card:hover,
    .quick-act:hover,
    .side-nav a:hover,
    .table tbody tr:hover {
        transform: none !important;
    }
}
