/* Table container for overlay positioning */
.table-container {
  position: relative;
  max-width: 1200px;
  width: 100%;
  margin: 20px auto;
  padding: 0 16px;
  box-sizing: border-box;
  overflow-x: visible;
  min-height: calc(
    100vh - 350px - 50px
  ); /* 100vh minus top margin minus bottom gap */
}

/* Table-specific loading overlay */
.table-loading-overlay {
  position: absolute;
  width: 100%;
  left: 0;
  transform: none;
  top: 0;
  bottom: 0;
  background: rgba(255, 255, 255);
  border: 2px solid #ccc;
  border-radius: 8px;
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 100;
  font-size: 3rem;
  color: #f5a623;
}

.table-loading-overlay.active {
  display: flex;
}
.controls button:disabled,
.controls select:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.controls .download-btn {
  background-color: white;
  color: var(--button-color);
  border: 2px solid var(--button-color) !important;
  font-weight: 600;
}

.controls .download-btn:hover {
  background-color: var(--button-color);
  color: white;
  transform: translateY(-1px);
}

.controls .download-btn:focus-visible {
  background-color: var(--button-color);
  color: white;
  outline: 3px solid var(--green-accent);
  outline-offset: 2px;
}

/* Table styling */
table {
  width: 100%;
  align-items: center;
  border-collapse: separate;
  border-spacing: 0;
  background-color: white;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

thead {
  background-color: var(--button-color);
  color: white;
}

thead th {
  padding: 15px;
  text-align: left;
  font-weight: 600;
  font-size: 16px;
  letter-spacing: 0.5px;
}

tbody tr {
  border-bottom: 1px solid #e0e0e0;
  transition: background-color 0.2s ease;
}

tbody tr:last-child {
  border-bottom: none;
}

tbody td {
  padding: 15px;
  font-size: 16px;
}

/* Zebra striping */
tbody tr.row-odd td,
tbody tr.row-odd + tr.hidden-data td {
  /*+ makes sure hidden-data rows are striped correctly */
  background-color: white;
}
tbody tr.row-even td,
tbody tr.row-even + tr.hidden-data td {
  background-color: #fafafa;
}

tbody tr:hover td {
  background-color: #f0f0f0;
}

/* Special styling for specific columns */
tbody td:nth-child(3), /* KW/H */
tbody td:nth-child(4), /* Sqft */
tbody td:nth-child(5)  /* EUI */ {
  font-family: inherit;
  font-weight: 600;
  text-align: left;
}

tbody td:nth-child(2) {
  /* Category */
  color: var(--green-accent);
  font-weight: 500;
}

/* Hide detail rows by default */
tr.hidden-data {
  display: none;
}

tr.hidden-data.open {
  display: table-row;
}

/* Style the expanded data, like solar array size */
tr.hidden-data td {
  color: Black;
  padding: 7px 15px;
  font-size: 14px;
  line-height: 1.3;
}

/* Adjusts EUI icon just for this page as it blends in w/ background */
.euiTipIcon {
  background-color: white;
  border-color: white;
  color: black;
  border: 2px solid white;
}

/*styling for the array size tooltip*/
.arrayTip {
  position: relative;
  display: inline-block;
  margin-left: 8px;
  margin-right: 30px;
}
.arrayTipIcon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  box-sizing: border-box;
  border-radius: 50%;
  background-color: var(--green-accent);
  border: 2px solid var(--green-accent);
  color: white;
  font-size: 16px;
  font-weight: bold;
  cursor: pointer;
  vertical-align: 2px;
}

.arrayTipBox {
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  background: #ffffff;
  border: 4px solid var(--green-accent);
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
  padding: 12px 16px;
  width: 260px;
  font-size: 14px;
  color: var(--primary-text);
  z-index: 999;
  opacity: 0;
  visibility: hidden;
  transition:
    opacity 0.2s ease,
    visibility 0.2s ease;
}

.tt {
  position: relative;
  display: inline-block;
  min-width: 24px;
  min-height: 24px;
  margin-left: 6px;
}

.tt .solar-icon {
  font-size: 20px;
}

.tt-bubble {
  position: absolute;
  bottom: 140%;
  left: 50%;
  transform: translateX(-50%);
  width: 140px;
  white-space: normal;
  text-align: center;
  font-weight: normal;
  padding: 6px 10px;
  border-radius: 8px;
  font-size: 13px;
  background: #ffffff;
  border: 3px solid var(--green-accent);
  color: var(--primary-text);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
  opacity: 0;
  visibility: hidden;
  z-index: 999;
  transition:
    opacity 0.2s ease,
    visibility 0.2s ease;
}

.arrayTipBox::before {
  content: "";
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  border: 7px solid transparent;
  border-top-color: var(--green-accent);
}

.arrayTipBox::after {
  content: "";
  position: absolute;
  top: calc(100% - 3px);
  left: 50%;
  transform: translateX(-50%);
  border: 6px solid transparent;
  border-top-color: #ffffff;
}

.arrayTip:hover .arrayTipBox,
.arrayTip:focus-within .arrayTipBox {
  opacity: 1;
  visibility: visible;
}

