/**
 * KSDMS — system-wide mobile & touch responsiveness
 */

html {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

body {
    overflow-x: hidden;
}

body.staff-sidebar-open,
body.ad-sidebar-open {
    overflow: hidden;
}

@media (max-width: 767.98px) {
    .btn,
    .ap-btn,
    .ad-btn-view,
    .ad-btn-view-all,
    .ad-btn-new,
    .pub-btn-hero-gold,
    .pub-btn-hero-outline,
    .form-control,
    .form-select,
    .page-link {
        min-height: 44px;
    }

    .btn-sm,
    .ap-btn-sm,
    .ad-btn-logout {
        min-height: 40px;
    }

    input.form-control,
    select.form-select,
    textarea.form-control {
        font-size: 16px !important;
    }

    .page-header-bar {
        flex-direction: column;
        align-items: flex-start !important;
        gap: 0.75rem;
    }

    .page-header-actions {
        width: 100%;
        display: flex;
        flex-wrap: wrap;
        gap: 0.5rem;
    }

    .page-header-actions .btn,
    .page-header-actions .ap-btn,
    .page-header-actions form {
        flex: 1 1 auto;
        min-width: 0;
    }

    .page-header-actions .btn,
    .page-header-actions .ap-btn {
        justify-content: center;
        width: 100%;
    }

    .ap-page-header,
    .ad-welcome {
        flex-direction: column;
        align-items: flex-start !important;
    }

    .ap-page-actions,
    .ad-welcome .ad-btn-new,
    .pub-hero-actions {
        width: 100%;
    }

    .ap-page-actions .ap-btn,
    .pub-hero-actions .pub-btn-hero-gold,
    .pub-hero-actions .pub-btn-hero-outline {
        flex: 1 1 auto;
        justify-content: center;
        width: 100%;
    }

    .ad-welcome .ad-btn-new {
        width: 100%;
        justify-content: center;
    }

    .ap-form-actions {
        flex-direction: column;
    }

    .ap-form-actions .ap-btn {
        width: 100%;
        justify-content: center;
    }

    .card-body,
    .ap-panel-body,
    .ad-panel-body {
        padding: 1rem !important;
    }

    #site-map-wrapper,
    #site-location-map,
    .leaflet-container {
        min-height: 220px !important;
        width: 100% !important;
    }

    .ts-wrapper {
        width: 100% !important;
    }

    .accordion-button {
        padding: 1rem;
        font-size: 0.95rem;
    }

    .modal-dialog {
        margin: 0.75rem;
    }

    .pagination {
        flex-wrap: wrap;
        justify-content: center;
    }

    .alert {
        font-size: 0.9rem;
    }

    .pub-footer .row > [class*="col-"] {
        margin-bottom: 0.5rem;
    }

    .pub-footer-bottom {
        flex-direction: column;
        text-align: center;
    }

    .pub-navbar .navbar-collapse {
        background: rgba(0, 61, 32, 0.98);
        border-radius: 12px;
        padding: 0.75rem;
        margin-top: 0.5rem;
    }

    .pub-navbar .nav-link {
        padding: 0.65rem 0.85rem !important;
        border-radius: 8px;
    }

    .pub-hero-visual--photo {
        max-height: 280px;
        min-height: 220px;
    }

    .pub-help-actions {
        flex-direction: column;
    }

    .pub-help-actions a {
        width: 100%;
        text-align: center;
    }

    .ap-form-progress {
        flex-direction: row;
        flex-wrap: nowrap;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        padding-bottom: 0.5rem;
    }

    .ap-form-step {
        flex-shrink: 0;
    }
}

.staff-sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    z-index: 1035;
}

.staff-sidebar-backdrop.show {
    display: block;
}

