/* ==========================================================================
   ÍNDICE DE CONTENIDOS
   1. Variables y Configuración Base
   2. Componentes Globales (Botones, Modales, Inputs)
   3. Layout y Navegación (Sidebar, Navbar)
   4. Módulo: Login
   5. Módulo: Dashboard (KPIs, Gráficos, Filtros)
   6. Módulo: Inventario (Tablas, Stocks)
   7. Módulo: Punto de Venta (Grid Productos, Tarjetas)
   8. Módulo: Carrito de Compras
   9. Responsividad (Media Queries)
   ========================================================================== */

/* ==========================================================================
   1. VARIABLES Y CONFIGURACIÓN BASE
   ========================================================================== */
:root {
  --primary-color: #1a237e; /* Indigo oscuro */
  --accent-color: #ffab40; /* Naranja suave */
  --text-soft: #c5cae9;
  --bg-light: #f4f7f9;
  --white: #ffffff;
  --danger: #ff5252;
  --success: #2e7d32;
  --warning: #f57c00;
  --gray-bg: #f0f2f5;
}

body {
  background-color: var(--bg-light);
  font-family: "Roboto", sans-serif;
  margin: 0;
}

/* Clases de utilidad para el body */
.dashboard-body {
  background-color: var(--gray-bg);
}

.login-body {
  background: linear-gradient(135deg, var(--primary-color) 0%, #000051 100%);
  display: flex;
  height: 100vh;
  align-items: center;
  justify-content: center;
}

/* ==========================================================================
   2. COMPONENTES GLOBALES
   ========================================================================== */
/* Tarjetas Genéricas */
.card {
  border-radius: 10px;
}

.card-panel h3 {
  font-size: 2rem;
}

/* Modales */
.modal {
  border-radius: 20px !important;
}

.modal .modal-footer {
  background-color: #f8f9fa;
  border-top: 1px solid #eee;
}

.modal.bottom-sheet {
  border-top-left-radius: 20px;
  border-top-right-radius: 20px;
  max-height: 85% !important;
}

/* Botones y Estructuras de Modal */
.container-botones {
  display: flex;
  justify-content: space-evenly;
  align-items: center;
  padding: 0 20px 15px 20px !important;
  height: 80px !important;
}

.btn-modal {
  width: 45%;
  height: 45px;
  line-height: 45px;
  border-radius: 8px;
}

/* Inputs */
.input-field .prefix {
  color: var(--primary-color);
}

/* ==========================================================================
   3. LAYOUT Y NAVEGACIÓN
   ========================================================================== */
nav {
  margin-bottom: 20px;
}

/* Navbar Dashboard */
.dashboard-nav {
  background: #fff;
  box-shadow: 0 2px 15px rgba(0, 0, 0, 0.05) !important;
  height: 70px;
  line-height: 70px;
}

.dashboard-nav .brand-logo {
  color: var(--primary-color);
  font-weight: 700;
  font-size: 1.5rem;
}

.dashboard-nav ul a {
  color: #555;
  font-weight: 500;
}

.dashboard-nav ul a:hover {
  background-color: rgba(0, 0, 0, 0.02);
  color: var(--primary-color);
}

/* Sidebar de Categorías (POS) */
.main-wrapper {
  display: flex;
  height: calc(100vh - 64px);
  overflow: hidden;
  background-color: #f4f7f6;
}

.sidebar-nav {
  width: 260px;
  background: #fff;
  border-right: 1px solid #e0e0e0;
  overflow-y: auto;
  padding-top: 10px;
  z-index: 10;
}

.sidebar-title {
  padding: 0 20px;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: #9e9e9e;
}

/* Items de Categoría (Unificados) */
.cat-item {
  padding: 15px 20px;
  display: flex;
  align-items: center;
  color: #546e7a;
  cursor: pointer;
  transition: all 0.2s ease;
  border-left: 4px solid transparent;
  font-weight: 500;
}

.cat-item:hover {
  background: #f5f5f5;
}

.cat-item.active {
  background: #e8eaf6;
  color: var(--primary-color);
  border-left-color: var(--primary-color);
  font-weight: 700;
}

.cat-item i {
  margin-right: 15px;
}

/* Contenedor Principal de Contenido */
.content-area {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
}

.main-container {
  padding-top: 30px;
  padding-bottom: 50px;
}

/* ==========================================================================
   4. MÓDULO: LOGIN
   ========================================================================== */
/* 1. Fondo General y Centrado */
.login-body {
  background-color: #f4f6f8; /* Tu gris suave original */
  height: 100vh;
  margin: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative; /* Necesario para la franja azul */
  font-family: "Roboto", sans-serif;
}

/* 2. La Franja Azul Diagonal (Tu diseño original) */
.login-body::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 300px; /* Altura de la franja */
  background: linear-gradient(135deg, var(--primary-color) 0%, #3949ab 100%);
  z-index: -1; /* Para que quede detrás de la tarjeta */
  clip-path: polygon(0 0, 100% 0, 100% 40%, 0% 100%); /* El corte diagonal */
}

/* 3. La Tarjeta de Login (Ajustada para Móvil) */
.login-card {
  background: #ffffff !important; /* Blanco sólido, sin transparencia */
  border-radius: 16px !important;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1) !important; /* Tu sombra original */
  border: none !important;
  padding: 40px 30px;

  /* RESPONSIVIDAD (Mi corrección) */
  width: 90%; /* En celular ocupa el 90% */
  max-width: 400px; /* En PC no pasa de 400px */
}
.logo-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-bottom: 20px;
}
/* 4. Estilos del Logo */
.logo-container img {
  width: 160px;
  height: 160px;
  object-fit: cover;
  border-radius: 50%;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
  border: 4px solid rgb(64, 62, 60); /* Quitamos el borde grueso si prefieres el estilo limpio */
  margin-bottom: 10px;
}

