/* ------------------------------------------------------
   Variables de color (Paleta Suave para Largas Jornadas)
--------------------------------------------------------- */
:root {
  --primary-color: #2C3E50;      /* Color principal: ideal para el sidebar */
  --secondary-color: #34495E;    /* Color secundario: para encabezados y fondos del sidebar */
  --accent-color: #256794;       /* Acento: para botones, hover y destacados */
  --text-color: #333333;         /* Texto en gris oscuro para mayor legibilidad */
  --bg-color: #e4e8ee;           /* Fondo principal: un off-white para evitar fatiga visual */
  --card-bg-color: #FFFFFF;      /* Fondo de tarjetas: se puede suavizar con sombras o bordes */
  --white-color: #F5F5F5;        /* Blanco suavizado para elementos puntuales */
  --sidebar-width: 250px;        /* Ancho del sidebar */
}

/* ------------------------------------------------------
   Reset básico y tipografía
--------------------------------------------------------- */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  background-color: var(--bg-color);
  color: var(--text-color);
  overflow-x: hidden;
}

a {
  text-decoration: none;
  color: inherit;
}

/* ------------------------------------------------------
   Controles comunes: formularios y botones
--------------------------------------------------------- */
.user-controls {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin: 1rem 0;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.search-form {
  display: flex;
  flex: 1;
  gap: 0.5rem;
  min-width: 200px;
}
.search-form input[type="text"] {
  padding: 0.5rem;
  border: 1px solid #ccc;
  border-radius: 4px;
  flex: 1;
  font-size: 1rem;
}

/* --- Filas de formulario en modales --- */
.input-row {
  margin-bottom: 1rem;
  display: flex;
  flex-direction: column;
}

.input-row label {
  margin-bottom: 0.3rem;
  font-weight: bold;
  color: var(--text-color);
}

.input-row input,
.input-row select {
  padding: 0.5rem;
  border: 1px solid #ccc;
  border-radius: 4px;
  font-size: 1rem;
}

.btn-search {
  background: var(--accent-color);
  border: none;
  color: #fff;
  padding: 0.5rem 1rem;
  border-radius: 4px;
  cursor: pointer;
  font-size: 1rem;
  transition: background 0.3s ease;
}
.btn-search:hover {
  background: #c73b3b;
}

.btn-add-user {
  background: var(--accent-color);
  border: none;
  color: #fff;
  padding: 0.5rem 1rem;
  border-radius: 4px;
  cursor: pointer;
  font-size: 1rem;
  transition: background 0.3s ease;
}
.btn-add-user:hover {
  background: #c73b3b;
}

/* ------------------------------------------------------
   Estructura general de la página
--------------------------------------------------------- */
.base-page {
  display: flex;
  min-height: 100vh;
  flex-direction: row;
}

/* ------------------------------------------------------
   SIDEBAR
--------------------------------------------------------- */
.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  width: var(--sidebar-width);
  height: 100%;
  background-color: var(--secondary-color);
  color: var(--white-color);
  z-index: 1001;
  transform: translateX(-100%);
  transition: transform 0.3s ease;
  display: flex;
  flex-direction: column;
}
.sidebar.open {
  transform: translateX(0);
}
.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 60px;
  padding: 0 1rem;
  background-color: var(--primary-color);
  font-size: 1.2rem;
  font-weight: bold;
}
/* Responsividad del h2 (EMPRESA_LARGO) en el sidebar */
.sidebar-header h2 {
  font-size: clamp(1rem, 2.5vw, 1.2rem);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100%;
  text-align: center;
}

.overflow-auto {
  background-color: var(--secondary-color);
}

@media (max-width: 768px) {
  .sidebar-header h2 {
    font-size: 1rem;
  }
}

.sidebar-menu {
  display: flex;
  flex-direction: column;
  flex: 1;              /* ocupa todo el espacio entre header y footer */
  margin: 0;            /* elimina márgenes preexistentes */
  padding: 0;           /* elimina padding preexistente */
  list-style: none;     /* quitamos bullets */
}
.sidebar-menu li.bottom {
  margin-top: auto;     /* empuja este <li> hasta abajo */
  border-top: 1px solid rgba(255,255,255,0.1);
}
.sidebar-menu li > a {
  position: relative;
  /* deja un poco de espacio a la derecha para que no choque con el padding */
  padding-right: 2.5rem;
}
.sidebar-menu li {
  border-bottom: 1px solid rgba(255,255,255,0.1);
}
.sidebar-menu a {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  color: var(--white-color);
  transition: background 0.2s ease, color 0.2s ease;
}
.sidebar-menu a:hover {
  background-color: rgba(0,0,0,0.2);
  text-decoration: none;
}
.submenu-link {
  justify-content: space-between;
}
.chevron-icon {
  margin-left: auto;
}

