/**
 * Mystic Data Table - Unified Responsive CSS
 * 
 * This file replaces all scattered mobile/tablet fixes with a clean, unified approach.
 * Key features:
 * - Sticky first column that works on all devices
 * - Proper horizontal scrolling for remaining columns
 * - Fixed tablet width issues
 * - Clean, maintainable code structure
 */

/* ========================================
   BASE TABLE STYLES
   ======================================== */

   .mystic-data-table-wrapper {
    width: 100%;
    position: relative;
    overflow: visible;
  }
  
  .mystic-data-table {
    width: 100%;
    border-collapse: collapse;
    font-family: inherit;
  }
  
  /* Sticky Column Layout */
  .mystic-data-table--sticky-column {
    display: flex;
    width: 100%;
    min-height: 200px;
    overflow: visible;
    position: relative;
  }
  
  .mystic-sticky-column {
    flex-shrink: 0;
    background: var(--mystic-bg-white);
    border-right: 1px solid var(--mystic-gray-200);
    position: relative;
    z-index: 10;
  }
  
  .mystic-scrollable-columns {
    flex: 1;
    min-width: 0;
    overflow-x: auto;
    overflow-y: visible;
    -webkit-overflow-scrolling: touch;
    position: relative;
  }
  
  /* Cell Base Styles */
  .mystic-sticky-column__cell,
  .mystic-scrollable-columns__cell {
    padding: 16px 12px;
    border-bottom: 1px solid var(--mystic-gray-200);
    display: flex;
    align-items: flex-start;
    min-height: 60px;
    box-sizing: border-box;
    word-wrap: break-word;
    overflow-wrap: break-word;
  }
  
  .mystic-sticky-column__header,
  .mystic-scrollable-columns__header {
    display: flex;
    flex-direction: column;
    border-bottom: 2px solid var(--mystic-gray-200);
  }
  
  .mystic-scrollable-columns__body {
    display: flex;
    flex-direction: column;
  }
  
  .mystic-scrollable-columns__row {
    display: flex;
    flex-direction: row;
    min-width: max-content;
  }
  
  /* Header Styles */
  .mystic-sticky-column__cell--header,
  .mystic-scrollable-columns__cell--header {
    font-weight: 600;
    background-color: var(--mystic-bg-light);
    color: var(--mystic-text-dark);
  }
  
  /* ========================================
     DESKTOP STYLES (1025px and above)
     ======================================== */
  
  @media (min-width: 1025px) {
    .mystic-sticky-column {
      width: 30%;
      min-width: 300px;
      max-width: 400px;
    }
    
    .mystic-scrollable-columns__cell {
      min-width: 200px;
      flex: 1;
      border-right: 1px solid var(--mystic-gray-200);
    }
    
    .mystic-scrollable-columns__cell:last-child {
      border-right: none;
    }
  }
  
  /* ========================================
     TABLET STYLES (769px - 1024px)
     ======================================== */
  
  @media (min-width: 769px) and (max-width: 1024px) {
    /* CRITICAL FIX: Ensure full width on tablet */
    .mystic-data-table-wrapper {
      width: 100% !important;
      max-width: none !important;
      min-width: 100% !important;
      overflow-x: auto;
      overflow-y: visible;
      -webkit-overflow-scrolling: touch;
    }
    
    .mystic-data-table--sticky-column {
      width: 100% !important;
      min-width: 900px !important; /* Force horizontal scroll on tablets */
      display: flex;
      flex-direction: row;
    }
    
    .mystic-sticky-column {
      width: 280px !important;
      min-width: 280px !important;
      max-width: 280px !important;
      flex: 0 0 280px !important;
      position: sticky;
      left: 0;
      background: var(--mystic-bg-white);
      box-shadow: 2px 0 8px var(--mystic-shadow-medium);
      z-index: 20;
    }
    
    .mystic-scrollable-columns {
      flex: 1;
      min-width: 620px !important; /* Ensure scrollable area is wide enough */
      overflow-x: visible; /* Let parent handle scrolling */
      overflow-y: visible;
    }
    
    .mystic-scrollable-columns__header,
    .mystic-scrollable-columns__body {
      width: max-content;
      min-width: 620px;
    }
    
    .mystic-scrollable-columns__row {
      display: flex;
      flex-direction: row;
      width: max-content;
      min-width: 620px;
    }
    
    .mystic-scrollable-columns__cell {
      min-width: 180px !important;
      width: 180px !important;
      flex: 0 0 180px !important;
      border-right: 1px solid var(--mystic-gray-200);
      padding: 14px 10px;
      font-size: 14px;
    }
    
    .mystic-sticky-column__cell {
      padding: 14px 12px;
      font-size: 14px;
    }
    
    /* Custom scrollbar for better UX */
    .mystic-data-table-wrapper::-webkit-scrollbar {
      height: 8px;
    }
    
    .mystic-data-table-wrapper::-webkit-scrollbar-track {
      background: var(--mystic-gray-100);
      border-radius: 4px;
    }
    
    .mystic-data-table-wrapper::-webkit-scrollbar-thumb {
      background: var(--mystic-gray-400);
      border-radius: 4px;
    }
    
    .mystic-data-table-wrapper::-webkit-scrollbar-thumb:hover {
      background: var(--mystic-gray-500);
    }
  }
  
  /* ========================================
     MOBILE STYLES (768px and below)
     ======================================== */
  
  @media (max-width: 768px) {
    /* CRITICAL FIX: Ensure full width and proper scrolling on mobile */
    .mystic-data-table-wrapper {
      width: 100% !important;
      max-width: none !important;
      overflow-x: scroll !important;
      overflow-y: visible !important;
      -webkit-overflow-scrolling: touch !important;
      display: block !important;
    }
    
    .mystic-data-table--sticky-column {
      width: 100% !important;
      min-width: 700px !important; /* Force horizontal scroll on mobile */
      display: flex !important;
      flex-direction: row !important;
    }
    
    .mystic-sticky-column {
      width: 200px !important;
      min-width: 200px !important;
      max-width: 200px !important;
      flex: 0 0 200px !important;
      position: sticky !important;
      left: 0 !important;
      background: var(--mystic-bg-white) !important;
      box-shadow: 2px 0 8px var(--mystic-shadow-medium) !important;
      z-index: 20 !important;
      border-right: 2px solid var(--mystic-gray-200);
    }
    
    .mystic-scrollable-columns {
      flex: 1 !important;
      min-width: 500px !important; /* Ensure scrollable area forces scroll */
      overflow-x: visible !important; /* Let parent wrapper handle scrolling */
      overflow-y: visible !important;
    }
    
    .mystic-scrollable-columns__header,
    .mystic-scrollable-columns__body {
      width: max-content !important;
      min-width: 500px !important;
    }
    
    .mystic-scrollable-columns__row {
      display: flex !important;
      flex-direction: row !important;
      width: max-content !important;
      min-width: 500px !important;
    }
    
    .mystic-scrollable-columns__cell {
      min-width: 150px !important;
      width: 150px !important;
      flex: 0 0 150px !important;
      border-right: 1px solid var(--mystic-gray-200);
      padding: 12px 8px;
      font-size: 13px;
    }
    
    .mystic-sticky-column__cell {
      padding: 12px 10px;
      font-size: 13px;
    }
    
    /* Header cells */
    .mystic-sticky-column__cell--header,
    .mystic-scrollable-columns__cell--header {
      padding: 10px 8px;
      font-size: 12px;
      font-weight: 600;
    }
    
    /* Custom scrollbar for mobile */
    .mystic-data-table-wrapper::-webkit-scrollbar {
      height: 6px;
    }
    
    .mystic-data-table-wrapper::-webkit-scrollbar-track {
      background: var(--mystic-shadow-light);
      border-radius: 3px;
    }
    
    .mystic-data-table-wrapper::-webkit-scrollbar-thumb {
      background: color-mix(in srgb, var(--mystic-text-dark) 30%, transparent);
      border-radius: 3px;
    }
  }
  
  /* ========================================
     SMALL MOBILE STYLES (590px and below)
     ======================================== */
  
  @media (max-width: 590px) {
    .mystic-data-table--sticky-column {
      min-width: 650px !important;
    }
    
    .mystic-sticky-column {
      width: 180px !important;
      min-width: 180px !important;
      max-width: 180px !important;
      flex: 0 0 180px !important;
    }
    
    .mystic-scrollable-columns {
      min-width: 470px !important;
    }
    
    .mystic-scrollable-columns__header,
    .mystic-scrollable-columns__body {
      min-width: 470px !important;
    }
    
    .mystic-scrollable-columns__row {
      min-width: 470px !important;
    }
    
    .mystic-scrollable-columns__cell {
      min-width: 130px !important;
      width: 130px !important;
      flex: 0 0 130px !important;
      padding: 12px 6px;
      font-size: 12px;
    }
    
    .mystic-sticky-column__cell {
      padding: 12px 8px;
      font-size: 12px;
    }
    
    .mystic-sticky-column__cell--header,
    .mystic-scrollable-columns__cell--header {
      padding: 8px 6px;
      font-size: 11px;
    }
  }
  
  /* ========================================
     CONTENT STYLES
     ======================================== */
  
  /* Text content */
  .mystic-table-main-content {
    width: 100%;
    word-wrap: break-word;
    overflow-wrap: break-word;
  }
  
  /* Bullet lists */
  .mystic-table-bullet-list {
    margin: 8px 0;
    padding-left: 16px;
    list-style: none;
  }
  
  .mystic-table-bullet-item {
    margin-bottom: 4px;
    position: relative;
    padding-left: 12px;
  }
  
  .mystic-table-bullet-item::before {
    content: "•";
    position: absolute;
    left: 0;
    color: var(--mystic-gray-500);
  }
  
  /* Note containers */
  .mystic-table-note-container {
    margin: 8px 0;
    padding: 8px 12px;
    border-radius: 4px;
    background-color: var(--mystic-bg-light);
    border-left: 3px solid var(--mystic-blue-600);
    font-size: 0.9em;
  }
  
  /* Highlights */
  .mystic-table-highlight {
    background-color: color-mix(in srgb, var(--mystic-warning) 10%, transparent);
    padding: 2px 4px;
    border-radius: 3px;
    font-weight: 600;
  }
  
  /* Icons */
  .mystic-checkmark-icon,
  .mystic-x-mark-icon {
    width: 20px;
    height: 20px;
    display: inline-block;
    vertical-align: middle;
  }
  
  @media (max-width: 768px) {
    .mystic-checkmark-icon,
    .mystic-x-mark-icon {
      width: 16px;
      height: 16px;
    }
  }
  
  /* Cell with icon layout */
  .mystic-table-cell-with-icon {
    display: flex;
    align-items: center;
    gap: 8px;
    justify-content: center;
  }
  
  .mystic-table-icon-label {
    font-weight: 600;
    font-size: 0.9em;
  }
  
  /* Links */
  .mystic-table-text-link {
    color: var(--mystic-blue-600);
    text-decoration: underline;
    transition: color 0.2s ease;
  }
  
  .mystic-table-text-link:hover {
    color: var(--mystic-brand-blue);
  }
  
  .mystic-table-text-link:visited {
    color: var(--mystic-blue-600);
  }
  
  /* ========================================
     ACCESSIBILITY & FOCUS STATES
     ======================================== */
  
  .mystic-sticky-column__cell:focus,
  .mystic-scrollable-columns__cell:focus {
    outline: 2px solid var(--mystic-blue-600);
    outline-offset: -2px;
  }
  
  /* Touch targets for mobile */
  @media (max-width: 768px) {
    .mystic-table-text-link {
      min-height: 44px;
      display: inline-flex;
      align-items: center;
      padding: 4px 0;
    }
  }
  
  /* High contrast support */
  @media (prefers-contrast: high) {
    .mystic-sticky-column {
      border-right-color: var(--mystic-text-dark);
      box-shadow: 2px 0 8px color-mix(in srgb, var(--mystic-text-dark) 50%, transparent);
    }
    
    .mystic-sticky-column__cell,
    .mystic-scrollable-columns__cell {
      border-color: var(--mystic-text-dark);
    }
  }
  
  /* Reduced motion support */
  @media (prefers-reduced-motion: reduce) {
    .mystic-data-table-wrapper {
      scroll-behavior: auto;
    }
    
    .mystic-table-text-link {
      transition: none;
    }
  }
  
  /* ========================================
     PRINT STYLES
     ======================================== */
  
  @media print {
    .mystic-data-table-wrapper {
      overflow: visible !important;
      width: 100% !important;
    }
    
    .mystic-data-table--sticky-column {
      flex-direction: column !important;
      min-width: 100% !important;
      width: 100% !important;
    }
    
    .mystic-sticky-column,
    .mystic-scrollable-columns {
      position: static !important;
      width: 100% !important;
      flex: none !important;
      overflow: visible !important;
      box-shadow: none !important;
    }
    
    .mystic-sticky-column__cell,
    .mystic-scrollable-columns__cell {
      background: var(--mystic-bg-white) !important;
      color: var(--mystic-text-dark) !important;
      border-color: var(--mystic-text-dark) !important;
      font-size: 12px !important;
      padding: 6px 8px !important;
    }
  }
  
  /* ========================================
     UTILITY CLASSES
     ======================================== */
  
  /* Remove borders from last elements */
  .mystic-scrollable-columns__cell:last-child {
    border-right: none !important;
  }
  
  .mystic-scrollable-columns__row:last-child .mystic-scrollable-columns__cell,
  .mystic-sticky-column__cell:last-child {
    border-bottom: none !important;
  }
  
  /* Merged cells */
  .mystic-scrollable-columns__cell--merged {
    text-align: center;
    font-weight: 500;
    background-color: color-mix(in srgb, var(--mystic-blue-600) 5%, transparent);
  }
  
  /* Hidden cells (part of merges) */
  .mystic-scrollable-columns__cell--hidden {
    display: none !important;
  }
  
  /* Striped rows */
  .mystic-data-table--striped .mystic-scrollable-columns__row:nth-child(odd) .mystic-scrollable-columns__cell {
    background-color: var(--mystic-bg-light);
  }
  
  .mystic-data-table--striped .mystic-sticky-column__cell:nth-child(odd) {
    background-color: var(--mystic-bg-light);
  }
  
  /* Healthcare striping: first row gray, second row white */
  .mystic-data-table--striped.mystic-data-table--healthcare .mystic-scrollable-columns__row.mystic-data-table__row--odd .mystic-scrollable-columns__cell,
  .mystic-data-table--striped.mystic-data-table--healthcare .mystic-sticky-column__cell--data.mystic-data-table__row--odd {
    background-color: var(--table-bg-secondary, #f7f7f8);
  }
  
  .mystic-data-table--striped.mystic-data-table--healthcare .mystic-scrollable-columns__row.mystic-data-table__row--even .mystic-scrollable-columns__cell,
  .mystic-data-table--striped.mystic-data-table--healthcare .mystic-sticky-column__cell--data.mystic-data-table__row--even {
    background-color: var(--table-bg-primary, #ffffff);
  }
  