/* Main table */
.po-table {
  width: 100%;
  table-layout: fixed;
}

.report-table-card {
  position: relative;
}

.loading-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.75);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
  z-index: 2;
}

.loading-overlay.active {
  opacity: 1;
  pointer-events: all;
}

.loading-spinner {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 3px solid #e5e7eb;
  border-top-color: #2563eb;
  animation: spin 0.8s linear infinite;
}

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

.po-table th.sortable {
  cursor: pointer;
  user-select: none;
}

.po-table th.sorted {
  color: #111827;
}

.sort-indicator {
  margin-left: 6px;
  font-size: 0.8em;
  color: #6b7280;
}

/* Lock parent columns */


.po-table th:nth-child(2),
.po-table td:nth-child(2) { width: 34%; }

.po-table th:nth-child(3),
.po-table td:nth-child(3),
.po-table th:nth-child(4),
.po-table td:nth-child(4) {
  width: 20%;
  text-align: right;
}

/* Details row */
.details-row td {
  padding: 8px 12px;
  background: #fafafac0;
}

/* Inner table should not affect layout */
.inner-table {
  width: 100%;
  table-layout: fixed;
background-color: #8d888841;
}

.inner-table th:nth-child(1),
.inner-table td:nth-child(1) {
  width: 35%;
}

.inner-table th:nth-child(2),
.inner-table td:nth-child(2),
.inner-table th:nth-child(3),
.inner-table td:nth-child(3) {
  width: 32.5%;
  text-align: right;
}

/* Highlight open (expanded) location row */
.main-row.open {
  background-color: #f0afaf; /* soft amber */
  box-shadow: inset 4px 0 0 #c44747; /* left accent bar */
}

/* Keep text readable */
.main-row.open td {
  font-weight: 600;
}

.main-row.open + .details-row td {
  border-top: 0;
}

.main-row.open + .details-row td {
  background-color: #e5e5e5;
}

.main-row {
  cursor: pointer;
}

.main-row:hover {
  background-color: #f9fafb;
}

.details-row {
  display: none;
}

.details-row.open {
  display: table-row;
}

.checkbox-row {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.95rem;
  white-space: nowrap;
}

.report-filters {
  margin-bottom: 0;
}

@media (max-width: 768px) {
  .report-controls {
    flex-direction: column;
    align-items: stretch !important;
    gap: 12px;
  }

  .report-filters {
    width: 100%;
  }

  .report-filters .form-group,
  .report-filters select,
  .report-controls button {
    width: 100%;
  }

  .report-filters .checkbox-row {
    margin-left: 0 !important;
    justify-content: center;
  }

  .report-filters .spread-toggle {
    text-align: center;
  }

}


@media (max-width: 768px) {

  /* Hide header */
  .po-table thead {
    display: none;
  }

  /* Main rows become cards */
  .main-row {
    display: block;
    padding: 12px;
    border-radius: 12px;
    margin-bottom: 12px;
    background: #fff;
  }

  /* Keep details rows as table-rows (CRITICAL) */
  .details-row {
    display: none;
  }

  .details-row.open {
    display: table-row;
  }

  /* Stack cells */
  .po-table > tbody > tr.main-row td {
    display: block !important;
    width: 100%;
    text-align: left !important;
    justify-content: flex-start !important;
  }

  .po-table > tbody > tr.main-row td::before {
    display: block;
    font-size: 0.72rem;
    font-weight: 600;
    letter-spacing: 0.02em;
    color: #6b7280;
    margin-bottom: 2px;
  }

  .po-table > tbody > tr.main-row td:nth-child(1)::before { content: "Site" !important; }
  .po-table > tbody > tr.main-row td:nth-child(2)::before { content: "Location" !important; }
  .po-table > tbody > tr.main-row td:nth-child(3)::before { content: "Total Net" !important; }
  .po-table > tbody > tr.main-row td:nth-child(4)::before { content: "Inc. Labour" !important; }

  /* Details row content */
  .details-row td {
    display: block;
    padding: 8px 12px;
  }

  /* Inner table safe stacking */
  .inner-table {
    width: 100%;
  }

  .inner-table td {
    display: block;
    text-align: left;
  }

  /* Stage name emphasis */
  .inner-table td:first-child {
    font-weight: 600;
    margin-bottom: 4px;
  }
}

@media (max-width: 768px) {

  /* === FIX INNER TABLE MOBILE RENDERING === */

  .inner-table {
    width: 100%;
    background-color: #e5e5e5;
  }

  .inner-table tr {
    display: block;
    padding: 10px 0;
    border-bottom: 1px solid #e5e7eb;
  }

  .inner-table td {
    display: block;
    width: 100% !important;   /* 🔴 critical fix */
    max-width: 100% !important;
    text-align: left;
    padding: 2px 0;
    white-space: normal;      /* allow normal wrapping */
  }

  /* Stage name */
  .inner-table td:nth-child(1) {
    font-weight: 600;
    margin-bottom: 6px;
  }

  /* Value labels */
  .inner-table td:nth-child(2)::before {
    content: "Net: ";
    font-weight: 500;
  }

  .inner-table td:nth-child(3)::before {
    content: "Gross: ";
    font-weight: 500;
  }

}