/* SUBMENÚS */
.submenu {
  position: relative;
}
.submenu-items {
  display: none;
  background-color: rgba(255,255,255,0.1);
  padding: 0px 0px 0px 0px;
}
.submenu.open-sub .submenu-items {
  display: block;
  list-style: none;
}
.submenu.open-sub > a {
  background-color: rgba(0,0,0,0.3) !important;
}

/* ------------------------------------------------------
   OVERLAY para el menú en dispositivos móviles
--------------------------------------------------------- */
.overlay {
  position: fixed;
  top: 0; 
  left: 0; 
  right: 0; 
  bottom: 0;
  background: rgba(0,0,0,0.5);
  backdrop-filter: blur(2px);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s ease, visibility 0.3s ease;
  z-index: 1000;
}
.overlay.open {
  opacity: 1;
  visibility: visible;
}

/* ------------------------------------------------------
   CONTENEDOR PRINCIPAL (contenido a la derecha del sidebar)
--------------------------------------------------------- */
.main-content {
  flex: 1;
  margin-left: 0; /* Sin margen cuando el menú está cerrado */
  display: flex;
  flex-direction: column;
  transition: margin-left 0.3s ease;
}
/* Solo empujar el contenido si el sidebar está abierto (desktop) */
.sidebar.open ~ .main-content {
  margin-left: var(--sidebar-width);
}
@media (max-width: 992px) {
  .sidebar.open ~ .main-content {
    margin-left: 0; /* En móviles el menú se superpone */
  }
}

/* ------------------------------------------------------
   TOPBAR (Barra superior)
--------------------------------------------------------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background-color: var(--white-color);
  color: var(--text-color);
  height: 60px;
  padding: 0 1rem;
  border-bottom: 1px solid #ccc;
}
.topbar-left {
  display: flex;
  align-items: center;
  gap: 1rem;
}
.topbar-center {
  display: flex;
  align-items: center;
  gap: 1rem;
}
.btn-toggle-sidebar {
  background: none;
  border: none;
  font-size: 1.4rem;
  cursor: pointer;
  color: var(--text-color);
}
.topbar-title {
  font-size: 1.2rem;
  font-weight: 600;
}
.topbar-empresa {
  font-size: 1.2rem;
  font-weight: 600;
}
.topbar-right {
  display: flex;
  align-items: center;
  gap: 1rem;
}
.user-info {
  font-size: 0.9rem;
  text-align: right;
  line-height: 1.2;
}
.btn-change-sucursal {
  color: var(--text-color);
  font-size: 1.2rem;
  transition: color 0.2s;
}
.btn-change-sucursal:hover {
  color: var(--accent-color);
}
.btn-logout {
  color: var(--text-color);
  font-size: 1.2rem;
  transition: color 0.2s;
}
.btn-logout:hover {
  color: var(--accent-color);
}

.btn-secondary {
  background: var(--secondary-color);
  border: none;
  color: #fff;
  padding: 0.5rem 1rem;
  border-radius: 4px;
  cursor: pointer;
  font-size: 1rem;
  transition: background 0.3s ease;
}
.btn-secondary:hover {
  background: #2b3f50;  /* un tono más oscuro */
}

/* ------------------------------------------------------
   CONTENIDO DE LA PÁGINA
--------------------------------------------------------- */
.content-wrapper {
  padding: 1.5rem;
  flex: 1;
  background-color: var(--bg-color);
  padding-left: clamp(0.5rem, 2vw, 1.5rem);
  padding-right: clamp(0.5rem, 2vw, 1.5rem);
}

.modal {
  display: none; /* Oculto por defecto */
  position: fixed;
  z-index: 1500;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  overflow: auto;
  background: rgba(0, 0, 0, 0.5);
  justify-content: center;
  align-items: center;
}

hr {
  border-top: 1px solid #ccc; /* Línea superior de 1px, color gris */
  border-bottom: none; /* Desactiva el borde inferior predeterminado */
  margin: 10px 0; /* Espacio superior e inferior de la línea */
}

