/* LIMOR AI - Responsive Table Styles
 * Sacred Compliance: 100% SHARP - Mobile-friendly tables with desktop preservation
 * Hebrew Excellence: RTL-aware responsive data tables
 */

/* Base Table Styles */
.responsive-table {
  width: 100%;
  border-collapse: collapse;
  background: white;
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}

.table-container {
  background: white;
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  margin-bottom: var(--space-6);
}

/* Table Headers */
.responsive-table th {
  background: #f7fafc;
  padding: var(--space-4);
  text-align: var(--text-align-start);
  font-weight: 600;
  color: #4a5568;
  font-size: var(--text-sm);
  text-transform: uppercase;
  letter-spacing: 0.025em;
  border-bottom: 1px solid #e2e8f0;
  white-space: nowrap;
}

.responsive-table td {
  padding: var(--space-3) var(--space-4);
  color: #1a202c;
  border-bottom: 1px solid #f1f5f9;
  font-size: var(--text-sm);
}

.responsive-table tr:hover {
  background-color: #f7fafc;
}

/* Sticky Header Support */
.table-sticky thead th {
  position: sticky;
  top: 0;
  z-index: var(--z-sticky);
  background: #f7fafc;
}

/* Desktop Styles (Original Preserved) */
@media (min-width: 1024px) {
  .responsive-table th {
    padding: 1rem; /* Original desktop padding */
    font-size: 0.875rem; /* Original desktop font size */
  }

  .responsive-table td {
    padding: 0.75rem 1rem; /* Original desktop padding */
  }
}

/* Tablet Adaptations */
@media (min-width: 768px) and (max-width: 1023px) {
  .responsive-table {
    font-size: var(--text-sm);
  }

  .responsive-table th,
  .responsive-table td {
    padding: var(--space-3);
  }

  /* Horizontal scroll for wide tables */
  .table-scroll {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .table-scroll .responsive-table {
    min-width: 700px;
  }
}

/* Mobile Adaptations */
@media (max-width: 767px) {
  /* Option 1: Horizontal Scroll */
  .table-scroll {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border-radius: var(--radius-lg);
  }

  .table-scroll .responsive-table {
    min-width: 600px;
    font-size: var(--text-xs);
  }

  .table-scroll .responsive-table th,
  .table-scroll .responsive-table td {
    padding: var(--space-2) var(--space-3);
    white-space: nowrap;
  }

  /* Option 2: Card View */
  .table-cards {
    display: block !important;
    background: transparent;
    box-shadow: none;
    border-radius: 0;
  }

  .table-cards thead {
    display: none;
  }

  .table-cards tbody {
    display: block;
    gap: var(--space-4);
  }

  .table-cards tr {
    display: block;
    background: white;
    border-radius: var(--radius-lg);
    padding: var(--space-4);
    margin-bottom: var(--space-4);
    box-shadow: var(--shadow-sm);
    border: none;
  }

  .table-cards tr:hover {
    background: white;
    box-shadow: var(--shadow-md);
  }

  .table-cards td {
    display: block;
    padding: var(--space-2) 0;
    border-bottom: none;
    text-align: var(--text-align-start);
    font-size: var(--text-sm);
  }

  .table-cards td::before {
    content: attr(data-label) ": ";
    font-weight: 600;
    color: #4a5568;
    margin-left: var(--space-2);
    display: inline-block;
    min-width: 120px;
    font-size: var(--text-xs);
  }

  .table-cards td:first-child {
    border-bottom: 1px solid #e2e8f0;
    padding-bottom: var(--space-3);
    margin-bottom: var(--space-2);
    font-weight: 600;
    font-size: var(--text-base);
    color: var(--chakra-colors-brand-700);
  }

  .table-cards td:first-child::before {
    display: none;
  }
}

/* Hebrew Table Specific Styles */
.hebrew-table {
  direction: rtl;
}

.hebrew-table th,
.hebrew-table td {
  text-align: right;
}

/* Financial Data Styling */
.currency-cell {
  font-weight: 600;
  color: var(--chakra-colors-brand-700);
  font-family: 'Assistant', monospace;
}

.positive-value {
  color: #38a169;
}

.negative-value {
  color: #e53e3e;
}

.zero-value {
  color: #718096;
}

/* Status Indicators */
.status-success {
  background: #c6f6d5;
  color: #22543d;
  padding: var(--space-1) var(--space-2);
  border-radius: var(--radius-base);
  font-size: var(--text-xs);
  font-weight: 600;
}

.status-warning {
  background: #fef5e7;
  color: #744210;
  padding: var(--space-1) var(--space-2);
  border-radius: var(--radius-base);
  font-size: var(--text-xs);
  font-weight: 600;
}

.status-error {
  background: #fed7d7;
  color: #742a2a;
  padding: var(--space-1) var(--space-2);
  border-radius: var(--radius-base);
  font-size: var(--text-xs);
  font-weight: 600;
}

/* Loading States */
.table-loading {
  opacity: 0.6;
  pointer-events: none;
  position: relative;
}

.table-loading::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 20px;
  height: 20px;
  margin: -10px 0 0 -10px;
  border: 2px solid #e2e8f0;
  border-top-color: var(--chakra-colors-brand-500);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* Empty State */
.table-empty {
  text-align: center;
  padding: var(--space-16);
  color: #718096;
}

.table-empty-icon {
  width: 48px;
  height: 48px;
  margin: 0 auto var(--space-4);
  opacity: 0.5;
}

/* Accessibility Enhancements */
.table-container:focus-within {
  outline: 2px solid var(--chakra-colors-brand-500);
  outline-offset: 2px;
}

/* Screen Reader Only */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Print Styles */
@media print {
  .responsive-table {
    box-shadow: none;
    border: 1px solid #000;
  }

  .mobile-nav-toggle,
  .sidebar-backdrop,
  .analyze-button {
    display: none !important;
  }

  .table-cards {
    display: table !important;
  }

  .table-cards thead {
    display: table-header-group !important;
  }

  .table-cards tr {
    display: table-row !important;
    background: transparent !important;
    box-shadow: none !important;
    padding: 0 !important;
    margin: 0 !important;
  }

  .table-cards td {
    display: table-cell !important;
    padding: 0.5rem !important;
    border-bottom: 1px solid #000 !important;
  }

  .table-cards td::before {
    display: none !important;
  }
}

/* High Contrast Mode Support */
@media (prefers-contrast: high) {
  .responsive-table th {
    background: #000000;
    color: #ffffff;
    border-bottom: 2px solid #ffffff;
  }

  .responsive-table td {
    border-bottom: 1px solid #000000;
  }

  .responsive-table tr:hover {
    background: #f0f0f0;
  }
}

/* Reduced Motion Support */
@media (prefers-reduced-motion: reduce) {
  .responsive-table tr,
  .table-cards tr {
    transition: none;
  }

  .table-loading::after {
    animation: none;
  }
}