/* Estilos generales para todos los formularios del sistema */

/* Cards de formularios */
.form-card {
  box-shadow: 0 0.15rem 1.75rem 0 rgba(58, 59, 69, 0.15) !important;
  border: none;
  margin-bottom: 1.5rem;
}

.form-card .card-header {
  background-color: #f8f9fa;
  border-bottom: 1px solid #e3e6f0;
  font-weight: 600;
  padding: 1rem 1.35rem;
}

.form-card .card-header i[data-feather] {
  width: 18px;
  height: 18px;
}

/* Labels */
.form-label {
  font-weight: 500;
  color: #5a5c69;
  margin-bottom: 0.5rem;
}

/* Inputs y selects */
.form-control:focus,
.form-select:focus {
  border-color: #0061f2;
  box-shadow: 0 0 0 0.25rem rgba(0, 97, 242, 0.25);
}

.form-control::placeholder,
.form-select option:disabled {
  color: #a7aeb8;
}

/* Botones */
.btn-primary {
  background-color: #0061f2;
  border-color: #0061f2;
  padding: 0.75rem 1.5rem;
  font-weight: 500;
}

.btn-primary:hover {
  background-color: #0051d2;
  border-color: #0051d2;
}

.btn-light {
  border-color: #e3e6f0;
  color: #5a5c69;
}

.btn-light:hover {
  background-color: #f8f9fa;
  border-color: #e3e6f0;
}

/* Alertas de error */
.alert-danger {
  border-left: 4px solid #e74a3b;
}

.alert-danger h5 {
  margin-bottom: 0.5rem;
  font-weight: 600;
}

.alert-danger i[data-feather] {
  width: 20px;
  height: 20px;
}

/* Iconos en botones */
.btn i[data-feather],
.page-header-icon i[data-feather] {
  width: 18px;
  height: 18px;
  vertical-align: middle;
}

/* Espaciado consistente */
.form-row-spacing .mb-3 {
  margin-bottom: 1rem !important;
}

/* Botones de acción en tablas - Estilos globales */
.btn-group {
  display: inline-flex;
  vertical-align: middle;
  gap: 0;
}

.btn-group .btn {
  position: relative;
  flex: 0 0 auto;
  border-radius: 0;
  padding: 0.375rem 0.75rem;
}

.btn-group .btn:first-child {
  border-top-left-radius: 0.35rem;
  border-bottom-left-radius: 0.35rem;
}

.btn-group .btn:last-child {
  border-top-right-radius: 0.35rem;
  border-bottom-right-radius: 0.35rem;
}

.btn-group .btn:not(:first-child):not(:last-child) {
  border-radius: 0;
}

.btn-group form {
  display: inline-block;
  margin: 0;
  vertical-align: top;
}

.btn-group form .btn {
  border-radius: 0;
  margin: 0;
}

.btn-group form:first-child .btn {
  border-top-left-radius: 0.35rem;
  border-bottom-left-radius: 0.35rem;
}

.btn-group form:last-child .btn {
  border-top-right-radius: 0.35rem;
  border-bottom-right-radius: 0.35rem;
}

.btn-group form:not(:first-child):not(:last-child) .btn {
  border-radius: 0;
}

/* Asegurar que los iconos Feather se rendericen en botones */
.btn i[data-feather] {
  width: 16px;
  height: 16px;
  stroke-width: 2;
}

/* Espaciado entre botones usando gap */
.d-flex.gap-2 {
  gap: 0.5rem !important;
}

.d-flex.gap-3 {
  gap: 0.75rem !important;
}

/* Mejoras en botones de acción en vistas show */
.card .card-body .d-flex.justify-content-between {
  padding: 1rem 0;
}

.card .card-body .btn {
  min-width: 50px;
  white-space: nowrap;
}

/* Responsive */
@media (max-width: 768px) {
  .form-card .card-body .row {
    margin-left: -0.75rem;
    margin-right: -0.75rem;
  }
  
  .form-card .card-body [class*="col-"] {
    padding-left: 0.75rem;
    padding-right: 0.75rem;
  }

  /* Botones apilados en móviles */
  .card .card-body .d-flex.justify-content-between {
    flex-direction: column;
    gap: 1rem;
  }

  .card .card-body .d-flex.gap-2 {
    width: 100%;
    justify-content: stretch;
  }

  .card .card-body .d-flex.gap-2 .btn {
    flex: 1;
  }
}

/* Estilos específicos para la tabla de productos */
.products-table-card {
  max-width: 100%;
  margin: 0 auto;
}

/* Botones extra pequeños para tablas */
.btn-xs {
  padding: 0.2rem 0.4rem;
  font-size: 0.7rem;
  line-height: 1.2;
  border-radius: 0.25rem;
}

.btn-xs i[data-feather] {
  width: 14px;
  height: 14px;
  stroke-width: 2;
}

