/* Estilo de la despensa. Recortado de accesorios/style.css: variables, header,
   tarjetas, formulario, encabezados de categoría (aquí tiendas y secciones),
   botones ✓ y ✕, total fijo abajo y toast. Fuera fundas, micas y analytics. */

/* ========== Variables ========== */
:root {
    --primary: #023265;
    --primary-hover: #0056b3;
    --primary-light: #e8f0fb;
    --success: #27ae60;
    --success-light: #eaf7ef;
    --danger: #e74c3c;
    --danger-dark: #c0392b;
    --warning: #b9770e;
    --bg: #f9f9f9;
    --surface: #ffffff;
    --text: #333333;
    --text-muted: #888888;
    --border: #e8e8e8;
    --shadow-sm: 0 2px 8px rgba(2, 50, 101, 0.07);
    --shadow: 0 4px 16px rgba(2, 50, 101, 0.1);
    --radius: 14px;
    --radius-sm: 8px;
    --section-gap: 40px;
}

/* ========== Reset & Base ========== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: 'Inter', 'Segoe UI', sans-serif;
    font-weight: 400;
    background-color: var(--bg);
    color: var(--text);
    padding-bottom: 90px;
    min-height: 100vh;
    -webkit-tap-highlight-color: transparent;
}

[hidden] { display: none !important; }

/* ========== Header sticky glassmorphism ========== */
header {
    position: sticky;
    top: 0;
    z-index: 100;
    background: rgba(255, 255, 255, 0.82);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid rgba(0, 0, 0, 0.06);
    padding: 14px 18px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

header h1 {
    font-family: 'Playfair Display', Georgia, serif;
    font-size: clamp(1.2em, 3vw, 1.8em);
    font-weight: 700;
    color: var(--primary);
    letter-spacing: -0.3px;
}

.header-subtitle {
    font-size: 0.8em;
    color: var(--text-muted);
    margin-top: 2px;
}

.header-link {
    color: var(--primary);
    text-decoration: none;
    font-size: 0.88em;
    font-weight: 600;
    border: 1.5px solid var(--primary);
    padding: 7px 16px;
    border-radius: 50px;
    transition: all 0.2s ease;
    white-space: nowrap;
}

.header-link:hover { background: var(--primary); color: white; }

/* ========== Layout ========== */
.container {
    max-width: 720px;
    margin: 0 auto;
    padding: 24px 18px;
}

.vacio {
    text-align: center;
    color: var(--text-muted);
    font-size: 0.9em;
    padding: 14px 0 4px;
}

/* ========== Card (formularios y avisos) ========== */
.card {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 24px 20px;
    box-shadow: var(--shadow);
    margin-bottom: 24px;
    border: 1px solid var(--border);
}

.card h2 {
    font-family: 'Playfair Display', Georgia, serif;
    font-size: 1.25em;
    color: var(--primary);
    margin-bottom: 16px;
}

/* ========== Formulario ========== */
label {
    font-size: 0.78em;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.7px;
    display: block;
    margin-bottom: 6px;
    margin-top: 16px;
}

label:first-of-type { margin-top: 0; }

input[type="text"],
input[type="number"],
input[type="search"],
select {
    width: 100%;
    padding: 12px 16px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 16px; /* Evita zoom en iOS */
    font-family: inherit;
    background-color: var(--bg);
    color: var(--text);
    transition: border-color 0.2s, box-shadow 0.2s, background 0.2s;
    outline: none;
    appearance: none;
}

select {
    padding-right: 36px;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' fill='none' stroke='%23888' stroke-width='2'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 14px center;
}

input:focus, select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(2, 50, 101, 0.08);
    background-color: var(--surface);
}

label.check {
    display: flex;
    align-items: center;
    gap: 10px;
    text-transform: none;
    letter-spacing: 0;
    font-size: 0.92em;
    color: var(--text);
}

label.check input { width: 20px; height: 20px; accent-color: var(--primary); }

.campos {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0 12px;
}

.campos .ancho { grid-column: 1 / -1; }
.campos label { margin-top: 12px; }

