/* FBvision - Custom CSS */
/* Ottimizzato per iPad landscape */

/* Alpine.js cloak - hide elements until Alpine loads */
[x-cloak] {
    display: none !important;
}

:root {
    --sidebar-blue: #1e4a7e;
    --sidebar-hover: #163b67;
    --primary-text: #2c5aa0;
    --card-bg: #ffffff;
    --body-bg: #f5f7fa;
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.06);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.08);
    --shadow-lg: 0 4px 20px rgba(0, 0, 0, 0.06);
    --border-radius: 16px;
    --breadcrumb-bg: #e8ecf1;
    --input-border: #e1e4e8;
    --text-muted: #6c757d;
}

/* Reset e Base */
html,
body {
    height: 100%;
    overflow: hidden;
}

body {
    background-color: var(--body-bg);
    font-family:
        -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue",
        Arial, sans-serif;
}

/* =============================================
   LAYOUT CONTAINER
   ============================================= */
.app-container {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

/* =============================================
   SIDEBAR
   ============================================= */
.sidebar {
    width: 260px;
    min-width: 260px;
    background: linear-gradient(180deg, var(--sidebar-blue) 0%, #163b67 100%);
    color: white;
    display: flex;
    flex-direction: column;
    box-shadow: 4px 0 12px rgba(0, 0, 0, 0.1);
    z-index: 1000;
}

.nav-section {
    flex: 1;
    padding-top: 1rem;
    overflow-y: auto;
}

.nav-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.5rem;
    color: white;
    text-decoration: none;
    font-size: 1rem;
    font-weight: 500;
    border-left: 4px solid transparent;
    transition: all 0.2s ease;
}

.nav-item:hover,
.nav-item.active {
    background-color: var(--sidebar-hover);
    border-left-color: rgba(255, 255, 255, 0.5);
    padding-left: 1.7rem;
    color: white;
}

.nav-item.active {
    border-left-color: white;
    background-color: rgba(255, 255, 255, 0.1);
}

.nav-item i {
    font-size: 1.1rem;
    opacity: 0.9;
}

.logout-section {
    padding: 1.5rem 1.5rem 3rem 1.5rem;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.logout-btn {
    display: flex;
    justify-content: space-between;
    align-items: center;
    color: white;
    text-decoration: none;
    padding: 0.5rem 0;
    transition: opacity 0.2s;
}

.logout-btn:hover {
    opacity: 0.8;
    color: white;
}

/* Sync Button in Sidebar */
.sync-section {
    padding: 1rem 1.5rem;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.sync-btn {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    padding: 0.75rem 1rem;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 8px;
    color: white;
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.2s;
}

.sync-btn:hover {
    background: rgba(255, 255, 255, 0.2);
}

.sync-btn.syncing {
    pointer-events: none;
    opacity: 0.7;
}

.sync-btn .spinner-border {
    width: 1rem;
    height: 1rem;
}

/* =============================================
   MAIN CONTENT
   ============================================= */
.main-content {
    flex: 1;
    overflow-y: auto;
    padding: 2rem;
    background-color: var(--body-bg);
}

/* =============================================
   HEADER LOGO
   ============================================= */
.header-logo {
    text-align: center;
    margin-bottom: 2.5rem;
    padding-top: 0.5rem;
}

.header-logo.compact {
    padding: 1.5rem 0 1rem;
    margin-bottom: 0;
}

.logo-text {
    font-size: 1.8rem;
    font-weight: 300;
    letter-spacing: 3px;
    color: var(--primary-text);
    margin-bottom: 0.2rem;
}

.logo-text span {
    font-weight: 600;
}

.logo-subtitle {
    font-size: 0.65rem;
    letter-spacing: 4px;
    color: #6c757d;
    text-transform: uppercase;
    font-weight: 600;
}

.header-logo-img {
    max-height: 60px;
    width: auto;
}

/* =============================================
   BREADCRUMB BAR
   ============================================= */
.breadcrumb-bar {
    background-color: var(--breadcrumb-bg);
    padding: 1rem 2rem;
    margin: 0 0 2rem;
    border-radius: 8px;
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.breadcrumb-bar a {
    color: var(--primary-text);
    text-decoration: none;
    font-weight: 600;
    font-size: 1.1rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    transition: opacity 0.2s;
}

.breadcrumb-bar a:hover {
    opacity: 0.8;
}

.breadcrumb-bar i {
    font-size: 1.4rem;
}

/* =============================================
   PRODUCTS GRID
   ============================================= */
.products-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1.5rem;
    max-width: 1400px;
    margin: 0 auto;
}

/* Product Card */
.product-card {
    background: var(--card-bg);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-sm);
    transition: all 0.3s ease;
    overflow: hidden;
    border: none;
    height: 100%;
    display: flex;
    flex-direction: column;
    text-decoration: none;
    color: inherit;
}

.product-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-md);
    text-decoration: none;
    color: inherit;
}