/* 5. Botón y Textos */
.btn-login {
  background: var(--primary-color) !important;
  height: 48px;
  line-height: 48px;
  border-radius: 8px !important;
  font-weight: 600;
  box-shadow: 0 4px 12px rgba(26, 35, 126, 0.3);
  width: 100%;
}

.btn-login:hover {
  background: #283593 !important;
  transform: translateY(-1px);
}
/* ==========================================================================
   5. MÓDULO: DASHBOARD
   ========================================================================== */
/* Filtros */
.filter-card {
  border-radius: 16px !important;
  border: none;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.03) !important;
}

.filter-wrapper {
  display: flex;
  align-items: center;
  gap: 20px;
  flex-wrap: wrap;
}

/* --- ARREGLO PARA FECHAS MATERIALIZE --- */

/* 1. Empujar el texto de la fecha a la derecha para que no toque el icono */
.input-field input[type="date"] {
  padding-left: 3rem !important; /* Espacio para el icono */
  box-sizing: border-box; /* Para que respete los bordes */
}

/* 2. Acomodar el icono del calendario para que quede centrado verticalmente */
.input-field .prefix {
  top: 0.5rem; /* Ajusta esto si el icono se ve muy arriba o abajo */
  font-size: 2rem; /* Tamaño del icono */
}

/* 3. Forzar que la etiqueta (Label) se quede siempre arriba */
/* Esto arregla que el texto "Desde" se monte sobre la fecha */
.input-field input[type="date"] + label {
  transform: translateY(-14px) scale(0.8);
  transform-origin: 0 0;
  color: #9e9e9e; /* Color gris suave */
}

/* --- ARREGLO DEL TÍTULO DEL FILTRO --- */
.card-title-small {
  display: block; /* IMPORTANTE: Hace que ocupe todo el ancho */
  margin-bottom: 25px; /* Empuja los calendarios hacia abajo (crea el espacio) */
  font-size: 1.1rem; /* Un poquito más grande */
  font-weight: bold; /* Negrita para que destaque */
  color: #1a237e; /* Tu color Indigo corporativo */
}

/* Opcional: Para que los inputs y el botón se alineen mejor */
.filter-wrapper {
  display: flex; /* Los pone en fila india */
  align-items: center; /* Los centra verticalmente */
  gap: 15px; /* Espacio entre ellos */
  flex-wrap: wrap; /* Si es celular, que bajen ordenados */
}

.filter-wrapper .input-field {
  margin: 0;
  flex: 1;
  min-width: 200px;
}

.btn-filter {
  background: var(--primary-color);
  color: white;
  border: none;
  padding: 0 25px;
  height: 45px;
  border-radius: 10px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 4px 10px rgba(26, 35, 126, 0.3);
  transition: transform 0.2s;
}
.btn-filter:hover {
  transform: translateY(-2px);
}

/* KPI Cards */
.kpi-card {
  background: white;
  border-radius: 20px;
  padding: 25px;
  position: relative;
  overflow: hidden;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.05);
  transition: all 0.3s ease;
  margin-bottom: 20px;
  height: 160px;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.kpi-card:hover {
  transform: translateY(-5px);
  box-shadow: 0 15px 35px rgba(0, 0, 0, 0.1);
}

