/* Reset básico */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
  }
  
  body {
    font-family: Arial, sans-serif;
    background-color: #ffffff;
    color: #2e7d32;
  }

  .layout {
    display: flex;
  }

  .logo {
    font-size: 1.5em;
    color: #2e7d32;
    font-weight: bold;
  }
  
  .toggle-btn {
    font-size: 24px;
    cursor: pointer;
    display: none;
  }
  
  /* Submenú header */
  .submenu-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 20px;
    font-size: 1.2em;
    font-weight: bold;
  }
  
  .back-icon {
    font-size: 1.4em;
    cursor: pointer;
  }
  
  .menu-title {
    font-size: 1.1em;
    font-weight: bold;
  }
  
  .submenu-list {
    display: flex;
    flex-direction: column;
    padding: 10px 0;
  }
  
  .submenu-list a {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 20px;
    text-decoration: none;
    color: #333;
  }
  
  .submenu-list img {
    width: 60px;
    height: 60px;
    border-radius: 6px;
    object-fit: cover;
  }
  
  /* Header
  header {
    background-color: #2e7d32;
    color: white;
    padding: 1em;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 1em;
  } */
  
  header input[type="text"] {
    padding: 0.5em;
    border: none;
    border-radius: 4px;
    width: 200px;
    flex: 1;
  }
  
  #toggleSidebar {
    display: none;
  }
  
   #cerrarSidebar {
    display: none;
    background: none;
    border: none;
    font-size: 1.4em;
    color: #2e7d32;
    float: right;
    cursor: pointer;
    margin-bottom: 1em;
  } 

  .vista-opciones button,
  #viewCart {
    background-color: #66bb6a;
    color: white;
    border: none;
    padding: 0.5em;
    border-radius: 4px;
    cursor: pointer;
  }
  
  .vista-opciones button:hover,
  #viewCart:hover {
    background-color: #43a047;
  }
  
  /* Contenedor general */
  .contenedor {
    display: flex;
  }

  .contenedor main {
    flex: 1;
    margin-left: 280px; /* ancho del sidebar */
    padding: 1em;
    transition: margin-left 0.3s ease;
  }
  
 /*  #sidebar {
    width: 100%; /* ✅ Permite que se adapte según el contexto 
    max-width: 280px; /* Solo se aplica en pantallas grandes    
    background-color: #e8f5e9;
    background: linear-gradient(to bottom, #e8f5e9, #c8e6c9);
    padding: 1.5em;
    /*
     height: 100vh;
    transform: translateX(0);
    position: fixed;
     top: 0;
    bottom: 0;
    z-index: 1000; 
    box-shadow: 2px 0 8px rgba(0,0,0,0.1);
    overflow-y: auto;
  }
  
  #sidebar h2 {
    margin-top: 0;
    color: #2e7d32;
    font-weight: 600;
  }

  
  #sidebar button {
    background: none;
    border: none;
    font-size: 1.2em;
    cursor: pointer;
    float: right;
    margin-bottom: 1em;
  }
  
  #sidebar ul {
    list-style: none;
    padding: 0;
  }
  
  #sidebar li {
    padding: 0.5em 0;
    border-bottom: 1px solid #c8e6c9;
    cursor: pointer;
  }
  
  #sidebar li:hover {
    background-color: #c8e6c9;
  }
  
  
#sidebar ul.menu-categorias > li {
    border-bottom: 1px solid #c8e6c9;
  } */
  
  /* Sidebar izquierdo */
#sidebar {
  width: 100%; 
  max-width: 280px;
  background: #fff;
  border-right: 1px solid #eee;
  height: 100vh;
  overflow-y: auto;
  padding-top: 10px;
  z-index: 1000;
  transform: translateX(0);
  position: fixed;
  top: 0;
  left: 0;
}

.main-content {
  margin-left: 250px;
  flex: 1;
  padding-top: 60px;
}