.product-image-container {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
    min-height: 180px;
    /*background: linear-gradient(180deg, #fafbfc 0%, #ffffff 100%);*/
    background: #ffffff;
}

.product-image {
    max-height: 140px;
    max-width: 100%;
    object-fit: contain;
    /*filter: drop-shadow(0 4px 6px rgba(0,0,0,0.05));*/
}

.product-placeholder {
    width: 100px;
    height: 100px;
    background: #e9ecef;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.product-placeholder i {
    font-size: 2.5rem;
    color: #adb5bd;
}

.product-footer {
    padding: 1rem 1.25rem;
    background: white;
    border-top: 1px solid #f0f0f0;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.product-card:hover .product-footer {
    background-color: #fafbfc;
}

.product-name {
    font-size: 1.05rem;
    font-weight: 600;
    color: var(--primary-text);
    margin: 0;
    letter-spacing: 0.3px;
}

.product-code {
    font-size: 0.75rem;
    color: #6c757d;
    margin-top: 0.25rem;
}

.arrow-icon {
    color: var(--primary-text);
    font-size: 1.2rem;
    transition: transform 0.2s;
}

.product-card:hover .arrow-icon {
    transform: translateX(3px);
}

/* Document Count Badge */
.doc-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    font-size: 0.75rem;
    color: #6c757d;
    background: #f8f9fa;
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
}

/* =============================================
   PRODUCT DETAIL PAGE
   ============================================= */

/* Detail page overrides */
.page-detail .main-content {
    padding: 0;
}

.page-detail .header-logo {
    padding: 1.5rem 0 1rem;
    margin-bottom: 0;
}

.page-detail .breadcrumb-bar {
    padding: 1rem 2.5rem;
    margin: 0 2.5rem 2rem;
}

.detail-container {
    padding: 0 2.5rem 2.5rem;
    max-width: 1400px;
    margin: 0 auto;
}

.product-detail-card {
    background: var(--card-bg);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-sm);
    padding: 2.5rem 3rem;
    display: flex;
    align-items: center;
    gap: 2rem;
    margin-bottom: 2rem;
    overflow: hidden;
}

.product-info-side {
    flex: 0 0 50%;
    text-align: center;
}

.product-image-side {
    flex: 0 0 auto;
    min-width: 0;
    overflow: hidden;
}

.product-title {
    font-size: 2.2rem;
    font-weight: 700;
    color: #2d3436;
    margin-bottom: 0.75rem;
}

.product-subtitle {
    font-size: 1.1rem;
    color: #636e72;
    line-height: 1.6;
    margin: 0;
}

.product-image-large {
    max-height: 250px;
    width: 100%;
    object-fit: contain;
}

/* Detail Grid Layout (2-column: product + documents list) */
.detail-grid {
    display: grid;
    grid-template-columns: 1.2fr 1fr;
    gap: 2rem;
}

.detail-grid .product-detail-card {
    padding: 3rem;
    text-align: center;
    height: fit-content;
    display: block;
}

.documents-list {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.documents-list .document-card {
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
}

.documents-list .document-card:hover {
    transform: translateX(4px);
}

.document-info h4 {
    font-size: 1.15rem;
    font-weight: 600;
    color: #2d3436;
    margin: 0 0 0.25rem;
}

.document-info .file-type {
    font-size: 0.9rem;
    color: #b2bec3;
    font-weight: 500;
}

.document-action {
    color: var(--primary-text);
    font-size: 1.4rem;
    opacity: 0.8;
    transition: transform 0.2s;
}

.document-card:hover .document-action {
    opacity: 1;
    transform: scale(1.1);
}

/* =============================================
   DOCUMENTS GRID
   ============================================= */
.documents-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1.5rem;
}

.document-card {
    background: var(--card-bg);
    border-radius: 12px;
    box-shadow: var(--shadow-sm);
    padding: 1rem;
    overflow: hidden;
    transition: all 0.2s ease;
    cursor: pointer;
    border: none;
    display: flex;
    flex-direction: column;
}

.document-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-md);
}

.document-card-image {
    width: 100%;
    aspect-ratio: 4 / 3;
    object-fit: cover;
    display: block;
    background: #f0f2f5;
}