/* Colores KPI */
.kpi-primary {
  border-left: 6px solid var(--primary-color);
}
.kpi-success {
  border-left: 6px solid var(--success);
}
.kpi-info {
  border-left: 6px solid #29b6f6;
}
.kpi-warning {
  border-left: 6px solid var(--accent-color);
}

.kpi-content p {
  color: #888;
  font-size: 0.9rem;
  margin: 0;
  text-transform: uppercase;
  font-weight: 600;
}

.kpi-content h4,
.kpi-content h5 {
  margin: 10px 0 0 0;
  font-weight: 700;
  color: #333;
}

.kpi-icon {
  position: absolute;
  right: 20px;
  top: 20px;
  width: 50px;
  height: 50px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 1;
  color: white;
}

.kpi-primary .kpi-icon {
  background: var(--primary-color);
  box-shadow: 0 5px 15px rgba(26, 35, 126, 0.4);
}
.kpi-success .kpi-icon {
  background: var(--success);
  box-shadow: 0 5px 15px rgba(46, 125, 50, 0.4);
}
.kpi-info .kpi-icon {
  background: #29b6f6;
  box-shadow: 0 5px 15px rgba(41, 182, 246, 0.4);
}
.kpi-warning .kpi-icon {
  background: var(--accent-color);
  box-shadow: 0 5px 15px rgba(255, 171, 64, 0.4);
}

/* Gráficos */
.chart-card {
  border-radius: 20px !important;
  box-shadow: 0 5px 20px rgba(0, 0, 0, 0.03) !important;
  border: none;
}

.card-header {
  padding: 20px 24px 0 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.chart-wrapper {
  position: relative;
  height: 350px;
  width: 100%;
}

/* Resumen Inferior */
.summary-card {
  border-radius: 20px !important;
  padding: 30px;
  display: flex;
  justify-content: space-around;
  align-items: center;
  box-shadow: 0 5px 20px rgba(0, 0, 0, 0.03) !important;
}

.summary-item {
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  flex: 1;
}

.summary-item i {
  font-size: 2.5rem;
  opacity: 0.3;
}

.divider-vertical {
  width: 1px;
  height: 60px;
  background-color: #eee;
}

/* ==========================================================================
   6. MÓDULO: INVENTARIO
   ========================================================================== */

/* --- CONTENEDOR DE TABLA CON SCROLL --- */
.table-scroll-container {
  /* CAMBIO: Usamos altura dinámica (65% de la altura de la ventana) */
  height: 65vh;
  min-height: 300px; /* Para que no sea enana */
  max-height: 600px; /* Para que no sea gigante */
  overflow-y: auto;
  border: 1px solid #e0e0e0;
  border-radius: 4px;
  box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.05);
}

/* --- TRUCO: CABECERA FIJA (STICKY HEADER) --- */
.table-scroll-container table thead th {
  position: sticky;
  top: 0;
  background-color: #fff; /* O el color de fondo de tu tarjeta */
  z-index: 1; /* Para que quede por encima del contenido */
  box-shadow: 0 2px 2px -1px rgba(0, 0, 0, 0.1); /* Sombrita debajo de los títulos */
}

/* --- PERSONALIZAR LA BARRA DE SCROLL (Para que se vea moderna) --- */
/* Ancho de la barra */
.table-scroll-container::-webkit-scrollbar {
  width: 8px;
}

/* El carril (fondo de la barra) */
.table-scroll-container::-webkit-scrollbar-track {
  background: #f1f1f1;
  border-radius: 4px;
}

/* La barra que se mueve (Thumb) */
.table-scroll-container::-webkit-scrollbar-thumb {
  background: #888;
  border-radius: 4px;
}

/* Al pasar el mouse por la barra */
.table-scroll-container::-webkit-scrollbar-thumb:hover {
  background: #555;
}

/* Corrección para botones de tabla */
.acciones-fila {
  display: flex !important; /* Activa el modo 'caja flexible' */
  gap: 10px; /* Espacio EXACTO entre botones (adiós &nbsp;) */
  justify-content: flex-start; /* Alinea a la izquierda (o usa 'center' para centrar) */
  align-items: center; /* Alineación vertical perfecta */
  flex-wrap: nowrap; /* PROHIBIDO bajar de línea (esto evita que se monten) */
}

