/* ==========================================
   COMPARADOR DE PRECIOS - STYLES
   Premium Design System
   ========================================== */

/* CSS Variables */
:root {
    /* Colors */
    --primary: #6366f1;
    --primary-dark: #4f46e5;
    --primary-light: #818cf8;
    --accent: #10b981;
    --accent-light: #34d399;

    /* Backgrounds */
    --bg-gradient-start: #667eea;
    --bg-gradient-end: #764ba2;
    --bg-card: rgba(255, 255, 255, 0.95);
    --bg-card-hover: rgba(255, 255, 255, 1);

    /* Text */
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --text-muted: #94a3b8;
    --text-white: #ffffff;

    /* Borders & Shadows */
    --border-light: rgba(255, 255, 255, 0.2);
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.1);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.1);
    --shadow-glow: 0 0 40px rgba(99, 102, 241, 0.3);

    /* Sizing */
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 24px;
}

/* Reset & Base */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
    background: linear-gradient(135deg, var(--bg-gradient-start) 0%, var(--bg-gradient-end) 100%);
    min-height: 100vh;
    color: var(--text-primary);
    line-height: 1.6;
}

/* App Container */
.app-container {
    max-width: 900px;
    margin: 0 auto;
    padding: 2rem 1rem;
}

/* ==========================================
   HEADER
   ========================================== */
.header {
    text-align: center;
    margin-bottom: 2rem;
    color: var(--text-white);
}

.logo {
    font-size: 3.5rem;
    margin-bottom: 0.5rem;
    animation: bounce 2s ease-in-out infinite;
}

@keyframes bounce {

    0%,
    100% {
        transform: translateY(0);
    }

    50% {
        transform: translateY(-10px);
    }
}

.header h1 {
    font-size: 2.5rem;
    font-weight: 800;
    margin-bottom: 0.5rem;
    text-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
}

.tagline {
    font-size: 1.1rem;
    opacity: 0.9;
    font-weight: 500;
}

/* ==========================================
   SUPERMARKET SELECTOR
   ========================================== */
.super-selector {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    margin-bottom: 1.5rem;
    box-shadow: var(--shadow-lg);
}

.super-selector h2 {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 1rem;
}

.super-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 0.75rem;
}

.super-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.6rem 0.8rem;
    background: #f8fafc;
    border: 2px solid transparent;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all 0.2s ease;
    user-select: none;
}

.super-item:hover {
    background: #f1f5f9;
}

.super-item.selected {
    background: linear-gradient(135deg, #ede9fe 0%, #ddd6fe 100%);
    border-color: var(--primary);
}

.super-item input {
    display: none;
}

.super-item .emoji {
    font-size: 1.2rem;
}

.super-item .name {
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text-primary);
}

.selector-actions {
    display: flex;
    justify-content: center;
    gap: 0.5rem;
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px solid #e2e8f0;
}

.btn-link {
    background: none;
    border: none;
    color: var(--primary);
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    padding: 0.25rem 0.5rem;
}

.btn-link:hover {
    text-decoration: underline;
}

.separator {
    color: var(--text-muted);
}

/* ==========================================
   SEARCH SECTION
   ========================================== */
.search-section {
    margin-bottom: 1.5rem;
}

.search-box {
    display: flex;
    gap: 0.75rem;
    background: var(--bg-card);
    padding: 1rem;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
}

#search-input {
    flex: 1;
    min-width: 0;
    padding: 1rem;
    border: 2px solid #e2e8f0;
    border-radius: var(--radius-sm);
    font-size: 1rem;
    font-family: inherit;
    transition: border-color 0.2s;
}

#search-input:focus {
    outline: none;
    border-color: var(--primary);
}

#cp-input {
    width: 100px;
    padding: 1rem;
    border: 2px solid #e2e8f0;
    border-radius: var(--radius-sm);
    font-size: 1rem;
    font-family: inherit;
    text-align: center;
}

#cp-input:focus {
    outline: none;
    border-color: var(--primary);
}

.btn-primary {
    padding: 1rem 1.5rem;
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    color: white;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 1rem;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
    white-space: nowrap;
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.4);
}

.btn-primary:active {
    transform: translateY(0);
}

.btn-primary:disabled {
    opacity: 0.7;
    cursor: wait;
    transform: none;
}

.status-text {
    text-align: center;
    margin-top: 1rem;
    font-size: 0.9rem;
    color: var(--text-white);
    opacity: 0.9;
}

/* ==========================================
   BEST DEAL BANNER
   ========================================== */
.best-deal {
    background: linear-gradient(135deg, #059669 0%, #10b981 100%);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    margin-bottom: 1.5rem;
    color: white;
    box-shadow: var(--shadow-lg);
}

.best-deal-content {
    display: flex;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
}

.trophy {
    font-size: 2.5rem;
}

.best-deal-info {
    display: flex;
    flex-direction: column;
}

.best-label {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    opacity: 0.9;
}

.best-price {
    font-size: 1.75rem;
    font-weight: 800;
}

.best-deal-details {
    margin-left: auto;
    text-align: right;
}

.best-deal-details span {
    display: block;
}

#best-store {
    font-weight: 600;
    font-size: 1rem;
}

#best-product {
    font-size: 0.85rem;
    opacity: 0.9;
    max-width: 250px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ==========================================
   RESULTS
   ========================================== */
.results-area {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 1.5rem;
}

.empty-state {
    grid-column: 1 / -1;
    text-align: center;
    padding: 3rem 2rem;
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    color: var(--text-secondary);
}

/* ==========================================
   SORTING CONTROLS
   ========================================== */
.sorting-section {
    margin-bottom: 1.5rem;
    animation: fadeIn 0.5s ease-out;
}

