/* style.css - Grafica Globale NGA Gestionale */
:root { 
    --nga-blue: #1e3a8a; 
    --nga-orange: #f97316; 
    --w3-orange: #f48120; 
    --dark: #0f172a; 
    --gray: #64748b; 
    --border: #e2e8f0; 
    --accent: #f8fafc; 
    --bg: #f4f7f9;
    --bg-main: #f4f7f9;
    --bg-light: #f8fafc;
    --sidebar-width: 260px;
}

body { 
    background-color: var(--bg-main, #f1f5f9); 
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    color: #334155;
    margin: 0; 
    padding: 0; 
    min-height: 100vh; 
    overflow-x: hidden;
    /* Anti-FOUC: parte invisibile, diventa visibile subito dopo il parse CSS */
    opacity: 0;
    transition: opacity 0.12s ease;
}
body.page-ready {
    opacity: 1;
}
* { box-sizing: border-box; }

/* COMPONENTI COMUNI */
.navbar { background: var(--nga-blue); border-bottom: 4px solid var(--nga-orange); padding: 12px 0; }
.navbar-logo { max-height: 40px; width: auto; margin-right: 12px; }
#toast-container { position: fixed; top: 20px; right: 20px; z-index: 9999; }
#loader-overlay { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(255, 255, 255, 0.95); display: none; justify-content: center; align-items: center; z-index: 10000; flex-direction: column; }
.spinner-nga { width: 45px; height: 45px; border: 4px solid #f3f3f3; border-top: 4px solid var(--nga-orange); border-radius: 50%; animation: spin 1s linear infinite; }
@keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }

/* PAGINA LOGIN */
#login-page { 
    opacity: 1 !important;
    display: flex; 
    align-items: center; 
    justify-content: center; 
    height: 100vh; 
    background: var(--nga-blue);
    background-image: 
        radial-gradient(circle at 20% 20%, rgba(249, 115, 22, 0.15) 0%, transparent 40%),
        radial-gradient(circle at 80% 80%, rgba(14, 165, 233, 0.1) 0%, transparent 40%),
        linear-gradient(135deg, #0f172a 0%, #020617 100%);
}
#login-page .login-card { background: white; padding: 40px; border-radius: 30px; box-shadow: 0 20px 40px rgba(0,0,0,0.3); width: 380px; text-align: center; }
#login-page .brand-logo { max-width: 150px; height: auto; margin-bottom: 15px; }

/* PAGINA ARCHIVIO (INDEX) */
.search-container { background: rgba(255, 255, 255, 0.7); backdrop-filter: blur(10px); padding: 25px; border-radius: 24px; box-shadow: 0 8px 32px rgba(0, 53, 102, 0.05); margin-bottom: 30px; border: 1px solid rgba(255, 255, 255, 0.8); }
.card-item { background: white; border-radius: 22px; transition: all 0.4s cubic-bezier(0.165, 0.84, 0.44, 1); height: 100%; border: 1px solid var(--border); text-align: center; padding: 25px; display: flex; flex-direction: column; justify-content: space-between; position: relative; overflow: hidden; }
.card-item::after { content: ""; position: absolute; top: 0; left: 0; width: 100%; height: 5px; background: linear-gradient(90deg, var(--nga-blue), var(--nga-orange)); opacity: 0; transition: 0.3s; }
.card-item:hover { transform: translateY(-10px); box-shadow: 0 15px 35px rgba(0, 53, 102, 0.1); border-color: var(--nga-blue); }
.card-item:hover::after { opacity: 1; }
.icon-folder { color: #ffca28; font-size: 3.5rem; filter: drop-shadow(0 5px 10px rgba(255, 202, 40, 0.3)); }
.icon-pdf { color: #ff5252; font-size: 3.5rem; filter: drop-shadow(0 5px 10px rgba(255, 82, 82, 0.3)); }
.icon-excel { color: #2ecc71; font-size: 3.5rem; filter: drop-shadow(0 5px 10px rgba(46, 204, 113, 0.3)); }
.icon-word { color: #3498db; font-size: 3.5rem; filter: drop-shadow(0 5px 10px rgba(52, 152, 219, 0.3)); }
.icon-image { color: #9b59b6; font-size: 3.5rem; filter: drop-shadow(0 5px 10px rgba(155, 89, 182, 0.3)); }
.icon-generic { color: #95a5a6; font-size: 3.5rem; }
.item-title { font-weight: 800; color: #1e293b; font-size: 0.85rem; margin: 15px 0; text-transform: uppercase; min-height: 40px; display: flex; align-items: center; justify-content: center; line-height: 1.3; }
.path-label { font-size: 0.7rem; color: #64748b; margin-bottom: 15px; display: block; font-weight: 600; background: #f1f5f9; padding: 4px; border-radius: 6px; }
.btn-action { border-radius: 12px; font-weight: 700; font-size: 0.75rem; text-transform: uppercase; padding: 10px; width: 100%; text-decoration: none; border: none; display: block; transition: all 0.3s cubic-bezier(0.165, 0.84, 0.44, 1); margin-bottom: 6px; cursor: pointer; }
.btn-action:hover { transform: translateY(-3px); box-shadow: 0 5px 15px rgba(0,0,0,0.1); }
.btn-folder { background: #fff8e1; color: #b45309; }
.btn-pdf { background: #f8fafc; color: #334155; border: 1px solid var(--border); }
.btn-download { background: #ecfdf5; color: #065f46; }
.btn-folder:hover, .btn-pdf:hover, .btn-download:hover { background: var(--nga-blue) !important; color: white !important; }
.breadcrumb { background: white; padding: 12px 25px; border-radius: 50px; box-shadow: 0 2px 10px rgba(0,0,0,0.03); border: 1px solid #edf2f7; }
.admin-controls { display: flex; gap: 10px; margin-bottom: 20px; align-items: stretch; }
.upload-zone { flex-grow: 1; border: 2px dashed #cbd5e1; border-radius: 20px; padding: 25px; text-align: center; background: white; transition: 0.3s; cursor: pointer; margin-bottom: 0; }
.btn-add-folder { background: white; border: 2px dashed #cbd5e1; border-radius: 20px; width: 100px; display: flex; flex-direction: column; align-items: center; justify-content: center; color: #64748b; transition: 0.3s; cursor: pointer; }
.upload-zone:hover, .btn-add-folder:hover { border-color: var(--nga-orange); background: #fff5ed; color: var(--nga-orange); }
#file_upload { display: none; }
.btn-delete-file { position: absolute; top: 10px; right: 10px; background: rgba(255, 82, 82, 0.1); color: #ff5252; border: none; width: 32px; height: 32px; border-radius: 50%; display: flex; align-items: center; justify-content: center; transition: 0.3s; z-index: 5; }
.btn-delete-file:hover { background: #ff5252; color: white; transform: scale(1.1); }
.pdf-viewer-container { height: 75vh; width: 100%; background: #525659; position: relative; }
#pdfFrame { display: block; width: 100%; height: 100%; border: none; opacity: 1; visibility: visible; }
.no-results { padding: 60px 20px; text-align: center; background: white; border-radius: 24px; border: 2px dashed var(--border); color: #64748b; }
.no-results i { font-size: 4rem; color: #cbd5e1; margin-bottom: 20px; display: block; }

/* PAGINA REPORT */
.stat-bar { background: rgba(255, 255, 255, 0.85); backdrop-filter: blur(10px); border-radius: 24px; padding: 15px 35px; margin-bottom: 35px; box-shadow: 0 10px 35px rgba(0, 53, 102, 0.08); border: 1px solid rgba(255, 255, 255, 0.7); display: flex; align-items: center; justify-content: space-between; }
.stat-item { flex-shrink: 0; min-width: 100px; text-align: center; }
.stat-label { font-size: 0.7rem; font-weight: 800; color: #64748b; text-transform: uppercase; display: block; margin-bottom: 2px; }
.stat-value { font-size: 2.2rem; font-weight: 900; color: var(--nga-blue); line-height: 1; letter-spacing: -1px; }
#assistente-container { flex-grow: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; border-left: 1px solid rgba(0,0,0,0.05); border-right: 1px solid rgba(0,0,0,0.05); margin: 0 20px; padding: 5px 20px; min-height: 70px; }
#assistente-wrapper { transition: all 0.5s cubic-bezier(0.4, 0, 0.2, 1); display: flex; align-items: center; justify-content: center; width: 100%; text-align: center; opacity: 1; transform: translateY(0); }
.assistente-hidden { opacity: 0 !important; transform: translateY(-10px) !important; }
.assistente-prepare { opacity: 0 !important; transform: translateY(10px) !important; }
.month-progress { height: 6px; background: var(--border); border-radius: 10px; width: 100%; max-width: 300px; margin-top: 10px; margin-bottom: 10px; overflow: hidden; }
.month-progress-bar { background: linear-gradient(90deg, var(--nga-blue), #3b82f6); height: 100%; }
.trend-badge { font-size: 0.85rem; padding: 6px 14px; border-radius: 50px; font-weight: 800; display: inline-flex; align-items: center; gap: 6px; }
.trend-up { background: #dcfce7; color: #15803d; } .trend-down { background: #fee2e2; color: #b91c1c; }
.table-ranking tbody tr:hover { background-color: #f1f5f9 !important; }
.card-custom { background: white; border-radius: 20px; border: 1px solid #edf2f7; padding: 25px; box-shadow: 0 5px 15px rgba(0,0,0,0.03); height: 100%; }
.form-label-custom { font-size: 0.65rem; font-weight: 800; color: var(--nga-blue); text-transform: uppercase; margin-bottom: 6px; display: block; opacity: 0.8; }
.form-control-custom { background-color: #f8fafc; border: 1px solid var(--border); border-radius: 12px; padding: 12px 18px; font-weight: 600; width: 100%; }
.target-card { background: white; border: 1px solid var(--border); border-radius: 24px; padding: 25px 15px; text-align: center; transition: all 0.3s ease; }
.target-card:hover { transform: translateY(-8px); box-shadow: 0 12px 25px rgba(0,0,0,0.05); }
.circle-wrapper { position: relative; width: 85px; height: 85px; margin: 0 auto 15px; }
.circle-wrapper svg { transform: rotate(-90deg); width: 85px; height: 85px; }
.circle-prog { fill: none; stroke-width: 7; stroke-linecap: round; transition: stroke-dashoffset 1.5s ease; }
.target-actual { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); font-weight: 900; color: var(--nga-blue); font-size: 1.4rem; }
.total-pill { background: var(--nga-orange); color: white; padding: 4px 12px; border-radius: 8px; font-weight: 800; }
.badge-custom { padding: 6px 12px; border-radius: 8px; font-weight: 700; font-size: 0.7rem; border: 1px solid transparent; }
.badge-fisso { background: #e0f2fe; color: #0369a1; border-color: #bae6fd; }
.badge-mobile { background: #fef3c7; color: #92400e; border-color: #fde68a; }
.badge-energia { background: #dcfce7; color: #166534; border-color: #bbf7d0; }
.badge-telefono { background: #f3e8ff; color: #7e22ce; border-color: #e9d5ff; }
.badge-extra { background: #f1f5f9; color: #475569; border-color: var(--border); }
.badge-very { background: #eefceb; color: #1a5c11; border-color: #c9e9c4; }

/* PAGINA PREVENTIVO */
#preventivo-page [contenteditable]:empty:before { content: attr(data-placeholder); color: #cbd5e1; font-weight: 400; cursor: text; }
#preventivo-page [contenteditable]:focus { outline: none; background: #fffdf9; border-radius: 4px; border-bottom: 1px solid var(--nga-orange) !important; }
.preventivo-sheet { background: white; width: 210mm; min-height: 297mm; margin: 20px auto; padding: 10mm 15mm; display: flex; flex-direction: column; box-shadow: 0 10px 30px rgba(0,0,0,0.1); position: relative; animation: fadeSlideUp 0.6s cubic-bezier(0.16,1,0.3,1) both; }
.preventivo-sheet header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 15px; }
.preventivo-sheet .logo-placeholder { width: 100px; height: auto; }
.preventivo-sheet .store-data { text-align: right; font-size: 11px; color: var(--gray); line-height: 1.4; }
.preventivo-sheet .client-info-header { display: grid; grid-template-columns: 1.2fr 2fr 0.8fr; gap: 0; background: var(--accent); border-radius: 12px; margin-bottom: 15px; border: 1px solid var(--border); border-bottom: 3px solid var(--nga-orange); }
.preventivo-sheet .fld { padding: 10px 15px; }
.preventivo-sheet .fld label { display: block; font-size: 9px; font-weight: 800; color: var(--w3-orange); text-transform: uppercase; margin-bottom: 2px; }
.preventivo-sheet .fld div, .preventivo-sheet .fld [contenteditable] { font-size: 14px; font-weight: 700; color: var(--dark); min-height: 20px; }
.preventivo-sheet .card-prev { border: 1px solid var(--border); border-radius: 14px; padding: 10px 15px; margin-bottom: 8px; display: grid; grid-template-columns: 35px 1fr 110px; gap: 12px; align-items: center; transition: all 0.2s; background: white; animation: fadeSlideUp 0.5s cubic-bezier(0.16,1,0.3,1) both; }
.preventivo-sheet .card-prev:nth-child(1) { animation-delay: 0.1s; }
.preventivo-sheet .card-prev:nth-child(2) { animation-delay: 0.15s; }
.preventivo-sheet .card-prev:nth-child(3) { animation-delay: 0.2s; }
.preventivo-sheet .card-prev:nth-child(4) { animation-delay: 0.25s; }
.preventivo-sheet .card-prev:hover { border-color: var(--w3-orange); box-shadow: 0 4px 12px rgba(0,0,0,0.05); }
.preventivo-sheet .icon-box { width: 35px; height: 35px; background: #f8fafc; border: 1px solid var(--border); border-radius: 10px; display: flex; align-items: center; justify-content: center; font-size: 16px; }
.preventivo-sheet .card-content h2 { font-size: 11px; font-weight: 800; margin: 0 0 4px; color: var(--nga-blue); text-transform: uppercase; }
.preventivo-sheet .grid-inputs { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.preventivo-sheet .input-item label { display: block; font-size: 7.5px; font-weight: 700; color: var(--gray); text-transform: uppercase; }
.preventivo-sheet .input-item [contenteditable] { font-size: 11.5px; color: var(--dark); border-bottom: 1px solid #f1f5f9; padding: 1px 0; min-height: 16px; font-weight: 600; }
.preventivo-sheet .card-price { text-align: right; border-left: 1px solid var(--border); padding-left: 12px; }
.preventivo-sheet .card-price label { display: block; font-size: 7.5px; font-weight: 700; color: var(--gray); text-transform: uppercase; }
.preventivo-sheet .card-price .val { font-size: 19px; font-weight: 800; color: var(--w3-orange); white-space: nowrap; }
.preventivo-sheet .bottom-section { margin-top: auto; padding-top: 10px; }
.preventivo-sheet .total-container { display: grid; grid-template-columns: 1fr 1fr; gap: 15px; margin-bottom: 10px; }
.preventivo-sheet .total-box { border-radius: 12px; padding: 10px 15px; display: flex; justify-content: space-between; align-items: center; }
.preventivo-sheet .main-total { background: var(--dark); color: white; }
.preventivo-sheet .accessori-total { background: #f8fafc; border: 1px solid var(--border); }
.preventivo-sheet .total-amount { font-size: 20px; font-weight: 800; }
.preventivo-sheet .footer-boxes { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; width: 100%; }
.preventivo-sheet .info-box { background: #fff; border: 1px solid var(--border); border-radius: 12px; padding: 10px; min-height: 85px; height: auto; }
.preventivo-sheet .info-box-header { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; border-bottom: 1px solid #f1f5f9; padding-bottom: 5px; }
.preventivo-sheet .info-box-header span { font-size: 9px; font-weight: 800; color: var(--nga-blue); text-transform: uppercase; }
.preventivo-sheet .info-box [contenteditable] { font-size: 11px; color: var(--dark); line-height: 1.4; outline: none; white-space: pre-wrap; word-wrap: break-word; }
.print-btn-container { max-width: 210mm; margin: 0 auto; display: flex; justify-content: flex-end; padding: 10px 0; }
.btn-print-action { background: var(--nga-orange); color: white; border: none; padding: 10px 25px; border-radius: 50px; font-weight: 800; cursor: pointer; transition: 0.3s; box-shadow: 0 4px 15px rgba(255,102,0,0.3); }

/* MEDIA QUERIES (Mobile e Stampa) */
@media print {
    @page { size: A4; margin: 0; }
    body { background: white; overflow: visible; -webkit-print-color-adjust: exact; print-color-adjust: exact; margin: 0; padding: 0; }
    #loader-overlay, .navbar, .print-btn-container, .no-print, .d-print-none { display: none !important; }
    .preventivo-sheet { width: 210mm !important; margin: 0 auto !important; padding: 10mm 15mm !important; height: auto !important; min-height: auto !important; max-height: none !important; box-shadow: none !important; border: none !important; font-size: 0.95em; }
    [contenteditable]:empty:before { content: "" !important; }
    .card-prev.no-print { display: none !important; }
    .card-prev { margin-bottom: 4px !important; padding: 6px 12px !important; border: 1px solid #e2e8f0 !important; break-inside: avoid; page-break-inside: avoid; }
    .bottom-section { margin-top: 5px !important; break-inside: avoid; page-break-inside: avoid; }
}

@media (max-width: 768px) {
    .navbar .container { padding-left: 10px; padding-right: 10px; }
    .navbar-logo { max-height: 28px; margin-right: 6px; }
    .fs-4 { font-size: 1.1rem !important; white-space: nowrap; }
    .navbar .btn-sm { padding: 5px 12px !important; font-size: 0.75rem !important; }
    .navbar .btn-sm span { display: none; }
    .navbar .d-flex.gap-2 { gap: 6px !important; }
    .stat-bar { flex-direction: column; gap: 15px; padding: 20px; text-align: center; border-radius: 18px; }
    .stat-item { width: 100%; min-width: auto; }
    #assistente-container { border: none; margin: 5px 0; padding: 5px 0; width: 100%; min-height: 50px; }
    .stat-value { font-size: 1.8rem; }
    .target-container { grid-template-columns: repeat(2, 1fr) !important; gap: 12px !important; }
    .circle-wrapper { width: 70px; height: 70px; }
    .circle-wrapper svg { width: 70px; height: 70px; }
    .target-actual { font-size: 1.1rem; }
    .table-registro thead th:nth-child(1), .table-registro tbody td:nth-child(1), .table-registro thead th:nth-child(3), .table-registro tbody td:nth-child(3) { display: none; }
    .table-registro td { padding: 10px 5px !important; font-size: 0.8rem; }
    .card-custom { padding: 15px; }
    .admin-controls { flex-direction: column; }
    .btn-add-folder { width: 100%; height: 60px; flex-direction: row; gap: 10px; }
    /* Nascondi colonne meno critiche su mobile per le tabelle di gestione */
    .target-mgmt-table thead th:nth-child(3), .target-mgmt-table tbody td:nth-child(3) { display: none; }
}