:root {
  --bg: #dde3eb;
  --surface: #ffffff;
  --brand-yellow: #f7e033;
  --brand-green: #8fd400;
  --brand-navy: #1a2480;
  --text: #121620;
  --muted: #5f6d7e;
  --border: #d4dce6;
  --header-bg: #0b0b0b;
  --tile-bg: #ffffff;
  --tile-hover: #f5fae8;
  --shadow: 0 8px 32px rgba(18, 30, 50, 0.12);
  --shell-max: 480px;
  --drawer-w: 400px;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: "Segoe UI", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
}
body.cart-open { overflow: hidden; }

.app-shell {
  max-width: var(--shell-max);
  margin: 0 auto;
  min-height: 100dvh;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}
.hidden { display: none !important; }

/* Header */
.app-header {
  background: var(--header-bg);
  padding: 0.75rem 1rem 1rem;
}
.header-bar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.5rem;
}
.profile-fields {
  flex: 1;
  display: grid;
  gap: 0.4rem;
  min-width: 0;
  max-width: 220px;
}
.profile-fields input {
  width: 100%;
  padding: 0.45rem 0.6rem;
  border-radius: 8px;
  border: 1px solid #333;
  background: #161616;
  color: #f0f0f0;
  font-size: 0.9rem;
}
.profile-fields input::placeholder { color: #888; }
.profile-fields input.input-readonly {
  opacity: 0.85;
  cursor: default;
}
.profile-banner {
  margin-top: 0.5rem;
  padding: 0.55rem 0.65rem;
  border-radius: 8px;
  font-size: 0.82rem;
  line-height: 1.35;
  max-width: 100%;
}
.profile-banner--welcome {
  background: rgba(143, 212, 0, 0.15);
  border: 1px solid rgba(143, 212, 0, 0.45);
  color: #d5de8a;
}
.profile-banner--register {
  background: rgba(247, 224, 51, 0.12);
  border: 1px solid rgba(247, 224, 51, 0.35);
  color: #f7e033;
}
.profile-banner--error {
  background: rgba(224, 82, 82, 0.12);
  border: 1px solid rgba(224, 82, 82, 0.35);
  color: #ffb4b4;
}
.pending-order-bar {
  margin-top: 0.5rem;
  padding: 0.65rem;
  border-radius: 10px;
  background: rgba(247, 224, 51, 0.14);
  border: 1px solid rgba(247, 224, 51, 0.45);
}
.pending-order-bar p {
  margin: 0 0 0.55rem;
  font-size: 0.82rem;
  line-height: 1.35;
  color: #f7e033;
}
.pending-order-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.45rem;
}
.pending-order-btn {
  width: 100%;
  padding: 0.5rem 0.55rem;
  border-radius: 8px;
  border: none;
  font-size: 0.78rem;
  font-weight: 700;
  cursor: pointer;
  background: var(--brand-green);
  color: #102010;
}
.pending-order-btn--muted {
  background: #2a2a2a;
  color: #ccc;
  border: 1px solid #444;
}
.cli-tel-display {
  margin: 0;
  font-size: 0.82rem;
  color: #b8c4d4;
  letter-spacing: 0.02em;
}
.link-btn {
  justify-self: start;
  margin: -0.15rem 0 0.1rem;
  padding: 0;
  border: none;
  background: none;
  color: #8fd400;
  font-size: 0.75rem;
  text-decoration: underline;
  cursor: pointer;
  width: auto;
}
.profile-fields input.profile-input--needed {
  border-color: #f7e033;
  box-shadow: 0 0 0 1px rgba(247, 224, 51, 0.35);
}
.brand-logo {
  display: block;
  width: min(200px, 70vw);
  height: auto;
  margin: 0 auto;
}
.cart-btn {
  position: relative;
  flex-shrink: 0;
  width: 48px;
  height: 48px;
  border: none;
  border-radius: 12px;
  background: #1a1a1a;
  cursor: pointer;
  display: grid;
  place-items: center;
  padding: 0;
}
.cart-btn img { display: block; opacity: 0.92; }
.cart-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  min-width: 20px;
  height: 20px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--brand-green);
  color: #102010;
  font-size: 0.72rem;
  font-weight: 800;
  line-height: 20px;
  text-align: center;
  transition: transform 0.2s ease;
}
.cart-btn.cart-pulse {
  animation: cartPulse 0.45s ease;
}
.cart-badge.badge-pop {
  animation: badgePop 0.45s ease;
}
@keyframes cartPulse {
  0%, 100% { transform: scale(1); }
  40% { transform: scale(1.12); }
}
@keyframes badgePop {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.35); }
}

