/**
 * Sublima App - Components
 * Stili strutturali (indipendenti dal tema light/dark)
 */

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

.app-body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    line-height: 1.5;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    margin: 0;
    -webkit-font-smoothing: antialiased;
}

/* ---- Navbar ---- */
.app-navbar {
    position: sticky;
    top: 0;
    z-index: 1030;
    padding: 0.5rem 1rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: 56px;
    transition: background-color 0.3s ease;
}

.app-navbar-brand {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    text-decoration: none;
    font-weight: 700;
    font-size: 1.1rem;
    color: var(--app-brand);
}

.app-navbar-brand img {
    height: 32px;
    width: auto;
}

.app-navbar-nav {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    list-style: none;
    margin: 0;
    padding: 0;
}

.app-navbar-nav .nav-link {
    display: flex;
    align-items: center;
    gap: 0.375rem;
    padding: 0.5rem 0.75rem;
    border-radius: 0.5rem;
    text-decoration: none;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--app-text-secondary);
    transition: all 0.15s ease;
    cursor: pointer;
    border: none;
    background: none;
}

.app-navbar-nav .nav-link:hover {
    color: var(--app-text-primary);
    background-color: var(--app-bg-hover);
}

.app-navbar-nav .nav-link.active {
    color: var(--app-primary);
    background-color: var(--app-primary-light);
}

.app-navbar-nav .nav-link i {
    font-size: 1.1rem;
}

/* Mobile hamburger */
.app-navbar-toggle {
    display: none;
    background: none;
    border: none;
    padding: 0.5rem;
    font-size: 1.5rem;
    color: var(--app-text-primary);
    cursor: pointer;
}

/* ---- Main Content ---- */
.app-main {
    flex: 1;
    padding: 1.5rem;
    max-width: 1200px;
    margin: 0 auto;
    width: 100%;
}

/* ---- Cards ---- */
.app-card {
    border-radius: 0.75rem;
    padding: 1.25rem;
    margin-bottom: 1rem;
    transition: box-shadow 0.2s ease;
}

.app-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1rem;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid var(--app-border-light);
}

.app-card-header h5,
.app-card-header h6 {
    margin: 0;
    font-weight: 600;
}

.app-card-body {
    font-size: 0.9375rem;
}

/* Stat card (dashboard) */
.app-stat-card {
    text-align: center;
    padding: 1.5rem 1rem;
}

.app-stat-card .stat-icon {
    font-size: 2rem;
    margin-bottom: 0.5rem;
    opacity: 0.8;
}

.app-stat-card .stat-value {
    font-size: 1.75rem;
    font-weight: 700;
    line-height: 1.2;
}

.app-stat-card .stat-label {
    font-size: 0.8125rem;
    color: var(--app-text-secondary);
    margin-top: 0.25rem;
}

.app-stat-card--link {
    cursor: pointer;
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.app-stat-card--link:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 16px rgba(0,0,0,0.10);
}

/* ---- Tables ---- */
.app-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
}

.app-table th {
    padding: 0.75rem;
    font-weight: 600;
    font-size: 0.8125rem;
    text-transform: uppercase;
    letter-spacing: 0.025em;
}

.app-table td {
    padding: 0.75rem;
    vertical-align: middle;
}

.app-table tbody tr {
    transition: background-color 0.1s ease;
    cursor: pointer;
}

/* ---- Loading Overlay ---- */
.app-loading {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.15);
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(2px);
}

.app-loading-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--app-border-color);
    border-top-color: var(--app-primary);
    border-radius: 50%;
    animation: app-spin 0.6s linear infinite;
}

@keyframes app-spin {
    to { transform: rotate(360deg); }
}

/* ---- Toast ---- */
.app-toast {
    min-width: 280px;
    max-width: 380px;
    border-radius: 0.5rem;
    overflow: hidden;
    box-shadow: var(--app-shadow-lg);
    animation: app-toast-in 0.3s ease;
}