.btn-group-xs .btn {
  padding: 0.2rem 0.4rem;
  font-size: 0.7rem;
  line-height: 1.2;
}

.btn-group-xs .btn i[data-feather] {
  width: 14px;
  height: 14px;
  stroke-width: 2;
}

/* Ajustes específicos para tablas con botones pequeños */
.table .btn-group-xs {
  display: inline-flex;
  vertical-align: middle;
}

.table .btn-group-xs .btn {
  border-radius: 0;
  min-width: auto;
}

.table .btn-group-xs .btn:first-child {
  border-top-left-radius: 0.25rem;
  border-bottom-left-radius: 0.25rem;
}

.table .btn-group-xs .btn:last-child {
  border-top-right-radius: 0.25rem;
  border-bottom-right-radius: 0.25rem;
}

.table .btn-group-xs .btn:not(:first-child):not(:last-child) {
  border-radius: 0;
}

.table .btn-group-xs form {
  display: inline-block;
  margin: 0;
}

.table .btn-group-xs form .btn {
  border-radius: 0;
  margin: 0;
}

/* Compatibilidad con #datatablesSimple específicamente */
#datatablesSimple .btn-group-xs {
  display: inline-flex;
  vertical-align: middle;
}

#datatablesSimple .btn-group-xs .btn {
  border-radius: 0;
  min-width: auto;
}

#datatablesSimple .btn-group-xs .btn:first-child {
  border-top-left-radius: 0.25rem;
  border-bottom-left-radius: 0.25rem;
}

#datatablesSimple .btn-group-xs .btn:last-child {
  border-top-right-radius: 0.25rem;
  border-bottom-right-radius: 0.25rem;
}

#datatablesSimple .btn-group-xs .btn:not(:first-child):not(:last-child) {
  border-radius: 0;
}

#datatablesSimple .btn-group-xs form {
  display: inline-block;
  margin: 0;
}

#datatablesSimple .btn-group-xs form .btn {
  border-radius: 0;
  margin: 0;
}

/* Alta rápida de producto: formulario ancho dentro del modal global */
#quickCreateModal .modal-dialog:has([data-product-quick-form]) {
  max-width: min(96vw, 1200px);
  width: 100%;
}

#quickCreateModal .modal-body:has([data-product-quick-form]) {
  max-height: min(85vh, 900px);
  overflow-y: auto;
}

/* Sucursales: una sola card fija al scroll en editar (botones en card-footer) */
@media (min-width: 992px) {
  header.page-header-sticky ~ .container-fluid .company-branch-form--edit .company-branch-form-card {
    position: sticky;
    top: calc(var(--page-header-sticky-top, 3.625rem) + 5rem + 0.75rem);
    z-index: 5;
    max-height: calc(100vh - var(--page-header-sticky-top, 3.625rem) - 5rem - 1.5rem);
    overflow-y: auto;
    margin-bottom: 0 !important;
  }

  body.staging-deployment-active.nav-fixed header.page-header-sticky ~ .container-fluid .company-branch-form--edit .company-branch-form-card,
  body.impersonation-active.nav-fixed header.page-header-sticky ~ .container-fluid .company-branch-form--edit .company-branch-form-card {
    top: calc(var(--page-header-sticky-top, 3.625rem) + 5rem + 0.75rem);
    max-height: calc(100vh - var(--page-header-sticky-top, 3.625rem) - 5rem - 1.5rem);
  }
}

.invoices-config-billing-type-hint {
  cursor: help;
  outline: none;
}

.invoices-config-billing-type-hint:focus-visible .fa-info-circle {
  outline: 2px solid var(--bs-info);
  outline-offset: 2px;
  border-radius: 50%;
}

/* Configuración de facturación: formulario legible */
.invoices-config-branch-meta {
  display: flex;
  gap: 1rem;
  padding: 0.5rem 0.75rem;
  background: var(--bs-light, #f8f9fa);
  border: 1px solid var(--bs-border-color-translucent, rgba(0, 0, 0, 0.08));
  border-radius: 0.375rem;
  min-height: calc(1.5em + 0.5rem + 2px);
  align-items: center;
}

.invoices-config-branch-meta__item {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  min-width: 0;
}

.invoices-config-branch-meta__label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  color: var(--bs-secondary-color);
  line-height: 1.2;
}

.invoices-config-options-group__title {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--bs-secondary-color);
  margin: 0 0 0.35rem;
  padding-bottom: 0.25rem;
  border-bottom: 1px solid var(--bs-border-color-translucent, rgba(0, 0, 0, 0.06));
}

.invoices-config-option {
  padding: 0.4rem 0;
  border-bottom: 1px solid var(--bs-border-color-translucent, rgba(0, 0, 0, 0.05));
}

.invoices-config-option:last-child {
  border-bottom: none;
}