/* Opcional: Asegura que los botones no tengan márgenes extraños */
.acciones-fila .btn-small {
  margin: 0 !important;
}

/* Tabla de Historial de Ventas */
.table-container {
  background: var(--white);
  border-radius: 15px;
  padding: 20px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.05);
  margin-top: 20px;
}

.stock-status {
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 0.8rem;
  font-weight: bold;
}

.stock-low {
  background-color: #ffebee;
  color: #c62828;
}
.stock-ok {
  background-color: #e8f5e9;
  color: var(--success);
}

/* --- NUEVOS ESTILOS RESPONSIVE --- */
/* Contenedor para que las tablas tengan scroll horizontal en celular */
.table-responsive-wrapper {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch; /* Scroll suave en iPhone */
  margin-bottom: 15px;
  border: 1px solid #e0e0e0;
  border-radius: 4px;
}

/*Ojo a este bloque*/
table thead th {
        vertical-align: middle !important; /* Centra el texto verticalmente */
        padding-top: 15px !important;
        padding-bottom: 15px !important;
        font-weight: bold;
        background-color: #f5f5f5; /* Un gris suave para diferenciar el header */
        border-bottom: 2px solid #ddd; /* Línea separadora clara */
    }

    /* 2. Alinear el cuerpo para que no choque */
    table tbody td {
        vertical-align: middle !important; /* Centra los botones al medio de su celda */
    }

    /* 3. Corrección específica para la columna de Acciones (la última) */
    table th:last-child, 
    table td:last-child {
        text-align: center; /* Centra los botones horizontalmente */
        min-width: 100px;   /* Asegura que quepan los dos botones */
    }

/*------------------------------*/

/* Ajustes para pantallas pequeñas (móviles) */
@media only screen and (max-width: 600px) {
  /* Reducir tamaño de letra en tablas */
  table.highlight td,
  table.highlight th {
    padding: 8px 5px;
    font-size: 0.85rem;
  }
  /* Ocultar columnas menos importantes en historial móvil si es necesario */
  .hide-on-mobile {
    display: none;
  }
  /* Botones de acción más grandes para tocar con el dedo */
  .btn-small {
    padding: 0 10px;
  }
  /* Ajustar el filtro de fechas para que no se vea apretado */
  .filter-wrapper {
    display: flex;
    flex-direction: column;
    gap: 10px;
  }
  .btn-filter {
    width: 100%;
    margin-top: 10px;
  }
}

/* Estilo del botón de filtrar */
.btn-filter {
  background-color: #1a237e;
  color: white;
  border: none;
  border-radius: 4px;
  padding: 0 15px;
  height: 36px;
  line-height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  width: 100%; /* Ocupa ancho disponible en su columna */
}
.btn-filter:hover {
  background-color: #283593;
}

/* ==========================================================================
   7. MÓDULO: PUNTO DE VENTA (PRODUCTOS)
   ========================================================================== */
.pos-container {
  padding-top: 20px;
}

.search-bar-container {
  background: var(--white);
  padding: 5px 20px;
  border-radius: 12px;
  margin-bottom: 25px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
}

/* Grid de Productos */
.products-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 20px;
}

/* Tarjeta de Producto (Unificada) */
.product-card {
  background: var(--white);
  border-radius: 15px !important;
  border: 1px solid #eee;
  transition: all 0.3s ease;
  cursor: pointer;
  height: 380px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.product-card:hover {
  transform: translateY(-5px);
  box-shadow: 0 10px 20px rgba(0, 0, 0, 0.1) !important;
}

.product-card .card-image {
  height: 180px;
  padding: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: #fff;
}

.product-card .card-image img {
  max-height: 100%;
  width: auto;
  object-fit: contain;
}

.product-card .card-content {
  padding: 15px !important;
  text-align: center;
  flex-grow: 1;
  background-color: #fafafa; /* Fondo ligero para separar texto de imagen */
}

.product-card .card-title {
  font-size: 1rem !important;
  height: 2.4rem;
  overflow: hidden;
  margin-bottom: 5px !important;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  -webkit-box-orient: vertical;
  color: #333;
}

.product-price {
  font-size: 1.3rem;
  font-weight: 800;
  color: var(--primary-color);
  margin: 10px 0;
}

/* ==========================================================================
   8. MÓDULO: CARRITO DE COMPRAS
   ========================================================================== */
.floating-cart {
  position: fixed !important;
  bottom: 30px !important;
  right: 25px !important;
  z-index: 2100 !important;
}

#badge-cart {
  position: absolute;
  top: -5px;
  right: -5px;
  background: var(--danger);
  color: var(--white);
  border-radius: 50%;
  padding: 2px 7px;
  font-size: 12px;
}

