/*
 * Mobile Responsive Styles for Merlin Flow Ticket System
 * 
 * Implements Requirements 1.4 and 21.1:
 * - Mobile breakpoints for optimal viewing
 * - Touch-friendly interactions
 * - Mobile navigation patterns
 * - Responsive layouts for ticket list and detail views
 */

/* ===== Mobile Breakpoints ===== */
:root {
  /* Touch target sizes (WCAG 2.1 Level AAA) */
  --touch-target-min: 44px;
  --touch-target-comfortable: 48px;
  
  /* Mobile spacing */
  --mobile-padding: 1rem;
  --mobile-padding-sm: 0.5rem;
  
  /* Mobile font sizes */
  --mobile-font-base: 16px;
  --mobile-font-sm: 14px;
  --mobile-font-xs: 12px;
}

/* ===== Base Mobile Styles (< 768px) ===== */
@media (max-width: 767.98px) {
  /* Body and container adjustments */
  body {
    font-size: var(--mobile-font-base);
  }
  
  .container-fluid {
    padding-left: var(--mobile-padding);
    padding-right: var(--mobile-padding);
  }
  
  /* ===== Mobile Navigation ===== */
  /* Hamburger menu button */
  .mobile-menu-toggle {
    display: block;
    position: fixed;
    top: 10px;
    left: 10px;
    z-index: 1050;
    width: var(--touch-target-comfortable);
    height: var(--touch-target-comfortable);
    padding: 0;
    background: var(--bs-primary);
    border: none;
    border-radius: 8px;
    color: white;
    font-size: 1.25rem;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    transition: transform 0.2s ease;
  }
  
  .mobile-menu-toggle:active {
    transform: scale(0.95);
  }
  
  /* Mobile sidebar overlay */
  .sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1040;
    opacity: 0;
    transition: opacity 0.3s ease;
  }
  
  .sidebar-overlay.active {
    display: block;
    opacity: 1;
  }
  
  /* Mobile sidebar */
  .mobile-sidebar {
    position: fixed;
    top: 0;
    left: -100%;
    width: 280px;
    max-width: 85vw;
    height: 100vh;
    background: var(--bs-body-bg);
    z-index: 1045;
    overflow-y: auto;
    transition: left 0.3s ease;
    box-shadow: 2px 0 8px rgba(0, 0, 0, 0.15);
  }
  
  .mobile-sidebar.active {
    left: 0;
  }
  
  .mobile-sidebar-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem;
    border-bottom: 1px solid var(--bs-border-color);
  }
  
  .mobile-sidebar-close {
    width: var(--touch-target-min);
    height: var(--touch-target-min);
    padding: 0;
    background: transparent;
    border: none;
    font-size: 1.5rem;
    color: var(--bs-body-color);
  }
  
  /* ===== Ticket List Mobile Styles ===== */
  /* Hide desktop sidebar on mobile */
  .col-md-3.col-lg-2 {
    display: none;
  }
  
  /* Full width ticket list */
  .col-md-9.col-lg-10 {
    flex: 0 0 100%;
    max-width: 100%;
  }
  
  /* Page header adjustments */
  .row.mb-4 .d-flex {
    flex-direction: column;
    gap: 1rem;
  }
  
  .row.mb-4 h1 {
    font-size: 1.5rem;
    margin-bottom: 0.5rem;
  }
  
  .row.mb-4 .btn-group {
    width: 100%;
    display: flex;
  }
  
  .row.mb-4 .btn-group .btn {
    flex: 1;
    font-size: var(--mobile-font-sm);
    padding: 0.5rem 0.25rem;
  }
  
  /* Mobile filter button */
  .mobile-filter-toggle {
    position: fixed;
    bottom: 80px;
    right: 16px;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--bs-primary);
    color: white;
    border: none;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
    z-index: 1000;
    font-size: 1.25rem;
    transition: transform 0.2s ease;
  }
  
  .mobile-filter-toggle:active {
    transform: scale(0.9);
  }
  
  /* Mobile filter panel */
  .mobile-filter-panel {
    position: fixed;
    bottom: -100%;
    left: 0;
    right: 0;
    max-height: 70vh;
    background: var(--bs-body-bg);
    border-top-left-radius: 16px;
    border-top-right-radius: 16px;
    box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.15);
    z-index: 1030;
    overflow-y: auto;
    transition: bottom 0.3s ease;
  }
  
  .mobile-filter-panel.active {
    bottom: 0;
  }
  
  .mobile-filter-panel-header {
    position: sticky;
    top: 0;
    background: var(--bs-body-bg);
    padding: 1rem;
    border-bottom: 1px solid var(--bs-border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    z-index: 1;
  }
  
  .mobile-filter-panel-content {
    padding: 1rem;
  }
  
  /* Search bar mobile */
  .card-header .input-group {
    width: 100% !important;
    margin-top: 0.5rem;
  }
  
  /* Bulk actions bar */
  #bulkActionsBar .d-flex {
    flex-direction: column;
    gap: 0.5rem;
  }
  
  #bulkActionsBar .btn-group {
    width: 100%;
  }
  
  #bulkActionsBar .btn-group .btn {
    flex: 1;
    font-size: var(--mobile-font-sm);
  }
  
  /* Table responsive adjustments */
  .table-responsive {
    border: none;
  }
  
  /* Hide less important columns on mobile */
  .column-reporter,
  .column-created-at,
  .column-product {
    display: none;
  }
  
  /* Adjust remaining columns */
  #ticketsTable th,
  #ticketsTable td {
    padding: 0.5rem 0.25rem;
    font-size: var(--mobile-font-sm);
  }
  
  #ticketsTable th:first-child,
  #ticketsTable td:first-child {
    padding-left: 0.5rem;
  }
  
  /* Reference column */
  .column-reference {
    min-width: 80px;
  }
  
  /* Title column - allow wrapping */
  .column-title {
    min-width: 150px;
    white-space: normal;
  }
  
  .column-title a {
    font-size: var(--mobile-font-sm);
    line-height: 1.3;
  }
  
  /* Status and priority badges */
  .column-status .badge,
  .column-priority .badge {
    font-size: 0.7rem;
    padding: 0.25rem 0.4rem;
  }
  
  /* Assigned to column */
  .column-assigned-to {
    font-size: var(--mobile-font-xs);
  }
  
  /* SLA column */
  .column-sla .badge {
    font-size: 0.65rem;
    padding: 0.2rem 0.3rem;
  }
  
  /* Actions column */
  #ticketsTable .btn-group-sm .btn {
    padding: 0.25rem 0.4rem;
    font-size: 0.75rem;
  }
  
  /* Mobile card view alternative (optional) */
  .mobile-ticket-card {
    display: block;
    padding: 1rem;
    margin-bottom: 0.5rem;
    border: 1px solid var(--bs-border-color);
    border-radius: 8px;
    background: var(--bs-body-bg);
    text-decoration: none;
    color: var(--bs-body-color);
    transition: box-shadow 0.2s ease;
  }
  
  .mobile-ticket-card:active {
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  }
  
  .mobile-ticket-card-header {
    display: flex;
    justify-content: space-between;
    align-items: start;
    margin-bottom: 0.5rem;
  }
  
  .mobile-ticket-card-reference {
    font-weight: 600;
    color: var(--bs-primary);
  }
  
  .mobile-ticket-card-title {
    font-size: var(--mobile-font-base);
    margin-bottom: 0.5rem;
    line-height: 1.4;
  }
  
  .mobile-ticket-card-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem;
    font-size: var(--mobile-font-xs);
  }
  
  /* Pagination mobile */
  .pagination {
    flex-wrap: wrap;
    justify-content: center;
  }
  
  .pagination .page-item {
    margin: 0.125rem;
  }
  
  .pagination .page-link {
    padding: 0.375rem 0.75rem;
    font-size: var(--mobile-font-sm);
    min-width: var(--touch-target-min);
    min-height: var(--touch-target-min);
    display: flex;
    align-items: center;
    justify-content: center;
  }
  
  /* ===== Ticket Detail Mobile Styles ===== */
  /* Breadcrumb mobile */
  .breadcrumb {
    font-size: var(--mobile-font-sm);
    padding: 0.5rem 0;
  }
  
  /* Ticket header */
  .card-header.bg-primary h4 {
    font-size: 1.25rem;
    line-height: 1.3;
  }
  
  .card-header.bg-primary .badge {
    font-size: 0.7rem;
    padding: 0.25rem 0.4rem;
    margin: 0.125rem;
  }
  
  .card-header.bg-primary .btn-group {
    margin-top: 0.5rem;
  }
  
  .card-header.bg-primary .btn-group .btn {
    font-size: var(--mobile-font-sm);
    padding: 0.375rem 0.75rem;
  }
  
  /* Ticket description */
  .ticket-description {
    font-size: var(--mobile-font-base);
    line-height: 1.6;
  }
  
  /* Collapsible sections */
  .collapse .table-responsive {
    overflow-x: auto;
  }
  
  /* Timeline mobile */
  .timeline-item {
    padding-left: 2rem;
    position: relative;
  }
  
  .timeline-marker {
    width: 12px;
    height: 12px;
    position: absolute;
    left: 0;
    top: 4px;
  }
  
  .timeline-content {
    font-size: var(--mobile-font-sm);
  }
  
  .timeline-content strong {
    display: block;
    margin-bottom: 0.25rem;
  }
  
  /* Comment section mobile */
  #commentSection .btn-group {
    flex-direction: column;
  }
  
  #commentSection .btn-group label {
    border-radius: 0.375rem !important;
    margin-bottom: 0.5rem;
  }
  
  #commentEditor {
    height: 150px !important;
  }
  
  #commentSection .form-check {
    margin-bottom: 0.5rem;
  }
  
  #commentSection .d-flex {
    flex-direction: column;
    gap: 0.5rem;
  }
  
  #commentSection .d-flex > div {
    width: 100%;
  }
  
  #commentSection .d-flex button {
    width: 100%;
  }
  
  /* Comments list mobile */
  .comment-item {
    font-size: var(--mobile-font-sm);
  }
  
  .comment-item .d-flex {
    flex-direction: column;
    align-items: start !important;
    gap: 0.5rem;
  }
  
  .comment-item .btn-group {
    margin-top: 0.5rem;
  }
  
  /* Sidebar on mobile - stack below main content */
  .col-lg-8,
  .col-lg-4 {
    flex: 0 0 100%;
    max-width: 100%;
  }
  
  .col-lg-4 {
    margin-top: 1rem;
  }
  
  /* Ticket details card mobile */
  .card-body dl.row {
    font-size: var(--mobile-font-sm);
  }
  
  .card-body dl.row dt {
    font-weight: 600;
    margin-bottom: 0.25rem;
  }
  
  .card-body dl.row dd {
    margin-bottom: 0.75rem;
  }
  
  /* SLA information mobile */
  .card-body dl.row .badge {
    font-size: 0.7rem;
  }
  
  /* ===== Touch-Friendly Interactions ===== */
  /* Increase touch targets */
  .btn,
  .form-control,
  .form-select,
  a.list-group-item {
    min-height: var(--touch-target-min);
  }
  
  /* Larger checkboxes and radio buttons */
  .form-check-input {
    width: 1.25rem;
    height: 1.25rem;
    margin-top: 0.125rem;
  }
  
  /* Touch feedback */
  .btn:active,
  .list-group-item:active,
  .dropdown-item:active {
    transform: scale(0.98);
    transition: transform 0.1s ease;
  }
  
  /* Prevent text selection on buttons */
  .btn,
  .list-group-item-action {
    -webkit-user-select: none;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
  }
  
  /* Swipe indicators */
  .swipeable {
    position: relative;
    touch-action: pan-y;
  }
  
  .swipeable::before {
    content: '';
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 4px;
    height: 40%;
    background: var(--bs-primary);
    opacity: 0;
    transition: opacity 0.2s ease;
  }
  
  .swipeable.swiping::before {
    opacity: 0.5;
  }
  
  /* ===== Mobile Modals ===== */
  .modal-dialog {
    margin: 0.5rem;
    max-width: calc(100% - 1rem);
  }
  
  .modal-fullscreen-sm-down {
    width: 100vw;
    max-width: none;
    height: 100%;
    margin: 0;
  }
  
  .modal-fullscreen-sm-down .modal-content {
    height: 100%;
    border: 0;
    border-radius: 0;
  }
  
  /* ===== Mobile Forms ===== */
  .form-label {
    font-size: var(--mobile-font-sm);
    font-weight: 600;
    margin-bottom: 0.375rem;
  }
  
  .form-control,
  .form-select {
    font-size: var(--mobile-font-base);
    padding: 0.625rem 0.75rem;
  }
  
  .form-control-sm,
  .form-select-sm {
    font-size: var(--mobile-font-sm);
    padding: 0.5rem 0.625rem;
  }
  
  /* ===== Mobile Floating Action Button ===== */
  .mobile-fab {
    position: fixed;
    bottom: 16px;
    right: 16px;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--bs-primary);
    color: white;
    border: none;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
    z-index: 1000;
    font-size: 1.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
  }
  
  .mobile-fab:active {
    transform: scale(0.9);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
  }
  
  /* ===== Mobile Bottom Navigation ===== */
  .mobile-bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 60px;
    background: var(--bs-body-bg);
    border-top: 1px solid var(--bs-border-color);
    display: flex;
    justify-content: space-around;
    align-items: center;
    z-index: 1020;
    box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.1);
  }
  
  .mobile-bottom-nav-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--bs-secondary);
    text-decoration: none;
    font-size: var(--mobile-font-xs);
    transition: color 0.2s ease;
    -webkit-tap-highlight-color: transparent;
  }
  
  .mobile-bottom-nav-item i {
    font-size: 1.25rem;
    margin-bottom: 0.25rem;
  }
  
  .mobile-bottom-nav-item.active {
    color: var(--bs-primary);
  }
  
  .mobile-bottom-nav-item:active {
    background: var(--bs-secondary-bg);
  }
  
  /* Add padding to body when bottom nav is present */
  body.has-mobile-bottom-nav {
    padding-bottom: 60px;
  }
}

