/* ============================================
   Responsive Overrides
   ============================================ */

/* Tablet and below */
@media (max-width: 991px) {
    :root {
        --sidebar-width: 260px;
    }

    .sidebar {
        transform: translateX(100%);
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .main-content {
        margin-right: 0;
        max-width: 100vw;
    }

    body.sidebar-collapsed .sidebar.open {
        transform: translateX(0);
    }

    .content-wrapper {
        padding: 16px;
    }

    .page-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .row .col-3,
    .row .col-4 {
        flex: 0 0 50%;
        max-width: 50%;
        margin-bottom: 8px;
    }
}

/* Mobile */
@media (max-width: 768px) {
    html {
        font-size: 13px;
    }

    /* 16px on fields so iOS Safari does not zoom the page on focus (13px root made them ~11.7px) */
    .form-control,
    .form-control-sm,
    .form-select,
    select,
    textarea,
    input[type="text"],
    input[type="search"],
    input[type="email"],
    input[type="number"],
    input[type="password"],
    input[type="tel"],
    input[type="url"],
    input[type="date"],
    input[type="datetime-local"],
    input[type="month"],
    input[type="time"],
    input:not([type]),
    .dataTables_wrapper .dataTables_filter input,
    .dataTables_wrapper .dataTables_length select,
    .select2-container--default .select2-selection--single .select2-selection__rendered,
    .select2-search--dropdown .select2-search__field,
    .select2-container .select2-search--inline .select2-search__field {
        font-size: 16px;
    }

    .content-wrapper {
        padding: 12px;
    }

    .card-body {
        padding: 14px;
    }

    .card-header {
        padding: 12px 14px;
    }

    .row .col-3,
    .row .col-4,
    .row .col-6 {
        flex: 0 0 50%;
        max-width: 50%;
    }

    .page-header h2 {
        font-size: 1.2rem;
    }

    /* DataTables mobile adjustments */
    .dataTables_wrapper .dataTables_length,
    .dataTables_wrapper .dataTables_filter {
        float: none;
        text-align: right;
    }

    .dataTables_wrapper .dataTables_filter input {
        width: 100%;
        margin-right: 0;
        margin-top: 8px;
    }

    .dataTables_wrapper .dataTables_info,
    .dataTables_wrapper .dataTables_paginate {
        float: none;
        text-align: center;
    }

    /* Sticky actions column on left (RTL) */
    .table-responsive table td.actions-sticky,
    .table-responsive table th.actions-sticky {
        position: sticky;
        left: 0;
        z-index: 2;
        background: var(--bg-card);
        box-shadow: 2px 0 8px rgba(0, 0, 0, 0.08);
        min-width: 90px;
    }

    .table-responsive table tbody tr:nth-child(even) td.actions-sticky {
        background: var(--bg-table-stripe);
    }

    .table-responsive table tbody tr:hover td.actions-sticky {
        background: var(--bg-table-hover);
    }

    /* Compact action buttons on mobile */
    .actions-cell {
        gap: 2px;
    }

    .actions-cell .btn {
        padding: 3px 6px;
        font-size: 0.75rem;
    }

    .actions-cell .btn-text {
        display: none;
    }

    /* Stat cards */
    .stat-card .stat-value {
        font-size: 1.4rem;
    }

    .stat-card .stat-label {
        font-size: 0.78rem;
    }

    /* Modal */
    .modal {
        width: 95%;
        max-height: 95vh;
    }

    .modal-body {
        padding: 14px;
    }

    .top-header {
        padding: 0 12px;
    }

    .user-dropdown-btn .user-name {
        display: none;
    }

    /* Quick Nav — mobile */
    .quick-nav-label { display: none; }
    .quick-nav-btn { padding: 7px 10px; }
    .quick-nav-panel {
        position: fixed;
        top: var(--header-height);
        right: 0;
        left: 0;
        min-width: unset;
        border-radius: 0 0 12px 12px;
        max-height: calc(100vh - var(--header-height));
        overflow-y: auto;
    }
    .qn-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 10px;
    }

    /* Notification panel — mobile */
    .notif-panel {
        position: fixed;
        top: var(--header-height);
        left: 0;
        right: 0;
        width: auto;
        border-radius: 0 0 12px 12px;
        max-height: calc(100vh - var(--header-height));
    }
}

/* Small mobile */
@media (max-width: 480px) {
    .row .col-3,
    .row .col-4,
    .row .col-6 {
        flex: 0 0 100%;
        max-width: 100%;
    }

    .stat-card {
        padding: 14px;
    }

    .login-card {
        padding: 24px;
    }

    .page-header .btn {
        width: 100%;
        justify-content: center;
    }
}

/* Large desktop */
@media (min-width: 1400px) {
    .content-wrapper {
        max-width: 1400px;
        /* width:100% keeps the full width: auto side margins on a flex item disable stretching */
        width: 100%;
        margin-inline: auto;
    }
}

/* Touch screens: at least 44x44px hit areas (desktop/mouse look unchanged) */
@media (pointer: coarse) {
    .btn-icon,
    .btn-icon.btn-sm,
    .actions-kebab,
    .modal-close,
    .btn-close,
    .sidebar-toggle,
    .notif-bell-btn {
        min-width: 44px;
        min-height: 44px;
    }

    /* Checkbox/radio rows wrapped in a .form-check label: the whole row is the target */
    .form-check {
        min-height: 44px;
    }

    /* Bare checkboxes/radios (e.g. inside tables) grow to 24px (WCAG 2.5.8) rather than 44px,
       which would distort table rows */
    input[type="checkbox"],
    input[type="radio"] {
        min-width: 24px;
        min-height: 24px;
    }
}

/* Respect the OS "reduce motion" setting: drop entrance/pulse animations */
@media (prefers-reduced-motion: reduce) {
    html {
        scroll-behavior: auto;
    }

    .fade-in,
    .slide-in,
    .flash-message,
    .login-card,
    .modal-backdrop,
    .quick-nav-panel,
    .notif-panel,
    .actions-drop-menu,
    .notif-badge,
    .tasks-panel.show,
    .td-backdrop.show,
    .tasks-fab.pulse::after {
        animation: none !important;
    }

    /* modalSlideIn also performed the scale(0.95) -> scale(1) step */
    .modal {
        animation: none !important;
        transform: translate(-50%, -50%);
    }

    .stat-card:hover,
    .quick-nav-btn:hover,
    .qn-link:hover,
    .tasks-fab:hover {
        transform: none !important;
    }
}
