/* Core table styling unified with high-priority overrides */
table,
.table,
table.table,
div table,
.paragraph-text table {
  border-collapse: collapse !important;
  border-radius: 10px !important;
  border: none !important;
  overflow: hidden !important;
  font-family: "Lato", "Arial", "Helvetica Neue", sans-serif !important;
  font-size: var(--font-size-sm) !important;
  font-weight: var(--font-weight-normal) !important;
  margin: var(--space-lg) 0 !important;
  width: 100% !important;
  color: var(--greyDarker) !important;
  background-color: transparent !important;
}

.table a {
  color: var(--qridaOrange);
}

table td,
table th,
.table td,
.table th,
table.table td,
table.table th,
div table td,
div table th,
.paragraph-text table td,
.paragraph-text table th {
  border: none !important;
  padding: var(--space-md) var(--space-lg) !important;
  box-shadow: none !important;
  line-height: 1.4 !important;
  font-weight: 400 !important;
}

/* Zebra striping - odd rows */
table tbody tr:nth-child(odd) td,
.table tbody tr:nth-child(odd) td,
table.table tbody tr:nth-child(odd) td,
div table tbody tr:nth-child(odd) td,
.paragraph-text table tbody tr:nth-child(odd) td {
  background-color: var(--white) !important;
}

/* Zebra striping - even rows */
table tbody tr:nth-child(even) td,
.table tbody tr:nth-child(even) td,
table.table tbody tr:nth-child(even) td,
div table tbody tr:nth-child(even) td,
.paragraph-text table tbody tr:nth-child(even) td {
  background-color: var(--greyLighter, #f5f5f5) !important;
}

/* Blue table header */
table thead th,
table thead td,
.table thead th,
.table thead td,
table.table thead th,
table.table thead td,
div table thead th,
div table thead td,
.paragraph-text table thead th,
.paragraph-text table thead td {
  background-color: var(--qridaOrange) !important;
  color: var(--white) !important;
  font-weight: var(--font-weight-bold) !important;
  border: none !important;
}

/* Borders removed on borderless tables */
.table-borderless th,
.table-borderless td {
  border: none !important;
  background-color: transparent !important;
}

.table-blank tr {
  background-color: transparent !important;
}

/* Legacy markup support */
table[align],
div table[align] {
  border-collapse: collapse !important;
  border: none !important;
}

table[align] td,
table[align] th {
  border: 1px solid var(--white) !important;
}

/* Webform Likert tables */
.webform-likert-table[data-likert-answers-count="2"] th:first-child {
  width: 75%;
}

.webform-likert-table[data-likert-answers-count="2"] th {
  width: 12.5%;
}

.webform-likert-table tr {
  background: transparent;
  background-color: rgba(72, 81, 99, 0.06); /* greyDarker with low opacity - using rgba for precise control */
  border: none !important;
}

.webform-likert-table td,
.webform-likert-table th {
  border: none !important;
}

.webform-likert-table thead th {
  color: var(--white) !important;
  font-family: var(--font-family-body);
  font-weight: var(--font-weight-bold) !important;
  text-align: center;
  background-color: var(--qridaOrange) !important;
  padding: var(--space-md) !important;
  border: none !important;
}

.webform-likert-table thead th:first-child {
  text-align: left;
}

.webform-likert-table tr.odd {
  background-color: var(--qg-bg) !important;
}

.webform-likert-table tr.even {
  background-color: var(--white) !important;
}

/* Reduce padding in likert table body cells for tighter row spacing */
.webform-likert-table tbody tr td {
  padding: var(--space-sm) var(--space-md);
}

/* Remove vertical margin from form items within likert table cells */
.webform-likert-table tbody tr td .form-item {
  margin-block: 0;
}

/* Remove vertical margin from labels within likert table cells */
.webform-likert-table tbody tr td .form-item__label {
  margin-block: 0;
}

/* Fix sticky header positioning after patches */
.webform-likert-table.sticky-header thead {
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

/* Ensure proper spacing when header is sticky */
.webform-likert-table.sticky-header tbody tr:first-child td {
  border-top: none;
}

/* Bootstrap table component neutralisers */
table.table,
.table {
  --bs-table-color: var(--textColor) !important;
  --bs-table-bg: transparent !important;
  --bs-table-border-color: transparent !important;
  --bs-table-striped-color: var(--textColor) !important;
  --bs-table-striped-bg: transparent !important;
  --bs-table-hover-color: var(--textColor) !important;
  --bs-table-hover-bg: transparent !important;
  color: var(--textColor) !important;
  background-color: transparent !important;
  border-color: transparent !important;
}

/* Ensure consistent cell spacing and remove Bootstrap shadows */
.table > :not(caption) > * > *,
table.table > :not(caption) > * > * {
  background-color: transparent !important;
  box-shadow: none !important;
  padding: var(--space-sm) var(--space-md) !important;
}

/* Neutralise Bootstrap variants */
.table-striped > tbody > tr:nth-of-type(odd) > * {
  background-color: transparent !important;
}

.table-hover > tbody tr:hover > * {
  background-color: transparent !important;
}

.table-borderless > :not(caption) > * > * {
  border-bottom-width: 0 !important;
}

/* ========================================
   RESPONSIVE TABLE WRAPPER
   ======================================== */

/* Responsive table wrapper for horizontal scrolling */
.table-responsive {
  display: block;
  overflow-x: auto;
  width: 100%;
  -webkit-overflow-scrolling: touch;
}

/* Ensure tables don't cause horizontal page scroll */
.table-responsive table {
  margin-bottom: 0;
  min-width: 100%;
}

/* Desktop: larger text */
@media screen and (min-width: 768px) {
  table,
  .table,
  table.table {
    font-size: var(--font-size-base);
  }
}

/* Mobile: stacked layout for simple tables */
@media screen and (max-width: 767px) {
  /* Stacked table layout option */
  table.table-stack {
    display: block;
  }

  table.table-stack thead {
    display: none;
  }

  table.table-stack tbody,
  table.table-stack tr,
  table.table-stack td {
    display: block;
    width: 100%;
  }

  table.table-stack tr {
    border: 1px solid var(--greyLight);
    border-radius: 8px;
    margin-bottom: 1.5rem;
    padding: 1rem;
  }

  table.table-stack td {
    padding: 0.5rem 0 !important;
    padding-left: 40% !important;
    position: relative;
    text-align: right;
  }

  table.table-stack td::before {
    content: attr(data-label);
    font-weight: bold;
    left: 0;
    position: absolute;
    text-align: left;
    top: 0.5rem;
  }

  /* Ensure carousel indicators are not in tab order on mobile */
  .carousel-indicators {
    display: none;
  }

  .carousel-indicators button {
    visibility: hidden;
  }
}
