/* ==========================================
   INKCUSMOS ERP - GLOBAL STYLES (CORREGIDO)
   ========================================== */
@import url("https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&display=swap");

:root {
  --primary: #dc2626;
  --primary-hover: #b91c1c;
  --dark: #0f172a;
  --dark-hover: #1e293b;
  --light: #ffffff;
  --bg-body: #f1f5f9;
  --surface: #ffffff;
  --text-main: #1e293b;
  --text-muted: #64748b;
  --border-color: #cbd5e1;
  --success: #10b981;
  --danger: #ef4444;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: "Inter", sans-serif;
}

body {
  background-color: var(--bg-body);
  color: var(--text-main);
  display: flex;
  min-height: 100vh;
  width: 100vw; /* Asegura que ocupe todo el ancho */
  overflow: hidden;
}

/* --- ARREGLO CRÍTICO: Contenedor principal ocupando toda la pantalla en PC --- */
#app-layout {
  display: none; /* auth-guard.js lo pasa a 'flex' */
  flex: 1; /* Esto obliga al panel a estirarse llenando el vacío gris */
  width: 100%;
  height: 100vh;
}

/* --- 1. LAYOUT PRINCIPAL (Sidebar y Contenido) --- */
aside {
  width: 260px;
  background: var(--dark);
  color: white;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}
.sidebar-logo {
  padding: 1.5rem;
  font-size: 1.5rem;
  font-weight: 800;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}
.sidebar-logo span {
  color: var(--primary);
}
.nav-menu {
  padding: 1rem 0;
  display: flex;
  flex-direction: column;
  gap: 5px;
  flex-grow: 1;
  overflow-y: auto;
}
.nav-item {
  padding: 1rem 1.5rem;
  cursor: pointer;
  color: #cbd5e1;
  font-weight: 500;
  transition: 0.2s;
  border-left: 4px solid transparent;
  display: flex; /* Añadido para los iconos */
  align-items: center; /* Centrado vertical */
  gap: 12px; /* Espacio entre icono y texto */
}

/* Forzar tamaño uniforme de los iconos del menú */
.nav-item i {
  font-size: 1.3rem;
}
.nav-item:hover {
  background: rgba(255, 255, 255, 0.05);
  color: white;
}
.nav-item.active {
  background: rgba(255, 255, 255, 0.1);
  color: white;
  border-left-color: var(--primary);
}
.btn-logout {
  margin-top: auto;
  padding: 1rem 1.5rem;
  background: #991b1b;
  color: white;
  border: none;
  cursor: pointer;
  font-weight: 600;
  text-align: left;
  transition: 0.2s;
}
.btn-logout:hover {
  background: #7f1d1d;
}

main {
  flex-grow: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  height: 100vh;
  background-color: var(--bg-body);
}
header {
  background: var(--surface);
  padding: 1rem 2rem;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-shrink: 0;
}
.header-title {
  font-size: 1.25rem;
  font-weight: 700;
}
.content-area {
  padding: 2rem;
  overflow-y: auto;
  flex-grow: 1;
  height: 100%;
  display: flex;
  flex-direction: column;
}
.section {
  flex: 1;
  display: flex;
  flex-direction: column;
}
.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
  flex-shrink: 0;
}

/* --- 2. CONTROLES Y WIDGETS GLOBALES --- */
.bcv-widget {
  background: #f8fafc;
  border: 2px solid var(--primary);
  padding: 0.5rem 1rem;
  border-radius: 8px;
  display: flex;
  align-items: center;
  gap: 15px;
}
.bcv-widget label {
  font-weight: 700;
  color: var(--primary);
  font-size: 0.9rem;
  text-transform: uppercase;
}
.bcv-widget input {
  width: 100px;
  padding: 0.5rem;
  border: 1px solid var(--border-color);
  border-radius: 4px;
  font-weight: bold;
  text-align: center;
  font-size: 1rem;
}
.bcv-widget button {
  background: var(--primary);
  color: white;
  border: none;
  padding: 0.5rem 1rem;
  border-radius: 4px;
  cursor: pointer;
  font-weight: bold;
}