.modal-content {
  background-color: var(--card-bg-color, #fff);
  width: 400px;
  padding: 1.5rem;
  border-radius: 8px;
  position: relative;
  box-shadow: 0 5px 15px rgba(0,0,0,0.3);
  animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
  from { opacity: 0; transform: scale(0.95); }
  to { opacity: 1; transform: scale(1); }
}

.modal-close {
  position: absolute;
  top: 0.5rem;
  right: 1rem;
  font-size: 1.5rem;
  cursor: pointer;
  color: var(--text-color);
}

.modal-title {
  margin-bottom: 1rem;
  font-size: 1.3rem;
  text-align: center;
  color: var(--text-color);
}

.modal.show-modal {
  display: flex;
}

/* ------------------------------------------------------
   Paginación, Tablas, Formularios y Botones
--------------------------------------------------------- */
:root {
  --clr-bg: #f5f7fa;
  --clr-card: #fff;
  --clr-primary: #256794;
  --clr-text: #2e3a46;
  --clr-muted: #6c757d;
  --radius: .5rem;
  --shadow: 0 4px 12px rgba(0,0,0,0.05);
}

.modern-table-container {
  background: var(--clr-card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow-x: auto;
  margin-bottom: 1.5rem;
}

/* Tabla */
.modern-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  min-width: 600px;  /* Ajusta según tus columnas */
  font-size: .95rem;
}
.modern-table thead th {
  position: sticky;
  top: 0;
  background: var(--clr-primary);
  color: #fff;
  text-align: left;
  padding: .75rem 1rem;
  font-weight: 600;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}
.modern-table tbody td {
  padding: .75rem 1rem;
  color: var(--clr-text);
  border-top: 1px solid var(--clr-bg);
}

/* Zebra-stripes */
.modern-table tbody tr:nth-child(odd) {
  background: var(--clr-bg);
}

/* Hover */
.modern-table tbody tr:hover {
  background: rgba(78,115,223,0.1);
  transition: background .2s;
}

/* Columna de acciones centrada */
.actions-col {
  width: 120px;
  text-align: center;
}

/* Botones de ícono */
.icon-btn {
  background: none;
  border: none;
  color: var(--clr-muted);
  margin: 0 .25rem;
  font-size: 1rem;
  cursor: pointer;
  transition: color .2s;
}
.icon-btn:hover {
  color: var(--clr-primary);
}

.table-active {
  background-color: var(--bs-light) !important;
}

/* Opcional: estilo para la fila detalle */
.detail-row td {
  background-color: #f9f9f9;
  border-top: none;
}

/* Ajusta los botones en móviles */
@media (max-width: 576px) {
  .detail-row .d-flex {
    flex-direction: column;
    gap: .5rem;
  }
}

/* Paginación moderna */
.modern-pagination {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: .5rem;
  margin-top: 1rem;
}
.modern-pagination .page-link {
  display: inline-block;
  padding: .5rem .75rem;
  background: var(--clr-card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  color: var(--clr-text);
  text-decoration: none;
  transition: background .2s, transform .2s;
}
.modern-pagination .page-link:hover,
.modern-pagination .page-link.active {
  background: var(--clr-primary);
  color: #fff;
  transform: translateY(-2px);
}

/* Responsive tweaks */
@media (max-width: 768px) {
  .modern-table {
    min-width: 100%;
  }
  .actions-col {
    width: auto;
  }
}

/* ------------------------------------------------------
   ESTILO PARA TARJETAS (Tiles) DE DASHBOARD
--------------------------------------------------------- */
.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 1rem;
  margin-top: 1rem;
}
.dashboard-card {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: flex-start;
  padding: 1rem;
  background-color: var(--card-bg-color);
  border-radius: 6px;
  box-shadow: 0 2px 5px rgba(0,0,0,0.1);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  position: relative;
  overflow: hidden;
}
.dashboard-card:hover {
  transform: translateY(-3px);
  box-shadow: 0 4px 10px rgba(0,0,0,0.15);
}
.dashboard-card i {
  font-size: 1.8rem;
  margin-bottom: 0.5rem;
}
.dashboard-card h3 {
  font-size: 1rem;
  margin: 0;
  font-weight: 600;
}
.dashboard-card .count {
  font-size: 1.2rem;
  font-weight: bold;
  margin-top: 0.25rem;
  color: var(--accent-color);
}
/* Ejemplos de colores para tarjetas específicas */
.dashboard-card.card-orange {
  border-left: 5px solid #f39c12;
}
.dashboard-card.card-green {
  border-left: 5px solid #27ae60;
}
.dashboard-card.card-blue {
  border-left: 5px solid #2980b9;
}
.dashboard-card.card-purple {
  border-left: 5px solid #8e44ad;
}
.dashboard-card.card-pink {
  border-left: 5px solid #e91e63;
}
.dashboard-card.card-gray {
  border-left: 5px solid #7f8c8d;
}
.dashboard-card.card-red {
  border-left: 5px solid #e74c3c;
}

/* ------------------------------------------------------
   BOTONES REUTILIZABLES y Toasts
--------------------------------------------------------- */
.btn {
  display: inline-block;
  padding: 0.5rem 1rem;
  background-color: var(--accent-color);
  color: #fff;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  transition: background 0.3s ease;
}
.badge-new {
  position: absolute;
  top: 50%;
  right: 1rem;              /* a 1rem del borde derecho del enlace */
  transform: translateY(-50%);
  display: inline-block;
  background-color: #dc3545;
  color: #fff;
  border-radius: 0.25rem;
  padding: 0.15em 0.5em;
  font-size: 0.75rem;
  font-weight: 600;
  white-space: nowrap;
}
.btn.btn-outline-secondary[disabled] {
  background-color: #cacaca;
}
.btn:hover,
.btn:focus {
  background-color: #0056b3;
}
.btn-secondary {
  background-color: var(--accent-color);
}
.btn-secondary:hover,
.btn-secondary:focus {
  background-color: #2b3f50;
}

.toast {
  position: fixed;
  top: 20px;
  right: 20px;
  padding: 1rem 1.5rem;
  border-radius: 4px;
  color: #fff;
  font-weight: bold;
  display: none;
  z-index: 2000;
}

.toast-success {
  background-color: #28a745;
}
.toast-error {
  background-color: #dc3545;
}

/* --- Botones en modales --- */
.modal-buttons {
  display: flex;
  justify-content: center;
  gap: 1rem;
  margin-top: 1rem;
}

.btn-confirm {
  padding: 0.5rem 1rem;
  background-color: var(--accent-color);
  color: #fff;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: 1rem;
  transition: background 0.3s ease;
}

.btn-confirm:hover {
  background-color: var(--primary-color);
}

.btn-cancel {
  padding: 0.5rem 1rem;
  background-color: #ccc;
  color: #000;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: 1rem;
  transition: background 0.3s ease;
}

.btn-cancel:hover {
  background-color: #999;
}

/* Input de búsqueda de producto */
input.product-search-input {
  width: 100%;
  padding: 0.5rem;
  border: 1px solid #ccc;
  border-radius: 4px;
  font-size: 1rem;
  margin-bottom: 0.5rem;
}

/* Select de producto filtrable */
select#mov_producto {
  width: 100%;
  padding: 0.5rem;
  border: 1px solid #ccc;
  border-radius: 4px;
  font-size: 1rem;
  height: auto;    /* para que crezca si pones size>1 */
}

