/* Responsive Table Styles */

/* Desktop Large: viewport >= 1300px - Tables can break out to 1200px */
@media screen and (min-width: 1300px) {
  /* Allow content area to have visible overflow for wide tables */
  .content {
    overflow-x: visible;
  }
  
  /* All tables get centered and can break out of content area */
  article table {
    margin: 2em auto;
    position: relative;
    left: 50%;
    transform: translateX(-50%);
    width: auto;
    max-width: min(1200px, calc(100vw - 100px)); /* Cap at 1200px with some viewport margin */
  }
  
  /* Very wide tables become scrollable at 1200px */
  article table.wide-table,
  article table:has(td:nth-child(15)) { /* Heuristic for wide tables with many columns */
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    max-width: 1200px;
    box-shadow: 0 2px 8px rgba(71, 102, 83, 0.1);
    border-radius: 6px;
    border: 2px solid var(--color-table-border);
  }
  
  /* Visual indicator for scrollable area */
  article table.wide-table::-webkit-scrollbar,
  article table:has(td:nth-child(15))::-webkit-scrollbar {
    height: 8px;
  }
  
  article table.wide-table::-webkit-scrollbar-track,
  article table:has(td:nth-child(15))::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.1);
    border-radius: 4px;
  }
  
  article table.wide-table::-webkit-scrollbar-thumb,
  article table:has(td:nth-child(15))::-webkit-scrollbar-thumb {
    background: var(--color-dark-green, #476653);
    border-radius: 4px;
  }
}

/* Desktop Medium: viewport 801px-1299px - Tables stay within content area */
@media screen and (min-width: 801px) and (max-width: 1299px) {
  /* Tables stay within content boundaries */
  .content {
    overflow-x: hidden;
  }
  
  /* Tables render within content area with scroll if needed */
  article table {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    max-width: 100%;
    margin: 2em 0;
  }
  
  /* Ensure tables don't break layout */
  article table td,
  article table th {
    white-space: nowrap;
  }
  
  /* Allow first column to wrap for readability */
  article table td:first-child,
  article table th:first-child {
    white-space: normal;
    min-width: 120px;
  }
  
  /* Visual scroll indicator */
  article table::-webkit-scrollbar {
    height: 8px;
  }
  
  article table::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.05);
    border-radius: 4px;
  }
  
  article table::-webkit-scrollbar-thumb {
    background: var(--color-dark-green, #476653);
    border-radius: 4px;
  }
  
  /* Add subtle shadow for scrollable tables */
  article table {
    box-shadow: 0 1px 6px rgba(71, 102, 83, 0.08);
    border-radius: 4px;
    border: 2px solid var(--color-table-border);
  }
}

/* Mobile: viewport <= 800px */
@media screen and (max-width: 800px) {
  /* Prevent horizontal page scroll */
  body, html {
    overflow-x: hidden;
  }
  
  /* Make article scrollable for wide tables */
  article {
    overflow-x: visible;
  }
  
  /* Tables become scrollable containers */
  article table {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    max-width: 100vw;
    margin: 1em -1ch; /* Negative margin to use full width */
  }
  
  /* Ensure table content doesn't wrap unnecessarily */
  article table td,
  article table th {
    white-space: nowrap;
    min-width: 100px;
  }
  
  /* Allow first column to wrap for readability */
  article table td:first-child,
  article table th:first-child {
    white-space: normal;
    min-width: 120px;
  }
  
  /* Visual scroll indicator */
  article table::-webkit-scrollbar {
    height: 6px;
  }
  
  article table::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.05);
  }
  
  article table::-webkit-scrollbar-thumb {
    background: var(--color-dark-green, #476653);
    border-radius: 3px;
  }
}

/* Common styles for better table appearance */
table {
  border-collapse: collapse;
  font-size: 0.9em;
  line-height: 1.4;
  background-color: var(--color-table-bg);
  border: 1px solid var(--color-table-border);
}

/* Table cell borders */
table th,
table td {
  border: 1px solid var(--color-table-border);
  padding: 8px 12px;
}

/* Table header styling */
table thead th,
table th {
  background-color: var(--color-table-header);
  font-weight: 600;
  color: var(--color-dark-green);
}

/* Alternating row colors for better readability */
table tbody tr:nth-child(even) {
  background-color: var(--color-table-row-alt);
}

/* Hover effect for table rows */
table tbody tr:hover {
  background-color: rgba(193, 221, 188, 0.15);
  transition: background-color 0.2s ease;
}

/* Visual scroll indicators - gradient shadows on sides */
.table-scroll-container {
  position: relative;
}

/* Gradient indicators for horizontally scrollable tables */
article table[style*="overflow-x: auto"]::before,
article table[style*="overflow-x: auto"]::after {
  content: '';
  position: sticky;
  top: 0;
  width: 20px;
  height: 100%;
  pointer-events: none;
  z-index: 1;
}

article table[style*="overflow-x: auto"]::before {
  left: 0;
  background: linear-gradient(to right, var(--color-table-bg), transparent);
}

article table[style*="overflow-x: auto"]::after {
  right: 0;
  background: linear-gradient(to left, var(--color-table-bg), transparent);
}

/* Ensure footnotes stay below tables */
.footnotes {
  clear: both;
  margin-top: 3em;
}

/* Prevent table from forcing viewport resize on mobile */
@media screen and (max-width: 800px) {
  .content {
    max-width: 100vw;
    overflow-x: hidden;
    padding-left: 1ch;
    padding-right: 1ch;
  }
}