.btn-main {
  background: var(--dark);
  color: white;
  border: none;
  padding: 0.75rem 1.5rem;
  border-radius: 8px;
  font-weight: 600;
  cursor: pointer;
  transition: 0.2s;
  text-transform: uppercase;
}
.btn-main:hover {
  background: var(--dark-hover);
}
.btn-main:disabled {
  background: #cbd5e1;
  cursor: not-allowed;
}
.btn-secondary {
  background: white;
  border: 1px solid var(--border-color);
  color: var(--text-main);
  padding: 0.75rem 1.5rem;
  border-radius: 8px;
  font-weight: 600;
  cursor: pointer;
  transition: 0.2s;
}
.btn-secondary:hover {
  background: #f8fafc;
}
.btn-sm {
  padding: 6px 12px;
  border-radius: 6px;
  font-weight: 600;
  font-size: 0.85rem;
  cursor: pointer;
  border: none;
  transition: 0.2s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-right: 5px;
}

/* --- TABLAS Y LISTADOS --- */
.card-table {
  background: var(--surface);
  border-radius: 12px;
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05);
  overflow: hidden;
  width: 100%;
}
table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
}
th {
  background: #f8fafc;
  padding: 1rem;
  font-size: 0.85rem;
  text-transform: uppercase;
  color: var(--text-muted);
  font-weight: 700;
  border-bottom: 2px solid var(--border-color);
}
td {
  padding: 1rem;
  border-bottom: 1px solid var(--border-color);
  vertical-align: middle;
  white-space: normal; /* AÑADIDO: Permite que el texto baje de línea */
  word-break: break-word; /* AÑADIDO: Rompe palabras gigantes */
  min-width: 150px; /* AÑADIDO: Mantiene legibilidad */
}
tr:last-child td {
  border-bottom: none;
}
tr:hover {
  background: #f8fafc;
}

/* --- BOTONES DE ACCIÓN EN TABLAS --- */
.action-container {
  display: flex;
  align-items: center;
  gap: 8px;
}
.btn-edit {
  background: #e0f2fe;
  color: #0284c7;
}
.btn-edit:hover {
  background: #bae6fd;
}
.btn-delete {
  background: #fee2e2;
  color: #b91c1c;
}
.btn-delete:hover {
  background: #fecaca;
}

/* --- INTERRUPTORES (SWITCHES) --- */
.switch-container {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-right: 15px;
}
.switch {
  position: relative;
  display: inline-block;
  width: 40px;
  height: 22px;
}
.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}
.slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: #cbd5e1;
  transition: 0.3s;
  border-radius: 24px;
}
.slider:before {
  position: absolute;
  content: "";
  height: 16px;
  width: 16px;
  left: 3px;
  bottom: 3px;
  background-color: white;
  transition: 0.3s;
  border-radius: 50%;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}
input:checked + .slider {
  background-color: var(--success);
}
input:checked + .slider:before {
  transform: translateX(18px);
}

/* --- CONTROLES DE FILTRO (Buscadores superiores) --- */
.filter-controls {
  display: flex;
  gap: 15px;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
  align-items: center;
  width: 100%;
}
.filter-controls input,
.filter-controls select {
  padding: 0.75rem 1rem;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  font-size: 0.95rem;
  outline: none;
  background: var(--surface);
  color: var(--text-main);
  transition: all 0.2s ease;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}
.filter-controls input:focus,
.filter-controls select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.1);
}
#adminSearch {
  flex: 2;
  min-width: 250px;
}
#adminCatFilter {
  flex: 1;
  min-width: 180px;
}

/* --- 3. FORMULARIOS GLOBALES --- */
.form-group {
  margin-bottom: 1.25rem;
}
.form-group label {
  display: block;
  font-weight: 600;
  margin-bottom: 0.5rem;
  color: var(--text-main);
  font-size: 0.9rem;
}
.form-control {
  width: 100%;
  padding: 0.75rem;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  font-size: 1rem;
  transition: 0.2s;
  background: #fff;
  outline: none;
}
.form-control:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.1);
}
textarea.form-control {
  resize: vertical;
  min-height: 80px;
}
.form-row {
  display: flex;
  gap: 15px;
}
.form-row .form-group {
  flex: 1;
}

