* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: "Segoe UI", Tahoma, sans-serif;
  color: var(--ink);
  background: linear-gradient(160deg, #f4fbf7 0%, #e6f3ec 100%);
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: linear-gradient(90deg, var(--brand), var(--brand-2));
  color: #fff;
  padding: 12px 16px;
  display: grid;
  grid-template-columns: auto auto 1fr auto auto;
  gap: 12px;
  align-items: center;
}

.topbar h1 {
  margin: 0;
  font-size: clamp(1.05rem, 2.2vw, 1.35rem);
}

.home-link {
  text-decoration: none;
  background: rgba(255, 255, 255, 0.16);
  border: 1px solid rgba(255, 255, 255, 0.36);
  color: #fff;
  padding: 8px 12px;
  border-radius: 10px;
  font-weight: 600;
}

.mispedidos-link {
  background: #ffffff;
  color: #0f724c;
  border-color: rgba(255, 255, 255, 0.85);
  font-weight: 800;
}

.mispedidos-link:hover,
.mispedidos-link:focus-visible {
  background: #f2fbf7;
  color: #0c6644;
}

.mode-switch {
  display: flex;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.45);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.2), 0 4px 14px rgba(7, 47, 31, 0.18);
  background: rgba(8, 55, 38, 0.34);
  padding: 2px;
  margin: 0 5px;
}

.mode-switch button {
  border: 0;
  margin: 0;
  padding: 8px 12px;
  color: #f5f8fc;
  background: #5f7386;
  font-weight: 700;
  cursor: pointer;
  min-width: 64px;
  opacity: 0.72;
  filter: none;
  transition: background 0.2s ease, color 0.2s ease, box-shadow 0.2s ease, opacity 0.2s ease, transform 0.2s ease;
  border-right: 1px solid rgba(255, 255, 255, 0.18);
  position: relative;
}

.mode-switch button:last-child {
  border-right: 0;
  border-top-right-radius: 10px;
  border-bottom-right-radius: 10px;
}

.mode-switch button:first-child {
  border-top-left-radius: 10px;
  border-bottom-left-radius: 10px;
}

.mode-switch button.active {
  opacity: 1;
  position: relative;
  z-index: 10;
  transform: scale(1.2) translateY(-4px);
  border-radius: 10px !important;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.4),
              0 0 0 2px rgba(255, 255, 255, 0.4);
  border: none;
  background-image: linear-gradient(to bottom, rgba(255,255,255,0.15), transparent);
}

.mode-switch button[data-mode="publico"] {
  background: #121212;
  color: #f3f3f3;
}

.mode-switch button[data-mode="afiliado"] {
  background: #7a838c;
  color: #f4f7fa;
}

.mode-switch button[data-mode="d5"] {
  background: #0d8d5e;
  color: #effcf7;
}

.mode-switch button[data-mode="d8"] {
  background: #f2c037;
  color: #2a2100;
}

.mode-switch button[data-mode="d15"] {
  background: #ef8c1f;
  color: #fff;
}

.mode-switch button:hover {
  opacity: 0.88;
}

.mode-switch button.active:hover {
  opacity: 1;
}

.mobile-cart-toggle {
  display: none;
  border: 1px solid rgba(255,255,255,0.35);
  background: rgba(255,255,255,0.15);
  color: #fff;
  border-radius: 10px;
  padding: 8px 10px;
  font-weight: 700;
}

.layout {
  max-width: 1400px;
  margin: 16px auto;
  padding: 0 12px 16px;
  display: grid;
  grid-template-columns: 1fr 320px;
  gap: 12px;
}

.status {
  background: #ffffffbf;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
  color: var(--muted);
}

.products-toolbar {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: 10px;
  margin-bottom: 10px;
}

