/*
 * Responsive Design Overrides
 * Mobile-first responsive styles for all screen sizes
 * Author: Factory AI
 * Version: 1.0
 */

/* ============================================
   Mobile First Base Styles
   ============================================ */
* {
  box-sizing: border-box;
}

/* Ensure touch targets are at least 44x44px */
button,
a,
input[type="button"],
input[type="submit"],
.btn {
  min-height: 44px;
  min-width: 44px;
}

/* ============================================
   Small Devices (phones, less than 768px)
   ============================================ */
@media (max-width: 767px) {
  
  /* Container Padding */
  .container-fluid {
    padding-left: 1rem;
    padding-right: 1rem;
  }
  
  /* Page Title */
  .page-breadcrumb h4.page-title {
    font-size: 1.25rem;
  }
  
  /* Hide breadcrumb on mobile */
  .page-breadcrumb .breadcrumb {
    display: none;
  }
  
  /* Cards - Full Width */
  .card {
    margin-bottom: 1rem;
  }
  
  .card-body {
    padding: 1rem;
  }
  
  /* Stat Cards - Stack Icon and Content */
  .card-stat .card-body {
    padding: 1.25rem;
  }
  
  .card-stat .stat-icon {
    width: 50px;
    height: 50px;
    font-size: 1.5rem;
  }
  
  .card-stat .stat-value {
    font-size: 1.5rem;
  }
  
  .card-stat .stat-label {
    font-size: 0.85rem;
  }
  
  /* Gradient Cards - Adjust for mobile */
  .card-gradient .card-body {
    padding: 1.25rem;
  }
  
  .card-gradient h3 {
    font-size: 1.25rem;
  }
  
  .card-gradient h1,
  .card-gradient .display-4 {
    font-size: 1.5rem !important;
  }
  
  /* Column Layout - Full Width */
  .col-md-3,
  .col-md-4,
  .col-md-6,
  .col-md-8,
  .col-md-9,
  .col-md-12 {
    flex: 0 0 100%;
    max-width: 100%;
    margin-bottom: 1rem;
  }
  
  /* Forms - Full Width */
  .form-control,
  .form-select,
  select.form-control,
  input.form-control {
    width: 100%;
    font-size: 16px; /* Prevents zoom on iOS */
  }
  
  .form-group {
    margin-bottom: 1rem;
  }
  
  /* Form Groups in Row - Stack */
  .form-group.d-flex {
    flex-direction: column;
    gap: 1rem !important;
  }
  
  .form-group.d-flex select {
    width: 100% !important;
  }
  
  /* Buttons - Full Width or Stack */
  .btn-group-mobile,
  .grupExport,
  .button-container {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    width: 100%;
  }
  
  .btn-group-mobile .btn,
  .grupExport .btn,
  .button-container .btn {
    width: 100%;
    margin: 0;
  }
  
  /* Tables - Horizontal Scroll with Shadow */
  .table-responsive {
    display: block;
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    box-shadow: inset -10px 0 10px -10px rgba(0, 0, 0, 0.1);
  }
  
  .table {
    min-width: 600px; /* Minimum width for tables */
  }
  
  .table thead th {
    white-space: nowrap;
    font-size: 0.85rem;
    padding: 0.75rem 0.5rem;
  }
  
  .table tbody td {
    font-size: 0.85rem;
    padding: 0.75rem 0.5rem;
  }
  
  /* Table Actions - Stack or Compact */
  .table-actions {
    flex-direction: column;
    gap: 0.25rem;
  }
  
  .table-actions .btn {
    font-size: 0.75rem;
    padding: 0.25rem 0.5rem;
  }
  
  /* DataTables Mobile */
  .dataTables_wrapper .dataTables_length,
  .dataTables_wrapper .dataTables_filter {
    margin-bottom: 1rem;
  }
  
  .dataTables_wrapper .dataTables_length select,
  .dataTables_wrapper .dataTables_filter input {
    width: 100%;
    margin-left: 0 !important;
    margin-top: 0.5rem;
  }
  
  .dataTables_wrapper .dataTables_info,
  .dataTables_wrapper .dataTables_paginate {
    text-align: center;
    margin-top: 1rem;
  }
  
  .dataTables_wrapper .dataTables_paginate .paginate_button {
    padding: 0.25rem 0.5rem;
    font-size: 0.85rem;
  }
  
  /* Modals - Full Screen on Mobile */
  .modal-dialog {
    margin: 0;
    max-width: 100%;
    height: 100%;
  }
  
  .modal-content {
    height: 100%;
    border-radius: 0;
  }
  
  .modal-body {
    overflow-y: auto;
    max-height: calc(100vh - 200px);
  }
  
  /* Sidebar - Full Width When Open */
  .left-sidebar {
    width: 260px;
  }
  
  /* Hide Sidebar by Default on Mobile */
  .mini-sidebar .left-sidebar {
    left: -260px;
  }
  
  .mini-sidebar.show-sidebar .left-sidebar {
    left: 0;
  }
  
  /* Hamburger Menu - Visible */
  .topbar .nav-toggler {
    display: block;
  }
  
  /* Top Bar Adjustments */
  .topbar {
    padding: 0 1rem;
  }
  
  .topbar .navbar-brand img {
    height: 28px;
    width: auto;
  }
  
  /* Search - Full Width */
  .search-modern {
    width: 100%;
    margin-bottom: 1rem;
  }
  
  /* Alerts - Adjust Padding */
  .alert {
    padding: 0.75rem 1rem;
    font-size: 0.9rem;
  }
  
  /* Cards with Flex Layout - Stack */
  .card-body.d-flex {
    flex-direction: column !important;
  }
  
  .card-body.d-flex .text-right {
    text-align: left !important;
    margin-top: 1rem;
  }
  
  /* Statistics Grid - Single Column */
  .row > [class*='col-md'] .card {
    margin-bottom: 1rem;
  }
  
  /* Progress Circle - Smaller */
  .progress-circle {
    width: 40px !important;
    height: 40px !important;
  }
  
  .progress-circle .inner-circle {
    width: 32px !important;
    height: 32px !important;
  }
  
  .progress-circle .progress-label {
    font-size: 8px !important;
  }
  
  /* Hide Desktop-Only Elements */
  .d-mobile-none {
    display: none !important;
  }
  
  /* Show Mobile-Only Elements */
  .d-mobile-block {
    display: block !important;
  }
  
  /* Scroll Container Hint */
  .table-responsive::after {
    content: '← Scroll →';
    display: block;
    text-align: center;
    color: #999;
    font-size: 0.75rem;
    padding: 0.5rem;
  }
}