.document-card-placeholder {
    width: 100%;
    aspect-ratio: 4 / 3;
    background: linear-gradient(135deg, #e8ecf1 0%, #f5f7fa 100%);
    display: flex;
    align-items: center;
    justify-content: center;
}

.document-card-placeholder i {
    font-size: 3rem;
    color: #b2bec3;
}

.document-card-footer {
    padding: 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.5rem;
}

.document-card-footer h4 {
    font-size: 0.95rem;
    font-weight: 600;
    color: #2d3436;
    margin: 0;
    line-height: 1.4;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    flex: 1;
}

.document-card-action {
    color: var(--primary-text);
    font-size: 1.2rem;
    opacity: 0.6;
    transition: all 0.2s;
    flex-shrink: 0;
}

.document-card:hover .document-card-action {
    opacity: 1;
}

.offline-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    font-size: 0.7rem;
    color: #059669;
    background: #d1fae5;
    padding: 0.2rem 0.5rem;
    border-radius: 4px;
}

/* =============================================
   LOGIN PAGE
   ============================================= */
body.login-page {
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: auto;
}

.login-page .header-logo {
    padding: 3rem 0 2rem;
    margin-bottom: 0;
}

.login-container {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 2rem 4rem;
}

.login-card {
    background: white;
    border-radius: 12px;
    box-shadow: var(--shadow-lg);
    padding: 3rem 3.5rem;
    width: 100%;
    max-width: 480px;
    border: none;
}

.login-title {
    font-size: 1.8rem;
    font-weight: 700;
    color: #2d3436;
    text-align: center;
    margin-bottom: 0.5rem;
}

.login-subtitle {
    text-align: center;
    color: var(--text-muted);
    margin-bottom: 2.5rem;
    font-size: 1rem;
}

/* Form Controls */
.login-page .form-floating {
    margin-bottom: 1.25rem;
}

.login-page .form-floating > .form-control {
    border: 1.5px solid var(--input-border);
    border-radius: 8px;
    height: 56px;
    font-size: 1rem;
}

.login-page .form-floating > .form-control:focus {
    border-color: var(--sidebar-blue);
    box-shadow: 0 0 0 3px rgba(30, 74, 126, 0.08);
}

.login-page .form-floating > label {
    color: #888;
    padding-left: 1rem;
}

/* Password Toggle */
.password-wrapper {
    position: relative;
}

.password-toggle {
    position: absolute;
    right: 1rem;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    color: #666;
    cursor: pointer;
    z-index: 10;
    padding: 0.5rem;
    font-size: 1.1rem;
}

.password-toggle:hover {
    color: var(--sidebar-blue);
}

/* Forgot Password */
.forgot-password {
    text-align: center;
    margin: 1.5rem 0 2rem;
    color: var(--text-muted);
    font-size: 0.95rem;
}

.forgot-password a {
    color: var(--primary-text);
    text-decoration: underline;
    font-weight: 500;
}

.forgot-password a:hover {
    color: var(--sidebar-blue);
}

/* Login Button */
.btn-login {
    background-color: var(--sidebar-blue);
    border: none;
    border-radius: 8px;
    padding: 1rem;
    font-size: 1.1rem;
    font-weight: 600;
    width: 100%;
    color: white;
    transition: all 0.2s;
    box-shadow: 0 4px 12px rgba(30, 74, 126, 0.25);
}

.btn-login:hover {
    background-color: #163b67;
    transform: translateY(-1px);
    box-shadow: 0 6px 16px rgba(30, 74, 126, 0.35);
    color: white;
}

.btn-login:active {
    transform: translateY(0);
}

/* Error message */
.error-message {
    background-color: #fee2e2;
    border: 1px solid #fecaca;
    color: #dc2626;
    padding: 0.75rem 1rem;
    border-radius: 8px;
    margin-bottom: 1.5rem;
    font-size: 0.9rem;
}

/* Django Messages for Login */
.alert-messages {
    position: fixed;
    top: 1rem;
    right: 1rem;
    z-index: 1050;
    min-width: 300px;
}

/* =============================================
   OFFLINE INDICATOR
   ============================================= */
.offline-indicator {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    background: #f59e0b;
    color: white;
    text-align: center;
    padding: 0.5rem;
    font-size: 0.85rem;
    z-index: 9999;
    display: none;
}

body.offline .offline-indicator {
    display: block;
}

body.offline .app-container {
    padding-top: 40px;
}

body.offline .online-only {
    opacity: 0.5;
    pointer-events: none;
}

/* =============================================
   SYNC PROGRESS
   ============================================= */
.sync-progress {
    margin-top: 0.75rem;
}

.sync-progress .progress {
    height: 6px;
    border-radius: 3px;
    background: rgba(255, 255, 255, 0.2);
}

.sync-progress .progress-bar {
    background: white;
}

.sync-message {
    font-size: 0.75rem;
    margin-top: 0.5rem;
    opacity: 0.9;
}

/* =============================================
   EMPTY STATE
   ============================================= */