.invoices-config-option--nested {
  margin-left: 1.25rem;
  padding-left: 0.75rem;
  border-left: 2px solid var(--bs-border-color-translucent, rgba(0, 0, 0, 0.12));
}

.invoices-config-option__check {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  min-height: 1.75rem;
}

.invoices-config-option__check .form-check-input {
  flex-shrink: 0;
}

.invoices-config-option__check .form-check-label {
  display: inline-flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.25rem;
  line-height: 1.35;
  cursor: pointer;
}

.invoices-config-option__label {
  font-size: 0.875rem;
}

.invoices-config-hint-btn {
  color: var(--bs-secondary-color);
  line-height: 1;
  vertical-align: middle;
  text-decoration: none;
}

.invoices-config-hint-btn:hover,
.invoices-config-hint-btn:focus {
  color: var(--bs-info);
}

.invoices-config-hint-btn .fa-circle-info {
  font-size: 0.85rem;
}

.popover {
  max-width: min(22rem, 90vw);
  font-size: 0.8125rem;
}

/* Tarjetas colapsables y reordenables — configuración de facturación */
.invoices-config-sections-hint {
  line-height: 1.35;
}

.invoices-config-section-card.collapsible-card .card-header.invoices-config-section-card__header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  user-select: none;
  transition: background-color 0.2s ease;
}

.invoices-config-section-card.collapsible-card .card-header.invoices-config-section-card__header:hover {
  background-color: rgba(0, 0, 0, 0.04);
}

.invoices-config-section-card__toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  cursor: pointer;
  min-width: 0;
}

.invoices-config-section-grip {
  flex-shrink: 0;
  cursor: grab;
  padding: 0.15rem 0.25rem;
  border-radius: 0.25rem;
  line-height: 1;
}

.invoices-config-section-grip:hover {
  color: var(--bs-primary) !important;
  background: rgba(13, 110, 253, 0.08);
}

.invoices-config-section-grip:active {
  cursor: grabbing;
}

.invoices-config-section-card--dragging {
  opacity: 0.65;
}

.invoices-config-section-card.collapsible-card .card-body {
  transition: max-height 0.35s ease, opacity 0.25s ease, padding 0.25s ease;
  overflow: hidden;
}

.invoices-config-section-card.collapsible-card .card-body.show {
  max-height: 4000px;
}

.invoices-config-section-card.collapsible-card .card-body:not(.show) {
  max-height: 0 !important;
  opacity: 0;
  padding-top: 0 !important;
  padding-bottom: 0 !important;
  margin-bottom: 0 !important;
}

.invoices-config-section-card.collapsible-card .collapse-icon {
  flex-shrink: 0;
  transition: transform 0.25s ease;
}

/* Legacy stack (new form no longer uses; keep for safety) */
.invoices-config-form-options-stack {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.invoices-config-form-options-section + .invoices-config-form-options-section {
  padding-top: 0.25rem;
  border-top: 1px solid var(--bs-border-color-translucent, rgba(0, 0, 0, 0.08));
}

/* Configuración de facturación: columna derecha fija al scroll (edit/new) */
@media (min-width: 992px) {
  .invoices-config-form-sidebar-col {
    align-self: flex-start;
  }

  header.page-header-sticky ~ .container-fluid .invoices-config-form--edit .invoices-config-form-sidebar {
    top: calc(var(--page-header-sticky-top, 3.625rem) + 5rem + 0.75rem);
    max-height: calc(100vh - var(--page-header-sticky-top, 3.625rem) - 5rem - 1.5rem);
  }

  body.staging-deployment-active.nav-fixed header.page-header-sticky ~ .container-fluid .invoices-config-form--edit .invoices-config-form-sidebar,
  body.impersonation-active.nav-fixed header.page-header-sticky ~ .container-fluid .invoices-config-form--edit .invoices-config-form-sidebar {
    top: calc(var(--page-header-sticky-top, 3.625rem) + 5rem + 0.75rem);
    max-height: calc(100vh - var(--page-header-sticky-top, 3.625rem) - 5rem - 1.5rem);
  }

  .invoices-config-form-sidebar {
    position: sticky;
    top: calc(var(--app-topnav-height, 3.625rem) + 0.75rem);
    z-index: 5;
    max-height: calc(100vh - var(--app-topnav-height, 3.625rem) - 1.5rem);
    overflow-y: auto;
    padding-bottom: 0.25rem;
  }

  body.staging-deployment-active.nav-fixed .invoices-config-form-sidebar,
  body.impersonation-active.nav-fixed .invoices-config-form-sidebar {
    top: calc(var(--page-header-sticky-top, 3.625rem) + 0.75rem);
    max-height: calc(100vh - var(--page-header-sticky-top, 3.625rem) - 1.5rem);
  }

  .invoices-config-form-sidebar .card:last-child {
    margin-bottom: 0 !important;
  }
}