/* Modal del Pedido Específico */
#modal-pedido {
  max-height: 85% !important;
  width: 100% !important;
  border-radius: 25px 25px 0 0 !important;
}

/* Items dentro del Carrito */
#lista-carrito .collection-item {
  display: flex !important;
  flex-direction: column !important;
  align-items: flex-start !important;
  padding: 15px !important;
}

.cart-controls-row,
.controles-item-carrito {
  display: flex;
  justify-content: space-between;
  width: 100%;
  align-items: center;
  margin-top: 10px;
}

.controles-carrito {
  display: flex;
  align-items: center;
  gap: 15px;
}

.btn-cant {
  background-color: #f5f5f5 !important;
  border: 1px solid #ddd !important;
  box-shadow: none !important;
}
.btn-cant:hover {
  background-color: #e0e0e0 !important;
}

.btn-cant i {
  color: var(--primary-color) !important;
  line-height: 32px !important;
  font-size: 20px !important;
  display: block !important;
}

.total-box {
  background: #f5f5f5;
  padding: 20px;
  border-radius: 15px;
  margin: 15px 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

/* ==========================================================================
   9. RESPONSIVIDAD (MEDIA QUERIES)
   ========================================================================== */

/* Tablets y Escritorios Pequeños (Hasta 992px) */
@media (max-width: 992px) {
  /* Login */
  .login-card {
    width: 90%;
  }

  /* Layout POS */
  .main-wrapper {
    display: block !important;
    height: auto !important;
    overflow: visible !important;
  }

  .content-area {
    height: auto !important;
    overflow: visible !important;
    padding-bottom: 80px;
  }

  /* Sidebar Horizontal */
  .sidebar-nav {
    width: 100% !important;
    height: auto !important;
    display: flex !important;
    flex-direction: row !important;
    overflow-x: auto !important;
    white-space: nowrap;
    position: sticky;
    top: 0;
    z-index: 1000;
    background: white;
    border-bottom: 1px solid #eee;
  }

  .sidebar-title {
    display: none;
  }

  .cat-item {
    display: inline-flex !important;
    padding: 10px 20px !important;
    border-left: none !important;
    border-bottom: 3px solid transparent;
  }

  .cat-item.active {
    border-bottom: 3px solid var(--primary-color);
  }
}

/* Escritorios Grandes (Más de 993px) */
@media (min-width: 993px) {
  #modal-pedido {
    width: 40% !important;
    right: 0;
    left: auto;
    border-radius: 20px 0 0 20px !important; /* Estilo drawer lateral */
    height: 100vh !important;
    max-height: 100vh !important;
    top: 0 !important;
  }
}

/* Móviles (Hasta 600px) */
@media (max-width: 600px) {
  /* Dashboard */
  .summary-card {
    flex-direction: column;
    gap: 30px;
  }
  .divider-vertical {
    width: 100%;
    height: 1px;
  }
  .kpi-card {
    /* ... resto de tus estilos ... */
    min-height: 160px; /* CAMBIO: Altura mínima, puede crecer si lo necesita */
    height: auto; /* Deja que crezca */
    /* ... resto de tus estilos ... */
  }
  .kpi-icon {
    position: relative;
    right: auto;
    top: auto;
    margin-bottom: 15px;
  }
  .card-panel h3 {
    font-size: 1.8rem;
  }

  /* Grid Productos */
  .products-grid {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 10px !important;
  }

  .product-card {
    height: 320px !important;
  }

  .product-card .card-image {
    height: 140px !important;
    padding: 10px !important;
  }

  .product-card .card-title {
    font-size: 0.85rem !important;
    height: 2rem;
  }

  .product-price {
    font-size: 1.1rem !important;
  }

  /* Tablas */
  #tabla-reporte td {
    border-bottom: 1px solid #f0f0f0;
  }
}

/* Pantallas MUY pequeñas (Menos de 360px) */
@media (max-width: 359px) {
  .products-grid {
    grid-template-columns: 1fr !important; /* 1 sola columna para que se vea bien */
  }

  .container-botones {
    flex-wrap: wrap; /* Que los botones bajen si no caben */
    height: auto !important;
    gap: 10px;
  }

  .btn-modal {
    width: 100%; /* Botones anchos para dedos grandes */
    margin-bottom: 5px;
  }
}