.arrayTip.tt-esc .arrayTipBox {
  opacity: 0 !important;
  visibility: hidden !important;
}

/* EUI tooltip: right-anchor so it opens leftward and stays on screen */
#euiHeader .euiTipBox {
  left: auto;
  right: 0;
  transform: none;
}

#euiHeader .euiTipBox::before,
#euiHeader .euiTipBox::after {
  left: auto;
  right: 10px;
  transform: none;
}

/* Expandable row chevron indicator */
tr.main-row.expandable {
  cursor: pointer;
}

/* Keep building label inline with sun icon */
tr.main-row.expandable .building-label {
  display: inline;
}

/* font awesome Chevron floats to the right side of the cell */
tr.main-row.expandable .expand-chevron {
  float: right;
  margin-left: 4px;
  color: var(--button-color);
  opacity: 0.35;
  font-size: 0.75rem;
  line-height: 1.5;
  vertical-align: middle;
  transition: opacity 0.25s ease;
  pointer-events: auto;
}

tr.main-row.expandable .expand-chevron i {
  display: inline;
  transition: transform 0.25s ease;
}

tr.main-row.expandable:hover .expand-chevron {
  opacity: 0.75;
}

tr.main-row.expandable.open .expand-chevron {
  transform: rotate(180deg);
}

.mobile-eui-info {
  display: none;
}

@media (max-width: 768px) {
  .table-container {
    min-height: auto;
    overflow: visible;
  }

  .mobile-eui-info {
    display: block;
    text-align: center;
    font-size: 14px;
    color: var(--primary-text);
    padding: 0 16px 8px;
    opacity: 0.75;
  }

  .tag-filter-popup {
    left: 50%;
    right: auto;
    transform: translateX(-50%);
    max-width: calc(100vw - 24px);
  }

  .table-loading-overlay {
    border-radius: 8px;
  }

  table {
    display: block;
    width: 100%;
    box-sizing: border-box;
    background: transparent;
    box-shadow: none;
  }

  thead {
    display: none;
  }

  tbody {
    display: block;
    width: 100%;
    box-sizing: border-box;
  }

  tbody tr.main-row {
    display: block;
    width: 100%;
    margin: 20px auto;
    box-sizing: border-box;
    background: white;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    margin-bottom: 12px;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.06);
  }

  /* Always flatten bottom corners on expandable cards since detail is always shown */
  tbody tr.main-row.expandable {
    border-radius: 8px 8px 0 0;
    margin-bottom: 0;
    border-bottom: none;
    cursor: default;
  }

  tr.main-row.expandable .expand-chevron {
    display: none;
  }

  tbody td {
    display: block;
    position: relative;
    padding: 8px 12px 8px 45%;
    font-size: 15px;
    border-bottom: 1px solid #f0f0f0;
    box-sizing: border-box;
    min-height: 38px;
  }

  tbody td:last-child {
    border-bottom: none;
  }

  tbody td::before {
    content: attr(data-label);
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    width: calc(45% - 20px);
    font-weight: 600;
    font-size: 13px;
    color: var(--button-color);
    text-transform: uppercase;
    letter-spacing: 0.04em;
  }

  /* Building name: full-width card title, no label */
  tbody td[data-label=""] {
    padding: 10px 36px 10px 12px;
    font-weight: 700;
    font-size: 16px;
    border-bottom: 2px solid #e0e0e0;
  }

  tbody td[data-label=""]::before {
    display: none;
  }

  /* Always show detail rows in card view */
  tr.hidden-data,
  tr.hidden-data.open {
    display: block;
    border: 1px solid #e0e0e0;
    border-top: none;
    border-radius: 0 0 8px 8px;
    margin-bottom: 12px;
    background: white;
    padding: 0;
  }

  tr.hidden-data td {
    display: block;
    padding: 0;
    border: none;
    min-height: auto;
  }

  /* Each info span becomes a card row matching the other rows */
  tr.hidden-data td > span:not(.arrayTip) {
    display: block;
    position: relative;
    padding: 8px 12px 8px 45%;
    font-size: 15px;
    border-top: 1px solid #f0f0f0;
    box-sizing: border-box;
    min-height: 38px;
  }

  /* Style the strong tag as a label matching ::before on other rows */
  tr.hidden-data td > span:not(.arrayTip) > strong {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    width: calc(45% - 20px);
    font-weight: 600;
    font-size: 13px;
    color: var(--button-color);
    text-transform: uppercase;
    letter-spacing: 0.04em;
  }

  /* Keep arrayTip inline with the value */
  tr.hidden-data .arrayTip {
    display: inline-block;
    margin-right: 0;
    margin-left: 8px;
  }

  tr.hidden-data td::before {
    display: none;
  }

  /* Zebra striping on block-display cards */
  tbody tr.row-odd td,
  tbody tr.row-odd + tr.hidden-data td {
    background-color: white;
  }

  tbody tr.row-even td,
  tbody tr.row-even + tr.hidden-data td {
    background-color: #fafafa;
  }
}
