/**
 * 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: #ffffff;
  border-right: 1px solid #eeeef0;
  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 #eeeef0;
  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 #eeeef0;
}

.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: #f8f9fa;
  color: #141414;
}

/* ========================================
   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 #eeeef0;
  }
  
  .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: #ffffff;
    box-shadow: 2px 0 8px rgba(0, 0, 0, 0.1);
    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 #eeeef0;
    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: #f1f1f1;
    border-radius: 4px;
  }
  
  .mystic-data-table-wrapper::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: 4px;
  }
  
  .mystic-data-table-wrapper::-webkit-scrollbar-thumb:hover {
    background: #a8a8a8;
  }
}

/* ========================================
   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: #ffffff !important;
    box-shadow: 2px 0 8px rgba(0, 0, 0, 0.1) !important;
    z-index: 20 !important;
    border-right: 2px solid #eeeef0;
  }
  
  .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 #eeeef0;
    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: rgba(0, 0, 0, 0.05);
    border-radius: 3px;
  }
  
  .mystic-data-table-wrapper::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.3);
    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: #666;
}

/* Note containers */
.mystic-table-note-container {
  margin: 8px 0;
  padding: 8px 12px;
  border-radius: 4px;
  background-color: #f8f9fa;
  border-left: 3px solid #0f7eba;
  font-size: 0.9em;
}

/* Highlights */
.mystic-table-highlight {
  background-color: rgba(176, 84, 13, 0.1);
  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: #0f7eba;
  text-decoration: underline;
  transition: color 0.2s ease;
}

.mystic-table-text-link:hover {
  color: #0a5a7d;
}

.mystic-table-text-link:visited {
  color: #0f7eba;
}

/* ========================================
   ACCESSIBILITY & FOCUS STATES
   ======================================== */

.mystic-sticky-column__cell:focus,
.mystic-scrollable-columns__cell:focus {
  outline: 2px solid #0f7eba;
  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: #000000;
    box-shadow: 2px 0 8px rgba(0, 0, 0, 0.5);
  }
  
  .mystic-sticky-column__cell,
  .mystic-scrollable-columns__cell {
    border-color: #000000;
  }
}

/* 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: white !important;
    color: black !important;
    border-color: #000000 !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: rgba(15, 85, 125, 0.05);
}

/* 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(even) .mystic-scrollable-columns__cell {
  background-color: #f8f9fa;
}

.mystic-data-table--striped .mystic-sticky-column__cell:nth-child(even) {
  background-color: #f8f9fa;
}