.empty-state {
    text-align: center;
    padding: 4rem 2rem;
}

.empty-state-icon {
    font-size: 4rem;
    color: #d1d5db;
    margin-bottom: 1rem;
}

.empty-state-text {
    color: #6b7280;
    font-size: 1.1rem;
}

/* =============================================
   CUSTOM SCROLLBARS
   ============================================= */
.main-content::-webkit-scrollbar,
.nav-section::-webkit-scrollbar {
    width: 8px;
}

.main-content::-webkit-scrollbar-track,
.nav-section::-webkit-scrollbar-track {
    background: #f1f1f1;
}

.main-content::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: 4px;
}

.main-content::-webkit-scrollbar-thumb:hover {
    background: #a1a1a1;
}

.nav-section::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.1);
}

.nav-section::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.3);
    border-radius: 4px;
}

/* =============================================
   ANIMATIONS
   ============================================= */
.spin {
    animation: spin 1s linear infinite;
}

@keyframes spin {
    from {
        transform: rotate(0deg);
    }
    to {
        transform: rotate(360deg);
    }
}

/* =============================================
   RESPONSIVE - iPad Landscape
   ============================================= */
@media (min-width: 1024px) and (max-width: 1366px) and (orientation: landscape) {
    .sidebar {
        width: 240px;
        min-width: 240px;
    }

    .main-content {
        padding: 1.5rem;
    }

    .products-grid {
        grid-template-columns: repeat(3, 1fr);
        gap: 1.25rem;
    }

    .header-logo {
        margin-bottom: 1.5rem;
    }

    .logo-text {
        font-size: 1.5rem;
    }

    .product-detail-card {
        padding: 2rem;
    }

    .documents-grid {
        grid-template-columns: repeat(3, 1fr);
        gap: 1.25rem;
    }

    .breadcrumb-bar {
        padding: 0.875rem 1.5rem;
    }

    .login-card {
        padding: 2.5rem 3rem;
        max-width: 440px;
    }
}

/* Detail page landscape overrides */
@media (max-width: 1024px) and (orientation: landscape) {
    .page-detail .breadcrumb-bar {
        margin: 0 2rem 1.5rem;
        padding: 0.875rem 1.5rem;
    }

    .detail-container {
        padding: 0 2rem 2rem;
    }

    .detail-grid {
        grid-template-columns: 1fr 1fr;
        gap: 1.5rem;
    }
}

/* =============================================
   RESPONSIVE - iPad Portrait
   ============================================= */
@media (max-width: 1024px) and (orientation: portrait) {
    .sidebar {
        width: 220px;
        min-width: 220px;
    }

    .products-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .documents-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .product-detail-card {
        flex-direction: column;
        text-align: center;
    }
}

/* =============================================
   RESPONSIVE - Mobile
   ============================================= */
@media (max-width: 768px) {
    .app-container {
        flex-direction: column;
    }

    .sidebar {
        width: 100%;
        min-width: 100%;
        height: auto;
        flex-direction: row;
        flex-wrap: wrap;
        display: none; /* Hide sidebar on mobile for login */
    }

    .nav-section {
        display: flex;
        flex-wrap: nowrap;
        overflow-x: auto;
        padding: 0.5rem;
    }

    .nav-item {
        padding: 0.75rem 1rem;
        white-space: nowrap;
    }

    .logout-section,
    .sync-section {
        display: none;
    }

    .main-content {
        height: calc(100vh - 60px);
    }

    .products-grid {
        grid-template-columns: 1fr;
    }

    .documents-grid {
        grid-template-columns: 1fr;
    }

    .product-detail-card {
        flex-direction: column;
        text-align: center;
        padding: 1.5rem;
    }

    .product-title {
        font-size: 1.75rem;
    }

    .page-detail .breadcrumb-bar {
        margin: 0 1rem 1rem;
        padding: 0.75rem 1rem;
    }

    .detail-container {
        padding: 0 1rem 1rem;
    }

    .detail-grid {
        grid-template-columns: 1fr;
    }

    .login-card {
        padding: 2rem 1.5rem;
    }

    .login-page .header-logo {
        padding: 2rem 0 1.5rem;
    }
}

/* =============================================
   iOS SAFE AREA
   ============================================= */
@supports (padding: env(safe-area-inset-left)) {
    .sidebar {
        padding-left: env(safe-area-inset-left);
    }

    .main-content {
        padding-right: env(safe-area-inset-right);
    }
}

/* =============================================
   PRINT
   ============================================= */
@media print {
    .sidebar,
    .sync-section,
    .offline-indicator {
        display: none !important;
    }

    .main-content {
        width: 100%;
        padding: 0;
    }
}
