/* ========================================
   La Barca degli Sconti - Mini App v2
   Modern Telegram Web App
   ======================================== */

:root {
    --brand-primary: #2563eb;
    --brand-primary-dark: #1d4ed8;
    --brand-accent: #f59e0b;
    --brand-success: #10b981;
    --brand-warning: #f59e0b;
    --brand-danger: #ef4444;
    --card-shadow: 0 1px 3px rgba(0,0,0,0.04), 0 1px 2px rgba(0,0,0,0.06);
    --card-shadow-hover: 0 4px 12px rgba(0,0,0,0.08);
}

* { box-sizing: border-box; }

body {
    padding-top: var(--tg-content-safe-area-inset-top, 0px);
    padding-left: var(--tg-safe-area-inset-left, 0px);
    padding-right: var(--tg-safe-area-inset-right, 0px);
    -webkit-overflow-scrolling: touch;
    -webkit-tap-highlight-color: transparent;
    font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'Segoe UI', Roboto, sans-serif;
    line-height: 1.5;
    letter-spacing: -0.01em;
}

[x-cloak] { display: none !important; }

/* ========================================
   Transizioni pagina
   ======================================== */
.page-enter { opacity: 0; transform: translateY(12px); }
.page-enter-active { opacity: 1; transform: translateY(0); transition: opacity 250ms cubic-bezier(.4,0,.2,1), transform 250ms cubic-bezier(.4,0,.2,1); }
.page-leave-active { opacity: 0; transition: opacity 150ms ease-in; }

/* ========================================
   Loading skeleton
   ======================================== */