/* Fly-to-cart (móvil) */
.fly-to-cart {
  position: fixed;
  z-index: 500;
  width: 28px;
  height: 28px;
  border-radius: 999px;
  background: var(--brand-green);
  color: #102010;
  font-size: 0.72rem;
  font-weight: 800;
  display: grid;
  place-items: center;
  pointer-events: none;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
}
.btn-add--hit {
  transform: scale(0.88);
  transition: transform 0.15s ease;
}
.btn-add {
  transition: transform 0.15s ease;
}

/* Toast discreto (desktop) — removed: mismo flujo que móvil */

/* Search */
.search-wrap {
  padding: 0.75rem 1rem;
  background: var(--header-bg);
  border-bottom: 3px solid var(--brand-green);
}
.search-wrap input {
  width: 100%;
  padding: 0.75rem 1rem;
  border: none;
  border-radius: 10px;
  font-size: 1rem;
  background: var(--surface);
}

/* Main */
.app-main {
  padding: 1rem;
}
.section-title {
  margin: 0 0 0.75rem;
  font-size: 0.85rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}
.back-btn {
  width: auto;
  background: none;
  border: none;
  color: var(--brand-navy);
  font-weight: 600;
  padding: 0;
  margin-bottom: 0.5rem;
  cursor: pointer;
  font-size: 0.95rem;
}

/* Tiendas grid */
.tiendas-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.65rem;
}
.tienda-tile {
  appearance: none;
  width: 100%;
  border: 2px solid var(--border);
  border-radius: 12px;
  background: var(--tile-bg);
  padding: 1.1rem 0.75rem;
  min-height: 72px;
  font-size: 0.82rem;
  font-weight: 800;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  text-align: center;
  color: var(--brand-navy);
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(18, 30, 50, 0.06);
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
  line-height: 1.25;
}
.tienda-tile:active { transform: scale(0.98); }
.tienda-tile:hover,
.tienda-tile:focus-visible {
  background: var(--tile-hover);
  border-color: var(--brand-green);
  outline: none;
}
.tienda-tile .tile-count {
  display: block;
  margin-top: 0.35rem;
  font-size: 0.7rem;
  font-weight: 500;
  color: var(--muted);
  text-transform: none;
  letter-spacing: 0;
}

