/* === BLOCCO: Stili Generali PWA === */
:root {
    --primary-color: #4a90d9;
    --success-color: #28a745;
    --danger-color: #dc3545;
    --warning-color: #ffc107;
}

/* === BLOCCO: Placeholder Input Chiaro === */
::placeholder {
    color: #c0c0c0 !important;
    opacity: 1 !important;
}
::-webkit-input-placeholder {
    color: #c0c0c0 !important;
    opacity: 1 !important;
}
::-moz-placeholder {
    color: #c0c0c0 !important;
    opacity: 1 !important;
}
:-ms-input-placeholder {
    color: #c0c0c0 !important;
    opacity: 1 !important;
}

* {
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    background-color: #f8f9fa;
}

/* === BLOCCO: Container Responsive === */
.container {
    max-width: 100%;
}

@media (min-width: 768px) {
    .container {
        max-width: 720px;
    }
}

@media (min-width: 992px) {
    .container {
        max-width: 960px;
    }
}

@media (min-width: 1200px) {
    .container {
        max-width: 1140px;
    }
}

/* Container stretto per login e pagine semplici */
.container-narrow {
    max-width: 500px;
    margin: 0 auto;
}

/* === BLOCCO: Avatar === */
.avatar-circle {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    font-size: 1.2rem;
}

/* === BLOCCO: Menu Cards === */
.menu-card {
    transition: transform 0.2s, box-shadow 0.2s;
    cursor: pointer;
}

.menu-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 .5rem 1rem rgba(0,0,0,.15)!important;
}

.menu-card:active {
    transform: scale(0.98);
}

.menu-icon {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto;
}

/* === BLOCCO: Login === */
.login-logo {
    width: 100px;
    height: 100px;
    background: linear-gradient(135deg, var(--primary-color), #6cb2eb);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto;
    box-shadow: 0 4px 15px rgba(74, 144, 217, 0.3);
}

.login-logo i {
    color: white !important;
}

/* === BLOCCO: OTP Inputs === */
.otp-input {
    width: 50px;
    height: 60px;
    font-size: 1.5rem;
    font-weight: bold;
    text-align: center;
    border: 2px solid #dee2e6;
    border-radius: 8px;
    padding: 0;
    line-height: 60px;
    caret-color: var(--primary-color);
}

.otp-input:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 0.2rem rgba(74, 144, 217, 0.25);
    outline: none;
}

.otp-inputs {
    display: flex;
    justify-content: center;
    gap: 8px;
    flex-wrap: nowrap;
}

/* === BLOCCO: Timbratura === */
.timbratura-btn {
    width: 200px;
    height: 200px;
    border-radius: 50%;
    font-size: 1.5rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    margin: 0 auto;
    border: none;
    box-shadow: 0 10px 40px rgba(0,0,0,0.2);
    transition: transform 0.2s, box-shadow 0.2s;
}

.timbratura-btn:hover {
    transform: scale(1.05);
}

.timbratura-btn:active {
    transform: scale(0.95);
}

.timbratura-btn i {
    font-size: 4rem;
    margin-bottom: 0.5rem;
}

