/* The Craving Spot — Pedido por WhatsApp (v3.1)
   Página pública de pedidos. Usa los tokens de style.css (:root) para verse
   igual que el resto de la plataforma. Mobile-first.                       */

html { scroll-behavior: smooth; }
html.pd-lock, html.pd-lock body { overflow: hidden; }

body.pedido { min-height: 100vh; }

.pd-sr {
    position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0;
    overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

.pedido :focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

/* ===== Encabezado ===== */
.pd-header {
    max-width: 1100px;
    margin: 0 auto;
    padding: max(22px, env(safe-area-inset-top, 0px)) 16px 10px;
}
.pd-brand { display: flex; align-items: center; gap: 12px; }
.pd-logo {
    width: 52px; height: 52px; flex: none;
    border-radius: 50%; object-fit: cover;
    box-shadow: 0 0 0 3px var(--bg-card), var(--shadow-md);
}
.pd-title { margin: 0; font-size: 23px; line-height: 1.1; letter-spacing: -0.015em; }
.pd-sub { margin: 3px 0 0; font-size: 14px; color: var(--text-soft); }

.pd-steps {
    list-style: none;
    display: flex; flex-wrap: wrap; gap: 6px;
    margin: 16px 0 0; padding: 0;
    font-size: 12.5px; color: var(--text-soft);
}
.pd-steps li {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 6px 11px 6px 6px;
    border-radius: 999px;
    background: var(--bg-soft);
}
.pd-steps b {
    display: inline-grid; place-items: center;
    width: 19px; height: 19px; border-radius: 50%;
    background: var(--primary); color: #fff; font-size: 11px;
}

/* ===== Categorías (fijas al hacer scroll) ===== */
.pd-cats {
    position: sticky; top: 0; z-index: 20;
    background: rgba(250, 246, 240, 0.94);
    -webkit-backdrop-filter: saturate(1.4) blur(10px);
    backdrop-filter: saturate(1.4) blur(10px);
    border-bottom: 1px solid var(--border);
}
.pd-cats-inner {
    display: flex; gap: 8px;
    max-width: 1100px; margin: 0 auto;
    padding: 10px 16px;
    overflow-x: auto;
    scrollbar-width: none;
}
.pd-cats-inner::-webkit-scrollbar { display: none; }
.pd-chip {
    flex: none;
    padding: 8px 15px;
    border: 1px solid var(--border); border-radius: 999px;
    background: var(--bg-card); color: var(--text);
    font-size: 14px; font-weight: 600; white-space: nowrap;
    transition: background 0.2s, color 0.2s, border-color 0.2s;
}
.pd-chip.is-active { background: var(--text); border-color: var(--text); color: #fff; }

/* ===== Menú ===== */
.pd-main {
    max-width: 1100px;
    margin: 0 auto;
    padding: 4px 16px calc(112px + var(--safe-bottom));
}
.pd-section { padding-top: 16px; scroll-margin-top: 62px; }
.pd-section-title { margin: 4px 0 12px; font-size: 19px; letter-spacing: -0.01em; }

.pd-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
@media (min-width: 640px) { .pd-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; } }
@media (min-width: 980px) { .pd-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); } }

/* ===== Tarjeta de producto ===== */
.pd-card {
    display: flex; flex-direction: column;
    overflow: hidden;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    transition: border-color 0.2s, box-shadow 0.2s;
}
.pd-card.in-cart { border-color: var(--primary); box-shadow: 0 0 0 1px var(--primary), var(--shadow-md); }

.pd-media {
    position: relative;
    aspect-ratio: 1 / 1;
    display: grid; place-items: center;
    background: var(--bg-soft);
}
.pd-media img { width: 100%; height: 100%; object-fit: cover; display: block; }
.pd-initial,
.pd-noimg::before { font-size: 46px; font-weight: 700; color: var(--accent); }
.pd-noimg::before { content: attr(data-initial); } /* la foto no cargó */
.pd-badge {
    position: absolute; top: 8px; left: 8px;
    padding: 4px 10px; border-radius: 999px;
    background: var(--text); color: #fff;
    font-size: 12px; font-weight: 700;
}
.pd-card.is-soldout .pd-media img,
.pd-card.is-soldout .pd-initial,
.pd-card.is-soldout .pd-noimg::before { filter: grayscale(1); opacity: 0.5; }

