/* Estilos base y temas para la aplicación de inventario de infraestructura */
:root {
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --secondary: #475569;
  --success: #16a34a;
  --warning: #ca8a04;
  --danger: #dc2626;
  --background: #f8fafc;
  --card-bg: #ffffff;
  --text-main: #0f172a;
  --text-muted: #64748b;
  --border: #e2e8f0;
}

body.auth-pending > .app-shell {
  visibility: hidden;
}

#auth-screen.hidden {
  display: none;
}

body {
  font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
  background-color: var(--background);
  color: var(--text-main);
  margin: 0;
  padding: 0;
  min-height: 100vh;
}

/* Estado explícito del menú móvil, independiente de la carga de Tailwind */
#app-sidebar.sidebar-open {
  transform: translateX(0) !important;
}

@media (min-width: 1024px) {
  #app-sidebar {
    transform: translateX(0) !important;
  }
}

@media (max-width: 1023px) {
  #btn-open-sidebar {
    display: inline-flex !important;
    flex-shrink: 0;
  }

  .sidebar-footer {
    align-items: stretch;
    flex-direction: column;
    gap: 0.5rem;
  }

  .sidebar-footer-actions {
    justify-content: flex-start;
    width: 100%;
  }

  #app-sidebar:not(.sidebar-open) {
    transform: translateX(-100%) !important;
  }

  #app-sidebar.sidebar-open {
    transform: translateX(0) !important;
  }
}

/* Los módulos con tablas aprovechan el alto disponible sin dejar un bloque vacío debajo. */
#tab-plataforma > .bg-white,
#tab-historiales > .bg-white {
  min-height: 100%;
  display: flex;
  flex-direction: column;
}

#tab-plataforma .table-container,
#tab-historiales .table-container {
  flex: 1;
  max-height: none;
}

.platform-table td {
  line-height: inherit;
  padding-bottom: 0.625rem;
  padding-top: 0.625rem;
  vertical-align: middle;
}

.platform-table td > div {
  line-height: inherit;
}

.sidebar-footer {
  align-items: stretch;
  flex-direction: column;
  gap: 0.5rem;
}

.sidebar-footer-actions {
  justify-content: flex-start;
  width: auto;
}

.sidebar-footer-top {
  min-height: 1.75rem;
}

/* Custom scrollbar */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}
::-webkit-scrollbar-track {
  background: #f1f5f9;
}
::-webkit-scrollbar-thumb {
  background: #cbd5e1;
  border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
  background: #94a3b8;
}

/* Tablas con scroll suave y encabezado fijo */
.table-container {
  max-height: calc(100vh - 280px);
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 0.5rem;
}

.table-container thead th {
  position: sticky;
  top: 0;
  background-color: #f8fafc;
  z-index: 10;
  box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
}

.inventory-filter-controls,
.inventory-filter-search,
.inventory-filter-selects {
  min-width: 0;
}

.inventory-filter-selects select {
  width: 100%;
  min-width: 0;
  min-height: 2.375rem;
  text-overflow: ellipsis;
}

@media (max-width: 639px) {
  .inventory-filter-bar {
    gap: 0.75rem;
  }

  .inventory-filter-controls {
    gap: 0.625rem;
  }

  .inventory-filter-selects {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    gap: 0.5rem;
  }

  .inventory-filter-selects select:last-child {
    grid-column: 1 / -1;
  }

  .inventory-filter-count {
    align-self: stretch;
    padding-top: 0.625rem;
    border-top: 1px solid var(--border);
  }
}

@media (max-width: 359px) {
  .inventory-filter-selects {
    grid-template-columns: minmax(0, 1fr) !important;
  }

  .inventory-filter-selects select:last-child {
    grid-column: auto;
  }
}

/* Animaciones */
.fade-in {
  animation: fadeIn 0.2s ease-in-out;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Visor de escáner */
#scanner-preview {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: min(100%, 480px) !important;
  max-width: 480px;
  height: min(42vh, 300px) !important;
  min-height: 180px !important;
  aspect-ratio: 16 / 9;
  margin: 0 auto;
  border-radius: 0.75rem;
  overflow: hidden;
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
  background: #000;
}

#scanner-preview video,
#scanner-preview canvas,
#scanner-preview img {
  display: block;
  width: 100% !important;
  height: 100% !important;
  margin: 0 auto;
  border-radius: 0.75rem;
  object-fit: cover;
  transform-origin: center center;
  max-width: none;
}

#scanner-preview > * {
  margin-inline: auto;
}

#scanner-zoom-control {
  position: relative;
  left: auto;
  right: auto;
  top: auto;
  bottom: auto;
  margin: 0.75rem auto 0;
  transform: none;
  width: min(100%, 560px);
}

.scanner-actions {
  position: relative;
  margin-left: auto;
  margin-right: auto;
  justify-content: center;
  align-items: stretch;
  margin-top: 0.75rem;
}

@media (max-width: 639px) {
  #scanner-zoom-control {
    width: min(100%, calc(100vw - 2rem));
    transform: none;
  }
}

.scanner-action-btn {
  min-width: 0;
  white-space: nowrap;
  text-align: center;
}

@media (min-width: 640px) {
  .scanner-actions {
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .scanner-action-btn {
    width: auto;
    max-width: 220px;
  }
}

@media (max-width: 640px) {
  #scanner-preview {
    height: min(34vh, 230px) !important;
    min-height: 170px !important;
  }
}

/* Tarjeta de activo escaneado */
.asset-badge {
  display: inline-flex;
  align-items: center;
  padding: 0.2rem 0.6rem;
  border-radius: 9999px;
  font-size: 0.75rem;
  font-weight: 600;
}

/* Drag and Drop Zone */
.drop-zone {
  border: 2px dashed #cbd5e1;
  transition: all 0.2s ease;
}

.drop-zone.dragover {
  border-color: #2563eb;
  background-color: #eff6ff;
}

/* Toast Notifications */
#toast-container {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  pointer-events: none;
}

.toast {
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.85rem 1.25rem;
  border-radius: 0.5rem;
  background: white;
  box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
  border-left: 4px solid;
  animation: slideIn 0.3s ease-out;
  max-width: 400px;
}

@keyframes slideIn {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

/* Altura fluida y desplazamiento suave en móviles */
.table-container {
  max-height: calc(100vh - 290px);
  -webkit-overflow-scrolling: touch;
}

@media (max-width: 1023px) {
  .table-container {
    max-height: calc(100vh - 280px);
  }
}

/* Espaciado para la barra de navegación del celular (safe-area en iPhone) */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
  .lg\:hidden.fixed.bottom-0 {
    padding-bottom: calc(0.375rem + env(safe-area-inset-bottom));
  }
}

/* Evitar que el texto se seleccione al tocar botones rápidamente */
button, .cursor-pointer {
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
/* Asegurar que el badge de archivo nunca desborde */
#file-status-badge {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#file-status-badge span {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}