.staff-menu-toggle {
    display: none;
    border: none;
    background: rgba(255, 255, 255, 0.15);
    color: #fff;
    width: 40px;
    height: 40px;
    border-radius: 8px;
    font-size: 1.35rem;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

@media (max-width: 767.98px) {
    .staff-menu-toggle {
        display: inline-flex;
    }

    .staff-sidebar {
        display: block !important;
        position: fixed !important;
        top: 0;
        left: 0;
        bottom: 0;
        z-index: 1040;
        width: min(280px, 88vw) !important;
        max-width: 88vw;
        min-height: 100vh;
        transform: translateX(-100%);
        transition: transform 0.25s ease;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        box-shadow: 4px 0 24px rgba(0, 0, 0, 0.2);
        flex: none !important;
        background: #fff;
    }

    .staff-sidebar.open {
        transform: translateX(0);
    }

    .dashboard-main {
        width: 100% !important;
        max-width: 100% !important;
        flex: 0 0 100% !important;
        padding-left: 1rem !important;
        padding-right: 1rem !important;
    }

    .dashboard-shell > .row {
        margin-left: 0;
        margin-right: 0;
    }

    .table-responsive {
        -webkit-overflow-scrolling: touch;
        border-radius: 8px;
    }

    .table-bungoma {
        font-size: 0.82rem;
    }

    .table-bungoma thead th,
    .table-bungoma tbody td {
        white-space: nowrap;
        padding: 0.65rem 0.75rem;
    }

    .ksdms-mobile-cards thead {
        display: none;
    }

    .ksdms-mobile-cards tbody tr {
        display: block;
        padding: 0.85rem 1rem;
        border-bottom: 1px solid #e5e7eb;
        background: #fff;
    }

    .ksdms-mobile-cards tbody td {
        display: flex;
        justify-content: space-between;
        align-items: flex-start;
        gap: 0.75rem;
        padding: 0.35rem 0;
        border: none;
        white-space: normal;
        text-align: right;
    }

    .ksdms-mobile-cards tbody td::before {
        content: attr(data-label);
        font-weight: 600;
        color: #6b7280;
        font-size: 0.72rem;
        text-transform: uppercase;
        text-align: left;
        flex-shrink: 0;
        max-width: 45%;
    }

    .ksdms-mobile-cards tbody td.ksdms-mobile-actions::before {
        display: none;
    }

    .ad-chart-wrap {
        flex-direction: column;
        align-items: center;
        text-align: center;
    }

    .ad-chart-legend {
        width: 100%;
    }

    .ad-donut {
        width: 140px;
        height: 140px;
    }

    .development-timeline {
        flex-direction: column;
    }

    .development-timeline-step {
        flex: 1 1 auto !important;
        width: 100%;
    }

    input[type="file"].form-control {
        font-size: 0.85rem;
    }
}

@media (min-width: 768px) and (max-width: 991.98px) {
    .ad-content,
    .dashboard-main {
        padding-left: 1.25rem !important;
        padding-right: 1.25rem !important;
    }

    .pub-hero-visual--photo {
        max-height: 360px;
    }
}

@supports (padding: max(0px)) {
    .ad-topbar,
    .kakamega-navbar,
    .pub-navbar {
        padding-left: max(0.75rem, env(safe-area-inset-left));
        padding-right: max(0.75rem, env(safe-area-inset-right));
    }

    .ad-content,
    .dashboard-main,
    .pub-footer {
        padding-bottom: max(1rem, env(safe-area-inset-bottom));
    }
}

@media (max-width: 575.98px) {
    .ad-topbar {
        padding: 0.65rem 0.75rem;
        gap: 0.5rem;
    }

    .ad-topbar-right {
        gap: 0.35rem;
    }

    .ad-topbar-user span {
        display: none;
    }

    .ad-btn-logout {
        padding: 0.35rem 0.6rem;
        font-size: 0.75rem;
    }

    .kakamega-navbar .text-white-50 {
        display: none !important;
    }

    .pub-brand-subtitle,
    .pub-brand-motto {
        display: none !important;
    }
}

img,
video,
canvas,
svg {
    max-width: 100%;
    height: auto;
}

iframe {
    max-width: 100%;
}

.auth-card .card-body {
    padding: 1.25rem !important;
}

.auth-card .btn-bungoma-green {
    min-height: 48px;
    font-size: 1rem;
}

@media (max-width: 767.98px) {
    .auth-card {
        border: none;
        box-shadow: none;
        background: transparent;
    }

    .container.py-5 {
        padding-top: 1.5rem !important;
        padding-bottom: 1.5rem !important;
    }
}