.pd-body { flex: 1; display: flex; flex-direction: column; gap: 4px; padding: 10px 10px 12px; }
.pd-name {
    margin: 0;
    font-size: 15px; line-height: 1.25; font-weight: 650;
    display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.pd-price {
    margin: auto 0 8px; padding-top: 4px;
    font-size: 17px; font-weight: 750; color: var(--primary-dark);
    font-variant-numeric: tabular-nums;
}

.pd-add {
    width: 100%; min-height: 44px;
    border: 0; border-radius: var(--radius-sm);
    background: var(--primary); color: #fff;
    font-size: 15px; font-weight: 700;
    transition: background 0.15s, transform 0.1s;
}
.pd-add:active { background: var(--primary-dark); transform: scale(0.97); }
.pd-add:disabled { background: var(--bg-soft); color: var(--text-soft); cursor: not-allowed; transform: none; }

.pd-step {
    display: grid; grid-template-columns: 44px 1fr 44px; align-items: center;
    min-height: 44px;
    border-radius: var(--radius-sm);
    background: var(--bg-soft);
    overflow: hidden;
}
.pd-step button {
    height: 44px; border: 0; background: transparent;
    font-size: 22px; font-weight: 600; line-height: 1;
    color: var(--primary-dark);
}
.pd-step button:active { background: var(--border); }
.pd-qty { text-align: center; font-size: 16px; font-weight: 750; font-variant-numeric: tabular-nums; }

/* ===== Estados vacíos / pie ===== */
.pd-empty-state { text-align: center; padding: 48px 12px; color: var(--text-soft); line-height: 1.5; }
.pd-empty-state p { margin: 0 0 18px; }
.pd-foot {
    display: flex; flex-wrap: wrap; justify-content: center; gap: 6px 14px;
    padding: 28px 0 0; font-size: 12px; color: var(--text-soft);
}
.pd-foot a { color: var(--text-soft); text-decoration: underline; }

/* ===== Barra inferior ===== */
.pd-bar {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
    padding: 14px 16px calc(12px + var(--safe-bottom));
    background: linear-gradient(to top, var(--bg) 62%, rgba(250, 246, 240, 0));
    animation: pd-up 0.25s ease-out;
}
.pd-bar-btn {
    display: flex; align-items: center; gap: 12px;
    width: 100%; max-width: 560px; min-height: 56px;
    margin: 0 auto; padding: 0 18px;
    border: 0; border-radius: 16px;
    background: var(--text); color: #fff;
    font-size: 16px; font-weight: 700;
    box-shadow: var(--shadow-lg);
}
.pd-bar-btn:active { transform: scale(0.99); }
.pd-bar-count {
    display: inline-grid; place-items: center;
    min-width: 28px; height: 28px; padding: 0 8px;
    border-radius: 999px;
    background: var(--accent); color: var(--text);
    font-size: 14px; font-variant-numeric: tabular-nums;
}
.pd-bar-label { flex: 1; text-align: left; }
.pd-bar-total { font-variant-numeric: tabular-nums; }
.pd-bump { animation: pd-bump 0.3s ease-out; }

/* ===== Hoja del pedido ===== */
.pd-backdrop {
    position: fixed; inset: 0; z-index: 60;
    background: rgba(61, 40, 23, 0.45);
    animation: pd-fade 0.2s ease-out;
}
.pd-sheet {
    position: fixed; z-index: 70; left: 0; right: 0; bottom: 0;
    max-height: 92vh; max-height: 92dvh;
    display: flex; flex-direction: column;
    background: var(--bg);
    border-radius: 22px 22px 0 0;
    box-shadow: var(--shadow-lg);
    animation: pd-up 0.28s cubic-bezier(0.2, 0.8, 0.2, 1);
}
@media (min-width: 768px) {
    .pd-sheet {
        top: 0; left: auto; width: 420px;
        max-height: none; border-radius: 0;
        animation-name: pd-left;
    }
}
.pd-pane { display: flex; flex-direction: column; min-height: 0; flex: 1; }

.pd-sheet-head {
    display: flex; align-items: center; justify-content: space-between;
    padding: 18px 16px 6px;
}
.pd-sheet-head h2 { margin: 0; font-size: 21px; }
.pd-close {
    width: 40px; height: 40px;
    border: 0; border-radius: 50%;
    background: var(--bg-soft); color: var(--text); font-size: 17px;
}
.pd-sheet-body { flex: 1; min-height: 0; overflow-y: auto; padding: 0 16px 14px; -webkit-overflow-scrolling: touch; }

.pd-line {
    display: grid; grid-template-columns: 1fr auto;
    gap: 8px 12px; align-items: center;
    padding: 12px 0;
    border-bottom: 1px solid var(--border);
}
.pd-line-name { font-size: 15px; font-weight: 650; line-height: 1.25; }
.pd-line-unit { margin-top: 2px; font-size: 13px; color: var(--text-soft); }
.pd-line-total { text-align: right; font-weight: 750; font-variant-numeric: tabular-nums; }
.pd-line .pd-step { width: 128px; min-height: 38px; grid-template-columns: 38px 1fr 38px; }
.pd-line .pd-step button { height: 38px; font-size: 20px; }
.pd-line-del {
    justify-self: end;
    padding: 8px 4px; border: 0; background: none;
    color: var(--text-soft); font-size: 13px; text-decoration: underline;
}
.pd-empty { margin: 0; padding: 28px 0; text-align: center; color: var(--text-soft); }

.pd-total {
    display: flex; justify-content: space-between; align-items: baseline;
    padding: 14px 0 4px; font-size: 17px;
}
.pd-total strong { font-size: 23px; font-variant-numeric: tabular-nums; }

.pd-field { display: block; margin-top: 14px; font-size: 14px; font-weight: 650; }
.pd-field span { font-weight: 400; color: var(--text-soft); }
.pd-field input,
.pd-field textarea {
    display: block; width: 100%;
    margin-top: 6px; padding: 12px 14px;
    font: inherit; font-size: 16px; /* 16px evita el zoom automático de iOS */
    color: var(--text);
    background: var(--bg-card);
    border: 1px solid var(--border); border-radius: var(--radius-sm);
}
.pd-field textarea { min-height: 66px; resize: vertical; }
.pd-field input:focus,
.pd-field textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(139, 111, 71, 0.18); }
.pd-hint { margin: 14px 0 0; font-size: 13px; line-height: 1.45; color: var(--text-soft); }