/* --- 4. MODALES Y TOAST --- */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(15, 23, 42, 0.8);
  backdrop-filter: blur(4px);
  display: none;
  justify-content: center;
  align-items: center;
  z-index: 2000;
}
.modal-content {
  background: var(--surface);
  width: 90%;
  max-width: 600px;
  max-height: 90vh;
  border-radius: 16px;
  display: flex;
  flex-direction: column;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
  overflow: hidden;
}
.modal-header {
  padding: 1.5rem;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.modal-header h2 {
  font-size: 1.25rem;
  color: var(--dark);
}
.close-btn {
  background: none;
  border: none;
  font-size: 1.5rem;
  color: var(--text-muted);
  cursor: pointer;
}
.modal-body {
  padding: 1.5rem;
  overflow-y: auto;
}
.modal-footer {
  padding: 1.5rem;
  border-top: 1px solid var(--border-color);
  background: #f8fafc;
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

#toast-container {
  position: fixed;
  bottom: 20px;
  right: 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 9999;
}

.toast {
  background: var(--dark);
  color: white;
  padding: 1rem 2rem;
  border-radius: 8px;
  font-weight: 600;
  transform: translateY(100px);
  opacity: 0;
  transition: 0.3s;
  box-shadow: 0 10px 15px rgba(0, 0, 0, 0.1);
}
.toast.show {
  transform: translateY(0);
  opacity: 1;
}
.toast.error {
  background: var(--danger);
}

/* --- 5. RESPONSIVE MOBILE --- */
@media (max-width: 768px) {
  body,
  #app-layout {
    flex-direction: column;
  }

  /* Rediseño del Sidebar a Topbar */
  aside {
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem;
    width: 100%;
    z-index: 100;
  }
  .sidebar-logo {
    padding: 0;
    font-size: 1.25rem;
    border: none;
    flex: 1;
    margin-bottom: 0;
  }
  .btn-logout {
    margin-top: 0;
    padding: 0.5rem 1rem;
    border-radius: 6px;
    order: 2;
    font-size: 0.8rem;
    width: auto;
  }
  .nav-menu {
    width: 100%;
    flex-direction: row;
    overflow-x: auto;
    order: 3;
    padding: 0;
    margin-top: 0.75rem;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    scrollbar-width: none;
  }
  .nav-menu::-webkit-scrollbar {
    display: none;
  }

  .nav-item {
    flex: 0 0 auto;
    text-align: center;
    padding: 0.8rem 1rem;
    white-space: nowrap;
    font-size: 0.85rem;
    border-left: none;
    border-bottom: 3px solid transparent;
  }
  .nav-item.active {
    border-left: none;
    border-bottom-color: var(--primary);
    background: transparent;
  }

  header {
    flex-direction: column;
    align-items: flex-start;
    padding: 1rem;
    gap: 12px;
  }
  .bcv-widget {
    width: 100%;
    justify-content: space-between;
  }

  .content-area {
    padding: 1rem;
  }
  .section-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
  }
  .btn-main {
    width: 100%;
    text-align: center;
    padding: 0.8rem;
  }

  /* ARREGLO CRÍTICO: Evitar Flexbox Blowout (Desbordamiento de tablas) */
  .content-area,
  .section {
    min-width: 0;
    width: 100%;
    overflow-x: hidden;
  }

  .filter-controls {
    flex-direction: column;
    width: 100%;
  }
  #adminSearch,
  #adminCatFilter {
    width: 100%;
    min-width: 100%;
  }

  .card-table {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border-radius: 8px;
  }
  table {
    min-width: 600px;
  }
  th,
  td {
    white-space: nowrap;
    font-size: 0.85rem;
    padding: 0.8rem;
  }

  .modal {
    align-items: flex-end;
  }
  .modal-content {
    width: 100%;
    max-height: 90vh;
    margin: 0;
    border-radius: 20px 20px 0 0;
  }
  .form-row {
    flex-direction: column;
    gap: 0;
  }
  .switch-container {
    margin-bottom: 8px;
  }
}
