/* =============================================================================
   SwiftRun Admin — Comprehensive Responsive Stylesheet
   Fixes every breakpoint gap in the Velonic Bootstrap 5 theme.
   Load AFTER app.min.css and icons.min.css.
   ============================================================================= */

/* ── 1. GLOBAL RESETS & UTILITIES ──────────────────────────────────────────── */

*,
*::before,
*::after {
  box-sizing: border-box;
}

img {
  max-width: 100%;
  height: auto;
}

/* Ensure all table containers scroll horizontally — no exceptions */
.table-responsive,
.card-body .table-responsive,
.table-container {
  -webkit-overflow-scrolling: touch;
  overflow-x: auto;
}

/* Force all bare tables inside cards to be scrollable */
.card-body > .table,
.card > .table {
  display: block;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  white-space: nowrap;
}

/* Prevent horizontal body overflow */
body {
  overflow-x: hidden;
}

/* ── 2. TOPBAR ──────────────────────────────────────────────────────────────── */

.navbar-custom {
  min-height: 60px;
}

.navbar-custom .topbar {
  padding: 0 12px;
  flex-wrap: nowrap;
  min-width: 0;
}

.topbar-menu {
  flex-shrink: 0;
  gap: 8px !important;
}

.logo-topbar .logo-lg img,
.leftside-menu .logo-lg img {
  max-width: 140px;
  height: auto !important;
}

.logo-topbar .logo-sm img,
.leftside-menu .logo-sm img {
  height: auto !important;
  max-height: 32px;
}

/* ── 3. SIDEBAR ─────────────────────────────────────────────────────────────── */

/* Ensure sidebar scrolls on short screens */
#leftside-menu-container {
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
}