/* ============================================
   Medium Devices (tablets, 768px to 991px)
   ============================================ */
@media (min-width: 768px) and (max-width: 991px) {
  
  /* Two Column Layout for Cards */
  .col-md-3,
  .col-md-4 {
    flex: 0 0 50%;
    max-width: 50%;
  }
  
  .col-md-6 {
    flex: 0 0 50%;
    max-width: 50%;
  }
  
  /* Adjust Card Padding */
  .card-body {
    padding: 1.25rem;
  }
  
  /* Form Inline on Tablet */
  .form-inline-tablet {
    display: flex;
    flex-direction: row;
    gap: 1rem;
  }
  
  .form-inline-tablet .form-control {
    flex: 1;
  }
  
  /* Buttons - Inline on Tablet */
  .btn-group-tablet {
    display: flex;
    flex-direction: row;
    gap: 0.5rem;
  }
  
  /* Tables - Better Spacing */
  .table thead th,
  .table tbody td {
    padding: 1rem;
    font-size: 0.9rem;
  }
  
  /* Modal - Centered */
  .modal-dialog {
    margin: 1.75rem auto;
    max-width: 600px;
  }
  
  /* Sidebar - Collapsible */
  .left-sidebar {
    width: 240px;
  }
}

/* ============================================
   Large Devices (desktops, 992px and up)
   ============================================ */