/* ===== Tablet Styles (768px - 991px) ===== */
@media (min-width: 768px) and (max-width: 991.98px) {
  /* Adjust sidebar width for tablets */
  .col-md-3 {
    flex: 0 0 25%;
    max-width: 25%;
  }
  
  .col-md-9 {
    flex: 0 0 75%;
    max-width: 75%;
  }
  
  /* Hide some columns on tablet */
  .column-reporter,
  .column-created-at {
    display: none;
  }
  
  /* Adjust font sizes */
  #ticketsTable th,
  #ticketsTable td {
    font-size: 0.875rem;
    padding: 0.5rem;
  }
}

/* ===== Landscape Phone Styles ===== */
@media (max-width: 767.98px) and (orientation: landscape) {
  /* Reduce vertical spacing in landscape */
  .card {
    margin-bottom: 0.5rem;
  }
  
  .card-body {
    padding: 0.75rem;
  }
  
  /* Compact header */
  .row.mb-4 {
    margin-bottom: 0.5rem !important;
  }
  
  /* Smaller modals in landscape */
  .modal-dialog {
    max-height: 90vh;
  }
  
  .modal-body {
    max-height: calc(90vh - 120px);
    overflow-y: auto;
  }
}

/* ===== Print Styles ===== */
@media print {
  /* Hide navigation and interactive elements */
  .mobile-menu-toggle,
  .mobile-fab,
  .mobile-bottom-nav,
  .mobile-filter-toggle,
  .btn-group,
  .sidebar-overlay,
  .mobile-sidebar {
    display: none !important;
  }
  
  /* Expand all content */
  .collapse {
    display: block !important;
    height: auto !important;
  }
  
  /* Show all columns */
  .column-reporter,
  .column-created-at,
  .column-product {
    display: table-cell !important;
  }
  
  /* Remove shadows and borders */
  .card {
    box-shadow: none;
    border: 1px solid #ddd;
  }
}

/* ===== Accessibility Enhancements ===== */
/* Focus visible for keyboard navigation */
@media (max-width: 767.98px) {
  .btn:focus-visible,
  .form-control:focus-visible,
  .form-select:focus-visible,
  .list-group-item:focus-visible {
    outline: 3px solid var(--bs-primary);
    outline-offset: 2px;
  }
  
  /* Skip to content link for mobile */
  .skip-to-content {
    position: fixed;
    top: -100px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 9999;
    padding: 0.75rem 1.5rem;
    background: var(--bs-primary);
    color: white;
    text-decoration: none;
    border-radius: 0 0 8px 8px;
    transition: top 0.3s ease;
  }
  
  .skip-to-content:focus {
    top: 0;
  }
}

/* ===== Reduced Motion Support ===== */
@media (prefers-reduced-motion: reduce) {
  .mobile-sidebar,
  .mobile-filter-panel,
  .sidebar-overlay,
  .mobile-fab,
  .btn,
  .list-group-item {
    transition: none !important;
  }
}