/* Sidebar links — comfortable tap targets */
.side-nav .side-nav-link {
  padding: 10px 20px;
  min-height: 44px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.side-nav-title {
  padding: 12px 20px 4px;
  font-size: 10px;
  letter-spacing: 0.8px;
  text-transform: uppercase;
}

/* ── 4. CONTENT PAGE ────────────────────────────────────────────────────────── */

.content-page {
  min-height: 100vh;
}

.content-page .content {
  padding: 0 12px 24px;
}

/* ── 5. PAGE TITLE & BREADCRUMB ─────────────────────────────────────────────── */

.page-title-box {
  display: flex;
  align-items: flex-start;
  flex-wrap: wrap;
  gap: 8px;
  padding: 20px 0 16px;
}

.page-title-box .page-title {
  margin: 0;
  font-size: 18px;
  flex-shrink: 0;
}

.page-title-right {
  margin-left: auto;
}

.breadcrumb {
  flex-wrap: wrap;
  margin-bottom: 0 !important;
}

.breadcrumb-item {
  font-size: 12px;
}

/* ── 6. STAT / KPI CARDS (dashboard + list page headers) ───────────────────── */

/* Any row of cards using col-md-3 should become 2-per-row on mobile */
.row > [class*="col-md-3"],
.row > [class*="col-xxl-3"] {
  /* We can't change the HTML, so use CSS grid override trick */
}

/* Override col-md-3 cards to be 2-up on small screens */
@media (max-width: 575.98px) {
  .row > .col-md-3,
  .row > .col-md-4,
  .row > .col-xxl-3,
  .row > .col-xxl-4 {
    flex: 0 0 50%;
    max-width: 50%;
  }

  .row > .col-md-2 {
    flex: 0 0 50%;
    max-width: 50%;
  }

  /* Quick action buttons — 2 per row on mobile */
  .row > .col-md-2 .btn {
    font-size: 12px;
    padding: 8px 10px;
  }
}

@media (min-width: 576px) and (max-width: 767.98px) {
  .row > .col-md-3,
  .row > .col-xxl-3 {
    flex: 0 0 50%;
    max-width: 50%;
  }

  .row > .col-md-2 {
    flex: 0 0 33.333%;
    max-width: 33.333%;
  }
}

/* ── 7. FILTER BARS ─────────────────────────────────────────────────────────── */

/* Filter rows: make each filter full-width on mobile, 2-up on tablet */
.card-body .row.mb-3 > [class*="col-md"],
.card-body .row.g-2 > [class*="col-md"],
.card-body .row.g-3 > [class*="col-md"],
.card-body form.row > [class*="col-md"],
.card-body form.row > [class*="col-auto"] {
  /* handled per breakpoint below */
}

@media (max-width: 575.98px) {
  /* All filter columns stack full-width on phones */
  .card-body .row.mb-3 > [class*="col-"],
  .card-body .row.g-2 > [class*="col-"],
  .card-body .row.g-3 > [class*="col-"],
  .card-body form.row > [class*="col-"] {
    flex: 0 0 100%;
    max-width: 100%;
    width: 100%;
  }

  .card-body form.row > .col-auto {
    flex: 0 0 100%;
    max-width: 100%;
  }

  .form-select,
  .form-control {
    width: 100% !important;
    max-width: 100% !important;
  }

  /* Filter submit buttons full width */
  .card-body form.row .btn {
    width: 100%;
    margin-bottom: 4px;
  }
}

@media (min-width: 576px) and (max-width: 991.98px) {
  /* Filter columns: 2-per-row on tablet */
  .card-body .row.mb-3 > .col-md-3,
  .card-body .row.mb-3 > .col-md-2,
  .card-body .row.g-2 > .col-md-3,
  .card-body .row.g-2 > .col-md-2 {
    flex: 0 0 50%;
    max-width: 50%;
  }
}

/* ── 8. TABLES ──────────────────────────────────────────────────────────────── */

/* All tables: force horizontal scroll container */
.table-responsive {
  border-radius: 0 0 8px 8px;
  margin-bottom: 0;
}

/* Remove nowrap on very small screens so text can wrap on critical columns */
@media (max-width: 575.98px) {
  .table.table-nowrap th,
  .table.table-nowrap td {
    white-space: normal;
    word-break: break-word;
  }

  /* But keep badge/status/amount columns from wrapping */
  .table td .badge,
  .table td .btn,
  .table td small.font-monospace {
    white-space: nowrap;
  }

  /* Smaller font in tables on mobile */
  .table th,
  .table td {
    font-size: 12px;
    padding: 8px 10px;
  }

  /* Hide low-priority table columns on phones */
  .table th.d-mobile-none,
  .table td.d-mobile-none {
    display: none !important;
  }
}

/* Action button cells: keep compact */
.table td:last-child .btn {
  white-space: nowrap;
}

/* ── 9. CARDS ───────────────────────────────────────────────────────────────── */

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

.card-header {
  padding: 14px 20px;
  border-bottom: 1px solid rgba(0, 0, 0, 0.07);
}

@media (max-width: 575.98px) {
  .card-body {
    padding: 14px;
  }

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

/* Widget / stat cards: ensure icon doesn't overflow */
.card.widget-flat .card-body {
  padding: 16px;
}

.widget-flat h2 {
  font-size: 22px;
  word-break: break-all;
}

.widget-flat .widget-icon {
  font-size: 24px;
}

@media (max-width: 575.98px) {
  .widget-flat h2 {
    font-size: 18px;
  }

  .widget-flat h6 {
    font-size: 10px;
  }

  .widget-flat .widget-icon {
    font-size: 20px;
  }

  .widget-flat p {
    font-size: 11px;
  }

  .widget-flat .badge {
    font-size: 10px;
    padding: 2px 6px;
  }
}

/* ── 10. DETAIL PAGES (two-column layouts) ───────────────────────────────────── */

/* col-lg-8 / col-lg-4 pair — stack below lg */
@media (max-width: 991.98px) {
  .row > .col-lg-8,
  .row > .col-lg-4,
  .row > .col-lg-6 {
    flex: 0 0 100%;
    max-width: 100%;
  }
}

/* Definition list rows in detail cards */
dl.row dt,
dl.row dd {
  padding: 4px 0;
}

@media (max-width: 575.98px) {
  dl.row dt {
    flex: 0 0 45%;
    max-width: 45%;
    font-size: 12px;
    color: #6c757d;
  }

  dl.row dd {
    flex: 0 0 55%;
    max-width: 55%;
    font-size: 12px;
    word-break: break-word;
  }
}

/* ── 11. FORMS ──────────────────────────────────────────────────────────────── */

.form-label {
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 4px;
}

@media (max-width: 575.98px) {
  .form-control,
  .form-select,
  textarea.form-control {
    font-size: 14px; /* prevent iOS zoom on focus */
    min-height: 42px;
  }

  /* Stack form rows */
  .row.g-3 > [class*="col-lg"],
  .row.g-3 > [class*="col-md"],
  .row.g-2 > [class*="col-lg"],
  .row.g-2 > [class*="col-md"] {
    flex: 0 0 100%;
    max-width: 100%;
  }
}

/* ── 12. BUTTONS ────────────────────────────────────────────────────────────── */

/* Minimum tap target 44px */
.btn {
  min-height: 36px;
  padding: 6px 14px;
}

.btn-lg {
  min-height: 44px;
}

.btn-sm {
  min-height: 30px;
  padding: 3px 10px;
  font-size: 12px;
}

/* Status filter button groups — scroll horizontally on mobile */
.btn-group-filter,
.page-title-box .btn-group,
.card-body .d-flex.gap-1,
.card-body .d-flex.gap-2 {
  flex-wrap: wrap;
  gap: 6px !important;
}

@media (max-width: 575.98px) {
  /* Status filter tabs in orders/drivers/customers */
  .page-title-box .d-flex,
  .page-title-box + .card .card-body .d-flex {
    flex-wrap: wrap;
    gap: 4px !important;
  }

  .page-title-box .btn,
  .page-title-box + .card .card-body .btn {
    font-size: 11px;
    padding: 5px 10px;
  }
}

/* ── 13. STATUS FILTER BUTTON BAR (orders, drivers, etc.) ───────────────────── */

.status-filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 12px 16px;
  background: #f8f9fa;
  border-bottom: 1px solid #e9ecef;
}

.status-filter-bar .btn {
  font-size: 12px;
  padding: 5px 12px;
  border-radius: 20px;
}

/* The existing inline btn groups in the page-title-box */
@media (max-width: 767.98px) {
  .page-title-right .d-flex,
  .page-title-box .page-title-right {
    width: 100%;
    margin-top: 8px;
  }

  .page-title-right .btn-group {
    flex-wrap: wrap;
  }
}

/* ── 14. BADGES ─────────────────────────────────────────────────────────────── */

.badge {
  font-size: 11px;
  padding: 4px 8px;
  white-space: nowrap;
  border-radius: 6px;
}

/* ── 15. PAGINATION ─────────────────────────────────────────────────────────── */

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

.page-link {
  min-width: 36px;
  min-height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
}

/* ── 16. MODALS ─────────────────────────────────────────────────────────────── */

@media (max-width: 575.98px) {
  .modal-dialog {
    margin: 8px;
    max-width: calc(100vw - 16px);
  }

  .modal-body {
    padding: 16px;
  }

  .modal-footer {
    flex-direction: column;
    gap: 8px;
  }

  .modal-footer .btn {
    width: 100%;
  }
}

/* ── 17. ALERTS / TOASTS ────────────────────────────────────────────────────── */

.alert {
  border-radius: 10px;
  font-size: 13px;
}

/* Fixed position alerts should not overflow viewport */
.position-fixed.alert,
div[style*="position: fixed"],
div[style*="position:fixed"] {
  max-width: calc(100vw - 24px) !important;
  min-width: unset !important;
  right: 12px !important;
  left: 12px !important;
  width: auto !important;
}

/* ── 18. DROPDOWN MENUS ─────────────────────────────────────────────────────── */

@media (max-width: 575.98px) {
  .dropdown-menu {
    min-width: 160px;
    font-size: 13px;
  }

  /* Profile dropdown — don't go off screen */
  .dropdown-menu-end {
    right: 0 !important;
    left: auto !important;
  }
}

/* ── 19. OFFCANVAS (theme settings panel) ───────────────────────────────────── */

@media (max-width: 575.98px) {
  .offcanvas {
    width: 100% !important;
  }
}

/* ── 20. LOGIN PAGE ─────────────────────────────────────────────────────────── */

.account-pages {
  min-height: 100vh;
  display: flex;
  align-items: center;
}

@media (max-width: 575.98px) {
  .account-pages {
    padding: 16px 0 !important;
    align-items: flex-start;
  }

  .account-pages .card {
    border-radius: 0;
    box-shadow: none !important;
    border: none;
  }

  .account-pages .p-4 {
    padding: 20px 16px !important;
  }

  .account-pages .auth-brand {
    padding: 16px !important;
  }

  .account-pages .auth-brand img {
    max-height: 30px !important;
  }
}

/* ── 21. ERRAND ORDER DETAIL (2-col → 1-col stacking) ──────────────────────── */

@media (max-width: 991.98px) {
  .col-lg-8,
  .col-lg-4 {
    width: 100%;
  }
}

/* Code verification card — scale code on mobile */
@media (max-width: 575.98px) {
  .card [style*="font-size: 3rem"],
  .card p[style*="font-size: 3rem"] {
    font-size: 2rem !important;
    letter-spacing: 0.3rem !important;
  }
}

/* ── 22. REVENUE / FINANCE PAGES ────────────────────────────────────────────── */

@media (max-width: 575.98px) {
  .col-md-6.col-lg-3,
  .col-md-6 {
    /* Already handled by Bootstrap col-md-6, but ensure cards stack */
    margin-bottom: 12px;
  }
}

/* ── 23. DATA TABLES (custom JS tables) ─────────────────────────────────────── */

/* Wrap any raw table that doesn't have table-responsive parent */
table.table:not(.table-responsive table) {
  min-width: 600px;
}

.card-body > table.table {
  display: block;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

/* ── 24. CHARTS (ApexCharts) ─────────────────────────────────────────────────── */

.apexcharts-canvas {
  max-width: 100% !important;
}

/* ── 25. MOBILE-SPECIFIC SPACING CLEANUP ────────────────────────────────────── */

@media (max-width: 575.98px) {
  /* Reduce excessive vertical gaps */
  .mb-4 { margin-bottom: 16px !important; }
  .mb-3 { margin-bottom: 12px !important; }
  .mt-4 { margin-top: 16px !important; }

  /* Container padding */
  .container-fluid {
    padding-left: 12px !important;
    padding-right: 12px !important;
  }

  /* Content page */
  .content {
    padding: 0 !important;
  }

  /* Page title */
  .page-title {
    font-size: 16px !important;
  }

  /* Breadcrumb — hide on phones to save space */
  .breadcrumb {
    display: none !important;
  }

  /* Gap utilities on mobile */
  .gap-3 { gap: 8px !important; }
  .gap-2 { gap: 6px !important; }
}

@media (min-width: 576px) and (max-width: 767.98px) {
  .container-fluid {
    padding-left: 16px !important;
    padding-right: 16px !important;
  }
}

/* ── 26. TOPBAR USER AVATAR & PROFILE ───────────────────────────────────────── */

.nav-user .account-user-avatar img {
  width: 32px;
  height: 32px;
  object-fit: cover;
}

@media (max-width: 575.98px) {
  .topbar-menu .nav-user h5 {
    font-size: 13px;
  }
}

/* ── 27. TOUCH-FRIENDLY INTERACTIVE ELEMENTS ────────────────────────────────── */

/* All clickable elements: 44px minimum touch target */
.side-nav-link,
.btn,
.nav-link,
.dropdown-item,
.page-link,
.form-check-label {
  cursor: pointer;
}

/* ── 28. PRINT STYLES ───────────────────────────────────────────────────────── */

@media print {
  .leftside-menu,
  .navbar-custom,
  .page-title-right,
  .btn-group {
    display: none !important;
  }

  .content-page {
    margin-left: 0 !important;
  }

  .card {
    box-shadow: none !important;
    border: 1px solid #dee2e6 !important;
  }

  .table-responsive {
    overflow: visible !important;
  }

  table.table {
    min-width: unset !important;
  }
}

/* ── 29. QUICK ACTIONS GRID (dashboard) ─────────────────────────────────────── */

@media (max-width: 767.98px) {
  /* Quick action col-md-2 buttons — 3 per row on tablet */
  .row > .col-md-2 {
    flex: 0 0 33.333%;
    max-width: 33.333%;
  }
}

@media (max-width: 575.98px) {
  /* Quick action buttons — 2 per row on phone */
  .row > .col-md-2 {
    flex: 0 0 50%;
    max-width: 50%;
  }

  .row > .col-md-2 .btn-lg {
    font-size: 12px;
    padding: 8px;
    min-height: 48px;
  }

  .row > .col-md-2 .btn-lg i {
    display: block;
    font-size: 20px;
    margin-bottom: 4px;
    margin-right: 0 !important;
  }
}

/* ── 30. DARK MODE RESPONSIVE OVERRIDES ─────────────────────────────────────── */

[data-bs-theme="dark"] .card {
  border-color: rgba(255, 255, 255, 0.1);
}

[data-bs-theme="dark"] .table {
  color: inherit;
}

/* ── 31. SMOOTH TRANSITIONS FOR SIDEBAR ─────────────────────────────────────── */

.leftside-menu {
  transition: width 0.2s ease, transform 0.2s ease;
}

.content-page {
  transition: margin-left 0.2s ease;
}

/* ── 32. SCROLLBAR STYLING (webkit) ─────────────────────────────────────────── */

.table-responsive::-webkit-scrollbar,
#leftside-menu-container::-webkit-scrollbar {
  height: 4px;
  width: 4px;
}

.table-responsive::-webkit-scrollbar-track,
#leftside-menu-container::-webkit-scrollbar-track {
  background: transparent;
}