/* Header fijo arriba */
header {
  position: fixed;
  top: 0;
  /* left: 250px; */
  height: 60px;
  /* width: calc(100% - 250px); */
  background: white;
  border-bottom: 1px solid #eee;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  z-index: 200;
  width: 100%;        /* Default for mobile */
  left: 0;            /* Default for mobile */
}

  .menu-categorias {
    list-style: none;
    padding: 0;
    margin: 0;
  }

  .menu-categorias li {
    background-color: #ffffff;
    margin: 0.4em 0;
    padding: 0.6em 0.8em;
    border-radius: 10px;
    transition: background 0.3s, transform 0.2s, box-shadow 0.2s;
    box-shadow: 0 1px 3px rgba(0,0,0,0.06);
  }
  
  .menu-categorias li:hover {
    background-color: #d7f5df;
    transform: translateX(4px);
    box-shadow: 0 2px 6px rgba(0,0,0,0.1);
    cursor: pointer;
  }

  .categoria-item {
    cursor: pointer;
    /* padding: 0.5em; */
    display: flex;
    justify-content: space-between;
    align-items: center;
    /* background-color: #e8f5e9; */
  }
  
  .subcategorias {
    list-style: none;
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease;
    padding-left: 1em;
    /* background: #f1f8e9; */
  }
  
  .subcategorias.expandida {
    max-height: 500px;
  }
  
  .subcategorias li {
    padding: 0.3em 0;
    font-size: 0.9em;
    color: #444;
    transition: color 0.3s;
  }
  /* .subcategorias li {
    padding: 0.4em 0;
    cursor: pointer;
  } */
  
  .subcategorias li:hover {
  color: #2e7d32;
  text-decoration: underline;
}
  .subcategorias.visible {
    max-height: 500px; /* altura máxima para mostrar */
  }
  
  .toggle-icon {
    font-size: 0.9em;
    transition: transform 0.3s ease;
  }
  
  .toggle-icon.rotate {
    transform: rotate(90deg);
  }
  
  /* Main */
  main {
    flex: 1;
    padding: 1em;
    margin-left: 250px;
    
  }
  
  #breadcrumb {
    margin-bottom: 1em;
    font-size: 0.9em;
    color: #4caf50;
  }
  
  .grid {
    display: grid;
    gap: 1em;
    padding-bottom: 100px; 
  }
  
  .columnas-1 {
    grid-template-columns: 1fr;
  }
  
  .columnas-2 {
    grid-template-columns: repeat(2, 1fr);
  }
  
  .columnas-4 {
    grid-template-columns: repeat(4, 1fr);
  }
  
  /* Tarjeta de producto */
  .card {
    background-color: white;
    border: 1px solid #c8e6c9;
    border-radius: 8px;
    padding: 1em;
    text-align: center;
    box-shadow: 0 2px 5px rgba(0,0,0,0.05);
    display: flex;
    transition: transform 0.2s;
    flex-direction: column;
    justify-content: space-between;
    align-items: center;
    min-height: 280px; /* opcional, para que todas midan igual */
  }
  
  .card:hover {
    transform: scale(1.02);
  }
  
  
  .card img {
    width: 100%;
    height: auto; 
    object-fit: contain; 
    margin-bottom: 0.5em;
    border-radius: 6px;

  }

  .card h4 {
    margin: 0.5em 0;
    font-size: 1em;
    color: #2e7d32;
  }
  
  /* Carrito dentro de card */
  .cart-controls {
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5em;
    margin-top: 0.5em;
  }
  
  .cantidad-input {
    width: 50px;
    padding: 0.3em;
    border: 1px solid #ccc;
    border-radius: 4px;
  }
  
  .cart-controls button,
  .cart-controls input {
    font-size: 0.9em;
}

  .add-to-cart {
    background-color: #2e7d32;
    color: white;
    border: none;
    padding: 0.3em 0.6em;
    border-radius: 4px;
    cursor: pointer;
  }
  
  .add-to-cart:hover {
    background-color: #388e3c;
  }
  
  /* Loader */
  #loader {
    text-align: center;
    padding: 2em;
    color: #888;
  }
  
  /* Modal carrito */
  .modal {
    display: none;
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background-color: rgba(0,0,0,0.5);
    justify-content: center;
    align-items: center;
    z-index: 200;
  }
  
  .modal-content {
    background: #ffffff;
    padding: 2em;
    border-radius: 8px;
    width: 90%;
    max-width: 400px;
    position: relative;
  }
  
  .close {
    position: absolute;
    top: 0.5em;
    right: 0.8em;
    font-size: 1.4em;
    cursor: pointer;
  }
  
  /* Responsive */
  @media (max-width: 768px) {
    main {
      margin-left: 0;
    }

    .layout {
      flex-direction: column;
    }

    .barra-superior {
      width: 100%;
      display: flex;
      flex-wrap: nowrap;
      gap: 0.5em;
      padding: 1em 0;
      margin-top: 60px; /* ✅ Añadido para dejar espacio al header fijo */
      background: #f9f9f9; /* opcional, para mayor contraste */
    }
  
    .barra-superior input,
    .barra-superior select,
    .barra-superior button {
      flex: 3 2 30%; /* ✅ Asegura que ocupen toda la fila en móviles */
      min-width: 0;
    }

    #sidebar {
      position: fixed;
      width: 80vw;
      left: 0;
      top: 60px;
      padding-top: 0;
      max-width: 320px;
      height: 100vh;
      transform: translateX(-100%);
      background: linear-gradient(to bottom, #e8f5e9, #c8e6c9);
      box-shadow: 2px 0 8px rgba(0, 0, 0, 0.2);
      transition: transform 0.3s ease;
      z-index: 2000;

    }
  
    #sidebar.visible {
      transform: translateX(0);
    }
    
    #sidebar.active {
      display: block;
    }
  
    .main-content {
      margin-left: 0;
      padding-top: 60px;
    }
  
    header {
      left: 0;
      width: 100%;
    }
  
    .toggle-btn {
      display: block;
    }
  
    .vista-opciones {
      width: 100%;
      display: flex;
      justify-content: flex-start;
      gap: 0.5em;
      margin-top: 0.5em;
    }
  
