/* ========== Variables ========== */
:root {
    --primary: #023265;
    --primary-hover: #0056b3;
    --primary-light: #e8f0fb;
    --success: #27ae60;
    --danger: #e74c3c;
    --danger-dark: #c0392b;
    --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);
    --shadow-hover: 0 10px 24px rgba(2, 50, 101, 0.15);
    --radius: 14px;
    --radius-sm: 8px;
    --section-gap: 80px;
}

/* ========== 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;
}

/* ========== 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: 16px 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

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

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

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

/* ========== Card (formulario) ========== */
.card {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 32px;
    box-shadow: var(--shadow);
    margin-bottom: 48px;
    border: 1px solid var(--border);
}

.card h2 {
    font-family: 'Playfair Display', Georgia, serif;
    font-size: 1.4em;
    font-weight: 700;
    color: var(--primary);
    margin-bottom: 24px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--border);
}

/* ========== 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: 20px;
}

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

input[type="text"],
input[type="number"],
select {
    width: 100%;
    padding: 12px 16px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 0.97em;
    font-family: 'Inter', sans-serif;
    background-color: var(--bg);
    color: var(--text);
    transition: border-color 0.2s, box-shadow 0.2s, background 0.2s;
    outline: none;
    appearance: none;
}

input[type="text"]:focus,
input[type="number"]:focus,
select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(26, 26, 26, 0.08);
    background-color: var(--surface);
}

/* ========== Opciones de categoría ========== */
.options-group {
    background: #fafafa;
    border-radius: var(--radius-sm);
    padding: 16px;
    margin-top: 16px;
    border: 1.5px solid var(--border);
}

.options-group > p {
    font-size: 0.75em;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.7px;
    margin-bottom: 12px;
}

/* Pills */
.pill-group {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.pill-group input[type="radio"],
.pill-group input[type="checkbox"] {
    display: none;
}

.pill-group label {
    display: inline-block;
    background: var(--surface);
    padding: 7px 16px;
    border-radius: 50px;
    border: 1.5px solid var(--border);
    cursor: pointer;
    font-size: 0.88em;
    font-weight: 500;
    color: var(--text);
    text-transform: none;
    letter-spacing: 0;
    margin: 0;
    transition: all 0.15s ease;
}

.pill-group label:hover {
    border-color: var(--primary);
    color: var(--primary);
}

.pill-group input[type="radio"]:checked + label,
.pill-group input[type="checkbox"]:checked + label {
    background: var(--primary);
    border-color: var(--primary);
    color: white;
}

/* ========== Botón principal ========== */
.btn-primary {
    width: 100%;
    margin-top: 28px;
    padding: 15px 24px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 0.97em;
    font-weight: 600;
    font-family: 'Inter', sans-serif;
    cursor: pointer;
    transition: background 0.25s, transform 0.15s, box-shadow 0.25s;
    letter-spacing: 0.4px;
}

.btn-primary:hover {
    background: var(--primary-hover);
    box-shadow: 0 4px 12px rgba(26, 26, 26, 0.2);
}

.btn-primary:active { transform: scale(0.98); }

/* ========== Secciones de categoría ========== */
.category-section { margin-top: var(--section-gap); }

.category-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--primary);
    color: white;
    padding: 13px 20px;
    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.82em;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.7px;
    padding: 14px 4px 8px;
    border-bottom: 1px solid var(--border);
    border-radius: 0;
    margin-top: 20px;
}

.category-subtotal {
    font-size: 0.88em;
    font-weight: 600;
    color: var(--success);
    padding: 6px 4px 16px;
}

/* ========== Card de producto ========== */
.product {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px 68px 20px 20px;
    margin-bottom: 10px;
    position: relative;
    box-shadow: var(--shadow-sm);
    transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.product:hover {
    transform: translateY(-3px);
    box-shadow: var(--shadow-hover);
}

.product h3 {
    font-size: 0.97em;
    font-weight: 600;
    color: var(--primary);
    margin-bottom: 10px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--border);
}