.table-responsive::-webkit-scrollbar-thumb,
#leftside-menu-container::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, 0.15);
  border-radius: 4px;
}

/* ── 33. SAFE AREA INSETS (notched devices) ─────────────────────────────────── */

@supports (padding: max(0px)) {
  .navbar-custom {
    padding-left: max(0px, env(safe-area-inset-left));
    padding-right: max(0px, env(safe-area-inset-right));
  }

  .leftside-menu {
    padding-bottom: max(0px, env(safe-area-inset-bottom));
  }

  .content-page {
    padding-bottom: max(16px, env(safe-area-inset-bottom));
  }
}

/* ── 34. LANDSCAPE PHONE TWEAKS ─────────────────────────────────────────────── */

@media (max-height: 500px) and (orientation: landscape) {
  .account-pages {
    align-items: flex-start;
    padding: 8px 0 !important;
  }

  .leftside-menu {
    overflow-y: auto;
  }
}

/* ── 35. FOCUS STATES (accessibility) ───────────────────────────────────────── */

.btn:focus-visible,
.form-control:focus,
.form-select:focus,
.nav-link:focus-visible {
  outline: 2px solid #0d6efd;
  outline-offset: 2px;
}

/* ── 36. TABLE COLUMN PRIORITY HELPERS ──────────────────────────────────────── */