/* Productos */
.productos-list { display: flex; flex-direction: column; gap: 0.5rem; }
.producto-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 0.4rem 0.5rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.65rem 0.75rem;
}
.producto-row--invalid {
  border-color: #e05252;
  box-shadow: 0 0 0 2px rgba(224, 82, 82, 0.15);
}
.producto-row .info {
  min-width: 0;
}
.producto-row strong {
  display: block;
  font-size: 0.95rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.producto-row .meta {
  font-size: 0.8rem;
  color: var(--muted);
}
.producto-row .precio {
  font-weight: 700;
  color: var(--brand-navy);
  white-space: nowrap;
  font-size: 0.88rem;
  text-align: left;
  padding-right: 0.15rem;
}
.producto-actions {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  flex-shrink: 0;
}
.qty-input {
  width: 3.1rem;
  padding: 0.35rem 0.25rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.88rem;
  text-align: center;
  font-variant-numeric: tabular-nums;
}
.qty-input:focus {
  outline: none;
  border-color: var(--brand-green);
  box-shadow: 0 0 0 2px rgba(143, 212, 0, 0.25);
}
.producto-row--invalid .qty-input {
  border-color: #e05252;
}
.btn-add {
  width: 36px;
  height: 36px;
  flex-shrink: 0;
  border: none;
  border-radius: 10px;
  background: var(--brand-green);
  color: #102010;
  cursor: pointer;
  padding: 0;
  display: grid;
  place-items: center;
}
.btn-add-icon {
  display: block;
  pointer-events: none;
}
.empty-msg {
  text-align: center;
  color: var(--muted);
  padding: 2rem 1rem;
  font-size: 0.95rem;
}

/* Cart drawer — siempre flotante, nunca en el flujo del documento */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  z-index: 200;
}
.cart-drawer {
  position: fixed;
  top: 0;
  right: 0;
  width: min(var(--drawer-w), 100vw);
  max-width: 100vw;
  height: 100dvh;
  background: var(--surface);
  z-index: 300;
  display: flex;
  flex-direction: column;
  box-shadow: -8px 0 32px rgba(0, 0, 0, 0.2);
  transform: translateX(105%);
  visibility: hidden;
  pointer-events: none;
  transition: transform 0.25s ease, visibility 0.25s;
  overflow: hidden;
}
.cart-drawer.open {
  transform: translateX(0);
  visibility: visible;
  pointer-events: auto;
}
.drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem;
  border-bottom: 1px solid var(--border);
  background: var(--header-bg);
  color: #fff;
  flex-shrink: 0;
}
.drawer-head h2 { margin: 0; font-size: 1.1rem; }
.drawer-head-actions {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}
.icon-btn {
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 8px;
  background: #222;
  color: #ccc;
  font-size: 1rem;
  cursor: pointer;
  padding: 0;
  flex-shrink: 0;
  display: grid;
  place-items: center;
}
.icon-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}
.icon-btn--danger {
  color: #ff8a8a;
}
.icon-btn--danger:not(:disabled):hover {
  background: #3a1a1a;
}
.icon-trash {
  display: block;
  pointer-events: none;
}
.cart-dialog {
  position: absolute;
  inset: 0;
  z-index: 20;
  background: rgba(0, 0, 0, 0.55);
  display: grid;
  place-items: center;
  padding: 1rem;
}
.cart-dialog-panel {
  background: var(--surface);
  border-radius: 14px;
  padding: 1.25rem 1rem 1rem;
  width: min(100%, 300px);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.25);
  text-align: center;
}
.cart-dialog-panel p {
  margin: 0 0 1.1rem;
  font-size: 0.95rem;
  line-height: 1.45;
  color: var(--text);
}
.cart-dialog-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.6rem;
}
.dialog-btn {
  width: 100%;
  padding: 0.65rem 0.75rem;
  border-radius: 10px;
  border: none;
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
}
.dialog-btn--danger {
  background: #e05252;
  color: #fff;
}
.dialog-btn--muted {
  background: #eef1f5;
  color: var(--brand-navy);
  border: 1px solid var(--border);
}
.drawer-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}
.drawer-body {
  padding: 0.75rem 1rem;
}
.drawer-footer {
  flex-shrink: 0;
  padding: 0.75rem 1rem 1.25rem;
  border-top: 1px solid var(--border);
  background: #f8fafc;
  box-shadow: 0 -4px 16px rgba(18, 30, 50, 0.06);
}
.drawer-footer label {
  display: block;
  font-size: 0.78rem;
  color: var(--muted);
  margin: 0.5rem 0 0.25rem;
}
.drawer-footer select {
  width: 100%;
  padding: 0.6rem 0.7rem;
  border-radius: 10px;
  border: 1px solid var(--border);
  font-size: 0.95rem;
}
.drawer-footer .total {
  margin: 0;
  padding: 0;
  border-top: none;
}
button#btn-checkout {
  width: 100%;
  margin-top: 0.75rem;
  padding: 0.65rem 0.7rem;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--brand-green), #6fb800);
  color: #102010;
  border: none;
  font-weight: 700;
  font-size: 0.95rem;
  cursor: pointer;
}
.cart-group {
  margin-bottom: 1rem;
}
.cart-group:last-child {
  margin-bottom: 0;
}
.cart-group-title {
  margin: 0 0 0.35rem;
  font-size: 0.92rem;
  font-weight: 700;
  color: var(--text);
  padding-bottom: 0.25rem;
  border-bottom: 1px solid var(--border);
}
.cart-item {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  padding: 0.55rem 0;
  border-bottom: 1px solid var(--border);
}
.cart-group .cart-item:last-child {
  border-bottom: none;
}
.cart-item-body {
  flex: 1;
  min-width: 0;
}
.cart-item-name {
  font-size: 0.9rem;
  font-weight: 600;
  line-height: 1.3;
  margin-bottom: 0.2rem;
}
.cart-item-line {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  font-size: 0.82rem;
  color: var(--muted);
}
.cart-qty-wrap {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  flex: 1;
  min-width: 0;
  flex-wrap: wrap;
}
.cart-qty-stepper {
  display: inline-flex;
  align-items: center;
  gap: 0.2rem;
  flex-shrink: 0;
}
.qty-step-btn {
  width: 28px;
  height: 28px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #f4f7fb;
  color: var(--brand-navy);
  font-size: 1rem;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  padding: 0;
  flex-shrink: 0;
}
.qty-step-btn:active {
  transform: scale(0.94);
  background: #e8eef5;
}
.cart-qty-input {
  width: 3rem;
}
.cart-qty-unit {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--muted);
}
.cart-unit-price {
  font-size: 0.78rem;
  white-space: nowrap;
}
.cart-item--invalid {
  background: rgba(224, 82, 82, 0.06);
  border-radius: 8px;
  margin: 0 -0.25rem;
  padding-left: 0.25rem;
  padding-right: 0.25rem;
}
.cart-item--invalid .cart-qty-input {
  border-color: #e05252;
}
.cart-item-qty {
  flex: 1;
  min-width: 0;
}
.cart-item-sub {
  font-weight: 700;
  color: var(--text);
  white-space: nowrap;
  font-size: 0.9rem;
}
.cart-item .info { flex: 1; min-width: 0; }
.cart-item strong { font-size: 0.9rem; }
.cart-item .meta { font-size: 0.78rem; color: var(--muted); }
.cart-item .sub { font-weight: 700; white-space: nowrap; font-size: 0.9rem; }
.btn-remove {
  width: 32px;
  height: 32px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  color: var(--muted);
  cursor: pointer;
  font-size: 0.85rem;
  padding: 0;
  flex-shrink: 0;
}
.total {
  margin: 0;
  padding: 0.75rem 1rem;
  font-size: 1.15rem;
  font-weight: 800;
  color: var(--brand-navy);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}
