/**
 * Mobile Responsive Fixes - 100% Mobile User Friendly
 * Prevents overflow, horizontal scroll, overlap on small screens
 */

/* Global: Prevent horizontal scroll */
html, body { overflow-x: hidden; max-width: 100vw; }
.wrapper { overflow-x: hidden; }
.content-wrapper { overflow-x: hidden; max-width: 100%; }
.main-content { overflow-x: hidden; }

/* Tables: Always allow horizontal scroll when needed */
.table-responsive { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table-responsive table { min-width: 100%; }

/* Cards and containers */
.card-body { overflow-x: auto; }
.container-fluid { max-width: 100%; padding-left: 0.5rem; padding-right: 0.5rem; }

/* Invoice create/edit: card-body overflow:auto clips the calendar; tables use .table-responsive for horizontal scroll */
.erp-invoice-form .card-body {
  overflow: visible !important;
}
@media (min-width: 768px) {
  .erp-invoice-form .table-responsive {
    overflow-x: visible !important;
  }
}

/* Tempus Dominus: never shrink inside a scrollable dropdown; stack above cards */
.bootstrap-datetimepicker-widget.dropdown-menu {
  z-index: 1060 !important;
  max-height: none !important;
  overflow: visible !important;
  overflow-y: visible !important;
}
@media (max-width: 575.98px) {
  .container-fluid { padding-left: 0.75rem; padding-right: 0.75rem; }
}

/* Touch targets: min 44x44px for critical action buttons (mobile only) */
@media (max-width: 767.98px) {
  .emp-btn-wa, .emp-btn-edit, .schedule-edit-btn {
    min-width: 44px !important;
    min-height: 44px !important;
    width: 44px !important;
    height: 44px !important;
    padding: 0.5rem !important;
  }
  .nav-link[data-widget="pushmenu"] { min-width: 44px; min-height: 44px; padding: 0.75rem; }
}

/* Navbar balance/text overflow */
@media (max-width: 767.98px) {
  .navbar .nav-link { padding: 0.5rem; font-size: 0.75rem; }
  .main-header .navbar-nav .nav-link { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 120px; }
}

/* Employee details: full width on mobile */
@media (max-width: 767.98px) {
  .col-md-4, .col-md-8 { flex: 0 0 100%; max-width: 100%; }
  .widget-user-image img { max-width: 100%; height: auto; }
}

/* Schedule grid: 2 columns on very small screens */
@media (max-width: 575.98px) {
  .emp-schedule-grid { grid-template-columns: repeat(2, 1fr) !important; }
  .schedule-slots { flex-direction: column !important; }
  .schedule-slot-card { max-width: 100% !important; }

}

/* Schedule modal: stack columns on mobile */
@media (max-width: 767.98px) {
  .schedule-slot-row { flex-wrap: wrap; }
  .schedule-slot-row .col-2 { flex: 0 0 50%; max-width: 50%; }
  .schedule-slot-row .col-3 { flex: 0 0 100%; max-width: 100%; }
  .schedule-slot-row .col-1 { flex: 0 0 100%; max-width: 100%; text-align: left !important; }
}

/* Email template preview: responsive on mobile */
@media (max-width: 767.98px) {
  .MainContainer, table.MainContainer { max-width: 100% !important; width: 100% !important; }
}

/* Connection list: branch boxes use col-6 col-sm-4 col-md-3 (handled in view) */
.connection-map-container { min-height: 400px !important; }
@media (max-width: 767.98px) {
  .connection-map-container { height: 450px !important; }
}

/* Map popups: responsive width */
@media (max-width: 575.98px) {
  .leaflet-popup-content-wrapper { max-width: 95vw !important; min-width: 0 !important; }
  .leaflet-popup-content { min-width: 0 !important; max-width: 95vw !important; }
  .map-popup-table { min-width: 0 !important; }
}

/* Fixed width elements: make responsive */
img { max-width: 100%; height: auto; }
table { width: 100% !important; max-width: 100%; }
input[type="date"], input[type="text"], input[type="number"], select, textarea {
  max-width: 100%;
}

/* Form filters: ensure full width when needed (target filter rows) */
@media (max-width: 767.98px) {
  .filter-row .col-md-1, .filter-row .col-md-2, .filter-row .col-md-3,
  .filter-row .col-md-4, .advance-search .col-md-2, .advance-search .col-md-3 {
    flex: 0 0 100%;
    max-width: 100%;
    margin-bottom: 0.5rem;
  }
}

/* Modal: full width on mobile */
@media (max-width: 767.98px) {
  .modal-dialog { margin: 0.5rem; max-width: calc(100% - 1rem); }
  .modal-lg { max-width: calc(100% - 1rem); }
}

/* DataTables: responsive - fix serial/+ alignment (serial below + issue) - ALL PAGES */
table.dataTable.dtr-inline.collapsed th:first-child,
table.dataTable.dtr-inline.collapsed td:first-child {
  min-width: 2.8rem !important;
}
table.dataTable.dtr-inline.collapsed tbody tr[role="row"] > td:first-child,
table.dataTable.dtr-inline.collapsed tbody tr[role="row"] > th:first-child {
  display: flex !important;
  align-items: center !important;
  flex-wrap: nowrap !important;
  min-width: 2.8rem !important;
  padding-left: 6px !important;
  white-space: nowrap !important;
}
table.dataTable.dtr-inline.collapsed tbody tr[role="row"] > td:first-child:before,
table.dataTable.dtr-inline.collapsed tbody tr[role="row"] > th:first-child:before {
  flex-shrink: 0 !important;
  position: static !important;
  margin-right: 6px !important;
  top: auto !important;
  left: auto !important;
  float: none !important;
}
/* DataTables: horizontal scroll when table overflows */
.dataTables_wrapper .dataTables_scrollBody,
.dataTables_wrapper .table-responsive { overflow-x: auto !important; -webkit-overflow-scrolling: touch; }
@media (max-width: 767.98px) {
  .dataTables_wrapper .dataTables_length,
  .dataTables_wrapper .dataTables_filter { text-align: left; margin-bottom: 0.5rem; }
  .dataTables_wrapper .dataTables_paginate { margin-top: 0.5rem; }
}

/* Card header + filter: fix broken layout on mobile - ALL PAGES */
@media (max-width: 767.98px) {
  .card-header {
    display: block !important;
    flex-wrap: wrap !important;
  }
  .card-header .card-title {
    display: block !important;
    width: 100% !important;
    margin-bottom: 0.5rem !important;
  }
  .card-header .card-tools {
    display: block !important;
    float: none !important;
    width: 100% !important;
    margin: 0 !important;
    padding: 0 !important;
  }
  .card-header .card-tools form,
  .card-header .card-tools .form-inline,
  .card-header .card-tools .d-inline-flex {
    display: flex !important;
    flex-wrap: wrap !important;
    gap: 6px !important;
    margin-bottom: 0.5rem !important;
    align-items: center !important;
  }
  .card-header .card-tools form select,
  .card-header .card-tools .form-control {
    flex: 1 1 100px !important;
    min-width: 0 !important;
    max-width: 100% !important;
  }
  .card-header .card-tools form .btn,
  .card-header .card-tools form a,
  .card-header .card-tools .btn {
    flex-shrink: 0 !important;
  }
  .card-header .card-tools > form,
  .card-header .card-tools > a,
  .card-header .card-tools > b {
    display: block !important;
    margin-bottom: 0.4rem !important;
  }
  .card-header .card-tools > b:last-child {
    margin-bottom: 0 !important;
  }
}

/* Prevent text overflow */
.text-nowrap { overflow-wrap: break-word; }
@media (max-width: 767.98px) {
  .text-nowrap { white-space: normal !important; }
}

/* Back to top button: mobile friendly */
.back-to-top { position: fixed; bottom: 20px; right: 20px; z-index: 999; min-width: 44px; min-height: 44px; }

/* ----- Login / auth (WebView-ready, touch-friendly) ----- */
.login-page { overflow-x: hidden; }
.login-page .login-brand-logo {
  max-width: min(220px, 85vw);
  width: auto;
  height: auto;
}
@media (max-width: 575.98px) {
  .login-page .login-box {
    width: 100%;
    max-width: 100%;
    padding-left: 12px;
    padding-right: 12px;
    margin-top: 0.5rem;
  }
  .login-page .login-card-body {
    padding: 1.25rem 1rem;
  }
  .login-page .input-group .form-control {
    min-height: 46px;
    font-size: 16px; /* reduces iOS zoom-on-focus */
  }
  .login-page .input-group-text {
    min-height: 46px;
    align-items: center;
  }
  .login-page .btn-login-submit {
    min-height: 48px;
    font-size: 1rem;
    font-weight: 600;
  }
  .login-page .icheck-primary label {
    padding-top: 2px;
    padding-bottom: 2px;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
  }
}

/* ----- Top navbar: wallet (amount + icon; compact on phone) ----- */
@media (max-width: 767.98px) {
  .main-header .navbar-nav a.erp-navbar-wallet {
    padding: 0.35rem 0.4rem !important;
    font-size: 0.72rem;
    line-height: 1.25;
    min-height: 2.25rem !important;
    height: auto !important;
    max-height: none !important;
    display: inline-flex !important;
    align-items: center;
    max-width: 46vw;
    white-space: nowrap;
    gap: 0.25rem;
  }
  .main-header .navbar-nav a.erp-navbar-wallet .erp-navbar-wallet-amt {
    font-variant-numeric: tabular-nums;
  }
}

/* Dashboard: check-in reminder — full-width CTA on small phones */
@media (max-width: 575.98px) {
  .erp-dash-checkin-banner {
    flex-direction: column !important;
    align-items: stretch !important;
  }
  .erp-dash-checkin-banner .erp-dash-checkin-btn {
    width: 100%;
    margin-left: 0 !important;
    margin-top: 0.65rem;
    min-height: 44px;
    font-weight: 600;
  }
}

/* Page header: breadcrumb stacks under title on narrow screens (partial: page_header) */
@media (max-width: 767.98px) {
  .content-header .breadcrumb {
    padding-left: 0;
    padding-right: 0;
    font-size: 0.875rem;
  }
}

/* ----- Report pages: wide tables + stacked header filters (.erp-report-page) ----- */
@media (max-width: 767.98px) {
  .erp-report-page .card-body .table-responsive {
    -webkit-overflow-scrolling: touch;
  }
  .erp-report-page .card-header .card-tools .erp-report-filter-form .form-control {
    min-height: 44px;
    font-size: 16px;
  }
  .erp-report-page .card-header .card-tools .erp-report-search-btn {
    min-height: 44px;
  }
}
@media (min-width: 768px) {
  .erp-report-page .card-header .card-tools .erp-report-search-btn.w-100 {
    width: auto !important;
  }
}

/* Client search in card header (e.g. expense/list) */
@media (min-width: 768px) {
  .erp-list-page .card-header .card-tools .erp-client-search-wrap {
    max-width: 280px;
  }
}
@media (max-width: 767.98px) {
  .erp-list-page .card-header .card-tools .erp-client-search-wrap .form-control {
    min-height: 44px;
    font-size: 16px;
  }
  .erp-list-page .card-header .card-tools .erp-client-search-wrap .btn {
    min-height: 44px;
    min-width: 44px;
  }
}

/* ----- List pages: filters + DataTables (wrapper: .erp-list-page) ----- */
@media (max-width: 767.98px) {
  .erp-list-page .card-tools .btn {
    min-height: 40px;
  }
  .erp-list-page .card-body .filter-row .btn {
    min-height: 42px;
    padding-left: 0.75rem;
    padding-right: 0.75rem;
  }
  .erp-list-page .dataTables_wrapper .page-link {
    min-height: 40px;
    min-width: 2.35rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }
  .erp-list-page .select2-container {
    width: 100% !important;
    max-width: 100%;
  }
}