.timbratura-btn.ingresso {
    background: linear-gradient(135deg, #28a745, #20c997);
    color: white;
}

.timbratura-btn.uscita {
    background: linear-gradient(135deg, #dc3545, #e74c3c);
    color: white;
}

/* === BLOCCO: QR Scanner === */
.qr-scanner-container {
    position: relative;
    width: 100%;
    max-width: 400px;
    margin: 0 auto;
    border-radius: 16px;
    overflow: hidden;
    box-shadow: 0 4px 20px rgba(0,0,0,0.2);
}

.qr-scanner-container video {
    width: 100%;
    display: block;
}

.qr-overlay {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 200px;
    height: 200px;
    border: 3px solid rgba(255,255,255,0.8);
    border-radius: 16px;
    box-shadow: 0 0 0 9999px rgba(0,0,0,0.3);
}

.qr-overlay::before,
.qr-overlay::after {
    content: '';
    position: absolute;
    width: 30px;
    height: 30px;
    border-color: var(--primary-color);
    border-style: solid;
}

.qr-overlay::before {
    top: -3px;
    left: -3px;
    border-width: 4px 0 0 4px;
    border-radius: 16px 0 0 0;
}

.qr-overlay::after {
    top: -3px;
    right: -3px;
    border-width: 4px 4px 0 0;
    border-radius: 0 16px 0 0;
}

/* === BLOCCO: Card Lista === */
.list-card {
    border-left: 4px solid transparent;
    transition: all 0.2s;
}

.list-card:hover {
    background-color: #f8f9fa;
}

.list-card.in_attesa {
    border-left-color: var(--warning-color);
}

.list-card.approvata {
    border-left-color: var(--success-color);
}

.list-card.rifiutata {
    border-left-color: var(--danger-color);
}

.list-card.in_attesa_admin {
    border-left-color: #17a2b8;
}

/* === BLOCCO: Timeline Tracciabilita === */
.tracking-timeline {
    background-color: #f8f9fa;
    border-radius: 6px;
    padding: 10px;
    border: 1px solid #e9ecef;
}

.tracking-step {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 4px 8px;
    border-radius: 4px;
    background-color: #fff;
    border: 1px solid #dee2e6;
}

.tracking-step.approved {
    background-color: #d4edda;
    border-color: #c3e6cb;
}

.tracking-step.rejected {
    background-color: #f8d7da;
    border-color: #f5c6cb;
}

.tracking-step.pending {
    background-color: #fff3cd;
    border-color: #ffeeba;
}

/* === BLOCCO: Badge Notifiche === */
.notification-badge {
    position: absolute;
    top: -5px;
    right: -5px;
    min-width: 20px;
    height: 20px;
    border-radius: 10px;
    background-color: var(--danger-color);
    color: white;
    font-size: 0.7rem;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 5px;
}

/* === BLOCCO: Empty State === */
.empty-state {
    padding: 3rem 1rem;
    text-align: center;
}

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

.empty-state h5 {
    color: #6c757d;
}

/* === BLOCCO: Loading === */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(255,255,255,0.9);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
}

/* === BLOCCO: PWA Install Banner === */
.install-banner {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: linear-gradient(135deg, var(--primary-color), #6cb2eb);
    color: white;
    padding: 1rem;
    z-index: 1000;
    box-shadow: 0 -4px 20px rgba(0,0,0,0.2);
}

/* === BLOCCO: Admin Sidebar Desktop === */
@media (min-width: 992px) {
    .admin-wrapper {
        display: flex;
    }
    
    .admin-sidebar {
        width: 250px;
        min-height: 100vh;
        background: #2c3e50;
        color: white;
        position: fixed;
        left: 0;
        top: 0;
    }
    
    .admin-content {
        margin-left: 250px;
        flex: 1;
        padding: 20px;
    }
    
    .admin-sidebar .nav-link {
        color: rgba(255,255,255,0.8);
        padding: 12px 20px;
        border-left: 3px solid transparent;
    }
    
    .admin-sidebar .nav-link:hover,
    .admin-sidebar .nav-link.active {
        background: rgba(255,255,255,0.1);
        color: white;
        border-left-color: var(--primary-color);
    }
    
    .admin-sidebar .nav-link i {
        width: 25px;
    }
}

/* === BLOCCO: Tabelle Responsive === */
.table-responsive-custom {
    overflow-x: auto;
}

@media (min-width: 768px) {
    .table-responsive-custom table {
        min-width: 100%;
    }
}

/* === BLOCCO: Grid Desktop === */
@media (min-width: 992px) {
    .dashboard-grid {
        display: grid;
        grid-template-columns: repeat(3, 1fr);
        gap: 20px;
    }
    
    .dashboard-grid-4 {
        grid-template-columns: repeat(4, 1fr);
    }
}

/* === BLOCCO: Responsive Mobile === */
@media (max-width: 576px) {
    .otp-input {
        width: 38px;
        height: 46px;
        font-size: 1.1rem;
        line-height: 1.2;
        padding: 10px 2px;
    }
    
    .otp-inputs {
        gap: 4px;
    }
    
    .timbratura-btn {
        width: 180px;
        height: 180px;
    }
    
    .timbratura-btn i {
        font-size: 3rem;
    }
    
    .btn-lg {
        padding: 0.75rem 1rem;
        font-size: 1rem;
    }
}

/* === BLOCCO: Animazioni === */
@keyframes pulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.05); }
    100% { transform: scale(1); }
}

.pulse {
    animation: pulse 2s infinite;
}

/* === BLOCCO: Safe Area iOS === */
@supports (padding: max(0px)) {
    body {
        padding-bottom: max(0px, env(safe-area-inset-bottom));
    }
    
    .footer {
        padding-bottom: max(1rem, env(safe-area-inset-bottom));
    }
}

/* === BLOCCO: Card migliorata === */
.card {
    border: none;
    border-radius: 12px;
}

.card-header {
    border-radius: 12px 12px 0 0 !important;
}

/* === BLOCCO: Form Control migliorato === */
.form-control:focus,
.form-select:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 0.2rem rgba(74, 144, 217, 0.25);
}