.sort-controls {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    background: rgba(255, 255, 255, 0.9);
    padding: 1rem;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    flex-wrap: wrap;
}

.sort-label {
    font-weight: 600;
    color: var(--text-secondary);
    font-size: 0.95rem;
}

.sort-buttons {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.sort-btn {
    background: transparent;
    border: 1px solid var(--text-muted);
    color: var(--text-secondary);
    padding: 0.4rem 0.8rem;
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.2s ease;
    font-weight: 500;
}

.sort-btn:hover {
    background: rgba(99, 102, 241, 0.1);
    border-color: var(--primary);
    color: var(--primary);
}

.sort-btn.active {
    background: var(--primary);
    border-color: var(--primary);
    color: white;
    box-shadow: 0 2px 4px rgba(99, 102, 241, 0.3);
}

.result-card {
    background: var(--bg-card);
    border-radius: var(--radius-md);
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    gap: 1rem;
    box-shadow: var(--shadow-sm);
    transition: transform 0.2s, box-shadow 0.2s;
    position: relative;
    height: 100%;
}

.result-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-md);
}

.result-card.cheapest {
    border: 2px solid var(--accent);
    background: linear-gradient(135deg, #ecfdf5 0%, #d1fae5 100%);
}

.result-card .rank {
    position: absolute;
    top: 12px;
    right: 12px;
    left: auto;
    /* Mover rank a la derecha */
    background: var(--primary);
    color: white;
    font-size: 0.75rem;
    font-weight: 700;
    padding: 4px 10px;
    border-radius: 999px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.result-card.cheapest .rank {
    background: var(--accent);
}

.store-info {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.store-name {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.store-name .emoji {
    font-size: 1rem;
}

.store-name .name {
    font-weight: 500;
    color: var(--text-secondary);
    font-size: 0.85rem;
    /* Un poco más pequeño como pidió el usuario */
}

.product-name {
    font-size: 1.15rem;
    /* Un poco más grande */
    font-weight: 700;
    color: var(--text-primary);
    line-height: 1.4;
    /* Permitir varias líneas */
    white-space: normal;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    line-clamp: 3;
    overflow: hidden;
}

.price-info {
    text-align: left;
    /* Alinear precios a la izquierda en tarjeta */
    margin-top: auto;
    /* Empujar al fondo */
    padding-top: 1rem;
    border-top: 1px solid var(--border-light);
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.unit-price {
    font-size: 1.4rem;
    /* Precio unidad Kg grande */
    font-weight: 800;
    color: var(--primary);
}

.result-card.cheapest .unit-price {
    color: #047857;
}

.total-price {
    font-size: 1.25rem;
    /* Solo ~1-2 puntos más pequeño que unit-price (1.4rem -> 1.25rem) */
    font-weight: 600;
    color: var(--text-secondary);
}

/* MODIFICACION USUARIO: Cuando orden es "total", invertir protagonismo */
.results-area.sort-ticket-active .unit-price {
    color: var(--text-secondary);
    /* Gris */
    font-size: 1.1rem;
    font-weight: 600;
}

.results-area.sort-ticket-active .total-price {
    color: var(--primary);
    /* Azul fuerte */
    font-size: 1.5rem;
    font-weight: 800;
}

.results-area.sort-ticket-active .result-card.cheapest .total-price {
    color: #047857;
    /* Verde si es el mejor */
}

/* Cuando orden es "ud", hacer grande el precio por unidad (extra-price) */
.results-area.sort-ud-active .unit-price {
    color: var(--text-secondary);
    font-size: 1.1rem;
    font-weight: 600;
}

.results-area.sort-ud-active .extra-price {
    color: var(--primary);
    font-size: 1.4rem;
    font-weight: 800;
}

.results-area.sort-ud-active .result-card.cheapest .extra-price {
    color: #047857;
}

.extra-price {
    font-size: 0.9rem;
    color: var(--text-muted);
    font-weight: 500;
}

.store-link {
    display: inline-block;
    margin-top: 0.25rem;
    font-size: 0.8rem;
    color: var(--primary);
    text-decoration: none;
}

.store-link:hover {
    text-decoration: underline;
}

.error-msg {
    background: #fef2f2;
    color: #dc2626;
    padding: 1.5rem;
    border-radius: var(--radius-md);
    text-align: center;
}

/* ==========================================
   FOOTER
   ========================================== */
.footer {
    margin-top: 3rem;
    text-align: center;
    color: var(--text-white);
    opacity: 0.8;
    font-size: 0.9rem;
}

/* ==========================================
   RESPONSIVE
   ========================================== */
@media (max-width: 640px) {
    .header h1 {
        font-size: 1.75rem;
    }

    .search-box {
        flex-direction: column;
    }

    #cp-input {
        width: 100%;
    }

    .best-deal-content {
        flex-direction: column;
        text-align: center;
    }

    .best-deal-details {
        margin-left: 0;
        text-align: center;
    }

    .result-card {
        grid-template-columns: 1fr;
        text-align: center;
    }

    .price-info {
        text-align: center;
    }

    .product-name {
        max-width: 100%;
    }
}

/* ==========================================
   PROGRESS BAR
   ========================================== */
.progress-container {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    padding: 2rem;
    text-align: center;
}

.progress-bar {
    width: 100%;
    height: 12px;
    background: #e2e8f0;
    border-radius: 6px;
    overflow: hidden;
    margin-bottom: 1rem;
}

.progress-fill {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, var(--primary) 0%, var(--accent) 100%);
    border-radius: 6px;
    transition: width 0.3s ease;
}

.progress-text {
    font-size: 1.1rem;
    font-weight: 500;
    color: var(--text-primary);
}