.product p {
    font-size: 0.88em;
    color: var(--text-muted);
    padding: 3px 0;
    line-height: 1.5;
}

.product p span {
    font-weight: 600;
    color: var(--text);
}

/* ========== Botón eliminar ========== */
.deleteBtn {
    position: absolute;
    top: 50%;
    right: 16px;
    transform: translateY(-50%);
    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:hover {
    background: var(--danger);
    border-color: var(--danger);
    color: white;
    transform: translateY(-50%) scale(1.1);
}

/* ========== Total general ========== */
#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: clamp(1em, 2.5vw, 1.2em);
    font-weight: 700;
    font-family: 'Playfair Display', Georgia, serif;
    text-align: center;
    padding: 14px 20px;
    z-index: 1000;
    letter-spacing: -0.2px;
}

/* ========== Nav de catálogos ========== */
.nav-links {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    justify-content: center;
    margin-top: var(--section-gap);
    padding-bottom: 24px;
}

.nav-links a {
    padding: 10px 22px;
    background: transparent;
    color: var(--primary);
    text-decoration: none;
    border-radius: 50px;
    font-size: 0.9em;
    font-weight: 600;
    border: 1.5px solid var(--primary);
    transition: all 0.2s ease;
    letter-spacing: 0.2px;
}

.nav-links a:hover {
    background: var(--primary);
    color: white;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(26, 26, 26, 0.15);
}

/* ========== Toast ========== */
#toast {
    position: fixed;
    bottom: 72px;
    left: 50%;
    transform: translateX(-50%) translateY(10px);
    background: var(--primary);
    color: white;
    padding: 11px 24px;
    border-radius: 50px;
    font-size: 0.88em;
    font-weight: 500;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s, transform 0.25s;
    z-index: 9999;
    white-space: nowrap;
    box-shadow: var(--shadow);
}

#toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

#toast.error   { background: var(--danger); }
#toast.success { background: var(--success); }

/* ========== Botón PDF ========== */
.btn-pdf {
    padding: 10px 22px;
    background: transparent;
    color: var(--primary);
    border: 1.5px solid var(--primary);
    border-radius: 50px;
    font-size: 0.9em;
    font-weight: 600;
    font-family: 'Inter', sans-serif;
    cursor: pointer;
    transition: all 0.2s ease;
    letter-spacing: 0.2px;
}

.btn-pdf:hover {
    background: var(--primary);
    color: white;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(2, 50, 101, 0.15);
}

/* ========== Header nav (link derecha) ========== */
.header-nav { display: flex; align-items: center; }

.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;
}

/* ========== Analytics: tabs ========== */
.tab-bar {
    display: flex;
    gap: 8px;
    margin-bottom: 32px;
}

.tab {
    padding: 9px 22px;
    border: 1.5px solid var(--border);
    background: var(--surface);
    border-radius: 50px;
    font-size: 0.9em;
    font-weight: 600;
    font-family: 'Inter', sans-serif;
    cursor: pointer;
    color: var(--text-muted);
    transition: all 0.15s;
}

.tab.active {
    background: var(--primary);
    border-color: var(--primary);
    color: white;
}

.tab.locked {
    opacity: 0.45;
    cursor: not-allowed;
}

/* ========== Analytics: stat grid ========== */
.stat-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 16px;
}

.stat-card {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 18px 20px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.stat-label {
    font-size: 0.72em;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.7px;
    color: var(--text-muted);
}

.stat-value {
    font-size: 1.15em;
    font-weight: 700;
    color: var(--primary);
    font-family: 'Playfair Display', Georgia, serif;
}

/* ========== Analytics: tabla ranking ========== */
.table-wrapper {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

#tabla-ranking {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9em;
}

#tabla-ranking th {
    text-align: left;
    padding: 10px 12px;
    font-size: 0.75em;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    border-bottom: 2px solid var(--border);
    white-space: nowrap;
}

#tabla-ranking th.sortable { cursor: pointer; user-select: none; }
#tabla-ranking th.sortable:hover { color: var(--primary); }