.drawer-checkout {
  padding: 0 1rem 1rem;
  background: #f8fafc;
}
.drawer-checkout h3 {
  margin: 0 0 0.5rem;
  padding-top: 0.5rem;
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}
.drawer-checkout label {
  display: block;
  font-size: 0.78rem;
  color: var(--muted);
  margin: 0.5rem 0 0.25rem;
}
.drawer-checkout input,
.drawer-checkout select {
  width: 100%;
  padding: 0.6rem 0.7rem;
  border-radius: 10px;
  border: 1px solid var(--border);
  font-size: 0.95rem;
}
.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
}
.dir-form .dir-field label,
.dir-form > label {
  display: block;
  font-size: 0.78rem;
  color: var(--muted);
  margin: 0.5rem 0 0.25rem;
}
.dir-form > label:first-child {
  margin-top: 0;
}
.dir-grid {
  margin-top: 0.15rem;
}
.dir-span-2 {
  grid-column: 1 / -1;
}
.dir-map-section {
  margin-top: 0.65rem;
}
.dir-map-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.35rem;
  font-size: 0.78rem;
  color: var(--muted);
}
.map-link-btn {
  border: none;
  background: none;
  padding: 0;
  color: var(--brand-navy);
  font-size: 0.75rem;
  font-weight: 600;
  text-decoration: underline;
  cursor: pointer;
  white-space: nowrap;
}
.dir-map {
  width: 100%;
  height: 180px;
  border-radius: 10px;
  border: 1px solid var(--border);
  overflow: hidden;
  z-index: 0;
}
.dir-map .leaflet-control-attribution {
  font-size: 0.62rem;
}

