:root {
  --bg-color: #ffffff;
  --text-color: #222222;
  --card-bg: #f9f9f9;
  --table-header: #e9ecef;
  --primary: #007bff;
  --secondary: #25d366;
  --highlight: #007bff;
}

.dark-mode {
  --bg-color: #121212;
  --text-color: #e0e0e0;
  --card-bg: #1e1e1e;
  --table-header: #2a2a2a;
  --primary: #1a73e8;
  --secondary: #20ba5a;
  --highlight: #1a73e8;
}

/* --- ANIMACIONES --- */
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

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

* {
  box-sizing: border-box;
  transition: 
    background-color 0.35s ease,
    color 0.35s ease,
    border-color 0.35s ease;
}

body {
  font-family: 'Nunito', sans-serif;
  background: var(--bg-color);
  color: var(--text-color);
  margin: 0;
  padding: 0;
  overflow-x: hidden;
}

/* --- HEADER --- */
header {
  background: var(--card-bg);
  padding: 10px 15px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 20px;
  font-weight: 700;
  border-bottom: 1px solid #ddd;
}
.login-header {
  justify-content: center;
}

.header-actions {
  display: flex;
  gap: 8px;
}

#darkModeBtn,
.logout {
  background: var(--primary);
  color: white;
  border: none;
  border-radius: 6px;
  padding: 6px 10px;
  cursor: pointer;
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.logout {
  background: crimson;
}

/* --- MAIN --- */
main {
  padding: 20px;
  max-width: 950px;
  margin: auto;
}

main > section, .tabla-container {
  animation: slideInUp 0.5s ease-out forwards;
}

input, select, button {
  padding: 8px 12px;
  border: 1px solid #ccc;
  border-radius: 6px;
  background: var(--card-bg);
  color: var(--text-color);
  font-family: 'Nunito', sans-serif;
  font-size: 14px;
}

button {
  cursor: pointer;
  background: var(--primary);
  color: white;
  border: none;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: transform 0.2s ease, opacity 0.2s ease;
}
button:hover { 
  opacity: 0.9;
  transform: scale(1.03);
}
button:active {
  transform: scale(0.98);
}


/* Estilos para SVG dentro de botones */
button svg {
  width: 16px;
  height: 16px;
  stroke: currentColor;
  pointer-events: none; /* Asegura que el clic se registre en el botón */
}
#logoutBtn svg, #darkModeBtn svg {
  stroke-width: 2.5;
}
.whatsapp-icon svg {
  width: 24px;
  height: 24px;
}


/* --- SECCION FORM --- */
.form-section {
  margin: 15px 0;
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}
.precio-ganancia-group {
  display: flex;
  gap: 10px;
}
.precio-ganancia-group input {
  width: 100%;
}
#gananciaUnidad, #gananciaKg {
    background-color: #e9ecef;
    cursor: not-allowed;
}
.dark-mode #gananciaUnidad, .dark-mode #gananciaKg {
    background-color: #2a2a2a;
}

/* --- TABLA --- */
.tabla-container {
  width: 100%;
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 20px;
  box-shadow: 0 2px 5px rgba(0,0,0,0.05);
  border-radius: 8px;
  overflow: hidden;
}
th, td {
  border: 1px solid #ddd;
  padding: 10px;
  text-align: center;
}
th {
  background: var(--table-header);
  font-weight: 700;
}
.total-row {
  font-weight: bold;
  background: var(--highlight);
  color: white;
}