#tabla-ranking td {
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
    color: var(--text);
}

#tabla-ranking tbody tr:last-child td { border-bottom: none; }
#tabla-ranking tbody tr:hover td { background: var(--primary-light); }

/* ========== Analytics: gráficas ========== */
.chart-container {
    max-width: 480px;
    margin: 0 auto;
    padding: 8px 0;
}

.chart-note {
    font-size: 0.82em;
    color: var(--text-muted);
    margin-bottom: 16px;
    line-height: 1.5;
}

/* ========== Analytics: proyecciones ========== */
.recomendacion {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 18px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    margin-bottom: 10px;
    font-size: 0.93em;
    color: var(--text);
}

.recomendacion-tipo {
    margin-left: auto;
    background: var(--primary);
    color: white;
    font-size: 0.78em;
    font-weight: 700;
    padding: 3px 10px;
    border-radius: 50px;
    white-space: nowrap;
}

.muted {
    color: var(--text-muted);
    font-size: 0.9em;
    padding: 8px 0;
}

/* ========== Print / PDF ========== */
@media print {
    /* Ocultar elementos no necesarios */
    header, nav.nav-links, .card, #toast, #totalPrice { display: none !important; }

    body {
        padding: 0;
        background: white;
        font-size: 11pt;
        color: #000;
    }

    .container { max-width: 100%; padding: 0; }

    /* Mostrar total al imprimir */
    #totalPrice {
        display: block !important;
        position: static !important;
        box-shadow: none !important;
        border-top: 2px solid #023265;
        padding: 12px 0;
        font-size: 14pt;
        color: #023265;
        background: white !important;
    }

    /* Categorías */
    .category-header {
        background: #023265 !important;
        color: white !important;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
        margin-top: 20px;
        border-radius: 4px;
        font-size: 11pt;
    }

    .category-header.sub {
        background: transparent !important;
        color: #555 !important;
        border-bottom: 1px solid #ccc;
    }

    .category-subtotal {
        font-size: 9pt;
        padding: 4px 4px 8px;
    }

    /* Producto */
    .product {
        padding: 10px 12px;
        margin-bottom: 6px;
        box-shadow: none !important;
        border: 1px solid #ddd;
        border-radius: 4px;
        page-break-inside: avoid;
    }

    .product:hover { transform: none; }

    .deleteBtn { display: none !important; }

    .product h3 { font-size: 10pt; }
    .product p  { font-size: 9pt; padding: 2px 0; }
}

/* ========== Responsive ========== */

/* Tablet */
@media (max-width: 768px) {
    header { padding: 14px 18px; }
    .container { padding: 32px 18px; }
    .card { padding: 24px 20px; }
    :root { --section-gap: 56px; }
}

/* Mobile */
@media (max-width: 480px) {
    header h1 { font-size: 1.2em; }
    .header-subtitle { display: none; }

    .container { padding: 20px 14px; }
    .card { padding: 18px 14px; }

    /* Formulario */
    input[type="text"],
    input[type="number"],
    select { font-size: 16px; } /* Evita zoom en iOS */

    .pill-group { gap: 6px; }
    .pill-group label { padding: 6px 12px; font-size: 0.85em; }

    .btn-primary { padding: 14px; font-size: 0.95em; }

    /* Productos */
    .product { padding: 14px 52px 14px 14px; }
    .product h3 { font-size: 0.92em; }
    .deleteBtn { width: 30px; height: 30px; font-size: 0.9em; right: 12px; }

    /* Categorías */
    .category-header { padding: 11px 14px; font-size: 0.92em; }

    /* Nav */
    .nav-links { gap: 8px; }
    .nav-links a { padding: 9px 14px; font-size: 0.85em; }

    /* Total */
    #totalPrice { font-size: 1em; padding: 12px 16px; }

    /* Toast */
    #toast { font-size: 0.82em; padding: 10px 18px; max-width: 90vw; white-space: normal; text-align: center; }

    :root { --section-gap: 40px; }
}
