/* ============================================
   SISFE V2 - Custom Styles
   Mobile-first responsive + Dark/Light mode
   ============================================ */

/* --- CSS Custom Properties --- */
:root {
  --sisfe-primary: #4361ee;
  --sisfe-primary-hover: #3a56d4;
  --sisfe-accent: #7209b7;
  --sisfe-success: #06d6a0;
  --sisfe-warning: #ffd166;
  --sisfe-danger: #ef476f;
  --sisfe-info: #118ab2;
  --sisfe-sidebar-width: 250px;
  --sisfe-bottomnav-height: 56px;
  --sisfe-transition: 0.25s ease;
}

/* --- z-index: NO elevar .app-main ---
   AdminLTE hierarchy: header(1034) < overlay(1037) < sidebar(1038).
   .app-main sin z-index para no tapar header dropdown ni sidebar.
   Modales BS5 usan position:fixed y escapan de overflow:auto sin problema. */

/* --- Logo --- */
.sisfe-logo {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 1.2rem;
  font-weight: 700;
  text-decoration: none;
  color: inherit;
}

.sisfe-logo code {
  font-family: 'Courier New', Courier, monospace;
  font-size: 1.1em;
  font-weight: 800;
  background: none;
  color: var(--sisfe-primary);
  padding: 0;
}

[data-bs-theme="dark"] .sisfe-logo code {
  color: #7b9cff;
}

.sisfe-logo span {
  font-family: 'Source Sans 3', sans-serif;
  letter-spacing: 0.5px;
}

/* --- Auth pages logo (larger) --- */
.sisfe-logo-lg {
  font-size: 2rem;
}

.sisfe-logo-lg code {
  font-size: 1.15em;
}

/* --- Theme Toggle Button --- */
.theme-toggle {
  background: none;
  border: none;
  padding: 0.5rem;
  cursor: pointer;
  color: inherit;
  font-size: 1.25rem;
  line-height: 1;
  border-radius: 0.375rem;
  transition: background-color var(--sisfe-transition);
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
}

.theme-toggle:hover {
  background-color: rgba(0, 0, 0, 0.08);
}

[data-bs-theme="dark"] .theme-toggle:hover {
  background-color: rgba(255, 255, 255, 0.1);
}

.theme-toggle .bi {
  transition: transform 0.3s ease;
}

.theme-toggle:active .bi {
  transform: rotate(30deg);
}

/* --- Status Badges --- */
.badge-aprobado {
  background-color: var(--sisfe-success) !important;
  color: #000 !important;
}

.badge-rechazado {
  background-color: var(--sisfe-danger) !important;
  color: #fff !important;
}

.badge-encolado {
  background-color: var(--sisfe-info) !important;
  color: #fff !important;
}

.badge-borrador {
  background-color: #6c757d !important;
  color: #fff !important;
}

.badge-generado {
  background-color: var(--sisfe-warning) !important;
  color: #000 !important;
}

.badge-cancelado {
  background-color: #343a40 !important;
  color: #fff !important;
}

.badge-aprobado-obs {
  background-color: #20c997 !important;
  color: #000 !important;
}

/* --- Cards --- */
.card {
  border-radius: 0.5rem;
  border: none;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
  transition: box-shadow var(--sisfe-transition);
}

.card:hover {
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
}

[data-bs-theme="dark"] .card {
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
}

[data-bs-theme="dark"] .card:hover {
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
}

.card-header {
  border-radius: 0.5rem 0.5rem 0 0 !important;
  font-weight: 600;
}

/* --- Filter Cards (collapsible on mobile) --- */
.filter-card .card-body {
  transition: max-height 0.35s ease, padding 0.35s ease, opacity 0.25s ease;
  overflow: hidden;
}

/* Cuando hay un Choices.js abierto adentro, no clipear (deja salir el dropdown) */
.filter-card .card-body:has(.choices.is-open),
.filter-card:has(.choices.is-open),
.card-body:has(.choices.is-open),
.card:has(.choices.is-open) {
  overflow: visible !important;
}

@media (max-width: 767.98px) {
  .filter-card .card-body.collapsed {
    max-height: 0 !important;
    padding-top: 0 !important;
    padding-bottom: 0 !important;
    opacity: 0;
  }

  .filter-card .card-body:not(.collapsed) {
    max-height: 500px;
    opacity: 1;
  }

  .filter-toggle-btn {
    display: inline-flex !important;
  }
}

@media (min-width: 768px) {
  .filter-card .card-body {
    max-height: none !important;
    opacity: 1 !important;
  }

  .filter-toggle-btn {
    display: none !important;
  }
}

