body:not(.has-company-context) .boveda-nav-item,
.boveda-nav-item.permission-hidden {
  display: none !important;
}

.boveda-head {
  align-items: flex-start;
  gap: 24px;
}

.boveda-subtitle {
  max-width: 820px;
  margin: 6px 0 0;
  color: var(--muted, #667085);
}

.boveda-company {
  display: grid;
  gap: 2px;
  min-width: 220px;
  padding: 12px 16px;
  border: 1px solid var(--border, #e5e7eb);
  border-radius: 12px;
  background: var(--surface, #fff);
  text-align: right;
}

.boveda-company span,
.boveda-company small {
  color: var(--muted, #667085);
}

.boveda-note {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  margin: 0 0 16px;
  padding: 12px 16px;
  border-left: 4px solid var(--brand-primary, #f2d200);
  border-radius: 8px;
  background: color-mix(in srgb, var(--brand-primary, #f2d200) 10%, white);
  color: var(--brand-text, #111827);
}

.boveda-view-switch {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  margin: 0 0 12px;
}

.boveda-view-switch .btn.is-active,
.boveda-view-switch .btn[aria-pressed="true"] {
  border-color: var(--brand-primary, #f2d200);
  background: var(--brand-primary, #f2d200);
  color: var(--brand-text, #111827);
}

.boveda-provider-note {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  margin: 0 0 14px;
  padding: 11px 14px;
  border: 1px solid var(--border, #e5e7eb);
  border-radius: 10px;
  background: var(--surface, #fff);
  color: var(--muted, #667085);
  font-size: 13px;
}

.boveda-provider-note[hidden] {
  display: none !important;
}

.boveda-provider-note strong {
  flex: 0 0 auto;
  color: var(--brand-text, #111827);
}

.boveda-filters {
  display: grid;
  grid-template-columns: repeat(6, minmax(140px, 1fr));
  gap: 12px;
  align-items: end;
  margin-bottom: 18px;
  padding: 16px;
  border: 1px solid var(--border, #e5e7eb);
  border-radius: 14px;
  background: var(--surface, #fff);
}

.boveda-filters label {
  display: grid;
  gap: 6px;
  font-size: 12px;
  font-weight: 700;
  color: var(--muted, #667085);
}

.boveda-filters input,
.boveda-filters select {
  min-height: 40px;
  width: 100%;
}

.boveda-filter-wide {
  grid-column: span 2;
}

.boveda-filter-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.boveda-kpis {
  display: grid;
  grid-template-columns: repeat(6, minmax(130px, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}

#boveda:has(#bovedaViewDetalle.is-active) .boveda-kpis {
  grid-template-columns: repeat(4, minmax(130px, 1fr));
}

/* En la vista principal sólo se conservan los cuatro KPIs ejecutivos.
   Los indicadores técnicos Tipo P siguen disponibles en el detalle/filtros,
   pero ya no ocupan espacio en la cabecera de Bóveda Fiscal. */
#boveda:has(#bovedaViewDetalle.is-active) .boveda-kpi:nth-child(n+5) {
  display: none;
}

.boveda-kpi {
  display: grid;
  gap: 4px;
  min-height: 96px;
  padding: 14px 16px;
  border: 1px solid var(--border, #e5e7eb);
  border-radius: 14px;
  background: var(--surface, #fff);
}

.boveda-kpi span,
.boveda-kpi small {
  color: var(--muted, #667085);
}

.boveda-kpi strong {
  font-size: 24px;
  line-height: 1.1;
}

/* loadBoveda() ya protege contra peticiones concurrentes con local.loading.
   Mientras renderLoading() deja la tabla sin thead y con empty-state,
   mostramos un spinner y bloqueamos visualmente las acciones de filtro. */
#bovedaTable:not(:has(thead)) > tbody .empty-state strong {
  display: inline-flex;
  align-items: center;
  gap: 9px;
}

#bovedaTable:not(:has(thead)) > tbody .empty-state strong::before {
  content: '';
  width: 16px;
  height: 16px;
  flex: 0 0 16px;
  border: 2px solid color-mix(in srgb, var(--muted, #667085) 28%, transparent);
  border-top-color: var(--brand-primary, #f2d200);
  border-radius: 50%;
  animation: boveda-filter-spin .75s linear infinite;
}

#boveda:has(#bovedaTable:not(:has(thead)) > tbody .empty-state) #bovedaApply,
#boveda:has(#bovedaTable:not(:has(thead)) > tbody .empty-state) #bovedaClear {
  pointer-events: none;
  cursor: wait;
  opacity: .62;
}

#boveda:has(#bovedaTable:not(:has(thead)) > tbody .empty-state) .boveda-filters {
  cursor: wait;
}

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

@media (prefers-reduced-motion: reduce) {
  #bovedaTable:not(:has(thead)) > tbody .empty-state strong::before {
    animation-duration: 1.5s;
  }
}

.boveda-table-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin: 0 0 10px;
}

.boveda-table-meta > div:first-child {
  display: grid;
  gap: 2px;
}

.boveda-table-meta span {
  color: var(--muted, #667085);
  font-size: 12px;
}

.boveda-table-wrap {
  max-height: 68vh;
  overflow: auto;
}

.boveda-table-wrap table {
  min-width: 1800px;
}

.boveda-table-wrap table.boveda-provider-table {
  min-width: 1750px;
}

.boveda-table-wrap thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--surface, #fff);
}

.boveda-table-wrap td {
  vertical-align: top;
}

.boveda-table-wrap td.numeric,
.boveda-table-wrap th.numeric {
  text-align: right;
  white-space: nowrap;
}

.boveda-uuid {
  max-width: 280px;
  overflow-wrap: anywhere;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
}

.boveda-provider-rfc {
  white-space: nowrap;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
}

.boveda-provider-name {
  min-width: 250px;
}

.boveda-detail-button {
  white-space: nowrap;
}

.boveda-detail-dialog {
  width: min(1180px, calc(100vw - 32px));
  max-height: calc(100vh - 40px);
  padding: 0;
  border: 0;
  border-radius: 18px;
  background: var(--surface, #fff);
  color: var(--brand-text, #111827);
}

.boveda-detail-dialog::backdrop {
  background: rgb(17 24 39 / 58%);
}

.boveda-detail-shell {
  display: grid;
  gap: 18px;
  padding: 22px;
  max-height: calc(100vh - 40px);
  overflow: auto;
}

.boveda-detail-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 20px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border, #e5e7eb);
}

.boveda-detail-head h2 {
  margin: 3px 0 4px;
}

.boveda-detail-subtitle {
  margin: 0;
  color: var(--muted, #667085);
  overflow-wrap: anywhere;
}

.boveda-detail-status {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  border: 1px solid var(--border, #e5e7eb);
  border-radius: 12px;
  background: color-mix(in srgb, var(--surface, #fff) 92%, var(--brand-primary, #f2d200));
}

.boveda-detail-total {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-left: auto;
}

.boveda-detail-total span {
  color: var(--muted, #667085);
  font-size: 12px;
}

.boveda-detail-total strong {
  font-size: 20px;
}

.boveda-detail-body {
  display: grid;
  gap: 18px;
}

.boveda-detail-group {
  padding: 16px;
  border: 1px solid var(--border, #e5e7eb);
  border-radius: 14px;
  background: var(--surface, #fff);
}

.boveda-detail-group h3 {
  margin: 0 0 14px;
  font-size: 16px;
}

.boveda-detail-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.boveda-detail-field {
  display: grid;
  gap: 4px;
  min-width: 0;
  padding: 10px 12px;
  border-radius: 10px;
  background: color-mix(in srgb, var(--surface, #fff) 94%, #667085);
}

.boveda-detail-field.is-wide {
  grid-column: 1 / -1;
}

.boveda-detail-field span {
  color: var(--muted, #667085);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .04em;
}

.boveda-detail-field strong {
  min-width: 0;
  font-size: 13px;
  font-weight: 600;
  overflow-wrap: anywhere;
}

.boveda-detail-empty {
  margin: 0;
  color: var(--muted, #667085);
}

.boveda-relation-heading,
.boveda-relation-card-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
}

.boveda-relation-heading h3 {
  margin-top: 2px;
}

.boveda-relation-list {
  display: grid;
  gap: 12px;
}

.boveda-relation-card {
  display: grid;
  gap: 14px;
  padding: 14px;
  border: 1px solid var(--border, #e5e7eb);
  border-radius: 12px;
  background: color-mix(in srgb, var(--surface, #fff) 96%, var(--brand-primary, #f2d200));
}

.boveda-relation-states {
  display: flex;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 6px;
}

@media (max-width: 1280px) {
  .boveda-filters {
    grid-template-columns: repeat(3, minmax(160px, 1fr));
  }

  .boveda-kpis,
  #boveda:has(#bovedaViewDetalle.is-active) .boveda-kpis {
    grid-template-columns: repeat(3, minmax(150px, 1fr));
  }
}

@media (max-width: 820px) {
  .boveda-detail-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 760px) {
  .boveda-head,
  .boveda-table-meta,
  .boveda-note,
  .boveda-provider-note,
  .boveda-detail-head {
    flex-direction: column;
    align-items: stretch;
  }

  .boveda-relation-heading,
  .boveda-relation-card-head {
    flex-direction: column;
  }

  .boveda-relation-states {
    justify-content: flex-start;
  }

  .boveda-company {
    text-align: left;
  }

  .boveda-filters,
  .boveda-kpis,
  #boveda:has(#bovedaViewDetalle.is-active) .boveda-kpis,
  .boveda-detail-grid {
    grid-template-columns: 1fr;
  }

  .boveda-filter-wide,
  .boveda-detail-field.is-wide {
    grid-column: auto;
  }

  .boveda-detail-total {
    width: 100%;
    margin-left: 0;
    justify-content: space-between;
  }
}