/* ========== Botones ========== */
.btn-primary {
    width: 100%;
    margin-top: 20px;
    padding: 14px 24px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 0.97em;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: background 0.25s, transform 0.15s;
    letter-spacing: 0.4px;
}

.btn-primary:hover { background: var(--primary-hover); }
.btn-primary:active { transform: scale(0.98); }
.btn-primary:disabled { opacity: 0.5; cursor: wait; }

.btn-mini {
    background: var(--surface);
    color: var(--primary);
    border: 1px solid var(--border);
    border-radius: 50px;
    padding: 8px 14px;
    font-family: inherit;
    font-size: 0.82em;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
    transition: background 0.2s, color 0.2s, border-color 0.2s;
}

.btn-mini:hover:not(:disabled) { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-mini:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-mini.principal { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-mini.peligro { color: var(--danger); }
.btn-mini.peligro:hover:not(:disabled) { background: var(--danger); border-color: var(--danger); color: #fff; }

.acciones { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }

/* ========== Tiendas (encabezado) y secciones (sub) ========== */
.tienda { margin-top: var(--section-gap); }
.tienda:first-of-type { margin-top: 0; }

.category-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    background: var(--primary);
    color: white;
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    margin-bottom: 6px;
    font-size: 1em;
    font-weight: 700;
    letter-spacing: 0.3px;
}

.category-header.sub {
    background: transparent;
    color: var(--text-muted);
    font-size: 0.78em;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.7px;
    padding: 14px 4px 6px;
    border-bottom: 1px solid var(--border);
    border-radius: 0;
    margin: 8px 0 8px;
}

.category-subtotal {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    font-size: 0.88em;
    font-weight: 600;
    color: var(--success);
    padding: 4px 4px 4px;
}

.btn-header {
    background: rgba(255, 255, 255, 0.15);
    color: white;
    border: 1px solid rgba(255, 255, 255, 0.4);
    border-radius: 50px;
    padding: 6px 12px;
    font-size: 0.78em;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    white-space: nowrap;
    transition: background 0.2s;
}

.btn-header:hover:not(:disabled) { background: rgba(255, 255, 255, 0.3); }
.btn-header:disabled { opacity: 0.45; cursor: default; }

/* ========== Renglón de producto ========== */
.product {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px 14px;
    margin-bottom: 8px;
    position: relative;
    box-shadow: var(--shadow-sm);
    transition: border-color 0.2s, background 0.2s, opacity 0.2s;
}

.product h3 {
    font-size: 0.97em;
    font-weight: 600;
    color: var(--primary);
    line-height: 1.35;
}

.product h3 small {
    font-weight: 400;
    color: var(--text-muted);
    font-size: 0.85em;
}

.product p {
    font-size: 0.86em;
    color: var(--text-muted);
    line-height: 1.45;
    padding-top: 2px;
}

.product p.nota { color: var(--text); font-style: italic; }

/* En la lista se toca todo el renglón para palomear */
.renglon {
    display: grid;
    grid-template-columns: 34px 1fr auto 30px;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    user-select: none;
}

.renglon .importe {
    font-weight: 700;
    font-size: 0.95em;
    color: var(--text);
    white-space: nowrap;
}

.renglon.ocupado { opacity: 0.55; pointer-events: none; }

.buyBtn, .deleteBtn {
    background: transparent;
    color: var(--border);
    border: 1.5px solid var(--border);
    width: 34px;
    height: 34px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 1em;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    line-height: 1;
}

.deleteBtn { width: 30px; height: 30px; font-size: 0.85em; }

.buyBtn:hover { border-color: var(--success); color: var(--success); }
.deleteBtn:hover { background: var(--danger); border-color: var(--danger); color: white; }

/* Palomeado: tachado, en verde, al final del bloque (el orden lo da /api/lista) */
.product.comprada { border-color: var(--success); background: var(--success-light); }
.product.comprada .buyBtn { background: var(--success); border-color: var(--success); color: white; }
.product.comprada h3,
.product.comprada p,
.product.comprada .importe {
    text-decoration: line-through;
    text-decoration-color: var(--success);
    color: var(--text-muted);
}

/* ≈ precio estimado: todavía no lo confirma un ticket ni se puso a mano */
.estimado { color: var(--warning); }
.product.comprada .estimado { color: inherit; }

/* ========== Catálogo ========== */
.buscador {
    position: sticky;
    top: 62px;
    z-index: 50;
    padding: 10px 0;
    background: var(--bg);
}

.producto-catalogo { cursor: pointer; }

/* Lo que se lleva a la vista no queda debajo del header y el buscador fijos */
.producto-catalogo, #nuevo { scroll-margin-top: 130px; }

.product h3, .candidato span { overflow-wrap: anywhere; }

.producto-catalogo .cabeza {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 10px;
}

.producto-catalogo .precio { font-weight: 700; white-space: nowrap; color: var(--text); }
.producto-catalogo.en-lista { border-color: var(--primary); }
.producto-catalogo.abierto { box-shadow: var(--shadow); }

.panel {
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid var(--border);
    cursor: default;
}

.fila {
    display: flex;
    gap: 8px;
    align-items: center;
}

.fila input { flex: 1; min-width: 0; }

.etiqueta {
    display: inline-block;
    background: var(--primary-light);
    color: var(--primary);
    font-size: 0.7em;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    padding: 2px 8px;
    border-radius: 50px;
    vertical-align: middle;
    white-space: nowrap;
}

.etiqueta.comprado { background: var(--success-light); color: var(--success); }

/* «¿Cuál de estos?» */
.candidatos {
    margin-top: 16px;
    padding: 14px;
    border: 1.5px solid var(--warning);
    border-radius: var(--radius-sm);
    background: #fffaf0;
}

.candidatos > p { font-size: 0.9em; font-weight: 600; margin-bottom: 10px; }

.candidato {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    padding: 8px 0;
    border-bottom: 1px solid var(--border);
    font-size: 0.9em;
}

.candidato:last-of-type { border-bottom: none; }
.candidato small { color: var(--text-muted); }

/* ========== Total fijo abajo ========== */
#totalPrice {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: rgba(255, 255, 255, 0.92);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-top: 1px solid rgba(0, 0, 0, 0.06);
    color: var(--primary);
    font-size: 1.1em;
    font-weight: 700;
    font-family: 'Playfair Display', Georgia, serif;
    text-align: center;
    padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
    z-index: 1000;
}

#totalPrice small {
    display: block;
    font-family: 'Inter', sans-serif;
    font-size: 0.68em;
    font-weight: 500;
    color: var(--text-muted);
}