@keyframes app-toast-in {
    from { transform: translateX(100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

/* ---- Pagination ---- */
.app-pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.25rem;
    margin-top: 1.5rem;
}

.app-pagination button {
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 36px;
    height: 36px;
    padding: 0 0.5rem;
    border: 1px solid var(--app-border-color);
    background: var(--app-card-bg);
    color: var(--app-text-primary);
    border-radius: 0.375rem;
    font-size: 0.875rem;
    cursor: pointer;
    transition: all 0.15s ease;
}

.app-pagination button:hover:not(:disabled) {
    background: var(--app-bg-hover);
    border-color: var(--app-primary);
    color: var(--app-primary);
}

.app-pagination button.active {
    background: var(--app-primary);
    border-color: var(--app-primary);
    color: var(--app-text-inverse);
}

.app-pagination button:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

/* ---- Empty State ---- */
.app-empty {
    text-align: center;
    padding: 3rem 1.5rem;
    color: var(--app-text-secondary);
}

.app-empty i {
    font-size: 3rem;
    opacity: 0.4;
    display: block;
    margin-bottom: 1rem;
}

.app-empty p {
    font-size: 0.9375rem;
    max-width: 320px;
    margin: 0 auto;
}

/* ---- Status Badges ---- */
.app-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.25rem 0.625rem;
    border-radius: 9999px;
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.01em;
}

.app-badge-success { background: var(--app-success-light); color: var(--app-success); }
.app-badge-warning { background: var(--app-warning-light); color: var(--app-warning); }
.app-badge-danger  { background: var(--app-danger-light); color: var(--app-danger); }
.app-badge-info    { background: var(--app-info-light); color: var(--app-info); }

/* ---- Section Header ---- */
.app-section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.25rem;
}

.app-section-header h4 {
    margin: 0;
    font-weight: 700;
    font-size: 1.25rem;
}

/* ---- Progress bar ---- */
.app-progress {
    height: 8px;
    border-radius: 4px;
    background: var(--app-bg-tertiary);
    overflow: hidden;
}

.app-progress-bar {
    height: 100%;
    border-radius: 4px;
    background: var(--app-primary);
    transition: width 0.4s ease;
}

/* ---- Responsive ---- */
@media (max-width: 768px) {
    .app-navbar-toggle {
        display: block;
    }

    .app-navbar-nav {
        display: none;
        position: absolute;
        top: 56px;
        left: 0;
        right: 0;
        flex-direction: column;
        padding: 0.5rem;
        background: var(--app-navbar-bg);
        border-bottom: 1px solid var(--app-navbar-border);
        box-shadow: var(--app-shadow-md);
    }

    .app-navbar-nav.open {
        display: flex;
    }

    .app-navbar-nav .nav-link {
        width: 100%;
        padding: 0.75rem 1rem;
    }

    .app-main {
        padding: 1rem;
    }

    .app-stat-card .stat-value {
        font-size: 1.5rem;
    }

    .app-table {
        font-size: 0.8125rem;
    }

    .app-table th,
    .app-table td {
        padding: 0.5rem;
    }

    /* Hide label on small screens, keep icon */
    .app-navbar-nav .nav-label {
        display: none;
    }
}

@media (max-width: 480px) {
    .app-main {
        padding: 0.75rem;
    }

    .app-card {
        padding: 1rem;
        border-radius: 0.5rem;
    }
}

/* ================================================================
 * BOTTOM NAVIGATION BAR — layout mode "app"
 * ================================================================ */

