/* ═══════════════════════════════════════════════════════════════════════════
   RESPONSIVE — conservative mobile/tablet tweaks.

   Tenant-agnostic, loaded for every install. Intentionally minimal after
   the v2 overhaul broke things — this file:
     - Only adjusts padding/font-size/spacing on small viewports
     - Does NOT override .modal positioning
     - Does NOT inject any bottom nav or DOM elements
     - Does NOT add position:sticky to table headers/cells
     - Does NOT change min-height of inputs/buttons (Rise's defaults stand)
     - DOES keep the one safe iOS no-zoom rule (font-size: 16px on inputs)
   ═══════════════════════════════════════════════════════════════════════════ */

/* ── Tablets and below (<= 991px) ────────────────────────────────────────── */
@media (max-width: 991px) {
    /* Topbar — slightly tighter */
    .navbar-custom { padding: 0 16px; }

    /* Cards — tighter on tablets */
    .card-header { padding: 14px 18px; }
    .card-body   { padding: 18px; }
    .card-footer { padding: 12px 18px; }

    /* Modals */
    .modal-header { padding: 14px 18px; }
    .modal-body   { padding: 18px; }
    .modal-footer { padding: 14px 18px; }

    /* Page title — smaller heading */
    .page-title h1 { font-size: 20px; }
}

/* ── Mobile (<= 767px) ───────────────────────────────────────────────────── */
@media (max-width: 767px) {

    /* Topbar */
    .navbar-custom { padding: 0 10px; }
    .navbar-custom .user-name { display: none; }
    .navbar-custom .avatar-xs { width: 30px; height: 30px; }

    /* Topbar dropdowns — don't escape the viewport */
    .navbar-custom .dropdown-menu { max-width: calc(100vw - 16px); }
    .dropdown-menu.notification-dropdown,
    .dropdown-menu.message-dropdown,
    .dropdown-menu.w400,
    .dropdown-menu.w300 {
        width: calc(100vw - 16px) !important;
        max-width: 400px;
    }

    /* Page title — smaller heading */
    .page-title h1 { font-size: 18px; }
    .title-button-group {
        display: flex;
        flex-wrap: wrap;
        gap: 6px;
    }

    /* Cards — tighter */
    .card-header { padding: 12px 14px; font-size: 14px; }
    .card-body   { padding: 14px; }
    .card-footer { padding: 11px 14px; }

    /* Modals — Bootstrap's default mobile modal stays put; just tighten chrome */
    .modal-header { padding: 12px 14px; }
    .modal-body   { padding: 14px; }
    .modal-footer {
        padding: 12px 14px;
        flex-wrap: wrap;
        gap: 6px;
    }
    .modal-title { font-size: 16px; }

    /* iOS no-zoom: form font-size >= 16px on touch devices */
    .form-control,
    .form-select,
    input[type="text"], input[type="email"], input[type="password"],
    input[type="number"], input[type="search"], input[type="tel"],
    input[type="url"], textarea, select {
        font-size: 16px;
    }

    /* DataTables toolbar — stack instead of cramming */
    .dataTables_wrapper .dataTables_filter,
    .dataTables_wrapper .dataTables_length {
        float: none !important;
        width: 100%;
        text-align: start;
        margin-bottom: 8px;
    }
    .dataTables_wrapper .dataTables_filter input { width: 100%; }
    .dataTables_wrapper .dt-buttons {
        float: none !important;
        display: flex;
        flex-wrap: wrap;
        gap: 6px;
        margin-bottom: 8px;
    }
    [dir="rtl"] .dataTables_wrapper .dataTables_filter,
    [dir="rtl"] .dataTables_wrapper .dataTables_length,
    [dir="rtl"] .dataTables_wrapper .dt-buttons {
        float: none !important;
        text-align: right;
    }

    /* Tabs scrollable horizontally rather than wrapping */
    .nav-tabs {
        flex-wrap: nowrap;
        overflow-x: auto;
        overflow-y: hidden;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
    }
    .nav-tabs::-webkit-scrollbar { display: none; }
    .nav-tabs .nav-link { white-space: nowrap; }
}