/* ========== Toast ========== */
#toast {
    position: fixed;
    bottom: 84px;
    left: 50%;
    transform: translateX(-50%) translateY(10px);
    background: var(--primary);
    color: white;
    padding: 10px 18px;
    border-radius: 50px;
    font-size: 0.85em;
    font-weight: 500;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s, transform 0.25s;
    z-index: 9999;
    max-width: 90vw;
    text-align: center;
    box-shadow: var(--shadow);
}

#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#toast.error   { background: var(--danger); }
#toast.success { background: var(--success); }

/* ========== Sin token: «abre tu liga otra vez» ========== */
.auth-overlay {
    position: fixed;
    inset: 0;
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background: var(--bg);
}

.auth-card { width: 100%; max-width: 380px; margin: 0; text-align: center; }
.auth-card p { color: var(--text-muted); font-size: 0.92em; line-height: 1.5; }

/* ========== Responsive ========== */
@media (max-width: 480px) {
    header h1 { font-size: 1.2em; }
    .header-subtitle { display: none; }
    .container { padding: 16px 12px; }
    .card { padding: 18px 14px; }
    .buscador { top: 56px; }
    select { padding-left: 12px; padding-right: 30px; background-position: right 10px center; }
    .renglon { grid-template-columns: 32px 1fr auto 32px; gap: 8px; padding: 10px 10px; }
    .buyBtn { width: 32px; height: 32px; }
    .deleteBtn { width: 32px; height: 32px; }
    .category-header { padding: 10px 12px; font-size: 0.95em; }
}