.skeleton {
    background: linear-gradient(90deg,
        var(--tg-theme-secondary-bg-color, #f0f0f0) 25%,
        rgba(255,255,255,0.4) 50%,
        var(--tg-theme-secondary-bg-color, #f0f0f0) 75%);
    background-size: 200% 100%;
    animation: skeleton-shimmer 1.5s ease-in-out infinite;
    border-radius: 12px;
}
@keyframes skeleton-shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }
.skeleton-text { height: 14px; margin-bottom: 8px; border-radius: 7px; }
.skeleton-title { height: 20px; width: 70%; margin-bottom: 12px; border-radius: 10px; }
.skeleton-card { height: 84px; margin-bottom: 12px; border-radius: 20px; }

/* ========================================
   Card sistema
   ======================================== */
.card {
    background: var(--tg-theme-section-bg-color, #ffffff);
    border-radius: 20px;
    padding: 16px;
    margin-bottom: 12px;
    box-shadow: var(--card-shadow);
    transition: box-shadow 200ms, transform 200ms;
}

.card-interactive {
    cursor: pointer;
}

.card-interactive:active {
    transform: scale(0.98);
    box-shadow: var(--card-shadow);
}

/* ========================================
   Immagine prodotto
   ======================================== */
.product-image-container {
    background: linear-gradient(135deg, #f8fafc 0%, #f1f5f9 100%);
    border-radius: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    position: relative;
}

.product-image-container img {
    object-fit: contain;
    transition: opacity 300ms;
}

/* Placeholder per immagini non caricate */
.product-image-placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #f1f5f9 0%, #e2e8f0 100%);
    color: #94a3b8;
}

/* Hero image per pagina prodotto */
.product-hero {
    width: 100%;
    aspect-ratio: 1;
    max-height: 220px;
    background: linear-gradient(145deg, #f8fafc 0%, #eef2ff 50%, #f1f5f9 100%);
    border-radius: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 16px;
    overflow: hidden;
    box-shadow: inset 0 2px 4px rgba(0,0,0,0.02);
}

.product-hero img {
    max-width: 70%;
    max-height: 80%;
    object-fit: contain;
    filter: drop-shadow(0 4px 12px rgba(0,0,0,0.08));
    transition: transform 200ms;
}

/* Mini thumbnail per liste */
.product-thumb {
    width: 56px;
    height: 56px;
    min-width: 56px;
    border-radius: 14px;
    background: linear-gradient(135deg, #f8fafc, #f1f5f9);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.product-thumb img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    padding: 4px;
}

/* ========================================
   Badge e pill
   ======================================== */
.badge-discount {
    display: inline-flex;
    align-items: center;
    padding: 6px 12px;
    border-radius: 12px;
    font-weight: 800;
    font-size: 15px;
    letter-spacing: -0.02em;
}

.badge-sm {
    padding: 3px 8px;
    border-radius: 8px;
    font-size: 11px;
    font-weight: 700;
}

/* ========================================
   Verdict card (analisi sconto)
   ======================================== */
.verdict-true-discount {
    background: linear-gradient(135deg, rgba(16,185,129,0.08), rgba(16,185,129,0.14));
    border: 1px solid rgba(16,185,129,0.15);
    color: #059669;
}

.verdict-fair-price {
    background: linear-gradient(135deg, rgba(245,158,11,0.08), rgba(245,158,11,0.14));
    border: 1px solid rgba(245,158,11,0.15);
    color: #d97706;
}

.verdict-inflated {
    background: linear-gradient(135deg, rgba(239,68,68,0.08), rgba(239,68,68,0.14));
    border: 1px solid rgba(239,68,68,0.15);
    color: #dc2626;
}

/* ========================================
   Progress bar
   ======================================== */
.progress-bar {
    height: 8px;
    border-radius: 4px;
    background: var(--tg-theme-secondary-bg-color, #e5e7eb);
    overflow: hidden;
}

.progress-bar-fill {
    height: 100%;
    border-radius: 4px;
    transition: width 400ms cubic-bezier(.4,0,.2,1);
}

/* ========================================
   Score bar (punteggio)
   ======================================== */
.score-block {
    height: 6px;
    flex: 1;
    border-radius: 3px;
    transition: background-color 300ms;
}

/* ========================================
   Toggle switch
   ======================================== */
.toggle-switch {
    position: relative;
    width: 52px;
    height: 32px;
    border-radius: 16px;
    cursor: pointer;
    transition: background-color 250ms cubic-bezier(.4,0,.2,1);
}
.toggle-switch.active { background-color: var(--brand-primary); }
.toggle-switch:not(.active) { background-color: var(--tg-theme-secondary-bg-color, #d1d5db); }
.toggle-switch::after {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    width: 28px;
    height: 28px;
    border-radius: 14px;
    background: white;
    box-shadow: 0 2px 6px rgba(0,0,0,0.15);
    transition: transform 250ms cubic-bezier(.4,0,.2,1);
}
.toggle-switch.active::after { transform: translateX(20px); }

/* ========================================
   Chip / tag
   ======================================== */
.chip {
    display: inline-flex;
    align-items: center;
    padding: 10px 16px;
    border-radius: 14px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all 200ms cubic-bezier(.4,0,.2,1);
    border: 1.5px solid transparent;
    user-select: none;
}
.chip.selected {
    background: rgba(37,99,235,0.1);
    color: var(--brand-primary);
    border-color: rgba(37,99,235,0.3);
    box-shadow: 0 0 0 1px rgba(37,99,235,0.1);
}
.chip:not(.selected) {
    background: var(--tg-theme-secondary-bg-color, #f3f4f6);
    color: var(--tg-theme-hint-color, #6b7280);
}
.chip:active { transform: scale(0.95); }

/* ========================================
   Keyword tag
   ======================================== */
.keyword-tag {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    border-radius: 12px;
    font-size: 13px;
    font-weight: 500;
    background: var(--tg-theme-secondary-bg-color, #f3f4f6);
    color: var(--tg-theme-text-color);
}
.keyword-tag button {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: rgba(0,0,0,0.08);
    border: none;
    cursor: pointer;
    color: inherit;
    font-size: 11px;
    transition: background 150ms;
}
.keyword-tag button:hover { background: rgba(0,0,0,0.15); }

/* ========================================
   Range slider
   ======================================== */
input[type="range"] {
    -webkit-appearance: none;
    width: 100%;
    height: 6px;
    border-radius: 3px;
    background: var(--tg-theme-secondary-bg-color, #e5e7eb);
    outline: none;
}
input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: var(--brand-primary);
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(37,99,235,0.3);
    transition: box-shadow 150ms;
}
input[type="range"]::-webkit-slider-thumb:active {
    box-shadow: 0 2px 12px rgba(37,99,235,0.5);
    transform: scale(1.1);
}

/* ========================================
   Stat card
   ======================================== */
.stat-card {
    background: var(--tg-theme-secondary-bg-color, #f3f4f6);
    border-radius: 18px;
    padding: 16px 12px;
    text-align: center;
    flex: 1;
    transition: transform 200ms;
}
.stat-card:active { transform: scale(0.97); }
.stat-card .stat-value { font-size: 24px; font-weight: 800; line-height: 1.1; letter-spacing: -0.03em; }
.stat-card .stat-label { font-size: 11px; font-weight: 500; color: var(--tg-theme-hint-color, #6b7280); margin-top: 4px; text-transform: uppercase; letter-spacing: 0.05em; }

/* ========================================
   Empty state
   ======================================== */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 56px 32px;
    text-align: center;
}
.empty-state svg { width: 56px; height: 56px; color: var(--tg-theme-hint-color, #cbd5e1); margin-bottom: 20px; opacity: 0.6; }
.empty-state .empty-title { font-size: 17px; font-weight: 700; margin-bottom: 8px; letter-spacing: -0.01em; }
.empty-state .empty-desc { font-size: 14px; color: var(--tg-theme-hint-color, #94a3b8); line-height: 1.5; max-width: 260px; }

/* ========================================
   Grafico storico prezzi
   ======================================== */
.chart-container {
    border-radius: 16px;
    overflow: hidden;
    background: var(--tg-theme-secondary-bg-color, #f9fafb);
    position: relative;
    min-height: 180px;
}

.chart-container img {
    width: 100%;
    height: auto;
    display: block;
    transition: opacity 400ms;
}

/* Loading shimmer per il grafico */
.chart-container::before {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(90deg, transparent 25%, rgba(255,255,255,0.3) 50%, transparent 75%);
    background-size: 200% 100%;
    animation: skeleton-shimmer 1.5s ease-in-out infinite;
    z-index: 1;
    pointer-events: none;
    opacity: 1;
    transition: opacity 300ms;
}

.chart-container.loaded::before { opacity: 0; }

.chart-container img { position: relative; z-index: 2; }

/* Range selector tabs */
.range-tabs {
    display: flex;
    gap: 4px;
    padding: 4px;
    border-radius: 14px;
    background: var(--tg-theme-secondary-bg-color, #f3f4f6);
}

.range-tab {
    flex: 1;
    padding: 8px 0;
    border-radius: 10px;
    font-size: 13px;
    font-weight: 700;
    text-align: center;
    cursor: pointer;
    transition: all 200ms cubic-bezier(.4,0,.2,1);
    border: none;
    background: transparent;
    color: var(--tg-theme-hint-color, #94a3b8);
    letter-spacing: -0.01em;
}

.range-tab.active {
    background: var(--tg-theme-section-bg-color, #ffffff);
    color: var(--brand-primary);
    box-shadow: 0 2px 8px rgba(0,0,0,0.06);
}

.range-tab:active { transform: scale(0.95); }

/* ========================================
   Tab bar (bottom navigation)
   ======================================== */
.tab-bar {
    -webkit-backdrop-filter: blur(20px) saturate(180%);
    backdrop-filter: blur(20px) saturate(180%);
    background: rgba(var(--tg-theme-section-bg-color-rgb, 255,255,255), 0.85);
    background: color-mix(in srgb, var(--tg-theme-section-bg-color, #ffffff) 85%, transparent);
    border-top: 0.5px solid rgba(0,0,0,0.08);
}

@supports not (backdrop-filter: blur(20px)) {
    .tab-bar { background: var(--tg-theme-section-bg-color, #ffffff); }
}

/* ========================================
   Sezione con header
   ======================================== */
.section-header {
    font-size: 13px;
    font-weight: 700;
    color: var(--tg-theme-hint-color, #94a3b8);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    margin-bottom: 12px;
}

/* ========================================
   Bottoni
   ======================================== */
.btn-primary {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    padding: 14px;
    border-radius: 16px;
    font-size: 15px;
    font-weight: 700;
    background: var(--brand-primary);
    color: white;
    border: none;
    cursor: pointer;
    transition: all 200ms;
    letter-spacing: -0.01em;
    box-shadow: 0 2px 8px rgba(37,99,235,0.25);
}

.btn-primary:active {
    transform: scale(0.98);
    box-shadow: 0 1px 4px rgba(37,99,235,0.2);
}

.btn-secondary {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    padding: 14px;
    border-radius: 16px;
    font-size: 15px;
    font-weight: 700;
    background: var(--brand-accent);
    color: white;
    border: none;
    cursor: pointer;
    transition: all 200ms;
    box-shadow: 0 2px 8px rgba(245,158,11,0.25);
}

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

/* ========================================
   Price display
   ======================================== */
.price-current {
    font-size: 32px;
    font-weight: 800;
    letter-spacing: -0.03em;
    line-height: 1;
}

.price-original {
    font-size: 15px;
    color: var(--tg-theme-hint-color, #94a3b8);
    text-decoration: line-through;
    font-weight: 500;
}

/* ========================================
   Savings badge (dashboard)
   ======================================== */
.savings-card {
    background: linear-gradient(135deg, rgba(16,185,129,0.06), rgba(16,185,129,0.12));
    border: 1px solid rgba(16,185,129,0.12);
    border-radius: 20px;
    padding: 20px;
    text-align: center;
}

/* ========================================
   Referral card
   ======================================== */
.referral-card {
    background: linear-gradient(135deg, rgba(245,158,11,0.05), rgba(245,158,11,0.1));
    border: 1px solid rgba(245,158,11,0.12);
    border-radius: 20px;
    padding: 16px;
}

/* ========================================
   Input fields
   ======================================== */
.input-field {
    width: 100%;
    padding: 12px 14px;
    border-radius: 14px;
    font-size: 15px;
    background: var(--tg-theme-secondary-bg-color, #f3f4f6);
    color: var(--tg-theme-text-color);
    border: 1.5px solid transparent;
    outline: none;
    transition: border-color 200ms, box-shadow 200ms;
}

.input-field:focus {
    border-color: rgba(37,99,235,0.4);
    box-shadow: 0 0 0 3px rgba(37,99,235,0.1);
}

.input-field::placeholder { color: var(--tg-theme-hint-color, #94a3b8); }