/* ── Small phones (<= 480px) ─────────────────────────────────────────────── */
@media (max-width: 480px) {
    .page-title h1 { font-size: 16px; }
    .card-body   { padding: 12px; }
    .card-header { padding: 11px 12px; }
    .signin-form { padding: 22px 18px !important; }
}

/* ── Coarse pointer — branded tap highlight, no hover-lift on touch ──────── */
@media (pointer: coarse) {
    * { -webkit-tap-highlight-color: rgba(37, 99, 235, 0.16); }
    .btn-primary:hover,
    .card.dashboard-icon-widget:hover {
        transform: none;
    }
}

/* ── Mobile topbar — search pill surfaces, user-avatar moves to sidebar ──── */
@media (max-width: 767px) {
    /* SEARCH PILL: re-enable on phones (replaces the avatar slot, per
       user request). Compact and capped at ~140px so there's still room
       for the language toggle and notification bell. Type-selector
       ("Tasks ▼") hidden — just the search input remains. */
    .navbar-custom .navbar-search-pill-wrapper {
        display: flex !important;
        flex: 1 1 auto;
        min-width: 0;
        max-width: 150px;       /* keep narrow so bell + AR|EN fit too */
        margin-inline: 6px;
    }
    .navbar-custom .navbar-search-box {
        height: 34px;
        max-width: 100%;
        padding-inline: 8px;
        gap: 4px;
    }
    /* Hide the type-selector on mobile — too much horizontal real estate.
       Search defaults to whatever's stored in the cookie. */
    .navbar-custom .navbar-search-box .navbar-search-type {
        display: none !important;
    }
    .navbar-custom .navbar-search-input {
        font-size: 13px;
        min-width: 0;
    }
    .navbar-custom .navbar-search-input::placeholder {
        font-size: 12px;
    }
    .navbar-custom .navbar-search-shortcut {
        display: none;        /* no physical "/" key on phones */
    }
    /* The icon-only search-btn (#topbar-search-btn) is now redundant with
       the inline pill — hide it to avoid two search affordances. */
    .navbar-custom #topbar-search-btn { display: none !important; }

    /* USER DROPDOWN (avatar+name): hide on phones — it now lives at the top
       of the sidebar (see .sidebar-user-profile block in left_menu.php). */
    .navbar-custom .topbar-user-dropdown-li { display: none !important; }

    /* Reminder/clock icon hidden on mobile — not critical, reachable from
       the bell's full notifications page or from the user's profile menu. */
    .navbar-custom .topbar-right .navbar-nav > li.nav-item.dropdown:has(#reminder-icon) {
        display: none !important;
    }

    /* Tighter navbar padding on phones */
    .navbar-custom { padding-inline: 12px; }
    .navbar-custom .topbar-left { gap: 4px; }
    .navbar-custom .topbar-right .navbar-nav { gap: 4px; }

    /* Brand logo cap a touch tighter on phones */
    .navbar-custom #dashboard-link.brand-logo img.dashboard-image {
        max-height: 28px;
    }

    /* ── Dashboard top widgets: 2×2 grid on phones ───────────────────────
       The 4 small "Clock In / My Open Tasks / Events Today / Due" cards
       are .widget-container.col-md-3 → full-width on mobile by default,
       which makes you scroll past 4 tall cards just to reach real data.
       Halve them so they pair up in a 2-column grid. The bigger charts
       below (col-md-4 / col-md-6 / col-md-8 with .card.bg-white) stay
       full-width because their internal layout doesn't fit half a phone. */
    .dashboards-row > .widget-container.col-md-3 {
        width: 50% !important;
        flex: 0 0 50% !important;
        max-width: 50% !important;
    }
    /* Explicitly force the bigger overview cards to stay full-width, in case
       any global rule starts shrinking them. */
    .dashboards-row > .widget-container.col-md-4,
    .dashboards-row > .widget-container.col-md-6,
    .dashboards-row > .widget-container.col-md-8,
    .dashboards-row > .widget-container.col-md-12 {
        width: 100% !important;
        flex: 0 0 100% !important;
        max-width: 100% !important;
    }

    /* Restructure the small icon-widgets to a vertical stack (icon row,
       then number/label below) — that gives the number+label the FULL
       card width so currency values like "38,600.00ر.س" fit without
       truncation. Original layout (float-left icon, absolute-right
       details) doesn't survive a half-phone-wide card. Scoped to the
       .card.dashboard-icon-widget so the bigger overview cards are
       untouched. */
    .dashboards-row > .widget-container .card.dashboard-icon-widget .card-body {
        display: flex !important;
        flex-direction: column;
        align-items: stretch;
        gap: 8px;
        padding: 12px 14px !important;
        position: relative;
    }
    .dashboards-row > .widget-container .card.dashboard-icon-widget .widget-icon {
        position: static !important;
        float: none !important;
        margin: 0 !important;
        flex-shrink: 0;
        width: 36px !important;
        height: 36px !important;
        border-radius: 8px;
        align-self: flex-start;     /* icon hugs leading edge */
    }
    [dir="rtl"] .dashboards-row > .widget-container .card.dashboard-icon-widget .widget-icon {
        align-self: flex-end;       /* RTL: icon hugs right edge */
    }
    .dashboards-row > .widget-container .card.dashboard-icon-widget .widget-icon .icon {
        width: 1.1rem !important;
        height: 1.1rem !important;
    }
    .dashboards-row > .widget-container .card.dashboard-icon-widget .widget-details {
        position: static !important;
        right: auto !important;
        left: auto !important;
        width: 100%;
        min-width: 0;
        text-align: start;
    }
    [dir="rtl"] .dashboards-row > .widget-container .card.dashboard-icon-widget .widget-details {
        text-align: right;
    }
    .dashboards-row > .widget-container .card.dashboard-icon-widget .widget-details h1 {
        font-size: 19px !important;
        line-height: 1.15;
        margin: 0;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }
    .dashboards-row > .widget-container .card.dashboard-icon-widget .widget-details span,
    .dashboards-row > .widget-container .card.dashboard-icon-widget .widget-details .bg-transparent-white {
        font-size: 12px;
        display: block;
        margin-top: 2px;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }
    /* Clock-In card has a button instead of an h1. Compact + full-width
       so the label "Clock In" / "تسجيل الدخول" doesn't overflow. */
    .dashboards-row > .widget-container .card.dashboard-icon-widget .widget-details .btn {
        padding: 5px 10px;
        font-size: 12px;
        white-space: nowrap;
        display: inline-flex;
        align-items: center;
        gap: 4px;
    }
    .dashboards-row > .widget-container .card.dashboard-icon-widget .widget-details .btn .icon-16 {
        width: 12px;
        height: 12px;
    }
}