/* Inputs tipo número y fecha */
input[type="number"],
input[type="date"] {
  width: 100%;
  padding: 0.5rem;
  border: 1px solid #ccc;
  border-radius: 4px;
  font-size: 1rem;
}

select#mov_tipo.entrada {
  color: green;
  font-weight: bold;
  font-size: 1.02em;
}
select#mov_tipo.salida {
  color: red;
  font-weight: bold;
  font-size: 1.02em;
}

/* En el historial */
td.tipo.entrada {
  color: green;
  font-weight: bold;
  font-size: 1.02em;
}
td.tipo.salida {
  color: red;
  font-weight: bold;
  font-size: 1.02em;
}

/* ------------------------------------------------------
   RESPONSIVIDAD GLOBAL
--------------------------------------------------------- */

/* --- Media Queries --- */

@media (max-width: 600px) {
  .table-responsive .table {
    /* Fija el layout para que no crezca más que el contenedor */
    table-layout: fixed;
    width: 100%;
  }
  /* Trunca el texto largo con ellipsis */
  .table th,
  .table td {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .table-responsive .table th:not(:nth-child(2)):not(:last-child),
  .table-responsive .table td:not(.actions-cell):not(:nth-child(2)) {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .table-responsive .table th:nth-child(2),
  .table-responsive .table td:nth-child(2) {
    white-space: normal;
    overflow: visible;
  }
  /* Ajusta los controles si no lo tienes ya */
  .user-controls {
    flex-direction: column;
    align-items: stretch;
  }
  .search-form {
    flex-direction: column;
  }
  .search-form input[type="text"],
  .btn-search,
  .btn-add-user {
    width: 100%;
  }
  .modal-content {
    width: 90%;
    padding: 1rem;
  }
}

@media (max-width: 768px) {
  .sidebar {
    width: 200px;
  }
  .topbar-title {
    font-size: 1rem;
  }
  .dashboard-grid {
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  }
  /* En dispositivos medianos, se puede ajustar la margen del contenido */
  .main-content.open {
    margin-left: 200px;
  }
}