.promos-button {
  border: 1px solid #a6d8c3;
  background: linear-gradient(135deg, #f5fff9, #e8f7ef);
  color: #0e6845;
  border-radius: 12px;
  padding: 8px 12px;
  display: inline-flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-weight: 800;
  cursor: pointer;
  min-width: 210px;
}

.promos-button:hover,
.promos-button:focus-visible {
  border-color: #6cbe9a;
  box-shadow: 0 0 0 2px rgba(39, 181, 127, 0.14);
}

.promos-button[disabled] {
  opacity: 0.55;
  cursor: not-allowed;
  box-shadow: none;
}

.promos-button-label {
  white-space: nowrap;
}

.promos-count {
  min-width: 26px;
  height: 26px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: #0f8f5f;
  color: #fff;
  font-size: 0.84rem;
  padding: 0 8px;
}

.product-search {
  background: #ffffffbf;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 6px 10px;
  display: flex;
  align-items: center;
}

.product-search input {
  width: 100%;
  border: 0;
  outline: none;
  background: transparent;
  color: var(--ink);
  font-size: 0.98rem;
}

.product-search input::placeholder {
  color: #759486;
}

.product-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: 12px;
}

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  overflow: hidden;
  box-shadow: 0 4px 14px rgba(14, 58, 39, 0.08);
  display: flex;
  flex-direction: column;
  cursor: pointer;
  transition: transform 0.16s ease, box-shadow 0.16s ease, border-color 0.16s ease;
}

.card.promo-product {
  border-color: #43b885;
  box-shadow: 0 10px 24px rgba(19, 126, 86, 0.2), 0 0 0 2px rgba(67, 184, 133, 0.16);
}

.promo-chip {
  position: absolute;
  right: 8px;
  top: 8px;
  background: #1e8d5f;
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.65);
  border-radius: 999px;
  padding: 2px 8px;
  font-size: 0.7rem;
  font-weight: 800;
  letter-spacing: 0.2px;
}

.card,
.card * {
  cursor: pointer;
}

.card:hover {
  transform: translateY(-4px) scale(1.01);
  border-color: #84c8a7;
  box-shadow: 0 16px 30px rgba(14, 58, 39, 0.2), 0 0 0 2px rgba(39, 181, 127, 0.16);
}

.card:focus-visible {
  outline: 3px solid #27b57f;
  outline-offset: 2px;
}

.card-media {
  position: relative;
}

.card img {
  width: 100%;
  height: 140px;
  object-fit: contain;
  background: #f7fcf9;
  border-bottom: 1px solid var(--line);
}

.product-code-badge {
  position: absolute;
  top: 8px;
  left: 8px;
  background: rgba(11, 80, 54, 0.9);
  color: #effcf6;
  border: 1px solid rgba(162, 222, 196, 0.62);
  border-radius: 999px;
  padding: 2px 8px;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.2px;
  line-height: 1.2;
}

.card-body {
  padding: 10px;
  display: grid;
  gap: 6px;
}

.name { font-weight: 700; min-height: 40px; }
.price {
  font-weight: 800;
  color: var(--good);
}
.pv {
  font-weight: 700;
  color: #6d7d74;
  font-size: 0.86rem;
  min-height: 1.05rem;
}

.pv.pv-hidden {
  visibility: hidden;
}