.filter-toggle-btn {
  font-size: 0.85rem;
  padding: 0.25rem 0.5rem;
}

/* --- Tables responsive --- */
.table-responsive {
  border-radius: 0.375rem;
}

.table th {
  font-weight: 600;
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  white-space: nowrap;
}

.table td {
  vertical-align: middle;
}

@media (max-width: 767.98px) {
  .table {
    font-size: 0.85rem;
  }

  .table th,
  .table td {
    padding: 0.4rem 0.5rem;
  }
}

/* --- Touch-friendly action buttons --- */
.btn-action {
  min-height: 38px;
  min-width: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

@media (max-width: 767.98px) {
  .btn-action {
    min-height: 44px;
    min-width: 44px;
  }

  .btn-mobile-full {
    width: 100%;
  }
}

/* --- Pagination mobile --- */
@media (max-width: 575.98px) {
  .pagination .page-item.d-mobile-none {
    display: none !important;
  }

  .pagination .page-link {
    min-width: 44px;
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .pagination-info {
    font-size: 0.8rem;
    text-align: center;
  }
}

/* --- Bottom Navigation (mobile only) --- */
.bottom-nav {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: var(--sisfe-bottomnav-height);
  background-color: var(--bs-body-bg);
  border-top: 1px solid var(--bs-border-color);
  z-index: 1040;
  padding: 0;
}

.bottom-nav-items {
  display: flex;
  justify-content: space-around;
  align-items: center;
  height: 100%;
  margin: 0;
  padding: 0;
  list-style: none;
}

.bottom-nav-item {
  flex: 1;
  text-align: center;
}

.bottom-nav-link {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 4px 0;
  color: var(--bs-secondary-color);
  text-decoration: none;
  font-size: 0.65rem;
  font-weight: 500;
  gap: 2px;
  transition: color var(--sisfe-transition);
  min-height: var(--sisfe-bottomnav-height);
}

.bottom-nav-link .bi {
  font-size: 1.25rem;
}

.bottom-nav-link:hover,
.bottom-nav-link.active {
  color: var(--sisfe-primary);
}

@media (max-width: 767.98px) {
  .bottom-nav {
    display: block;
  }

  /* Add padding at bottom for content not to be hidden */
  .app-main {
    padding-bottom: calc(var(--sisfe-bottomnav-height) + 0.5rem);
  }

  /* Breadcrumb hidden on mobile */
  .breadcrumb {
    display: none !important;
  }

  /* App content header compact */
  .app-content-header {
    padding: 0.5rem 0;
  }

  .app-content-header h3 {
    font-size: 1.1rem;
  }

  /* Footer hidden on mobile (bottom nav takes its place) */
  .app-footer {
    display: none;
  }
}

/* --- Sidebar overlay on mobile --- */
@media (max-width: 991.98px) {
  .sidebar-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1037;
    display: none;
  }

  .sidebar-overlay.show {
    display: block;
  }
}

/* --- Auth pages (split panel) --- */
.auth-split {
  --auth-brand-1: #0b1f4d;
  --auth-brand-2: #123a8f;
  --auth-brand-3: #1c52d0;
  min-height: 100vh;
  display: grid;
  grid-template-columns: minmax(0, 460px) 1fr;
  background: var(--bs-body-bg);
}

/* Panel de marca (izquierda) */
.auth-brand {
  position: relative;
  overflow: hidden;
  padding: 3rem 2.75rem;
  display: flex;
  flex-direction: column;
  justify-content: center;
  color: #eaf1ff;
  background: linear-gradient(160deg, var(--auth-brand-1) 0%, var(--auth-brand-2) 55%, var(--auth-brand-3) 130%);
}

.auth-brand-glow {
  position: absolute;
  inset: auto -30% -40% -30%;
  height: 70%;
  background: radial-gradient(circle at 50% 100%, rgba(80, 140, 255, 0.35), transparent 70%);
  pointer-events: none;
}

.auth-brand-shield {
  width: 104px;
  height: 104px;
  margin: 0 auto 2rem;
  display: grid;
  place-items: center;
  border-radius: 26px;
  font-size: 3rem;
  color: #dbe7ff;
  background: linear-gradient(150deg, rgba(90, 150, 255, 0.35), rgba(40, 90, 220, 0.15));
  border: 1px solid rgba(150, 190, 255, 0.35);
  box-shadow: 0 18px 40px rgba(10, 30, 90, 0.5), inset 0 1px 0 rgba(255, 255, 255, 0.25);
}

.auth-brand-title {
  margin: 0;
  text-align: center;
  font-size: 1.7rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.auth-brand-text {
  margin: 0.75rem auto 2.5rem;
  max-width: 21rem;
  text-align: center;
  color: #b9c9ee;
  font-size: 0.95rem;
  line-height: 1.6;
}

.auth-features {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.75rem;
}

.auth-features li {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.35rem;
  text-align: center;
}

.auth-features strong {
  font-size: 0.9rem;
  font-weight: 600;
}

.auth-features small {
  font-size: 0.7rem;
  color: #9fb2dc;
  line-height: 1.3;
}

.auth-feature-icon {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 12px;
  font-size: 1.15rem;
  color: #cfe0ff;
  background: rgba(120, 165, 255, 0.16);
  border: 1px solid rgba(150, 190, 255, 0.25);
}

/* Panel de contenido (derecha) */
.auth-panel {
  display: grid;
  place-items: center;
  padding: 2.5rem 1.5rem;
  overflow-y: auto;
}

.auth-panel-inner {
  width: 100%;
  max-width: 380px;
}

.auth-panel .form-control {
  padding: 0.7rem 0.85rem;
  border-radius: 0.65rem;
}

.auth-panel .input-group-text {
  border-radius: 0.65rem 0 0 0.65rem;
  min-width: 46px;
  justify-content: center;
  color: var(--sisfe-primary);
}

.auth-panel .input-group .form-control {
  border-radius: 0 0.65rem 0.65rem 0;
}

.auth-btn {
  padding: 0.75rem 1.5rem;
  border-radius: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.3px;
  background: var(--sisfe-primary);
  border-color: var(--sisfe-primary);
  transition: all var(--sisfe-transition);
}

.auth-btn.btn-primary {
  background: linear-gradient(135deg, var(--auth-brand-3, #1c52d0), var(--sisfe-primary));
  border: none;
  box-shadow: 0 10px 24px rgba(37, 99, 235, 0.3);
}

.auth-btn:hover {
  background: var(--sisfe-primary-hover);
  border-color: var(--sisfe-primary-hover);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(67, 97, 238, 0.35);
}

@media (max-width: 767.98px) {
  .auth-split {
    grid-template-columns: 1fr;
  }
  .auth-brand {
    display: none;
  }
}

/* Páginas allauth con elementos "pelados" (confirmación social, connections,
   reauth, etc.) — sin clases Bootstrap. Se estilan aquí sin pisar nuestras
   páginas propias que ya usan .btn / .form-control. */
.auth-panel h1 {
  text-align: center;
  font-size: 1.5rem;
  font-weight: 700;
  margin: 0 0 0.75rem;
  color: var(--bs-emphasis-color);
}

.auth-panel form p {
  color: var(--bs-secondary-color);
  margin-bottom: 1rem;
}

.auth-panel button:not(.btn):not(.btn-close),
.auth-panel a[role="button"]:not(.btn) {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  width: 100%;
  padding: 0.75rem 1.5rem;
  margin-top: 0.5rem;
  border: none;
  border-radius: 0.75rem;
  font-weight: 600;
  color: #fff;
  background: linear-gradient(135deg, var(--auth-brand-3, #1c52d0), var(--sisfe-primary));
  box-shadow: 0 10px 24px rgba(37, 99, 235, 0.3);
  cursor: pointer;
  text-decoration: none;
}

.auth-panel button:not(.btn):not(.btn-close):hover {
  filter: brightness(1.05);
  transform: translateY(-1px);
}

.auth-panel form label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  margin-bottom: 0.35rem;
}

.auth-panel form :is(input, select, textarea):not(.form-control):not([type="checkbox"]):not([type="radio"]) {
  width: 100%;
  padding: 0.7rem 0.85rem;
  border-radius: 0.65rem;
  border: 1px solid var(--bs-border-color);
  background: var(--bs-body-bg);
  color: var(--bs-body-color);
}

/* --- Profile page --- */
.profile-avatar {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  object-fit: cover;
  border: 3px solid var(--sisfe-primary);
}

.empresa-card {
  border-left: 4px solid var(--sisfe-primary);
  transition: transform var(--sisfe-transition);
}

.empresa-card:hover {
  transform: translateX(4px);
}

/* --- Password strength indicator --- */
.password-strength {
  height: 4px;
  border-radius: 2px;
  margin-top: 0.5rem;
  background-color: var(--bs-secondary-bg);
  overflow: hidden;
  transition: all 0.3s ease;
}

.password-strength-bar {
  height: 100%;
  border-radius: 2px;
  transition: width 0.3s ease, background-color 0.3s ease;
}

.password-strength-bar.weak {
  width: 25%;
  background-color: var(--sisfe-danger);
}

.password-strength-bar.fair {
  width: 50%;
  background-color: var(--sisfe-warning);
}

.password-strength-bar.good {
  width: 75%;
  background-color: var(--sisfe-info);
}

.password-strength-bar.strong {
  width: 100%;
  background-color: var(--sisfe-success);
}

/* --- Utility classes --- */
.text-truncate-2 {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.min-h-44 {
  min-height: 44px;
}

/* --- Empty state --- */
.empty-state {
  text-align: center;
  padding: 3rem 1.5rem;
  color: var(--bs-secondary-color);
}

.empty-state .bi {
  font-size: 3rem;
  margin-bottom: 1rem;
  opacity: 0.5;
}

.empty-state p {
  font-size: 1rem;
  margin: 0;
}

/* --- Smooth transitions for theme change --- */
html {
  transition: background-color 0.3s ease, color 0.3s ease;
}

/* --- Fix sidebar inheriting theme --- */
.app-sidebar {
  transition: background-color 0.3s ease;
}

/* --- Scrollbar styling --- */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--bs-secondary-bg);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--bs-secondary-color);
}

/* ===========================================================================
   REGLA: PROHIBIDO SCROLL HORIZONTAL EN TABLAS
   En tablet y celular las tablas NO deben desbordar lateralmente. El contenido
   ocupa las líneas necesarias (wrap) y, en pantallas chicas, las tablas con
   .table-stack se reorganizan en formato apilado (una "tarjeta" por fila).
   =========================================================================== */

/* Tablas apilables: en <=767px se vuelven bloques verticales legibles.
   Cada <td> muestra su etiqueta vía data-label. */
@media (max-width: 767.98px) {
  .table-responsive {
    overflow-x: visible; /* sin scroll lateral en mobile/tablet */
  }

  table.table-stack thead {
    display: none;
  }

  /* Etiquetas inline (<th> dentro de <tbody>) se ocultan en mobile.
     La etiqueta visible la provee data-label en cada <td>. */
  table.table-stack tbody th {
    display: none;
  }

  table.table-stack,
  table.table-stack tbody,
  table.table-stack tr,
  table.table-stack td {
    display: block;
    width: 100%;
  }

  table.table-stack tr {
    margin-bottom: 0.75rem;
    border: 1px solid var(--bs-border-color, #dee2e6);
    border-radius: 0.375rem;
    padding: 0.25rem 0.5rem;
  }

  table.table-stack td {
    border: none;
    border-bottom: 1px solid var(--bs-border-color, #f1f1f1);
    padding: 0.45rem 0.25rem;
    text-align: left !important;
  }

  table.table-stack td:last-child {
    border-bottom: none;
  }

  /* Etiqueta de cada celda (definida con data-label="...") */
  table.table-stack td[data-label]::before {
    content: attr(data-label);
    display: block;
    font-weight: 600;
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    color: var(--bs-secondary-color, #6c757d);
    margin-bottom: 0.15rem;
  }
}

/* ===========================================================================
   Choices.js — integración Bootstrap form-control + dark mode (estilo Filament)
   Match exacto con .form-control: padding, font-size, line-height, colores.
   =========================================================================== */
.choices {
  margin-bottom: 0;
  font-size: 1rem;
  font-family: inherit;
}

.choices__inner {
  min-height: calc(1.5em + 0.75rem + 2px);
  padding: 0.375rem 0.75rem;
  border-radius: var(--bs-border-radius, 0.375rem);
  border: var(--bs-border-width, 1px) solid var(--bs-border-color);
  background-color: var(--bs-body-bg);
  color: var(--bs-body-color);
  font-size: 1rem;
  line-height: 1.5;
}

.choices.is-focused .choices__inner,
.choices.is-open .choices__inner {
  border-color: var(--sisfe-primary);
  box-shadow: 0 0 0 0.25rem rgba(67, 97, 238, 0.25);
}

.choices[data-type*="select-one"] .choices__inner {
  padding-bottom: 0.375rem;
}

.choices__list--single {
  padding: 0;
}

.choices__list--single .choices__item {
  color: var(--bs-body-color);
  font-size: 1rem;
  line-height: 1.5;
}

.choices__placeholder {
  opacity: 0.6;
  color: var(--bs-secondary-color);
}

/* Dropdown — ancho exacto del control (full width del contenedor padre) */
.choices__list--dropdown,
.choices__list[aria-expanded] {
  background-color: var(--bs-body-bg);
  border-color: var(--bs-border-color);
  color: var(--bs-body-color);
  font-size: 0.95rem;
  z-index: 1056;
  box-shadow: 0 0.5rem 1rem rgba(0, 0, 0, 0.15);
  width: 100% !important;
  min-width: 100%;
  max-width: 100%;
}

.choices__list--dropdown .choices__list,
.choices__list[aria-expanded] .choices__list {
  min-height: 10rem !important;
  max-height: 60vh !important;
  overflow-y: auto !important;
}

.choices__list--dropdown .choices__item,
.choices__list[aria-expanded] .choices__item {
  color: var(--bs-body-color);
  font-size: 0.875rem;
  padding: 0.3rem 0.6rem;
  line-height: 1.3;
  white-space: normal;
  word-break: break-word;
}

.choices__list--dropdown .choices__item--selectable.is-highlighted,
.choices__list[aria-expanded] .choices__item--selectable.is-highlighted {
  background-color: var(--sisfe-primary);
  color: #fff;
}

.choices__list--dropdown .choices__item--selectable[data-select-text],
.choices__list[aria-expanded] .choices__item--selectable[data-select-text] {
  padding-right: 0.75rem;
}

/* Search input dentro del dropdown */
.choices__input {
  background-color: var(--bs-body-bg);
  color: var(--bs-body-color);
  border: var(--bs-border-width, 1px) solid var(--bs-border-color);
  border-radius: var(--bs-border-radius, 0.375rem);
  font-size: 0.95rem;
  padding: 0.375rem 0.5rem;
  margin: 0.25rem;
  width: calc(100% - 0.5rem);
}

.choices__input:focus {
  outline: none;
  border-color: var(--sisfe-primary);
}

/* Flecha del select */
.choices[data-type*="select-one"]::after {
  border-color: var(--bs-body-color) transparent transparent transparent;
}

.choices[data-type*="select-one"].is-open::after {
  border-color: transparent transparent var(--bs-body-color) transparent;
}

/* ----- Dark mode ----- */
[data-bs-theme="dark"] .choices__inner {
  background-color: var(--bs-body-bg);
  color: var(--bs-body-color);
  border-color: var(--bs-border-color);
}

[data-bs-theme="dark"] .choices__list--single .choices__item {
  color: var(--bs-body-color);
}

[data-bs-theme="dark"] .choices__list--dropdown,
[data-bs-theme="dark"] .choices__list[aria-expanded] {
  background-color: var(--bs-tertiary-bg, #2b3035);
  border-color: var(--bs-border-color);
  color: var(--bs-body-color);
  box-shadow: 0 0.5rem 1rem rgba(0, 0, 0, 0.5);
}

[data-bs-theme="dark"] .choices__list--dropdown .choices__item,
[data-bs-theme="dark"] .choices__list[aria-expanded] .choices__item {
  color: var(--bs-body-color);
  background-color: transparent;
}

[data-bs-theme="dark"] .choices__list--dropdown .choices__item--selectable.is-highlighted,
[data-bs-theme="dark"] .choices__list[aria-expanded] .choices__item--selectable.is-highlighted {
  background-color: var(--sisfe-primary);
  color: #fff;
}

[data-bs-theme="dark"] .choices__input {
  background-color: var(--bs-body-bg);
  color: var(--bs-body-color);
  border-color: var(--bs-border-color);
}

[data-bs-theme="dark"] .choices__placeholder {
  color: var(--bs-secondary-color);
}

[data-bs-theme="dark"] .choices[data-type*="select-one"]::after {
  border-color: var(--bs-body-color) transparent transparent transparent;
}

[data-bs-theme="dark"] .choices[data-type*="select-one"].is-open::after {
  border-color: transparent transparent var(--bs-body-color) transparent;
}

/* Disabled state */
.choices.is-disabled .choices__inner,
.choices.is-disabled .choices__input {
  background-color: var(--bs-secondary-bg);
  opacity: 0.65;
}

/* En mobile el dropdown ocupa casi todo el ancho útil del viewport */
@media (max-width: 575.98px) {
  .choices__list--dropdown,
  .choices__list[aria-expanded] {
    max-width: calc(100vw - 1rem);
    width: calc(100vw - 1rem);
  }

  .choices__list--dropdown .choices__item,
  .choices__list[aria-expanded] .choices__item {
    white-space: normal;
  }
}

/* Bloques de código (JSON/XML) legibles sin scroll horizontal forzado */
.code-block {
  white-space: pre-wrap;
  word-break: break-word;
  overflow-wrap: anywhere;
  max-height: 420px;
  overflow-y: auto;
  background: var(--bs-tertiary-bg, #f8f9fa);
  border: 1px solid var(--bs-border-color, #dee2e6);
  border-radius: 0.375rem;
  padding: 0.75rem;
  font-size: 0.8rem;
}
