:root {
    --bg: #f6f6f7;
    --card: #ffffff;
    --text: #1c1c1e;
    --muted: #6b6b70;
    --border: #e4e4e7;
    --accent: #d7263d;
    --accent-dark: #ad1d30;
    --ok: #1b9c5a;
    --warn: #c98a00;
    --radius: 14px;
    --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

/* El atributo hidden debe ganarle a las reglas con display propio */
[hidden] { display: none !important; }

html, body {
    margin: 0;
    padding: 0;
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
}

a { color: var(--accent); }

/* ── Topbar ── */
.topbar {
    position: sticky;
    top: 0;
    z-index: 50;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    background: var(--card);
    border-bottom: 1px solid var(--border);
}
.topbar-info { flex: 1; min-width: 0; }
.topbar h1 {
    margin: 0;
    font-size: 1.05rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.topbar-horario { font-size: 0.72rem; color: var(--muted); text-align: right; }
.badge {
    display: inline-block;
    margin-top: 3px;
    padding: 2px 9px;
    border-radius: 999px;
    background: var(--accent);
    color: #fff;
    font-size: 0.68rem;
    font-weight: 700;
    letter-spacing: 0.05em;
    text-transform: uppercase;
}
.badge-soft { background: var(--muted); }
.btn-volver {
    text-decoration: none;
    font-size: 1.3rem;
    color: var(--text);
    padding: 0 6px;
}

/* ── Navegación de rubros ── */
.rubro-nav {
    position: sticky;
    top: 57px;
    z-index: 40;
    display: flex;
    gap: 8px;
    padding: 10px 12px;
    overflow-x: auto;
    background: var(--bg);
    scrollbar-width: none;
}
.rubro-nav::-webkit-scrollbar { display: none; }
.chip {
    flex: 0 0 auto;
    padding: 6px 14px;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--card);
    color: var(--muted);
    font-size: 0.76rem;
    font-weight: 600;
    text-decoration: none;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}
.chip:active { background: var(--accent); color: #fff; border-color: var(--accent); }

/* ── Contenido ── */
.contenido { padding: 8px 12px calc(96px + var(--safe-bottom)); max-width: 680px; margin: 0 auto; }
.contenido-form { padding-bottom: 32px; }
.rubro { margin-bottom: 26px; scroll-margin-top: 104px; }
.rubro-titulo {
    margin: 18px 0 4px;
    font-size: 1rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.1em;
}
.rubro-desc { margin: 0 0 10px; font-size: 0.8rem; color: var(--muted); }
.subrubro-titulo {
    margin: 16px 0 8px;
    font-size: 0.74rem;
    font-weight: 700;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--muted);
    text-align: center;
}

/* ── Producto ── */
.producto {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 14px;
    margin-bottom: 8px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}
.producto-info { flex: 1; min-width: 0; }
.producto-nombre { margin: 0 0 2px; font-size: 0.95rem; font-weight: 600; }
.producto-desc { margin: 0 0 4px; font-size: 0.78rem; color: var(--muted); line-height: 1.35; }
.producto-precio { font-size: 0.95rem; font-weight: 700; }
.tag-tacc {
    margin-left: 6px;
    padding: 1px 6px;
    border-radius: 4px;
    background: #eef7ee;
    color: var(--ok);
    font-size: 0.6rem;
    font-weight: 700;
    vertical-align: middle;
}
.producto-accion { position: relative; }
.btn-add {
    width: 42px;
    height: 42px;
    border: none;
    border-radius: 50%;
    background: var(--accent);
    color: #fff;
    font-size: 1.5rem;
    line-height: 1;
    cursor: pointer;
}
.btn-add:active { background: var(--accent-dark); }
.qty-badge {
    position: absolute;
    top: -6px;
    right: -4px;
    min-width: 20px;
    height: 20px;
    padding: 0 5px;
    border-radius: 999px;
    background: var(--text);
    color: #fff;
    font-size: 0.7rem;
    font-weight: 700;
    line-height: 20px;
    text-align: center;
}

/* ── Barra carrito ── */
.barra-carrito {
    position: fixed;
    left: 12px;
    right: 12px;
    bottom: calc(12px + var(--safe-bottom));
    z-index: 60;
    display: flex;
    align-items: center;
    gap: 10px;
    width: calc(100% - 24px);
    max-width: 656px;
    margin: 0 auto;
    padding: 14px 18px;
    border: none;
    border-radius: var(--radius);
    background: var(--accent);
    color: #fff;
    font-size: 0.95rem;
    font-weight: 700;
    box-shadow: 0 6px 20px rgba(0,0,0,0.18);
    cursor: pointer;
}
.barra-count {
    min-width: 26px;
    padding: 2px 7px;
    border-radius: 999px;
    background: rgba(255,255,255,0.22);
}
.barra-total { margin-left: auto; }

/* ── Panel carrito ── */
.panel-fondo {
    position: fixed;
    inset: 0;
    z-index: 70;
    background: rgba(0,0,0,0.45);
}
.panel-carrito {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    z-index: 80;
    display: flex;
    flex-direction: column;
    width: min(88vw, 400px);
    background: var(--card);
    border-left: 1px solid var(--border);
    border-radius: 18px 0 0 18px;
    box-shadow: -8px 0 28px rgba(0,0,0,0.18);
    animation: entrar-lateral 0.24s ease-out;
}
@keyframes entrar-lateral { from { transform: translateX(100%); } to { transform: translateX(0); } }
.panel-head {
    display: flex;
    align-items: center;
    padding: calc(14px + env(safe-area-inset-top, 0px)) 16px 14px;
    border-bottom: 1px solid var(--border);
}
.panel-head h2 { margin: 0; font-size: 1rem; font-weight: 700; }
.btn-cerrar {
    margin-left: auto;
    width: 34px;
    height: 34px;
    border: none;
    border-radius: 50%;
    background: var(--bg);
    font-size: 1.3rem;
    line-height: 1;
    cursor: pointer;
}
.panel-items { flex: 1; overflow-y: auto; padding: 8px 16px; }
.panel-linea {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 0;
    border-bottom: 1px solid var(--border);
}
.panel-linea-info { flex: 1; min-width: 0; }
.panel-linea-nom { font-size: 0.9rem; font-weight: 600; }
.panel-linea-precio { font-size: 0.78rem; color: var(--muted); }
.stepper { display: flex; align-items: center; gap: 8px; }
.stepper button {
    width: 30px;
    height: 30px;
    border: 1px solid var(--border);
    border-radius: 50%;
    background: var(--card);
    font-size: 1.05rem;
    line-height: 1;
    cursor: pointer;
}
.stepper span { min-width: 18px; text-align: center; font-weight: 700; }
.panel-linea-sub { min-width: 72px; text-align: right; font-weight: 700; font-size: 0.88rem; }
.panel-foot {
    padding: 14px 16px calc(16px + var(--safe-bottom));
    border-top: 1px solid var(--border);
}
.panel-total {
    display: flex;
    justify-content: space-between;
    margin-bottom: 12px;
    font-size: 1.05rem;
}

/* ── Botones y formularios ── */
.btn-primario, .btn-secundario {
    display: block;
    width: 100%;
    padding: 15px;
    margin-top: 8px;
    border: none;
    border-radius: var(--radius);
    font-size: 1rem;
    font-weight: 700;
    text-align: center;
    text-decoration: none;
    cursor: pointer;
}
.btn-primario { background: var(--accent); color: #fff; }
.btn-primario:active { background: var(--accent-dark); }
.btn-secundario { background: var(--bg); color: var(--text); border: 1px solid var(--border); }
.btn-danger { color: var(--accent); }
.btn-link {
    display: block;
    width: 100%;
    margin-top: 10px;
    border: none;
    background: none;
    color: var(--muted);
    font-size: 0.82rem;
    text-decoration: underline;
    cursor: pointer;
}

.card {
    padding: 16px;
    margin: 12px 0;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}
.card h2 { margin: 0 0 12px; font-size: 0.92rem; text-transform: uppercase; letter-spacing: 0.08em; }
label { display: block; margin: 12px 0 5px; font-size: 0.8rem; font-weight: 600; }
.opc { color: var(--muted); font-weight: 400; }
input[type=text], input[type=email], input[type=tel], textarea {
    width: 100%;
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: #fff;
    font-size: 16px;
    font-family: inherit;
}
input:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
input:user-invalid { border-color: var(--accent); }
.ayuda { margin: 6px 0 0; font-size: 0.75rem; color: var(--muted); line-height: 1.35; }
.error-campo { margin: 6px 0 0; font-size: 0.78rem; font-weight: 600; color: var(--accent); }

/* ── Detalle del pedido ── */
.detalle { list-style: none; margin: 0; padding: 0; }
.detalle li {
    display: flex;
    gap: 10px;
    padding: 8px 0;
    border-bottom: 1px solid var(--border);
    font-size: 0.88rem;
}
.det-cant { font-weight: 700; color: var(--muted); }
.det-nom { flex: 1; }
.det-nota { display: block; font-size: 0.75rem; color: var(--muted); }
.det-sub { font-weight: 700; }
.total-final {
    display: flex;
    justify-content: space-between;
    padding-top: 12px;
    font-size: 1.05rem;
}

/* ── Avisos ── */
.pantalla-centro {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 24px 16px;
}
.aviso { width: 100%; max-width: 440px; text-align: center; }
.aviso-icono { font-size: 3rem; margin-bottom: 8px; }
.aviso h1 { font-size: 1.25rem; margin: 0 0 8px; }
.aviso p { color: var(--muted); font-size: 0.9rem; margin: 0 0 12px; }
.estado-ok .aviso-icono { color: var(--ok); }
.estado-bad .aviso-icono { color: var(--accent); }
.estado-wait .aviso-icono { color: var(--warn); }
.card-resumen { text-align: left; }
.ref { font-size: 0.8rem; color: var(--muted); }
.monto-sim { font-size: 1.6rem; font-weight: 800; margin: 4px 0 12px; }
.nota-simulacion { margin-top: 10px; font-size: 0.75rem; color: var(--warn); text-align: center; }

.alerta {
    margin: 12px;
    padding: 12px 14px;
    border-radius: 10px;
    background: #fff7e6;
    border: 1px solid #f0d9a8;
    font-size: 0.85rem;
}
.alerta-error { background: #fdecee; border-color: #f3c3c9; color: var(--accent-dark); }
.vacio { text-align: center; color: var(--muted); padding: 32px 12px; }

/* ── Notificaciones propias ── */
.toast-stack {
    position: fixed;
    left: 12px;
    right: 12px;
    top: calc(12px + env(safe-area-inset-top, 0px));
    z-index: 200;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    pointer-events: none;
}
.toast {
    max-width: 420px;
    width: fit-content;
    padding: 11px 16px;
    border-radius: 999px;
    background: var(--text);
    color: #fff;
    font-size: 0.85rem;
    font-weight: 600;
    text-align: center;
    box-shadow: 0 6px 18px rgba(0,0,0,0.22);
    animation: toast-in 0.2s ease-out;
}
.toast.saliendo { animation: toast-out 0.25s ease-in forwards; }
.toast-ok { background: var(--ok); }
.toast-error { background: var(--accent); }
@keyframes toast-in { from { opacity: 0; transform: translateY(-10px); } to { opacity: 1; transform: none; } }
@keyframes toast-out { to { opacity: 0; transform: translateY(-10px); } }

/* ── Confirmación ── */
.modal-fondo {
    position: fixed;
    inset: 0;
    z-index: 150;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background: rgba(0,0,0,0.45);
}
.modal-caja {
    width: 100%;
    max-width: 340px;
    padding: 20px;
    border-radius: var(--radius);
    background: var(--card);
    text-align: center;
    animation: toast-in 0.18s ease-out;
}
.modal-caja p { margin: 0 0 14px; font-size: 0.95rem; }
.modal-acciones { display: flex; gap: 10px; }
.modal-acciones button { flex: 1; margin-top: 0; }

@media (min-width: 720px) {
    .producto-nombre { font-size: 1rem; }
    .panel-carrito { width: 420px; }
}