.pd-sheet-foot {
    padding: 12px 16px calc(12px + var(--safe-bottom));
    border-top: 1px solid var(--border);
    background: var(--bg);
}

/* Botón de WhatsApp: verde oscuro para que el texto blanco se lea bien (contraste AA) */
.pd-send {
    display: flex; align-items: center; justify-content: center; gap: 10px;
    width: 100%; min-height: 56px; padding: 0 16px;
    border-radius: 16px;
    background: #15803D; color: #fff;
    font-size: 17px; font-weight: 750; text-decoration: none;
    box-shadow: 0 6px 18px rgba(21, 128, 61, 0.28);
    transition: background 0.15s, transform 0.1s;
}
.pd-send:active { background: #166534; transform: scale(0.99); }
.pd-send[aria-disabled="true"] { opacity: 0.45; pointer-events: none; }
.pd-send-inline { display: inline-flex; width: auto; padding: 0 24px; }

/* Estado "enviado" */
.pd-sent {
    justify-content: center; text-align: center;
    padding: 30px 20px calc(22px + var(--safe-bottom));
}
.pd-sent-ico {
    display: grid; place-items: center;
    width: 66px; height: 66px; margin: 0 auto 14px;
    border-radius: 50%;
    background: #DCFCE7; color: #15803D;
    font-size: 32px; font-weight: 700;
}
.pd-sent h2 { margin: 0 0 8px; font-size: 21px; line-height: 1.25; }
.pd-sent p { margin: 0 0 20px; line-height: 1.5; color: var(--text-soft); }
.pd-new {
    width: 100%; min-height: 52px; margin-top: 10px;
    border: 0; border-radius: 16px;
    background: var(--text); color: #fff;
    font-size: 16px; font-weight: 700;
}
.pd-retry {
    display: flex; align-items: center; justify-content: center;
    min-height: 50px; padding: 0 16px;
    border: 2px solid #15803D; border-radius: 16px;
    color: #15803D; font-size: 15px; font-weight: 700; text-decoration: none;
}
.pd-link-btn {
    margin-top: 6px; padding: 12px;
    border: 0; background: none;
    color: var(--primary-dark); font-size: 15px; font-weight: 600; text-decoration: underline;
}

/* El aviso flota arriba de la barra inferior */
.pedido .toast {
    bottom: calc(96px + var(--safe-bottom));
    max-width: calc(100% - 32px);
    text-align: center;
}

@keyframes pd-up { from { transform: translateY(100%); } to { transform: none; } }
@keyframes pd-left { from { transform: translateX(100%); } to { transform: none; } }
@keyframes pd-fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes pd-bump { 50% { transform: scale(1.2); } }

@media (prefers-reduced-motion: reduce) {
    html { scroll-behavior: auto; }
    .pd-bar, .pd-sheet, .pd-backdrop, .pd-bump { animation: none; }
    .pd-add, .pd-send, .pd-chip, .pd-card { transition: none; }
}