/* === BLOCCO: Navbar Desktop === */
@media (min-width: 992px) {
    .navbar-expand-lg .navbar-nav {
        flex-direction: row;
    }
    
    .navbar .nav-item {
        margin: 0 5px;
    }
}

/* === BLOCCO: Layout App-Like === */
.app-container {
    padding: 0.75rem;
    min-height: calc(100vh - 56px);
    display: flex;
    flex-direction: column;
}

.app-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 0.75rem;
}

.app-header h4 {
    margin: 0;
    font-size: 1.1rem;
}

.app-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.card-compact {
    border-radius: 12px;
}

.card-compact .card-header {
    padding: 0.5rem 0.75rem;
}

.card-compact .card-body {
    padding: 0.75rem;
}

/* === BLOCCO: QR Scanner Fullscreen-like === */
#qr-reader {
    max-height: 280px;
    overflow: hidden;
    border-radius: 12px;
}

#qr-reader video {
    max-height: 280px !important;
    object-fit: cover;
}

.scanner-active .hide-on-scan {
    display: none !important;
}

/* === BLOCCO: Padding ridotti mobile === */
@media (max-width: 576px) {
    .py-4 {
        padding-top: 0.75rem !important;
        padding-bottom: 0.75rem !important;
    }
    
    .g-3 {
        --bs-gutter-y: 0.5rem;
        --bs-gutter-x: 0.5rem;
    }
    
    .mb-3 {
        margin-bottom: 0.5rem !important;
    }
    
    .mb-4 {
        margin-bottom: 0.75rem !important;
    }
    
    .card-body {
        padding: 0.75rem;
    }
    
    .card-header {
        padding: 0.5rem 0.75rem;
    }
    
    h4 {
        font-size: 1.15rem;
    }
    
    .alert {
        padding: 0.5rem 0.75rem;
        font-size: 0.9rem;
    }
    
    .navbar {
        padding: 0.35rem 0.75rem;
    }
    
    .navbar-brand {
        font-size: 0.95rem;
    }
    
    footer {
        padding: 0.5rem !important;
        font-size: 0.75rem;
    }
    
    .btn-sm {
        padding: 0.25rem 0.5rem;
        font-size: 0.8rem;
    }
}

/* === BLOCCO: Footer compatto === */
footer.compact {
    padding: 0.35rem !important;
    font-size: 0.7rem;
}

/* === BLOCCO: Nascondi footer durante scanner === */
.scanner-active footer {
    display: none;
}

/* === BLOCCO: Navbar migliorata - Allineamento icone e testo === */
.navbar .nav-link {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.5rem 0.75rem;
    white-space: nowrap;
}

.navbar .nav-link i {
    font-size: 0.9rem;
    width: 1rem;
    text-align: center;
}

.navbar .nav-link .badge {
    margin-left: 0.25rem;
    vertical-align: middle;
}

.navbar .dropdown-toggle::after {
    vertical-align: middle;
    margin-left: 0.35rem;
}

.navbar .dropdown-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.navbar .dropdown-item i {
    width: 1.25rem;
    text-align: center;
}

.navbar-brand {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
}

.navbar-brand i {
    font-size: 1.1rem;
}

/* Desktop: compatta navbar per evitare scroll orizzontale */
@media (min-width: 992px) {
    .navbar .nav-link {
        padding: 0.4rem 0.5rem;
        font-size: 0.85rem;
        gap: 0.25rem;
    }
    
    .navbar .nav-link i {
        font-size: 0.8rem;
        width: 0.9rem;
    }
    
    .navbar-brand {
        font-size: 0.9rem;
        gap: 0.35rem;
    }
    
    .navbar-brand small {
        font-size: 0.7rem;
    }
    
    .navbar .dropdown-toggle::after {
        margin-left: 0.2rem;
    }
}

/* Schermi molto larghi: padding leggermente maggiore */
@media (min-width: 1400px) {
    .navbar .nav-link {
        padding: 0.5rem 0.65rem;
        font-size: 0.875rem;
    }
}

@media (max-width: 991.98px) {
    .navbar .nav-link {
        padding: 0.65rem 1rem;
        border-bottom: 1px solid rgba(255,255,255,0.1);
    }
    
    .navbar .dropdown-menu {
        background: transparent;
        border: none;
        padding-left: 1rem;
    }
    
    .navbar .dropdown-item {
        color: rgba(255,255,255,0.85);
        padding: 0.5rem 1rem;
    }
    
    .navbar .dropdown-item:hover {
        background: rgba(255,255,255,0.1);
        color: #fff;
    }
}