/* Bottom bar container */
.w20-bottombar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 1042;
    display: flex;
    align-items: stretch;
    justify-content: space-around;
    height: 60px;
    padding-bottom: env(safe-area-inset-bottom, 0);
    border-top: 1px solid var(--app-border, var(--app-border-color));
    background: var(--app-bottombar-bg, var(--app-bg-secondary, #f8f9fa));
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
}

/* Individual tab item */
.w20-bottombar-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    text-decoration: none;
    color: var(--app-text-secondary, #6c757d);
    font-size: 0.625rem;
    font-weight: 500;
    letter-spacing: 0.01em;
    padding: 6px 4px 4px;
    position: relative;
    transition: color 0.15s ease;
    -webkit-tap-highlight-color: transparent;
    cursor: pointer;
    border: none;
    background: none;
}

.w20-bottombar-item:hover {
    color: var(--app-text-primary, #212529);
    text-decoration: none;
}

.w20-bottombar-item.active {
    color: var(--app-primary, #2563eb);
}

/* Active dot indicator */
.w20-bottombar-item.active::before {
    content: '';
    position: absolute;
    top: 2px;
    width: 4px;
    height: 4px;
    border-radius: 50%;
    background: var(--app-primary, #2563eb);
}

.w20-bottombar-item i {
    font-size: 1.25rem;
    line-height: 1;
}

.w20-bottombar-item span {
    line-height: 1;
}

/* Cart badge on bottom bar */
.w20-bottombar-badge {
    position: absolute;
    top: 4px;
    right: calc(50% - 16px);
    min-width: 16px;
    height: 16px;
    padding: 0 4px;
    border-radius: 8px;
    background: var(--app-danger, #ef4444);
    color: #fff;
    font-size: 0.6rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}

/* Body padding when bottom bar active */
body.w20-layout-app {
    padding-bottom: calc(60px + env(safe-area-inset-bottom, 0));
}

/* ================================================================
 * APP MODE HEADER — minimal header for layout "app"
 * ================================================================ */

.w20-header-app {
    position: sticky;
    top: 0;
    z-index: 1030;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.5rem 1rem;
    min-height: 50px;
    border-bottom: 1px solid var(--app-border, var(--app-border-color));
    background: var(--app-bottombar-bg, var(--app-bg-secondary, #f8f9fa));
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
}

.w20-header-app-brand {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    text-decoration: none;
    font-weight: 700;
    font-size: 1.1rem;
    color: var(--app-brand, var(--app-text-primary));
}

.w20-header-app-brand img {
    height: 30px;
    width: auto;
}

.w20-header-app-actions {
    display: flex;
    align-items: center;
    gap: 0.375rem;
}

.w20-header-app-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: none;
    background: transparent;
    color: var(--app-text-secondary);
    font-size: 1.125rem;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
    text-decoration: none;
    padding: 0;
}

.w20-header-app-btn:hover {
    background: var(--app-bg-hover, var(--app-bg-tertiary));
    color: var(--app-text-primary);
}

/* ================================================================
 * BOTTOM SHEET — "Altro" menu
 * Colori hardcoded (no CSS variables) per evitare trasparenze
 * da conflitti di compositing con backdrop-filter della bottombar.
 * ================================================================ */

/* Nascondi la bottombar quando lo sheet è aperto */
.w20-bottombar.w20-bb-hidden {
    visibility: hidden;
    pointer-events: none;
}

.w20-sheet-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1050;
    background: rgba(0, 0, 0, 0.45);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.25s ease, visibility 0.25s ease;
}

.w20-sheet-backdrop.open {
    opacity: 1;
    visibility: visible;
}

.w20-sheet {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 1051;
    max-height: 70vh;
    border-radius: 1rem 1rem 0 0;
    padding: 0;
    padding-bottom: env(safe-area-inset-bottom, 0);
    transform: translateY(100%);
    transition: transform 0.3s cubic-bezier(0.32, 0.72, 0, 1);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    background: #1a1a1a;
    border-top: 1px solid #333;
}

[data-theme="light"] .w20-sheet {
    background: #ffffff;
    border-top-color: #dee2e6;
}

.w20-sheet.open {
    transform: translateY(0);
}

/* Sheet handle bar */
.w20-sheet-handle {
    display: flex;
    justify-content: center;
    padding: 10px 0 6px;
}

.w20-sheet-handle::before {
    content: '';
    width: 36px;
    height: 4px;
    border-radius: 2px;
    background: #404040;
}

[data-theme="light"] .w20-sheet-handle::before {
    background: #adb5bd;
}

/* Sheet menu list */
.w20-sheet-list {
    list-style: none;
    margin: 0;
    padding: 0 0.5rem 0.5rem;
}

.w20-sheet-list li {
    margin: 0;
}

.w20-sheet-list a {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.875rem 1rem;
    border-radius: 0.75rem;
    text-decoration: none;
    color: #f5f5f5;
    font-size: 0.9375rem;
    font-weight: 500;
    transition: background 0.12s ease;
}

[data-theme="light"] .w20-sheet-list a {
    color: #212529;
}

.w20-sheet-list a:hover {
    background: #262626;
}

[data-theme="light"] .w20-sheet-list a:hover {
    background: #f1f3f5;
}

.w20-sheet-list a i {
    font-size: 1.25rem;
    width: 24px;
    text-align: center;
    color: #a3a3a3;
}

[data-theme="light"] .w20-sheet-list a i {
    color: #6c757d;
}

.w20-sheet-divider {
    height: 1px;
    background: #333;
    margin: 0.25rem 1rem;
}

[data-theme="light"] .w20-sheet-divider {
    background: #dee2e6;
}

/* Hide bottom bar on desktop (>=992px) and show full navbar instead */
@media (min-width: 992px) {
    .w20-bottombar {
        display: none;
    }

    .w20-header-app {
        display: none;
    }

    body.w20-layout-app {
        padding-bottom: 0;
    }

    /* In app mode on desktop, show the full navbar fallback */
    .w20-app-desktop-nav {
        display: flex !important;
    }
}

/* On mobile (<992px) hide desktop nav links in app mode */
@media (max-width: 991.98px) {
    .w20-app-desktop-nav {
        display: none !important;
    }
}

/* ================================================================
 * APP MODE — child page adjustments
 * ================================================================ */

/* Footer: nascosto su mobile in app mode (la bottom bar gestisce la navigazione) */
@media (max-width: 991.98px) {
    body.w20-layout-app .w20-footer {
        display: none;
    }
}

/* Sticky top: in app mode su tablet (768-991px) l'header è 50px non ~65px.
   Riduce il gap morto sopra i pannelli sticky. */
@media (min-width: 768px) and (max-width: 991.98px) {
    body.w20-layout-app .w20-cart-summary,
    body.w20-layout-app .w20-co-summary,
    body.w20-layout-app .w20-det-gallery {
        top: calc(50px + 0.5rem);
    }
}

/* Toast container: offset verso l'alto per non sovrapporsi alla bottom bar */
@media (max-width: 991.98px) {
    body.w20-layout-app #app-toasts {
        bottom: calc(60px + env(safe-area-inset-bottom, 0)) !important;
    }
}

/* ================================================================
 * W20 CAROUSEL SCROLL-SNAP — sezioni articoli homepage
 * Layout: scroll orizzontale nativo, zero dipendenze JS
 * ================================================================ */

.w20-carousel-scroll {
    display: flex;
    gap: 0.75rem;
    overflow-x: auto;
    scroll-snap-type: x mandatory;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;         /* Firefox */
    padding-bottom: 0.25rem;       /* spazio per box-shadow delle card */
    margin-left: calc(var(--bs-gutter-x, 0) * -0.5);
    margin-right: calc(var(--bs-gutter-x, 0) * -0.5);
    padding-left: calc(var(--bs-gutter-x, 0) * 0.5);
    padding-right: calc(var(--bs-gutter-x, 0) * 0.5);
}

.w20-carousel-scroll::-webkit-scrollbar {
    display: none;
}

/* Item: 2 per riga mobile, 3 tablet, 4 desktop */
.w20-carousel-item {
    flex: none;
    width: calc(50% - 0.375rem);
    scroll-snap-align: start;
    display: flex;               /* inner .w20-prd-card si estende in altezza */
}

.w20-carousel-item .w20-prd-card {
    width: 100%;                 /* riempie la larghezza dell'item carousel */
}

@media (min-width: 576px) {
    .w20-carousel-item {
        width: calc(33.333% - 0.5rem);
    }
}

@media (min-width: 992px) {
    .w20-carousel-item {
        width: calc(25% - 0.5625rem);
    }
}

/* Container: full-width nei container Bootstrap per avere overflow visibile */
.container-xl .w20-carousel-scroll,
.container .w20-carousel-scroll {
    overflow-x: auto;
}

/* Wrapper con frecce prev/next (visibili solo su desktop ≥768px) */
.w20-carousel-wrap {
    position: relative;
}

.w20-carousel-prev,
.w20-carousel-next {
    display: none;
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    z-index: 10;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: 1px solid var(--app-border, #e2e8f0);
    background: var(--app-bg-secondary);
    color: var(--app-text-primary);
    font-size: 1rem;
    cursor: pointer;
    align-items: center;
    justify-content: center;
    transition: background 0.15s, box-shadow 0.15s;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
    padding: 0;
}

.w20-carousel-prev { left: -18px; }
.w20-carousel-next { right: -18px; }

.w20-carousel-prev:hover,
.w20-carousel-next:hover {
    background: var(--app-bg-tertiary);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.16);
}

.w20-carousel-prev:disabled,
.w20-carousel-next:disabled {
    opacity: 0.35;
    cursor: default;
    box-shadow: none;
}

@media (min-width: 768px) {
    .w20-carousel-prev,
    .w20-carousel-next {
        display: flex;
    }
}

/* ================================================================
 * W20 PRODUCT CARD — .w20-prd-card
 * Usata dalla macro _prd_card.html nelle sezioni articoli homepage
 * ================================================================ */

.w20-prd-card {
    background: var(--app-bg-secondary);
    border: 1px solid var(--app-border, #e2e8f0);
    border-radius: 0.75rem;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    height: 100%;
    transition: box-shadow 0.2s ease, transform 0.2s ease;
}

.w20-prd-card:hover {
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.1);
    transform: translateY(-2px);
}

/* Wrapper immagine: aspect-ratio 1:1 */
.w20-prd-img-wrap {
    display: block;
    overflow: hidden;
    aspect-ratio: 1 / 1;
    background: var(--app-bg-tertiary, #f1f5f9);
    flex-shrink: 0;
}

.w20-prd-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.3s ease;
}

.w20-prd-card:hover .w20-prd-img {
    transform: scale(1.04);
}

/* Placeholder immagine assente */
.w20-prd-img-ph {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--app-text-muted, #94a3b8);
    font-size: 2.5rem;
}

/* Corpo card: denominazione, brand, prezzo, bottone */
.w20-prd-body {
    padding: 0.75rem 0.875rem 0.875rem;
    display: flex;
    flex-direction: column;
    flex: 1;
    gap: 0.2rem;
}

.w20-prd-brand {
    font-size: 0.6875rem;
    font-weight: 600;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    color: var(--app-text-muted, #94a3b8);
    line-height: 1.2;
}

.w20-prd-name {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--app-text-primary);
    text-decoration: none;
    line-height: 1.35;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.w20-prd-name:hover {
    color: var(--app-primary, #2563eb);
    text-decoration: none;
}

.w20-prd-price {
    margin-top: auto;
    padding-top: 0.375rem;
}

.w20-prd-price-fin {
    font-size: 1rem;
    font-weight: 700;
    line-height: 1.2;
}

.w20-prd-footer {
    margin-top: 0.5rem;
}

.w20-btn-primary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.5rem 1.25rem;
    border-radius: 0.5rem;
    background: var(--app-primary, #2563eb);
    color: #fff !important;
    font-size: 0.9375rem;
    font-weight: 600;
    text-decoration: none;
    border: none;
    transition: background 0.15s ease, box-shadow 0.15s ease;
    cursor: pointer;
}

.w20-btn-primary:hover {
    background: var(--app-primary-hover, #1d4ed8);
    color: #fff !important;
    text-decoration: none;
}

.w20-prd-btn {
    display: block;
    width: 100%;
    text-align: center;
    padding: 0.4375rem 0.75rem;
    border-radius: 0.5rem;
    background: var(--app-primary, #2563eb);
    color: #fff;
    font-size: 0.8125rem;
    font-weight: 600;
    text-decoration: none;
    transition: background 0.15s ease;
}

.w20-prd-btn:hover {
    background: var(--app-primary-hover, #1d4ed8);
    color: #fff;
    text-decoration: none;
}