/* ── Slide-over form modals: full-width on phones (Pass 2 companion) ─────── */
@media (max-width: 767px) {
    .modal.fade .modal-dialog.modal-lg,
    .modal.fade .modal-dialog.modal-extra-large,
    .modal.fade .modal-dialog.modal-xl {
        max-width: 100% !important;
    }
    .modal-dialog.modal-lg .modal-header,
    .modal-dialog.modal-extra-large .modal-header,
    .modal-dialog.modal-xl .modal-header {
        padding: 14px 16px;
    }
    .modal-dialog.modal-lg .modal-body,
    .modal-dialog.modal-extra-large .modal-body,
    .modal-dialog.modal-xl .modal-body,
    .modal-dialog.modal-lg #ajaxModalContent,
    .modal-dialog.modal-extra-large #ajaxModalContent,
    .modal-dialog.modal-xl #ajaxModalContent {
        padding: 16px;
    }
    .modal-dialog.modal-lg .modal-footer,
    .modal-dialog.modal-extra-large .modal-footer,
    .modal-dialog.modal-xl .modal-footer {
        padding: 12px 16px;
    }
}

/* ─── Accessibility: comfortable touch targets on coarse pointers ─────────────
   WCAG 2.5.5 — interactive controls should be at least ~44px on touch. Scoped
   to coarse pointers so it never bloats the desktop density. */
@media (pointer: coarse) {
    .table td .btn,
    table.dataTable td .btn,
    .dropdown-menu .dropdown-item,
    .kanban-item .kanban-item-actions a,
    .nav-tabs .nav-link {
        min-height: 44px;
        display: inline-flex;
        align-items: center;
    }
    .dropdown-menu .dropdown-item { min-height: 40px; }
}
