/* baselio-core.css — consolidated styles (dark-mode + tables + UI components) */

/* ═══════════════════════════════════════════════════════════════════
   Dark mode overrides for elements not covered by Tailwind dark:
   ═══════════════════════════════════════════════════════════════════ */
.dark body { background: #111827; color: #f3f4f6; }
.dark .bg-white { background: #1f2937 !important; }
.dark .bg-gray-50 { background: #1f2937 !important; }
.dark .bg-gray-100 { background: #111827 !important; }
.dark .border-b { border-color: #374151 !important; }
.dark .border-t { border-color: #374151 !important; }
.dark .border-gray-100, .dark .border-gray-200, .dark .border-gray-300 { border-color: #374151 !important; }
.dark .text-gray-900 { color: #f3f4f6 !important; }
.dark .text-gray-700 { color: #d1d5db !important; }
.dark .text-gray-600 { color: #9ca3af !important; }
.dark .text-gray-500 { color: #9ca3af !important; }
.dark .text-gray-400 { color: #6b7280 !important; }
.dark .shadow, .dark .shadow-sm, .dark .shadow-md, .dark .shadow-lg, .dark .shadow-xl, .dark .shadow-2xl {
    box-shadow: 0 1px 3px rgba(0,0,0,0.3) !important;
}
.dark input, .dark select, .dark textarea {
    background: #374151 !important; color: #f3f4f6 !important;
    border-color: #4b5563 !important;
}
.dark input:disabled, .dark select:disabled, .dark textarea:disabled {
    background: #1f2937 !important; color: #9ca3af !important;
}
.dark .hover\:bg-gray-50:hover { background: #374151 !important; }
.dark .hover\:bg-gray-100:hover { background: #374151 !important; }

/* Dark mode: navbar search */
.dark #navbar-search-input { background: #374151 !important; color: #f3f4f6 !important; border-color: #4b5563 !important; }
.dark #navbar-search-input:focus { background: #1f2937 !important; border-color: #06b6d4 !important; }
.dark #navbar-search-kbd { background: #374151 !important; border-color: #4b5563 !important; color: #6b7280 !important; }
.dark #navbar-search-dropdown { background: #1f2937 !important; border-color: #374151 !important; }
.dark #navbar-search-results .search-result-item:hover { background: #374151 !important; }
.dark #navbar-search-results .search-result-item.active { background: #374151 !important; }

/* Dark mode: sticky columns in tables */
.dark .sticky-col-1,
.dark .sticky-col-2 {
    background: #1f2937 !important;
    border-right-color: #374151 !important;
}
.dark thead .sticky-col-1,
.dark thead .sticky-col-2 {
    background: #111827 !important;
}
.dark tr:hover .sticky-col-1,
.dark tr:hover .sticky-col-2 {
    background: #374151 !important;
}

/* Dark mode: colored *-50 backgrounds */
.dark .bg-green-50 { background: rgba(34, 197, 94, 0.1) !important; }
.dark .bg-emerald-50 { background: rgba(16, 185, 129, 0.1) !important; }
.dark .bg-yellow-50 { background: rgba(234, 179, 8, 0.1) !important; }
.dark .bg-amber-50 { background: rgba(245, 158, 11, 0.1) !important; }
.dark .bg-blue-50 { background: rgba(59, 130, 246, 0.1) !important; }
.dark .bg-orange-50 { background: rgba(249, 115, 22, 0.1) !important; }
.dark .bg-red-50 { background: rgba(239, 68, 68, 0.1) !important; }
.dark .bg-cyan-50 { background: rgba(6, 182, 212, 0.1) !important; }
.dark .bg-purple-50 { background: rgba(168, 85, 247, 0.1) !important; }
.dark .bg-indigo-50 { background: rgba(99, 102, 241, 0.1) !important; }

/* Dark mode: colored *-100 backgrounds (badges) */
.dark .bg-green-100 { background: rgba(34, 197, 94, 0.2) !important; }
.dark .bg-emerald-100 { background: rgba(16, 185, 129, 0.2) !important; }
.dark .bg-yellow-100 { background: rgba(234, 179, 8, 0.2) !important; }
.dark .bg-amber-100 { background: rgba(245, 158, 11, 0.2) !important; }
.dark .bg-blue-100 { background: rgba(59, 130, 246, 0.2) !important; }
.dark .bg-orange-100 { background: rgba(249, 115, 22, 0.2) !important; }
.dark .bg-red-100 { background: rgba(239, 68, 68, 0.2) !important; }
.dark .bg-cyan-100 { background: rgba(6, 182, 212, 0.2) !important; }
.dark .bg-purple-100 { background: rgba(168, 85, 247, 0.2) !important; }
.dark .bg-indigo-100 { background: rgba(99, 102, 241, 0.2) !important; }
.dark .bg-teal-100 { background: rgba(20, 184, 166, 0.2) !important; }

/* Dark mode: hover colored backgrounds */
.dark .hover\:bg-green-100:hover { background: rgba(34, 197, 94, 0.2) !important; }
.dark .hover\:bg-emerald-100:hover { background: rgba(16, 185, 129, 0.2) !important; }
.dark .hover\:bg-yellow-100:hover { background: rgba(234, 179, 8, 0.2) !important; }
.dark .hover\:bg-amber-100:hover { background: rgba(245, 158, 11, 0.2) !important; }
.dark .hover\:bg-blue-100:hover { background: rgba(59, 130, 246, 0.2) !important; }
.dark .hover\:bg-orange-100:hover { background: rgba(249, 115, 22, 0.2) !important; }
.dark .hover\:bg-red-100:hover { background: rgba(239, 68, 68, 0.2) !important; }
.dark .hover\:bg-cyan-50:hover { background: rgba(6, 182, 212, 0.15) !important; }
.dark .hover\:bg-purple-100:hover { background: rgba(168, 85, 247, 0.2) !important; }

/* Dark mode: colored text (dark shades → light equivalents) */
.dark .text-green-800 { color: #86efac !important; }
.dark .text-green-700 { color: #86efac !important; }
.dark .text-green-600 { color: #4ade80 !important; }
.dark .text-emerald-700 { color: #6ee7b7 !important; }
.dark .text-yellow-800 { color: #fde047 !important; }
.dark .text-yellow-700 { color: #fde047 !important; }
.dark .text-amber-800 { color: #fcd34d !important; }
.dark .text-amber-700 { color: #fcd34d !important; }
.dark .text-amber-600 { color: #fbbf24 !important; }
.dark .text-blue-800 { color: #93c5fd !important; }
.dark .text-blue-700 { color: #93c5fd !important; }
.dark .text-blue-600 { color: #60a5fa !important; }
.dark .text-orange-800 { color: #fdba74 !important; }
.dark .text-orange-700 { color: #fdba74 !important; }
.dark .text-orange-600 { color: #fb923c !important; }
.dark .text-red-800 { color: #fca5a5 !important; }
.dark .text-red-700 { color: #fca5a5 !important; }
.dark .text-red-600 { color: #f87171 !important; }
.dark .text-cyan-800 { color: #67e8f9 !important; }
.dark .text-cyan-700 { color: #22d3ee !important; }
.dark .text-cyan-600 { color: #06b6d4 !important; }
.dark .text-purple-800 { color: #d8b4fe !important; }
.dark .text-purple-700 { color: #c084fc !important; }
.dark .text-purple-600 { color: #a855f7 !important; }
.dark .text-indigo-800 { color: #a5b4fc !important; }
.dark .text-indigo-700 { color: #818cf8 !important; }
.dark .text-indigo-600 { color: #6366f1 !important; }
.dark .text-teal-800 { color: #5eead4 !important; }

/* Dark mode: colored borders */
.dark .border-green-200 { border-color: rgba(34, 197, 94, 0.3) !important; }
.dark .border-green-400 { border-color: rgba(34, 197, 94, 0.6) !important; }
.dark .border-yellow-200 { border-color: rgba(234, 179, 8, 0.3) !important; }
.dark .border-yellow-400 { border-color: rgba(234, 179, 8, 0.6) !important; }
.dark .border-amber-200 { border-color: rgba(245, 158, 11, 0.3) !important; }
.dark .border-blue-200 { border-color: rgba(59, 130, 246, 0.3) !important; }
.dark .border-blue-500 { border-color: rgba(59, 130, 246, 0.6) !important; }
.dark .border-orange-200 { border-color: rgba(249, 115, 22, 0.3) !important; }
.dark .border-red-200 { border-color: rgba(239, 68, 68, 0.3) !important; }
.dark .border-red-400 { border-color: rgba(239, 68, 68, 0.6) !important; }
.dark .border-cyan-200 { border-color: rgba(6, 182, 212, 0.3) !important; }
.dark .border-cyan-300 { border-color: rgba(6, 182, 212, 0.4) !important; }
.dark .border-purple-200 { border-color: rgba(168, 85, 247, 0.3) !important; }
.dark .border-indigo-200 { border-color: rgba(99, 102, 241, 0.3) !important; }

/* Dark mode: Elio chat */
@media (max-width: 767px) {
    .dark #elio-container { background: #111827 !important; }
}
.dark .bubble-bot {
    background: #374151 !important;
    color: #f3f4f6 !important;
    border-color: #4b5563 !important;
}
.dark .feedback-btn:hover {
    color: #d1d5db !important;
    background: #374151 !important;
}
.dark .feedback-btn.active-up {
    color: #4ade80 !important;
    background: rgba(34, 197, 94, 0.15) !important;
    border-color: rgba(34, 197, 94, 0.3) !important;
}
.dark .feedback-btn.active-down {
    color: #f87171 !important;
    background: rgba(239, 68, 68, 0.15) !important;
    border-color: rgba(239, 68, 68, 0.3) !important;
}

/* Dark mode: navbar active state */
.dark .nav-active {
    background: rgba(6, 182, 212, 0.1) !important;
    color: #22d3ee !important;
}
.dark .nav-active:hover {
    background: rgba(6, 182, 212, 0.15) !important;
}

/* Dark mode: modals */
.dark .bg-white.rounded-lg.shadow-xl,
.dark [id^="modal"] .bg-white {
    background: #1f2937 !important;
}


/* ═══════════════════════════════════════════════════════════════════
   Shared table styles: sticky columns, excel filters
   ═══════════════════════════════════════════════════════════════════ */
.sticky-col-1 {
    position: -webkit-sticky;
    position: sticky;
    left: 0;
    z-index: 5;
    background: var(--sticky-bg, white);
    border-right: 1px solid #e5e7eb;
}
.sticky-col-2 {
    position: -webkit-sticky;
    position: sticky;
    left: var(--col1-width, 80px);
    z-index: 5;
    background: var(--sticky-bg, white);
    border-right: 2px solid #d1d5db;
}
thead .sticky-col-1,
thead .sticky-col-2 {
    z-index: 15;
    background: #f9fafb;
}
tr:hover .sticky-col-1,
tr:hover .sticky-col-2 {
    background: #f9fafb;
}

/* Sticky thead per liste lunghe: bounded scroll interno con header agganciato in cima */
.sticky-list-wrap {
    max-height: calc(100vh - 220px);
    overflow: auto;
}
.sticky-list-wrap table thead th {
    position: -webkit-sticky;
    position: sticky;
    top: 0;
    z-index: 10;
    background-color: #f9fafb;
}
.dark .sticky-list-wrap table thead th {
    background-color: #111827;
}
/* Combina con sticky-col-*: header colonne fissate orizzontalmente vincono in z-index */
.sticky-list-wrap thead .sticky-col-1,
.sticky-list-wrap thead .sticky-col-2 {
    z-index: 20;
}
/* Sidebar attivita (Per Tecnico/Societa/Servizio): scroll interno, viene fitted via JS */
.attivita-sidebar {
    max-height: calc(100vh - 220px);
    overflow-y: auto;
}
/* Su touch device (mobile/iPad) disabilita il bounded scroll: nested-scroll
   e' fastidioso col dito. Page scrolla naturalmente come prima. */
@media (pointer: coarse) {
    .sticky-list-wrap,
    .checkup-matrix-wrap,
    .attivita-sidebar {
        max-height: none !important;
        overflow: visible !important;
    }
    .sticky-list-wrap table thead th {
        position: static !important;
    }
}
/* Su viewport non molto alto torna allo scroll di pagina: la finestrella
   bounded con 2-3 righe visibili e' inutilizzabile. JS rifinisce dopo. */
@media (max-height: 899px) {
    .sticky-list-wrap,
    .checkup-matrix-wrap,
    .attivita-sidebar {
        max-height: none;
        overflow: visible;
    }
    .sticky-list-wrap table thead th {
        position: static;
    }
}

/* Touch-friendly filter buttons */
.excel-filter-btn {
    min-width: 32px;
    min-height: 32px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    -webkit-tap-highlight-color: transparent;
}
@media (pointer: coarse) {
    .excel-filter-btn {
        min-width: 40px;
        min-height: 40px;
    }
}


/* ═══════════════════════════════════════════════════════════════════
   UI components (previously inline in base.html)
   ═══════════════════════════════════════════════════════════════════ */

/* Scrollbar hide utility */
.scrollbar-hide::-webkit-scrollbar { display: none; }
.scrollbar-hide { -ms-overflow-style: none; scrollbar-width: none; }

/* Navbar extras: show only when there's enough room (≥1536px) */
.nav-brand-logo { display: none !important; }
@media (min-width: 1536px) {
    div.nav-brand-logo { display: flex !important; }
    span.nav-brand-logo { display: inline-flex !important; }
}
* { touch-action: manipulation; }

/* Page transition fade-in */
@media (prefers-reduced-motion: no-preference) {
    .page-fade-in { opacity: 0; }
    .page-fade-in.page-ready {
        opacity: 1;
        animation: fadeInUp 0.2s ease-out;
    }
    @keyframes fadeInUp {
        from { opacity: 0; transform: translateY(8px); }
        to { opacity: 1; transform: translateY(0); }
    }
}

/* Page navigation loading overlay — covers current page during navigation.
   Uses transition-delay so fast navigations (<150ms) never show the overlay,
   but the class is applied immediately so Safari picks it up before unload. */
.nav-loading-overlay {
    position: fixed; inset: 0; z-index: 9998;
    background: rgba(243, 244, 246, 0.6);
    backdrop-filter: blur(2px);
    display: flex; align-items: center; justify-content: center;
    opacity: 0; pointer-events: none;
    transition: opacity 0.2s ease 150ms; /* 150ms delay before fade starts */
}
.nav-loading-overlay .nav-loading-spinner {
    opacity: 0;
    transition: opacity 0.15s ease 300ms; /* spinner appears after overlay */
}
.nav-loading-overlay.active {
    opacity: 1; pointer-events: auto;
}
.nav-loading-overlay.active .nav-loading-spinner {
    opacity: 1;
}
.dark .nav-loading-overlay { background: rgba(17, 24, 39, 0.6); }

/* NProgress-style top loading bar */
#nprogress-bar {
    position: fixed; top: 0; left: 0; height: 3px; z-index: 9999;
    background: linear-gradient(90deg, #06b6d4, #0891b2);
    transition: width 0.2s ease;
    box-shadow: 0 0 8px rgba(6, 182, 212, 0.4);
}

/* Toast notifications */
#toast-container {
    position: fixed; top: 1rem; right: 1rem; z-index: 9998;
    display: flex; flex-direction: column; gap: 0.5rem;
    pointer-events: none; max-width: 420px; width: calc(100% - 2rem);
}
.toast-item {
    pointer-events: auto;
    animation: toastSlideIn 0.3s ease-out;
    position: relative; overflow: hidden;
}
.toast-item.toast-exit {
    animation: toastSlideOut 0.2s ease-in forwards;
}
@keyframes toastSlideIn {
    from { opacity: 0; transform: translateX(100%); }
    to { opacity: 1; transform: translateX(0); }
}
@keyframes toastSlideOut {
    from { opacity: 1; transform: translateX(0); }
    to { opacity: 0; transform: translateX(100%); }
}
.toast-progress {
    position: absolute; bottom: 0; left: 0; height: 3px;
    animation: toastProgress linear forwards;
}
@keyframes toastProgress {
    from { width: 100%; }
    to { width: 0%; }
}
@media (prefers-reduced-motion: reduce) {
    .toast-item, .toast-item.toast-exit { animation: none; }
}

/* Confirm modal */
.confirm-backdrop {
    position: fixed; inset: 0; z-index: 9997;
    background: rgba(0,0,0,0.5);
    display: flex; align-items: center; justify-content: center;
    animation: fadeIn 0.15s ease-out;
}
@keyframes fadeIn {
    from { opacity: 0; } to { opacity: 1; }
}

/* Global search modal */
#search-modal { display: none; }
#search-modal.active { display: flex; }

/* Navbar search dropdown slide-in */
#navbar-search-dropdown.active { display: block; animation: dropdownSlide 0.15s ease-out; }
@keyframes dropdownSlide { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: translateY(0); } }
.search-result-item.active { background: #f0f9ff; }

/* Button loading state */
.btn-loading { pointer-events: none; opacity: 0.7; }
.btn-loading .btn-text { visibility: hidden; }
.btn-loading .btn-spinner { display: inline-flex !important; position: absolute; }

/* Offline banner */
#offline-banner {
    display: none; position: fixed; top: 0; left: 0; right: 0; z-index: 10000;
    background: #fbbf24; color: #92400e; text-align: center;
    padding: 0.5rem; font-size: 0.875rem; font-weight: 500;
}
#offline-banner.show { display: block; }

/* Dynamic swap loading overlay */
#results { position: relative; min-height: 100px; }
#results.results-loading::after {
    content: ''; position: absolute; inset: 0;
    background: rgba(255,255,255,0.6); backdrop-filter: blur(4px);
    z-index: 50; border-radius: 0.5rem;
}
.dark #results.results-loading::after { background: rgba(17,24,39,0.6); }
#results.results-loading::before {
    content: ''; position: absolute; top: 50%; left: 50%;
    transform: translate(-50%,-50%); width: 2rem; height: 2rem;
    border: 3px solid #06b6d4; border-top-color: transparent;
    border-radius: 50%; animation: results-spin 0.6s linear infinite; z-index: 51;
}
@keyframes results-spin { to { transform: translate(-50%,-50%) rotate(360deg); } }

/* ═══════════════════════════════════════════════════════════════════
   1. Instant nav feedback on click
   ═══════════════════════════════════════════════════════════════════ */
/* Desktop nav: instant active on click */
nav a.nav-click-active {
    background: #ecfeff !important;
    color: #0e7490 !important;
    transition: none !important;
}
.dark nav a.nav-click-active {
    background: rgba(6, 182, 212, 0.1) !important;
    color: #22d3ee !important;
}
/* Mobile bottom tab: instant active on tap */
#bottom-tab-bar a.tab-click-active,
#bottom-tab-bar button.tab-click-active {
    color: #0891b2 !important;
    transition: none !important;
}

/* ═══════════════════════════════════════════════════════════════════
   2. Skeleton loader for tables
   ═══════════════════════════════════════════════════════════════════ */
.skeleton-row td {
    padding: 0.75rem 0.5rem;
}
.skeleton-bar {
    height: 0.75rem;
    border-radius: 0.25rem;
    background: linear-gradient(90deg, #e5e7eb 25%, #f3f4f6 50%, #e5e7eb 75%);
    background-size: 200% 100%;
    animation: skeleton-shimmer 1.5s ease-in-out infinite;
}
.dark .skeleton-bar {
    background: linear-gradient(90deg, #374151 25%, #4b5563 50%, #374151 75%);
    background-size: 200% 100%;
}
@keyframes skeleton-shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* ═══════════════════════════════════════════════════════════════════
   3. Row action feedback animations
   ═══════════════════════════════════════════════════════════════════ */
/* Flash green on saved/updated row */
@keyframes row-flash-green {
    0% { background-color: #dcfce7; }
    100% { background-color: transparent; }
}
.row-saved {
    animation: row-flash-green 1.2s ease-out;
}
.dark .row-saved {
    animation: row-flash-green-dark 1.2s ease-out;
}
@keyframes row-flash-green-dark {
    0% { background-color: rgba(34, 197, 94, 0.15); }
    100% { background-color: transparent; }
}
/* Slide-out on deleted row */
@keyframes row-slide-out {
    0% { opacity: 1; max-height: 60px; transform: translateX(0); }
    70% { opacity: 0; transform: translateX(40px); }
    100% { opacity: 0; max-height: 0; padding-top: 0; padding-bottom: 0; overflow: hidden; }
}
.row-deleting {
    animation: row-slide-out 0.4s ease-in forwards;
    pointer-events: none;
}

/* ═══════════════════════════════════════════════════════════════════
   7. Filter badge + summary bar
   ═══════════════════════════════════════════════════════════════════ */
.excel-filter-btn { position: relative; }
.filter-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    min-width: 16px;
    height: 16px;
    padding: 0 4px;
    border-radius: 9999px;
    background: #06b6d4;
    color: white;
    font-size: 9px;
    font-weight: 700;
    line-height: 16px;
    text-align: center;
    pointer-events: none;
}
.filter-summary-bar {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
    padding: 0.5rem 0.75rem;
    margin-bottom: 0.5rem;
    background: #f0fdfa;
    border: 1px solid #99f6e4;
    border-radius: 0.5rem;
    font-size: 0.8125rem;
    color: #0f766e;
}
.dark .filter-summary-bar {
    background: rgba(6, 182, 212, 0.08);
    border-color: rgba(6, 182, 212, 0.2);
    color: #5eead4;
}
.filter-pill {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.125rem 0.5rem;
    background: #ccfbf1;
    border-radius: 9999px;
    font-size: 0.75rem;
    font-weight: 500;
    color: #0d9488;
    white-space: nowrap;
}
.dark .filter-pill {
    background: rgba(6, 182, 212, 0.15);
    color: #5eead4;
}
.filter-pill button {
    display: inline-flex;
    margin-left: 0.125rem;
    color: inherit;
    opacity: 0.6;
    cursor: pointer;
}
.filter-pill button:hover { opacity: 1; }

/* ═══════════════════════════════════════════════════════════════════
   8. Horizontal scroll fade indicator for tables on mobile
   ═══════════════════════════════════════════════════════════════════ */
.table-scroll-wrapper {
    position: relative;
}
.table-scroll-wrapper::after {
    content: '';
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    width: 32px;
    background: linear-gradient(to right, transparent, rgba(243, 244, 246, 0.9));
    pointer-events: none;
    opacity: 1;
    transition: opacity 0.3s ease;
    z-index: 6;
}
.dark .table-scroll-wrapper::after {
    background: linear-gradient(to right, transparent, rgba(17, 24, 39, 0.9));
}
.table-scroll-wrapper.scrolled-end::after {
    opacity: 0;
}
@media (min-width: 768px) {
    .table-scroll-wrapper::after {
        display: none;
    }
}
