/* App-like helpers e variabili per mobile - Versione Ottimizzata Core Web Vitals */
/* === SAFE-AREA CORE (unifica plugin + env) =============================== */
:root {
    /* Valori scritti dal plugin JS (Capacitor) — inizializzati a 0 */
    --safe-top: 0px;
    --safe-right: 0px;
    --safe-bottom: 0px;
    --safe-left: 0px;

    /* Fallback/env iOS (fuori da Capacitor o su Safari) */
    --sat-env: env(safe-area-inset-top, 0px);
    --sar-env: env(safe-area-inset-right, 0px);
    --sab-env: env(safe-area-inset-bottom, 0px);
    --sal-env: env(safe-area-inset-left, 0px);

    /* Valori EFFETTIVI: prendono il massimo tra plugin e env */
    --safe-top-effective: max(var(--safe-top), var(--sat-env));
    --safe-right-effective: max(var(--safe-right), var(--sar-env));
    --safe-bottom-effective: max(var(--safe-bottom), var(--sab-env));
    --safe-left-effective: max(var(--safe-left), var(--sal-env));

    /* Variabili di layout e colori base */
    --app-radius: 16px;
    --app-pad: 16px;
    --header-h: 70px;
    --bottom-nav-h: 65px;

    --bg-primary: #0f172a;
    --bg-secondary: #1e293b;
    --bg-tertiary: #334155;
    --text-primary: #e2e8f0;
    --text-secondary: #94a3b8;
    --text-tertiary: #64748b;
    --accent-primary: #0ea5e9;
    --accent-secondary: #10b981;
    --border-primary: #475569;
    --border-secondary: #334155;
}

/* Reset e base styles */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html, body {
    height: 100%;
    scroll-behavior: smooth;
    scroll-padding-top: calc(var(--header-h) + var(--safe-top-effective) + 16px);
    scroll-padding-bottom: calc(var(--bottom-nav-h) + var(--safe-bottom-effective) + 16px);
}

body {
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background-color: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.5;
}

/* Performance optimizations */
img {
    max-width: 100%;
    height: auto;
    display: block;
}

/* Rimuove highlight sui tap su mobile */
* {
    -webkit-tap-highlight-color: transparent;
}

/* Scrollbar personalizzate */
.scroll-container {
    scrollbar-width: thin;
    scrollbar-color: var(--text-tertiary) var(--bg-secondary);
}

.scroll-container::-webkit-scrollbar { height: 8px; width: 8px; }
.scroll-container::-webkit-scrollbar-thumb { background: var(--text-tertiary); border-radius: 8px; }
.scroll-container::-webkit-scrollbar-track { background: var(--bg-secondary); }
.scroll-container::-webkit-scrollbar-thumb:hover { background: var(--text-secondary); }

/* Layout utilities */
.flex { display: flex; }
.items-center { align-items: center; }
.items-end { align-items: flex-end; }
.justify-center { justify-content: center; }
.justify-between { justify-content: space-between; }
.flex-1 { flex: 1 1 0%; }
.gap-2 { gap: 0.5rem; }
.gap-3 { gap: 0.75rem; }
.hidden { display: none; }
.relative { position: relative; }
.absolute { position: absolute; }
.fixed { position: fixed; }
.sticky { position: sticky; }
.inset-0 { top: 0; right: 0; bottom: 0; left: 0; }
.top-0 { top: 0; }
.left-2 { left: 0.5rem; }
.top-2 { top: 0.5rem; }
.right-1\.5 { right: 0.375rem; }
.top-1\/2 { top: 50%; }
.-translate-y-1\/2 { transform: translateY(-50%); }
.-translate-x-1\/2 { transform: translateX(-50%); }
.left-1\/2 { left: 50%; }