@media (min-width: 992px) {
  
  /* Container Max Width */
  .container-fluid {
    max-width: 1400px;
    margin: 0 auto;
  }
  
  /* Card Hover Effects - Desktop Only */
  .card-modern:hover {
    /* Removed transform animation - no movement */
  }
  
  /* Table - Better Hover */
  .table-modern tbody tr:hover {
    /* Removed transform animation - no movement */
  }
  
  /* Sidebar - Always Visible */
  .left-sidebar {
    width: 260px;
  }
  
  /* Hide Mobile Menu */
  .topbar .nav-toggler {
    display: none;
  }
}

/* ============================================
   Extra Large Devices (large desktops, 1200px and up)
   ============================================ */
@media (min-width: 1200px) {
  
  /* Larger Container */
  .container-fluid {
    max-width: 1600px;
  }
  
  /* Four Column Layout for Small Cards */
  .col-xl-3 {
    flex: 0 0 25%;
    max-width: 25%;
  }
  
  /* Larger Stat Values */
  .card-stat .stat-value {
    font-size: 2.5rem;
  }
}

/* ============================================
   Landscape Orientation (phones in landscape)
   ============================================ */
@media (max-height: 500px) and (orientation: landscape) {
  
  /* Reduce Vertical Spacing */
  .card {
    margin-bottom: 0.5rem;
  }
  
  .card-body {
    padding: 0.75rem;
  }
  
  /* Compact Modal */
  .modal-header,
  .modal-footer {
    padding: 0.75rem 1rem;
  }
  
  .modal-body {
    padding: 1rem;
    max-height: 60vh;
    overflow-y: auto;
  }
}

/* ============================================
   Print Styles
   ============================================ */
@media print {
  
  /* Hide Navigation */
  .topbar,
  .left-sidebar,
  .page-breadcrumb,
  .btn,
  .modal,
  .alert {
    display: none !important;
  }
  
  /* Full Width Content */
  .page-wrapper {
    margin: 0;
    padding: 0;
  }
  
  /* Remove Shadows and Transitions */
  .card,
  .table {
    box-shadow: none !important;
    page-break-inside: avoid;
  }
  
  /* Black and White */
  * {
    color: #000 !important;
    background: #fff !important;
  }
}

/* ============================================
   Accessibility Improvements
   ============================================ */

/* Focus Visible - Better Keyboard Navigation */
*:focus-visible {
  outline: 3px solid #4e73df;
  outline-offset: 2px;
}

/* Reduced Motion for Accessibility */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* High Contrast Mode */
@media (prefers-contrast: high) {
  .btn-modern,
  .card-modern,
  .form-control-modern {
    border: 2px solid currentColor;
  }
}

/* ============================================
   iOS Specific Fixes
   ============================================ */
@supports (-webkit-touch-callout: none) {
  /* iOS Safari - Prevent zoom on input focus */
  input[type="text"],
  input[type="email"],
  input[type="number"],
  input[type="tel"],
  input[type="password"],
  select,
  textarea {
    font-size: 16px !important;
  }
  
  /* iOS Safari - Fix position fixed */
  .modal-backdrop {
    position: absolute;
  }
}

/* ============================================
   Utility Classes for Responsive Control
   ============================================ */

/* Show/Hide on Mobile */
@media (max-width: 767px) {
  .hide-mobile {
    display: none !important;
  }
  
  .show-mobile {
    display: block !important;
  }
}

/* Show/Hide on Tablet */
@media (min-width: 768px) and (max-width: 991px) {
  .hide-tablet {
    display: none !important;
  }
  
  .show-tablet {
    display: block !important;
  }
}

/* Show/Hide on Desktop */
@media (min-width: 992px) {
  .hide-desktop {
    display: none !important;
  }
  
  .show-desktop {
    display: block !important;
  }
}

/* Text Alignment - Responsive */
@media (max-width: 767px) {
  .text-mobile-center {
    text-align: center !important;
  }
  
  .text-mobile-left {
    text-align: left !important;
  }
  
  .text-mobile-right {
    text-align: right !important;
  }
}

/* Spacing - Responsive */
@media (max-width: 767px) {
  .mb-mobile-3 {
    margin-bottom: 1rem !important;
  }
  
  .mt-mobile-3 {
    margin-top: 1rem !important;
  }
  
  .px-mobile-2 {
    padding-left: 0.5rem !important;
    padding-right: 0.5rem !important;
  }
}