/* Precio/PV cambian segun el modo seleccionado */
body[data-mode="publico"] .price { color: #1f2933; }
body[data-mode="afiliado"] .price { color: #46594f; }

body[data-mode="d5"] .price { color: #0d8d5e; }

body[data-mode="d8"] .price { color: #c58d00; }

body[data-mode="d15"] .price { color: #ef8c1f; }

.card-hint {
  margin-top: 6px;
  border: 1px dashed #9dc5e8;
  border-radius: 10px;
  padding: 7px;
  text-align: center;
  color: #3e6f98;
  font-weight: 700;
  font-size: 0.82rem;
  background: #f4f9ff;
}

.cart-panel {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: 0 4px 14px rgba(14, 41, 67, 0.08);
  position: sticky;
  top: 76px;
  height: fit-content;
}

.cart-header {
  padding: 12px;
  font-weight: 800;
  color: #fff;
  border-radius: 14px 14px 0 0;
  background: linear-gradient(90deg, #28a745, #1e8d5f);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.close-cart-btn {
  display: none;
  width: 28px;
  height: 28px;
  border: 1px solid rgba(255,255,255,0.55);
  border-radius: 8px;
  background: rgba(255,255,255,0.18);
  color: #fff;
  font-weight: 800;
  cursor: pointer;
  line-height: 1;
  padding: 0;
}

.cart-list {
  max-height: 52vh;
  overflow: auto;
  padding: 10px;
  display: grid;
  gap: 8px;
}

.cart-item {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
}

.cart-item.cart-item-promo {
  border-color: #e6c66f;
  background: #fffaf0;
}

.cart-item-name { font-weight: 700; }
.cart-item-sub { color: var(--muted); font-size: 0.86rem; }
.cart-promo-banner {
  border: 1px dashed #e6c66f;
  border-radius: 10px;
  background: #fff6df;
  color: #7a4f05;
  padding: 8px 9px;
  font-size: 0.8rem;
  line-height: 1.25;
  font-weight: 800;
}
.qty-controls {
  display: flex;
  align-items: center;
  gap: 6px;
}
.qty-controls button {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  border: 1px solid #b7ccdf;
  background: #f5f9ff;
  cursor: pointer;
}

.cart-totals {
  border-top: 1px solid var(--line);
  padding: 10px 12px;
  display: grid;
  gap: 6px;
}
.cart-totals div {
  display: flex;
  justify-content: space-between;
}

.cart-pv-row.pv-hidden {
  visibility: hidden;
}

.cart-actions {
  padding: 0 12px 12px;
}
.cart-actions .danger {
  width: 100%;
  border: 0;
  border-radius: 10px;
  padding: 9px;
  background: #d9414c;
  color: #fff;
  font-weight: 700;
  cursor: pointer;
}

.whatsapp-btn {
  width: 100%;
  margin-top: 8px;
  border: 0;
  border-radius: 10px;
  padding: 10px;
  background: linear-gradient(90deg, #1eab61, #0f8f4d);
  color: #fff;
  font-weight: 800;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.cart-divider {
  margin: 10px 0 8px;
  border-top: 1px solid #d8e5dd;
}

.save-order-btn {
  width: 100%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 10px;
  padding: 10px;
  background: linear-gradient(90deg, #1f7e57, #126a47);
  color: #fff;
  font-weight: 800;
  letter-spacing: 0.03em;
  text-decoration: none;
  cursor: pointer;
}

.save-order-btn:hover,
.save-order-btn:focus-visible {
  filter: brightness(1.05);
}

.wa-icon {
  width: 20px;
  height: 20px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: #fff;
  color: #0f8f4d;
  font-size: 0.66rem;
  font-weight: 900;
}

.wa-modal {
  position: fixed;
  inset: 0;
  z-index: 120;
  display: none;
}

.wa-modal.open {
  display: block;
}

.wa-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(5, 20, 33, 0.5);
}

.wa-modal-card {
  position: relative;
  z-index: 1;
  width: min(460px, calc(100% - 24px));
  margin: 72px auto;
  background: #fff;
  border-radius: 14px;
  border: 1px solid #cfe1f3;
  box-shadow: 0 20px 44px rgba(8, 28, 46, 0.32);
  padding: 14px;
  display: grid;
  gap: 10px;
}

.wa-modal-card h3 {
  margin: 0;
  color: #13456f;
}

.wa-field-row {
  display: grid;
  grid-template-columns: 110px 1fr;
  gap: 8px;
  font-size: 0.86rem;
  color: #5d748b;
}

.wa-field-grid {
  display: grid;
  grid-template-columns: 110px 1fr;
  gap: 8px;
}

.wa-modal-card select,
.wa-modal-card input,
.wa-modal-card textarea {
  width: 100%;
  border: 1px solid #bcd2e7;
  border-radius: 10px;
  padding: 10px;
  outline: none;
  font-size: 0.96rem;
}

.wa-modal-card select:focus,
.wa-modal-card input:focus,
.wa-modal-card textarea:focus {
  border-color: #4a9ae1;
  box-shadow: 0 0 0 2px rgba(74, 154, 225, 0.18);
}

.wa-error {
  min-height: 20px;
  color: #b3261e;
  font-size: 0.88rem;
}

.wa-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.wa-cancel,
.wa-submit {
  border: 0;
  border-radius: 10px;
  padding: 9px 14px;
  font-weight: 700;
  cursor: pointer;
}

.wa-cancel {
  background: #e8eef6;
  color: #2a435a;
}

.wa-submit {
  background: #1eab61;
  color: #fff;
}

.promos-modal {
  position: fixed;
  inset: 0;
  z-index: 130;
  display: none;
}

.promos-modal.open {
  display: block;
}

.promos-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(8, 22, 36, 0.56);
}

.promos-modal-card {
  position: relative;
  z-index: 1;
  width: min(700px, calc(100% - 24px));
  margin: 56px auto;
  background: #fff;
  border: 1px solid #cbe1d4;
  border-radius: 14px;
  box-shadow: 0 24px 50px rgba(8, 33, 22, 0.32);
  padding: 14px;
  display: grid;
  gap: 10px;
  max-height: calc(100dvh - 112px);
  overflow: auto;
}

.promos-modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.promos-modal-head h3 {
  margin: 0;
  color: #0f5e40;
}

.promos-close {
  border: 1px solid #b9d6c6;
  background: #f1fbf5;
  border-radius: 10px;
  width: 30px;
  height: 30px;
  line-height: 1;
  font-weight: 800;
  cursor: pointer;
}

.promos-periodo {
  color: #4c7260;
  font-size: 0.9rem;
}

.promos-empty {
  border: 1px dashed #bfd7ca;
  background: #f8fffb;
  border-radius: 10px;
  padding: 10px;
  color: #577768;
  font-weight: 600;
}

.promos-list {
  display: grid;
  gap: 8px;
}

.promo-row {
  border: 1px solid #d0e6db;
  border-radius: 10px;
  padding: 10px;
  display: grid;
  gap: 5px;
  background: #fcfffd;
}

.promo-row-name {
  color: #0f5f40;
  font-weight: 800;
}

.promo-row-desc {
  color: #365747;
  font-size: 0.92rem;
}

.promo-row-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 2px;
}

.promo-row-actions {
  margin-top: 4px;
}

.promo-buy-btn {
  border: 1px solid #8ec7ae;
  background: linear-gradient(90deg, #137f56, #0f6e4a);
  color: #fff;
  border-radius: 10px;
  padding: 8px 10px;
  font-weight: 800;
  cursor: pointer;
  letter-spacing: 0.02em;
}

.promo-buy-btn[disabled] {
  opacity: 0.5;
  cursor: not-allowed;
  background: #9db7aa;
  border-color: #9db7aa;
}

.promo-tag {
  border-radius: 999px;
  padding: 4px 9px;
  font-size: 0.76rem;
  font-weight: 800;
  border: 1px solid transparent;
}

.promo-tag-condicion {
  background: #ebf5ff;
  color: #1f5f94;
  border-color: #b6d5ef;
}

.promo-tag-regalo {
  background: #edfdf5;
  color: #0b6b48;
  border-color: #b4e6ce;
}

@media (max-width: 1024px) {
  .topbar {
    grid-template-columns: 1fr auto;
    grid-template-areas:
      "title cart"
      "home mispedidos"
      "modes modes";
    row-gap: 8px;
    align-items: center;
  }
  .home-link-main { grid-area: home; justify-self: start; }
  .mispedidos-link { grid-area: mispedidos; justify-self: end; }
  .topbar h1 { grid-area: title; }
  .mode-switch {
    grid-area: modes;
    width: 100%;
    margin: 0;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  .mode-switch button {
    min-width: 58px;
  }
  .mode-switch button.active {
    transform: scale(1.04) translateY(-1px);
  }
  .mobile-cart-toggle {
    grid-area: cart;
    display: inline-flex;
    justify-self: end;
    align-items: center;
  }

  .layout {
    grid-template-columns: 1fr;
  }

  .products-toolbar {
    grid-template-columns: 1fr;
  }

  .promos-button {
    min-width: 0;
    width: 100%;
  }

  .cart-panel {
    position: fixed;
    right: 0;
    left: auto;
    top: 0;
    bottom: 0;
    width: min(92vw, 380px);
    height: 100dvh;
    z-index: 60;
    transform: translateX(calc(100% + 24px));
    transition: transform 0.25s ease;
    max-height: none;
    display: grid;
    grid-template-rows: auto 1fr auto auto;
    border-radius: 14px 0 0 14px;
    box-shadow: -14px 0 30px rgba(6, 34, 23, 0.24);
  }

  .cart-panel.open {
    transform: translateX(0);
  }

  .cart-list { max-height: none; }

  .close-cart-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  .cart-item {
    padding: 6px 8px;
    grid-template-columns: 1fr auto;
    align-items: center;
    gap: 6px;
    border-radius: 8px;
  }

  .cart-item-name {
    font-size: 0.94rem;
    line-height: 1.2;
    margin-bottom: 2px;
  }

  .cart-item-sub {
    font-size: 0.8rem;
    line-height: 1.2;
  }

  .qty-controls {
    gap: 4px;
  }

  .qty-controls button {
    width: 26px;
    height: 26px;
    border-radius: 6px;
    font-size: 0.95rem;
    line-height: 1;
    padding: 0;
  }
}