/* Spacing utilities */
.mb-1 { margin-bottom: 0.25rem; }
.mb-2 { margin-bottom: 0.5rem; }
.mb-3 { margin-bottom: 0.75rem; }
.mb-4 { margin-bottom: 1rem; }
.mb-6 { margin-bottom: 1.5rem; }
.mt-1 { margin-top: 0.25rem; }
.mt-2 { margin-top: 0.5rem; }
.mt-3 { margin-top: 0.75rem; }
.ml-3 { margin-left: 0.75rem; }
.px-1 { padding-left: 0.25rem; padding-right: 0.25rem; }
.px-2 { padding-left: 0.5rem; padding-right: 0.5rem; }
.px-3 { padding-left: 0.75rem; padding-right: 0.75rem; }
.px-4 { padding-left: 1rem; padding-right: 1rem; }
.px-5 { padding-left: 1.25rem; padding-right: 1.25rem; }
.py-1 { padding-top: 0.25rem; padding-bottom: 0.25rem; }
.py-2 { padding-top: 0.5rem; padding-bottom: 0.5rem; }
.py-3 { padding-top: 0.75rem; padding-bottom: 0.75rem; }
.py-5 { padding-top: 1.25rem; padding-bottom: 1.25rem; }
.p-1 { padding: 0.25rem; }
.p-3 { padding: 0.75rem; }
.p-4 { padding: 1rem; }
.p-6 { padding: 1.5rem; }
.pl-9 { padding-left: 2.25rem; }
.pr-16 { padding-right: 4rem; }

/* Sizing utilities */
.w-4 { width: 1rem; }
.w-8 { width: 2rem; }
.w-32 { width: 8rem; }
.w-full { width: 100%; }
.w-auto { width: auto; }
.h-4 { height: 1rem; }
.h-5 { height: 1.25rem; }
.h-6 { height: 1.5rem; }
.h-8 { height: 2rem; }
.h-12 { height: 3rem; }
.h-full { height: 100%; }
.h-auto { height: auto; }
.h-1\.5 { height: 0.375rem; }
.h-\[140px\] { height: 140px; }
.min-w-0 { min-width: 0; }
.min-w-\[240px\] { min-width: 240px; }
.max-w-\[260px\] { max-width: 260px; }
.max-w-2xl { max-width: 42rem; }
.max-w-7xl { max-width: 80rem; }
.max-h-\[90vh\] { max-height: 90vh; }
.w-\[92vw\] { width: 92vw; }

/* Text utilities */
.text-xs { font-size: 0.75rem; line-height: 1rem; }
.text-sm { font-size: 0.875rem; line-height: 1.25rem; }
.text-base { font-size: 1rem; line-height: 1.5rem; }
.text-lg { font-size: 1.125rem; line-height: 1.75rem; }
.text-xl { font-size: 1.25rem; line-height: 1.75rem; }
.text-\[9px\] { font-size: 9px; }
.text-\[10px\] { font-size: 10px; }
.text-\[11px\] { font-size: 11px; }
.font-medium { font-weight: 500; }
.font-semibold { font-weight: 600; }
.font-bold { font-weight: 700; }
.font-mono { font-family: ui-monospace, SFMono-Regular, "SF Mono", monospace; }
.text-center { text-align: center; }
.leading-snug { line-height: 1.375; }
.leading-relaxed { line-height: 1.625; }