.wa-choice-overlay {
  position: fixed;
  inset: 0;
  z-index: 400;
  background: rgba(0, 0, 0, 0.55);
  display: grid;
  place-items: center;
  padding: 1rem;
}
.wa-choice-panel {
  background: var(--surface);
  border-radius: 16px;
  padding: 1.25rem 1rem 1rem;
  width: min(100%, 320px);
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.28);
  text-align: center;
}
.wa-choice-panel h3 {
  margin: 0 0 0.35rem;
  font-size: 1.05rem;
  color: var(--brand-navy);
}
.wa-choice-hint {
  margin: 0 0 1rem;
  font-size: 0.88rem;
  color: var(--muted);
  line-height: 1.4;
}
.wa-choice-actions {
  display: grid;
  gap: 0.55rem;
}
.wa-choice-btn {
  display: block;
  width: 100%;
  padding: 0.75rem 1rem;
  border-radius: 12px;
  font-weight: 700;
  font-size: 0.95rem;
  text-decoration: none;
  color: #102010;
}
.wa-choice-btn--personal {
  background: linear-gradient(135deg, #25d366, #128c7e);
  color: #fff;
}
.wa-choice-btn--business {
  background: linear-gradient(135deg, #25d366, #075e54);
  color: #fff;
}
.wa-choice-fallback {
  display: inline-block;
  margin-top: 0.85rem;
  font-size: 0.8rem;
  color: var(--brand-navy);
}
.wa-choice-close {
  margin-top: 0.65rem;
  border: none;
  background: none;
  color: var(--muted);
  font-size: 0.85rem;
  cursor: pointer;
  text-decoration: underline;
}
.error-msg {
  margin: 0.5rem 0 0;
  color: #b42318;
  font-size: 0.85rem;
  min-height: 1.2em;
}
.badge {
  display: inline-block;
  background: #eef8dc;
  color: var(--brand-navy);
  padding: 0.05rem 0.4rem;
  border-radius: 999px;
  font-size: 0.68rem;
  font-weight: 600;
}
.dir-option {
  display: flex;
  gap: 0.5rem;
  align-items: flex-start;
  margin: 0.35rem 0;
  font-size: 0.88rem;
}
.dir-option input { width: auto; margin-top: 0.2rem; }

/* Desktop: misma columna que móvil, centrada; drawer pegado a la app */
@media (min-width: 600px) {
  body {
    display: flex;
    justify-content: center;
    background: var(--bg);
  }
  .app-shell {
    width: 100%;
    max-width: var(--shell-max);
    min-height: 100dvh;
    position: relative;
  }
  .cart-drawer {
    right: max(0px, calc((100vw - var(--shell-max)) / 2));
    width: min(var(--drawer-w), var(--shell-max));
  }
}

@media (min-width: 900px) {
  :root { --drawer-w: 400px; }
}

@media (max-width: 380px) {
  .tiendas-grid { grid-template-columns: 1fr; }
  .grid-2 { grid-template-columns: 1fr; }
}