/* Add these classes to table cells to control mobile visibility */
@media (max-width: 575.98px) {
  .col-hide-xs { display: none !important; }
}
@media (max-width: 767.98px) {
  .col-hide-sm { display: none !important; }
}
@media (max-width: 991.98px) {
  .col-hide-md { display: none !important; }
}

/* ── 37. CARD DECK EQUAL HEIGHT ─────────────────────────────────────────────── */

.row.row-deck > [class*="col"] {
  display: flex;
  flex-direction: column;
}

.row.row-deck > [class*="col"] > .card {
  flex: 1;
}

/* ── 38. INLINE STATUS BADGES IN TABLES ─────────────────────────────────────── */

.badge.fs-6 {
  font-size: 12px !important;
  padding: 5px 10px;
}

/* ── 39. FORM SECTIONS IN DETAIL PAGES ──────────────────────────────────────── */

@media (max-width: 575.98px) {
  .card-body .d-flex.justify-content-between {
    flex-direction: column;
    gap: 12px;
  }

  .card-body .d-flex.justify-content-between .btn {
    width: 100%;
  }

  /* Status update form */
  .card-body form.d-flex.gap-2 {
    flex-direction: column;
  }

  .card-body form.d-flex.gap-2 .btn {
    width: 100%;
  }

  .card-body form.d-flex.gap-2 > div {
    width: 100%;
  }
}

/* ── 40. RESPONSIVE IMAGES IN CARDS ─────────────────────────────────────────── */

.card-body img {
  max-width: 100%;
  height: auto;
}

/* Product/item images in tables */
.table img {
  max-width: 48px;
  height: 48px;
  object-fit: cover;
  border-radius: 6px;
}

/* ── 41. HAMBURGER / SIDEBAR TOGGLE (mobile) ─────────────────────────────────── */

/* Ensure hamburger button has a proper 44px touch target on mobile */
@media (max-width: 767.98px) {
  .button-toggle-menu {
    min-width: 44px;
    min-height: 44px;
    display: flex !important;
    align-items: center;
    justify-content: center;
    padding: 0 8px;
  }

  .button-toggle-menu i {
    font-size: 22px;
  }

  /* Sidebar overlays content on mobile — ensure it sits above everything */
  .leftside-menu {
    z-index: 1055;
  }

  /* Dim overlay when sidebar is open on mobile */
  body.sidebar-enable::before {
    content: '';
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    z-index: 1050;
    pointer-events: none;
  }

  /* Content area should not shift on mobile — sidebar overlays */
  body.sidebar-enable .content-page {
    margin-left: 0 !important;
  }
}