/*     header {
      flex-direction: row;
      align-items: center;
      justify-content: space-between;
      flex-wrap: wrap;
      gap: 0.5em;
    }
     */
    header h1 {
      font-size: 1.2em;
      flex-grow: 1;
      margin: 0;
    }

    #toggleSidebar {
      display: inline-block;
      background: none;
      border: none;
      font-size: 1.5em;
      cursor: pointer;
      color: rgb(180, 11, 11);
    }

    
    /*#sidebar {
        position: fixed;
        top: 0;
        left: 0;
        width: 80vw; /* ✅ ancho ideal en móviles 
        max-width: 320px;
        height: 100vh;
        transform: translateX(-100%);
        background: linear-gradient(to bottom, #e8f5e9, #c8e6c9);
        box-shadow: 2px 0 8px rgba(0, 0, 0, 0.2);
        transition: transform 0.3s ease;
        z-index: 2000;
      }
    
      
      #sidebar.visible {
        transform: translateX(0);
      }*/
/* 
      #sidebar {
        display: none;
        width: 100vw; /* ✅ Forzar ancho completo en pantalla 
        max-width: 100vw;
        box-shadow: none;
        padding: 1em;
      }
    
      #sidebar.visible {
        display: block;
      } */

      #cerrarSidebar {
        display: none;
      }

      #sidebar.visible #cerrarSidebar {
        display: inline-block;
      } 

      .contenedor {
        flex-direction: column;
         display: column; 
      }

      .contenedor main {
        margin-left: 0 !important;
      }
 
      #sidebarOverlay {
        display: none;
        position: fixed;
        inset: 0;
        background-color: rgba(0, 0, 0, 0.3);
        z-index: 1000;
      }
    
      #sidebar.visible + #sidebarOverlay {
        display: block;
      } 
    }

    #breadcrumb a {
        color: #2e7d32;
        text-decoration: underline;
        cursor: pointer;
      }
      
      #breadcrumb a:hover {
        text-decoration: none;
      }
    
      .btn-general {
        background-color: #2e7d32;
        color: white;
        border: none;
        padding: 0.5em 1em;
        margin: 0.5em 0 1em;
        border-radius: 5px;
        cursor: pointer;
      }
      
      .btn-general:hover {
        background-color: #388e3c;
      }

      #btnMostrarTodoMain,
      #btnMostrarTodoSidebar {
        display: none;
      }
      
      #btnMostrarTodoSidebar {
        margin-bottom: 1em;
        background-color: #a5d6a7;
        border: none;
        padding: 0.5em 1em;
        border-radius: 6px;
        color: #1b5e20;
        cursor: pointer;
        font-weight: bold;
        transition: background 0.3s;
      }

      #btnMostrarTodoSidebar:hover {
        background-color: #81c784;
      }

      
      #sidebar .btn-general {
        width: 100%;
        margin-bottom: 1em;
        background-color: #2e7d32;
        color: white;
        border: none;
        padding: 0.6em;
        font-size: 1em;
        border-radius: 4px;
        cursor: pointer;
      }
      
      #sidebar .btn-general:hover {
        background-color: #43a047;
      }

  
      .orden-container {
        margin: 1em 0;
        display: flex;
        align-items: center;
        gap: 0.5em;
        font-size: 0.95em;
      }
      
      #ordenar {
        padding: 0.3em 0.5em;
        border-radius: 4px;
        border: 1px solid #ccc;
      }

      .barra-superior {
        display: flex;
        flex-wrap: wrap;
        align-items: center;
        justify-content: space-between;
        gap: 1em;
        margin-bottom: 1em;
      }

      .barra-superior input,
      .barra-superior select {
        padding: 0.5em;
        border-radius: 4px;
        border: 1px solid #ccc;
      }

      .cart-sidebar {
        position: fixed;
        top: 0;
        right: -100%;
        width: 350px;
        height: 100%;
        background-color: #ffffff;
        box-shadow: -2px 0 10px rgba(0, 0, 0, 0.2);
        z-index: 1500;
        display: flex;
        flex-direction: column;
        transition: right 0.4s ease;
        padding: 1em;
      }
      
      .cart-sidebar.visible {
        right: 0;
      }
      
      .cart-header {
        display: flex;
        justify-content: space-between;
        align-items: center;
        margin-bottom: 1em;
      }
      
      .close-btn {
        background: none;
        border: none;
        font-size: 1.4em;
        cursor: pointer;
      }
      
      .cart-items {
        flex: 1;
        overflow-y: auto;
        margin-bottom: 1em;
      }
      
      .cart-items .item {
        border-bottom: 1px solid #eee;
        padding: 0.5em 0;
      }
      
      .cart-items .item input {
        width: 50px;
        padding: 0.2em;
        margin-left: 0.5em;
      }
      
      .cart-actions label {
        display: block;
        margin-bottom: 0.5em;
        font-size: 0.95em;
      }
      
      .cart-actions input {
        width: 100%;
        padding: 0.4em;
        margin-top: 0.2em;
        border: 1px solid #ccc;
        border-radius: 4px;
      }
      
      .cart-buttons {
        display: flex;
        gap: 0.5em;
        margin-top: 1em;
      }
      
      .cart-buttons button {
        flex: 1;
        padding: 0.5em;
        border: none;
        border-radius: 5px;
        cursor: pointer;
      }
      
      .cart-buttons .danger {
        background-color: #c62828;
        color: white;
      }
      
      .cart-buttons .light {
        background-color: #eeeeee;
        color: #333;
      }
      
      .cart-buttons .success {
        background-color: #2e7d32;
        color: white;
      }

      .cart-controls {
        display: flex;
        align-items: center;
        gap: 0.3em;
        margin-top: 0.5em;
      }
      
      .cart-controls input.cantidad-input {
        width: 50px;
        text-align: center;
        padding: 0.3em;
        border: 1px solid #ccc;
        border-radius: 4px;
      }
      
      .cart-controls .btn-mas,
      .cart-controls .btn-menos {
        background-color: #e0e0e0;
        border: none;
        padding: 0.3em 0.6em;
        font-size: 1em;
        border-radius: 4px;
        cursor: pointer;
      }
      
      .cart-controls .btn-mas:hover,
      .cart-controls .btn-menos:hover {
        background-color: #c8e6c9;
      }

      .mensaje-carrito {
        position: fixed;
        bottom: 20px;
        right: 20px;
        background-color: #c37f09;
        color: white;
        padding: 0.7em 1.2em;
        border-radius: 6px;
        font-size: 0.95em;
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.4s ease;
        z-index: 9999;
      }
      
      .mensaje-carrito.visible {
        opacity: 1;
      }

      .cart-item-controls {
        display: flex;
        align-items: center;
        gap: 0.5em;
        margin-top: 0.4em;
      }
      
      .cart-item-controls input {
        width: 50px;
        text-align: center;
        padding: 0.2em;
      }
      
      .cart-item-controls button {
        padding: 0.2em 0.5em;
        border: none;
        background-color: #e0e0e0;
        border-radius: 4px;
        cursor: pointer;
      }
      
      .cart-item-controls button:hover {
        background-color: #c8e6c9;
      }
      
      .snackbar-confirmacion {
        position: fixed;
        bottom: 20px;
        right: 20px;
        background: #ffffff;
        border: 1px solid #ccc;
        border-left: 5px solid #2e7d32;
        box-shadow: 0 2px 6px rgba(0,0,0,0.15);
        padding: 1em;
        border-radius: 8px;
        display: none;
        z-index: 9999;
        animation: fadeIn 0.3s ease;
      }
      
      .snackbar-confirmacion.visible {
        display: flex;
        align-items: center;
        gap: 1em;
      }
      
      .snackbar-botones {
        display: flex;
        gap: 0.5em;
      }
      
      .btn-snackbar {
        padding: 0.4em 0.9em;
        border: none;
        border-radius: 4px;
        cursor: pointer;
      }
      
      .btn-snackbar.verde {
        background-color: #2e7d32;
        color: white;
      }
      
      .btn-snackbar.gris {
        background-color: #e0e0e0;
        color: #333;
      }

      #productos {
        display: grid;
        gap: 1rem;
        padding: 1rem;
        /* grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));  */
        max-width: 1200px;
        margin: 0 auto;
      }
    
      @media (min-width: 769px) {
        #sidebar {
          top: 60px; /* Altura estimada del header, ajústalo si tu header es más alto */
          height: calc(100vh - 60px);
        }


      
        .contenedor main {
          margin-left: 280px;
          padding-top: 1em;
        }
      
        header {
          position: fixed;
          top: 0;
          left: 0;
          right: 0;
          height: 60px;
          /* background-color: #2e7d32; */
          z-index: 1100;
          display: flex;
          align-items: center;
          justify-content: space-between;
          padding: 0 1em;
          box-shadow: 0 2px 5px rgba(0,0,0,0.1);
        }
      
        body {
          padding-top: 60px; /* desplaza todo para dejar espacio al header fijo */
        }
      }

      @keyframes fadeIn {
        from { opacity: 0; transform: translateY(10px); }
        to   { opacity: 1; transform: translateY(0); }
      }
      
      
            

    