td button {
  padding: 4px 8px;
  min-width: auto;
  width: auto !important;
  margin: 0 2px;
}
.eliminar-btn { background-color: #dc3545; }
.editar-btn { background-color: #6c757d; }

/* --- MODALES --- */
dialog {
  transition: opacity 0.2s ease, transform 0.2s ease;
  border: none;
  border-radius: 8px;
  box-shadow: 0 4px 15px rgba(0,0,0,0.2);
  padding: 20px;
  background-color: var(--card-bg);
  color: var(--text-color);
  min-width: 300px;
}
dialog[open] {
  animation: fadeIn 0.3s ease forwards;
}
dialog::backdrop {
  background: rgba(0, 0, 0, 0.5);
  animation: fadeIn 0.3s ease forwards;
}

.modal-botones {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 20px;
}

/* NUEVO: Estilos para el formulario de edición de producto */
.form-group-modal {
  display: grid;
  grid-template-columns: 1fr; /* Por defecto 1 columna (móvil) */
  gap: 5px;
  margin-bottom: 12px;
}
.form-group-modal label {
  font-weight: 600;
  margin-bottom: 2px;
}

/* Media query para aplicar 2 columnas en pantallas más grandes (PC) */
@media (min-width: 500px) {
  #editarModal {
    min-width: 450px; /* Hacemos el modal un poco más ancho en PC */
  }
  .form-group-modal {
    grid-template-columns: 140px 1fr; /* Columna de etiqueta y columna de input */
    align-items: center;
    gap: 15px;
  }
  .form-group-modal label {
    text-align: right;
    margin-bottom: 0;
  }
}


/* --- WHATSAPP FLOATING BUTTON (Desktop) --- */
.whatsapp-btn {
  position: fixed;
  bottom: 20px;
  right: 20px;
  background: var(--secondary);
  color: white;
  border-radius: 50%;
  width: 50px;
  height: 50px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  box-shadow: 0 2px 5px rgba(0,0,0,0.3);
  z-index: 1000;
}
.whatsapp-icon {
  font-size: 24px;
  display: inline;
}
.whatsapp-text {
  display: none;
}


/* --- FOOTER --- */
.footer {
  text-align: left;
  padding: 10px;
  font-size: 12px;
  color: #888;
  position: fixed;
  bottom: 0;
  left: 10px;
}
.dark-mode .footer {
    color: #555;
}


/* --- RESPONSIVE TABLE (mobile) --- */
@media (max-width: 768px) {
  main {
      padding: 10px;
      padding-bottom: 70px;
  }
  .form-section {
      flex-direction: column;
  }
  .precio-ganancia-group {
      width: 100%;
  }

  table, thead, tbody, th, td, tr {
    display: block;
  }
  thead {
    display: none;
  }
  tr {
    margin-bottom: 15px;
    border: 1px solid #ddd;
    border-radius: 8px;
    background: var(--card-bg);
    padding: 10px;
  }
  td {
    border: none;
    text-align: right;
    display: flex;
    justify-content: space-between;
    padding: 8px;
    border-bottom: 1px solid var(--table-header);
  }
  td:last-child {
      border-bottom: none;
  }
  td::before {
    content: attr(data-label);
    font-weight: bold;
    color: var(--primary);
    text-align: left;
  }
  td[data-label="Acciones"] {
    justify-content: flex-end;
  }
  td[data-label="Acciones"] button {
    width: auto !important;
    padding: 6px 10px;
    font-size: 14px;
  }
  input, select, button {
    width: 100%;
  }

  .whatsapp-btn {
    position: static;
    display: flex;
    width: 95%;
    max-width: 400px;
    margin: 20px auto;
    border-radius: 8px;
    padding: 12px;
    font-size: 16px;
    height: auto;
    text-align: center;
  }
  .whatsapp-icon {
    display: none;
  }
  .whatsapp-text {
    display: inline;
    font-weight: bold;
  }
  
  .footer {
    position: static;
    text-align: center;
    padding-bottom: 15px;
  }
}

/* === ESTILOS AGREGADOS Y MODIFICADOS === */

/* Separador visual */
.separator {
  border: 0;
  height: 1px;
  background-image: linear-gradient(to right, rgba(0, 0, 0, 0), rgba(0, 0, 0, 0.2), rgba(0, 0, 0, 0));
  margin: 40px auto;
  width: 90%;
  max-width: 950px;
}
.dark-mode .separator {
  background-image: linear-gradient(to right, rgba(255, 255, 255, 0), rgba(255, 255, 255, 0.2), rgba(255, 255, 255, 0));
}

/* Contenedor principal de las nuevas secciones */
.section {
  padding: 40px 20px;
  margin: 20px auto;
  max-width: 950px;
}
.section .container {
    max-width: 600px;
    margin: 0 auto;
}
.section-title {
  text-align: center;
  font-size: 28px;
  font-weight: 700;
  margin-bottom: 20px;
}

/* Clases de utilidad */
.text-center { text-align: center; }
.mb-3 { margin-bottom: 1rem; }
.mt-2 { margin-top: 0.5rem; }
.mt-4 { margin-top: 1.5rem; }
.mb-0 { margin-bottom: 0; }
.w-100 { width: 100%; }
small { font-size: 80%; }

/* Estilo de la tarjeta del formulario */
.card {
  border: 1px solid #ddd;
  box-shadow: 0 1px 3px rgba(0,0,0,0.05);
  padding: 20px;
  background: var(--card-bg);
  border-radius: 16px;
}

/* Elementos del formulario de compra */
.form-label {
  display: block;
  margin-bottom: 5px;
  font-weight: 600;
  text-align: left;
}
.form-control, .form-select {
  width: 100%;
}
.text-muted {
  color: #6c757d;
}

/* Botón de compra verde */
#compraForm button[type="submit"] {
  background-color: var(--secondary);
  border: none;
}
#compraForm button[type="submit"]:hover {
  background-color: #20ba5a;
  opacity: 1;
}

/* Nuevo Footer con fondo negro */
footer#terminos {
  background-color: #111;
  color: #f8f9fa;
  padding: 30px 20px;
  text-align: left;
  width: 100%;
}
footer#terminos .container {
  max-width: 950px;
  margin: 0 auto;
}
footer#terminos h4 {
  color: #ffffff;
  border-bottom: 1px solid #444;
  padding-bottom: 5px;
  margin-top: 10px;
  font-weight: 700;
}
footer#terminos p {
  font-size: 14px;
  line-height: 1.6;
}
footer#terminos a {
  color: #0d6efd;
  text-decoration: none;
}
footer#terminos a:hover {
  text-decoration: underline;
}

/* Ajustes responsivos para la tarjeta del formulario */
@media (min-width: 768px) {
  .p-md-4 {
    padding: 1.5rem;
  }
}