/* Color utilities */
.text-slate-100 { color: #f1f5f9; }
.text-slate-200 { color: #e2e8f0; }
.text-slate-300 { color: #cbd5e1; }
.text-slate-400 { color: #94a3b8; }
.text-white { color: #ffffff; }
.text-red-400 { color: #f87171; }
.text-emerald-100 { color: #d1fae5; }
.text-rose-100 { color: #ffe4e6; }
.text-rose-400 { color: #fb7185; }
.bg-white { background-color: #ffffff; }
.bg-black\/70 { background-color: rgba(0,0,0,0.7); }
.bg-slate-500 { background-color: #64748b; }
.bg-slate-600 { background-color: #475569; }
.bg-slate-700 { background-color: #334155; }
.bg-slate-700\/30 { background-color: rgba(51,65,85,0.3); }
.bg-slate-700\/50 { background-color: rgba(51,65,85,0.5); }
.bg-slate-800 { background-color: #1e293b; }
.bg-emerald-500 { background-color: #10b981; }
.bg-emerald-600 { background-color: #059669; }
.bg-rose-600 { background-color: #e11d48; }
.bg-rose-600\/20 { background-color: rgba(225,29,72,0.2); }
.bg-rose-600\/30 { background-color: rgba(225,29,72,0.3); }
.bg-red-500 { background-color: #ef4444; }
.bg-red-600 { background-color: #dc2626; }

/* Border utilities */
.border { border-width: 1px; }
.border-t { border-top-width: 1px; }
.border-b { border-bottom-width: 1px; }
.border-slate-600 { border-color: #475569; }
.divide-y > :not([hidden]) ~ :not([hidden]) { border-top-width: 1px; border-color: #475569; }
.divide-slate-600 > :not([hidden]) ~ :not([hidden]) { border-color: #475569; }

/* Border radius */
.rounded { border-radius: 0.25rem; }
.rounded-md { border-radius: 0.375rem; }
.rounded-lg { border-radius: 0.5rem; }
.rounded-xl { border-radius: 0.75rem; }
.rounded-2xl { border-radius: 1rem; }
.rounded-sm { border-radius: 0.125rem; }
.rounded-full { border-radius: 9999px; }

/* Shadow utilities */
.shadow-lg { box-shadow: 0 10px 15px -3px rgba(0,0,0,0.1), 0 4px 6px -2px rgba(0,0,0,0.05); }
.shadow-2xl { box-shadow: 0 25px 50px -12px rgba(0,0,0,0.25); }

/* Overflow utilities */
.overflow-hidden { overflow: hidden; }
.overflow-x-auto { overflow-x: auto; }
.overflow-x-hidden { overflow-x: hidden; }
.overflow-y-auto { overflow-y: auto; }
.object-cover { object-fit: cover; }

/* Flex utilities */
.flex-col { flex-direction: column; }
.shrink-0 { flex-shrink: 0; }

/* Position utilities */
.z-20 { z-index: 20; }
.z-30 { z-index: 30; }
.z-40 { z-index: 40; }
.z-50 { z-index: 50; }

/* Grid utilities */
.grid { display: grid; }
.grid-cols-\[60px\,1fr\] { grid-template-columns: 60px 1fr; }

/* Space utilities */
.space-y-2 > :not([hidden]) ~ :not([hidden]) { margin-top: 0.5rem; }
.space-y-4 > :not([hidden]) ~ :not([hidden]) { margin-top: 1rem; }

/* Layout utilities */
.mx-auto { margin-left: auto; margin-right: auto; }

/* Text utilities */
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.placeholder\:text-slate-400::placeholder { color: #94a3b8; }

/* Cursor utilities */
.cursor-pointer { cursor: pointer; }

/* Select utilities */
.select-none { user-select: none; }

/* Scroll utilities */
.snap-x { scroll-snap-type: x mandatory; }
.snap-mandatory { scroll-snap-type: mandatory; }
.snap-start { scroll-snap-align: start; }
.scroll-p-2 { scroll-padding: 0.5rem; }

/* Animation utilities */
.transition-colors {
    transition-property: color, background-color, border-color, text-decoration-color, fill, stroke;
    transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
    transition-duration: 150ms;
}
.transition-all {
    transition-property: all;
    transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
    transition-duration: 150ms;
}
.duration-300 { transition-duration: 300ms; }
.ease-in-out { transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1); }
.ease-out { transition-timing-function: cubic-bezier(0, 0, 0.2, 1); }

/* Hover utilities */
.hover\:bg-slate-500:hover { background-color: #64748b; }
.hover\:bg-slate-700:hover { background-color: #334155; }
.hover\:bg-emerald-500:hover { background-color: #10b981; }
.hover\:bg-emerald-700:hover { background-color: #047857; }
.hover\:bg-rose-600\/30:hover { background-color: rgba(225,29,72,0.3); }
.hover\:text-slate-200:hover { color: #e2e8f0; }
.hover\:text-slate-300:hover { color: #cbd5e1; }

/* Focus utilities */
.focus\:ring-2:focus { box-shadow: 0 0 0 2px var(--accent-primary); }
.focus\:ring-emerald-500:focus { box-shadow: 0 0 0 2px #10b981; }
.focus\:border-transparent:focus { border-color: transparent; }

/* Spazio sicuro per area contenuto principale */
.safe-container {
    padding-top: calc(var(--safe-top-effective) + 8px);
    padding-bottom: calc(var(--bottom-nav-h) + var(--safe-bottom-effective) + 30px);
    padding-left: 16px;
    padding-right: 16px;
}

/* Header compatto che va sotto la status bar */
.app-header-compact {
    position: sticky;
    top: 0;
    z-index: 20;
    margin: 0 -16px 16px;
    padding: calc(var(--safe-top-effective) + 12px) 16px 14px;
    border-bottom: 1px solid var(--border-secondary);
    background: var(--bg-secondary);
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.4);
}

/* Pulsanti principali app-like */
.btn-app {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 16px;
    border-radius: 14px;
    border: 1px solid var(--border-primary);
    background: var(--bg-tertiary);
    color: var(--text-primary);
    font-weight: 500;
    min-height: 44px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    transition: all 0.2s ease-in-out;
    cursor: pointer;
    text-decoration: none;
}
.btn-app:hover { background: var(--border-primary); transform: translateY(-1px); box-shadow: 0 4px 12px rgba(0,0,0,0.2); }
.btn-app:active { transform: translateY(1px); }

/* Pulsanti secondari */
.btn-secondary {
    padding: 8px 12px;
    border-radius: 10px;
    border: 1px solid var(--border-primary);
    background: var(--bg-tertiary);
    color: var(--text-primary);
    font-size: 14px;
    min-height: 36px;
    transition: all 0.2s ease-in-out;
    cursor: pointer;
}
.btn-secondary:hover { background: var(--border-primary); }

/* Pulsanti piccoli */
.btn-small {
    padding: 6px 10px;
    border-radius: 8px;
    border: 1px solid var(--border-primary);
    font-size: 12px;
    min-height: 32px;
    transition: all 0.2s ease-in-out;
    cursor: pointer;
    background: var(--bg-tertiary);
    color: var(--text-primary);
}
.btn-small:hover { background: var(--border-primary); }

/* Input app-like */
.app-input {
    background: var(--bg-secondary);
    color: var(--text-primary);
    border: 1px solid var(--border-primary);
    min-height: 44px;
    transition: all 0.2s ease-in-out;
}
.app-input:focus {
    outline: none;
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 3px rgba(14, 165, 233, 0.1);
}
.app-input::placeholder { color: var(--text-tertiary); }

/* Floating Action Button migliorato */
.fab {
    position: fixed;
    right: 20px;
    bottom: calc(var(--bottom-nav-h) + var(--safe-bottom-effective) + 16px);
    z-index: 40;
    padding: 16px;
    border-radius: 50%;
    background: var(--accent-primary);
    color: white;
    border: none;
    min-width: 56px;
    min-height: 56px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    font-weight: bold;
    box-shadow: 0 8px 24px rgba(14, 165, 233, 0.4);
    transition: all 0.3s ease-in-out;
    cursor: pointer;
}
.fab:hover { transform: translateY(-2px); box-shadow: 0 12px 28px rgba(14,165,233,0.5); }
.fab:active { transform: translateY(1px); }

/* Bottom Navigation compatta */
.bottom-nav-compact {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 30;
    padding: 6px 8px calc(6px + var(--safe-bottom-effective));
    background: var(--bg-secondary);
    border-top: 1px solid var(--border-secondary);
    display: flex;
    gap: 2px;
    justify-content: space-between;
    box-shadow: 0 -2px 12px rgba(0, 0, 0, 0.4);
}
.nav-btn-compact {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    padding: 6px 2px;
    border-radius: 8px;
    font-size: 9px;
    font-weight: 500;
    color: var(--text-secondary);
    background: transparent;
    border: none;
    min-height: 40px;
    transition: all 0.2s ease-in-out;
    cursor: pointer;
}
.nav-btn-compact:hover { background: rgba(71,85,105,0.3); }
.nav-btn-compact.active { background: var(--accent-primary); color: white; box-shadow: 0 2px 8px rgba(14,165,233,0.4); }

/* Cards e highlights migliorati */
.channel-card {
    transition: all 0.2s ease-in-out;
    contain: layout style paint;
}
.channel-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 24px rgba(0,0,0,0.2);
    border-color: var(--border-primary);
}
.highlight-card {
    transition: all 0.2s ease-in-out;
    cursor: pointer;
    contain: layout style paint;
}
.highlight-card:hover { transform: translateY(-2px); box-shadow: 0 8px 24px rgba(0,0,0,0.2); }
.highlight-skeleton { border: 1px solid var(--border-primary); background: var(--bg-tertiary); }

/* Modal styles */
.modal-backdrop {
    background: rgba(0,0,0,0.7);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
}

/* Scroll margins per navigazione */
.now-row, .channel-card {
    scroll-margin-top: calc(var(--header-h) + var(--safe-top-effective) + 12px);
}

/* Utility per troncamento testo */
.line-clamp-2 {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}
.line-clamp-3 {
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* Animazioni loading */
@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}
.animate-pulse { animation: pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite; }

@keyframes ping {
    75%, 100% { transform: scale(2); opacity: 0; }
}
.animate-ping { animation: ping 1s cubic-bezier(0, 0, 0.2, 1) infinite; }

/* Logo containers per migliorare contrasto */
.logo-container {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 28px;
    min-height: 24px;
}
.logo-container-small {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 20px;
    min-height: 18px;
}

/* Media queries per desktop */
@media (min-width: 768px) {
    .safe-container { padding-left: 24px; padding-right: 24px; }

    /* Header desktop: rimane nei confini del container */
    .app-header-compact {
        margin: 0 0 16px;
        padding: calc(var(--safe-top-effective) + 12px) 24px 14px;
        border-radius: 16px;
        max-width: 1280px;
        margin-left: auto;
        margin-right: auto;
    }

    /* Bottom nav desktop: segue la larghezza del contenuto */
    .bottom-nav-compact {
        left: 50%;
        right: auto;
        transform: translateX(-50%);
        width: 100%;
        max-width: 1280px;
        border-radius: 16px 16px 0 0;
    }

    .fab { right: max(24px, calc(50vw - 640px + 24px)); }

    /* Responsive text sizing */
    .md\:text-lg { font-size: 1.125rem; line-height: 1.75rem; }
    .md\:text-base { font-size: 1rem; line-height: 1.5rem; }
    .md\:text-sm { font-size: 0.875rem; line-height: 1.25rem; }

    /* Responsive flex */
    .md\:flex { display: flex; }

    /* Titoli non troncati su desktop */
    .truncate { overflow: visible; text-overflow: clip; white-space: normal; }

    /* Highlights e descrizioni con più righe su desktop */
    .line-clamp-2 {
        display: block !important;
        -webkit-line-clamp: none !important;
        -webkit-box-orient: unset !important;
        overflow: visible !important;
    }
}

/* Stili per stati focus e accessibility */
.btn-app:focus,
.btn-secondary:focus,
.btn-small:focus,
.nav-btn-compact:focus,
.app-input:focus {
    outline: 2px solid var(--accent-primary);
    outline-offset: 2px;
}

/* Miglioramenti per device con touch */
@media (hover: none) and (pointer: coarse) {
    .btn-app:hover,
    .btn-secondary:hover,
    .channel-card:hover,
    .highlight-card:hover { transform: none; }

    .btn-app:active,
    .btn-secondary:active { transform: scale(0.98); }
}

/* Performance optimizations */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    :root {
        --border-primary: #94a3b8;
        --text-tertiary: #475569;
    }
}
