/* ============================================================
   Tema "V3 Verde Gradient Moderno" — Galenica Meschiari
   Applicato ai 3 panel (admin/operatore/referente)
   Selettori verificati per Filament 5.6.
   ============================================================ */

:root {
    --gal-brand: #006636;
    --gal-brand-light: #00a86b;
    --gal-brand-deep: #004a27;
    --gal-brand-50: #f0f7f2;
    --gal-brand-100: #d4ebde;
    --gal-brand-200: #b1dac1;
    --gal-brand-glow: rgba(0, 168, 107, 0.22);

    --gal-ink: #0f1a14;
    --gal-ink-soft: #42554a;
    --gal-ink-mute: #5a6b62;
    --gal-line: #e4ece7;
    --gal-line-soft: #eef3f0;
    --gal-canvas: #f4f7f3;
    --gal-card: #ffffff;

    --gal-grad: linear-gradient(135deg, #006636 0%, #00a86b 100%);
    --gal-radius: 18px;
    --gal-radius-sm: 12px;

    --gal-shadow-sm: 0 1px 2px rgba(0, 70, 40, 0.05), 0 2px 8px rgba(0, 70, 40, 0.04);
    --gal-shadow-md: 0 6px 18px rgba(0, 82, 46, 0.08), 0 2px 6px rgba(0, 82, 46, 0.05);
    --gal-shadow-lg: 0 24px 60px -20px rgba(0, 82, 46, 0.28), 0 8px 24px rgba(0, 82, 46, 0.10);

    /* Compat con regole storiche */
    --glass-bg: var(--gal-card);
    --glass-border: var(--gal-line);
    --glass-shadow: var(--gal-shadow-md);
    --glass-shadow-hover: var(--gal-shadow-lg);
}

/* --- Card V3: asseconda la card nativa Filament (bg-white, ring-1, rounded-xl, p-6),
   applica SOLO un tocco brand (ombra verde tenue). UN SOLO livello di card:
   niente background/border/border-radius/!important sopra il vendor (R6).
   La stat È già una card nativa; la card del grafico è invece la sua SECTION
   contained interna (vedi regola sotto), quindi il wrapper .fi-wi-chart resta
   trasparente e porta solo l'effetto hover (transform). --- */
.fi-wi-stats-overview-stat {
    box-shadow: var(--gal-shadow-md);
    transition: transform 0.25s ease, box-shadow 0.25s ease;
}

/* --- Section REALI "contained" (form, infolist, card grafico apex): solo ombra brand
   sulla card nativa. Esclude la section trasparente .fi-section-not-contained che
   avvolge le stats, evitando la doppia ombra/doppio bordo (R6). --- */
.fi-section:not(.fi-section-not-contained):not(.fi-aside) {
    box-shadow: var(--gal-shadow-md);
    transition: box-shadow 0.25s ease;
}

/* Wrapper grafico (trasparente): solo transizione per l'hover-lift. */
.fi-wi-chart,
.filament-apex-charts-widget {
    transition: transform 0.25s ease;
}

/* --- Hover lift su card interattive (solo transform/opacity) --- */
.fi-wi-stats-overview-stat:hover {
    transform: translateY(-2px);
    box-shadow: var(--gal-shadow-lg);
}
/* Sul grafico la "card" è la section interna: alziamo il wrapper (transform)
   e rinforziamo l'ombra solo sulla section, non sul wrapper trasparente. */
.fi-wi-chart:hover,
.filament-apex-charts-widget:hover {
    transform: translateY(-2px);
}
.fi-wi-chart:hover .fi-section:not(.fi-section-not-contained),
.filament-apex-charts-widget:hover .fi-section:not(.fi-section-not-contained) {
    box-shadow: var(--gal-shadow-lg);
}

/* --- Fade-in staggered --- */
@keyframes fadeInUp {
    from { opacity: 0; transform: translateY(12px); }
    to   { opacity: 1; transform: translateY(0); }
}

.fi-wi-stats-overview-stat,
.fi-wi-chart,
.filament-apex-charts-widget {
    animation: fadeInUp 0.5s ease both;
}

.fi-wi-stats-overview-stat:nth-child(1) { animation-delay: 0.05s; }
.fi-wi-stats-overview-stat:nth-child(2) { animation-delay: 0.10s; }
.fi-wi-stats-overview-stat:nth-child(3) { animation-delay: 0.15s; }
.fi-wi-stats-overview-stat:nth-child(4) { animation-delay: 0.20s; }
.fi-wi-stats-overview-stat:nth-child(5) { animation-delay: 0.25s; }
.fi-wi-stats-overview-stat:nth-child(6) { animation-delay: 0.30s; }

.fi-wi > div:nth-child(1) .fi-wi-chart,
.fi-wi > div:nth-child(1) .filament-apex-charts-widget { animation-delay: 0.1s; }
.fi-wi > div:nth-child(2) .fi-wi-chart,
.fi-wi > div:nth-child(2) .filament-apex-charts-widget { animation-delay: 0.2s; }
.fi-wi > div:nth-child(3) .fi-wi-chart,
.fi-wi > div:nth-child(3) .filament-apex-charts-widget { animation-delay: 0.3s; }
.fi-wi > div:nth-child(4) .fi-wi-chart,
.fi-wi > div:nth-child(4) .filament-apex-charts-widget { animation-delay: 0.4s; }

/* --- ApexCharts trasparente --- */
.apexcharts-canvas,
.apexcharts-svg,
.filament-apex-charts-chart-container {
    background: transparent !important;
}

/* --- Sfondo pagina V3: mesh radiale + dot-grid mascherato + noise tenue --- */
.fi-body {
    background-color: var(--gal-canvas) !important;
    background-image:
        radial-gradient(40% 50% at 78% 12%, rgba(0, 168, 107, 0.16), transparent 60%),
        radial-gradient(46% 46% at 12% 88%, rgba(0, 102, 54, 0.13), transparent 62%),
        radial-gradient(36% 40% at 90% 92%, rgba(70, 200, 140, 0.10), transparent 60%) !important;
    background-attachment: fixed !important;
    position: relative;
}
/* Dot-grid mascherato (pseudo fisso, sotto il contenuto) */
.fi-body::before {
    content: "";
    position: fixed;
    inset: 0;
    z-index: 0;
    pointer-events: none;
    opacity: 0.5;
    background-image: radial-gradient(rgba(0, 90, 50, 0.10) 1px, transparent 1.4px);
    background-size: 26px 26px;
    -webkit-mask-image: radial-gradient(120% 90% at 60% 20%, #000 35%, transparent 78%);
    mask-image: radial-gradient(120% 90% at 60% 20%, #000 35%, transparent 78%);
}
/* Velatura noise (multiply, molto tenue) */
.fi-body::after {
    content: "";
    position: fixed;
    inset: 0;
    z-index: 0;
    pointer-events: none;
    opacity: 0.035;
    mix-blend-mode: multiply;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='2'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}
/* Il main resta sopra le velature di sfondo */
.fi-main,
.fi-sidebar {
    position: relative;
    z-index: 1;
}

/* --- Heading pagina (.fi-header-heading): display font + accento --- */
.fi-header-heading {
    font-family: var(--gal-ff-display, "Bricolage Grotesque"), sans-serif;
    color: var(--gal-ink) !important;
    font-weight: 700;
    letter-spacing: -0.02em;
}

/* --- Bottone primario (.fi-btn.fi-color-primary): gradiente verde V3 --- */
.fi-header-actions-ctn .fi-btn.fi-color-primary,
.fi-btn.fi-color-primary {
    background: var(--gal-grad) !important;
    color: #ffffff !important;
    border: 0 !important;
    box-shadow: 0 10px 22px -8px rgba(0, 140, 80, 0.55), inset 0 1px 0 rgba(255, 255, 255, 0.25) !important;
    transition: transform 0.2s cubic-bezier(0.3, 1.3, 0.5, 1), box-shadow 0.2s ease, filter 0.2s ease;
}
.fi-btn.fi-color-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 16px 30px -10px rgba(0, 140, 80, 0.6), inset 0 1px 0 rgba(255, 255, 255, 0.25) !important;
    filter: saturate(115%);
}
.fi-btn.fi-color-primary:active {
    transform: translateY(0) scale(0.98);
}

/* --- Section headers: accento verde sul titolo --- */
.fi-section-header-heading {
    font-family: var(--gal-ff-display, "Bricolage Grotesque"), sans-serif;
    color: var(--gal-ink) !important;
    font-weight: 600;
    letter-spacing: -0.01em;
}

/* --- Tab attiva: pill brand (F5.6) --- */
.fi-tabs-item.fi-active {
    background: var(--gal-brand-50) !important;
}
.fi-tabs-item.fi-active .fi-tabs-item-label {
    color: var(--gal-brand) !important;
    font-weight: 600;
}

/* --- Badge primary (.fi-badge.fi-color-primary): gradiente verde V3 --- */
.fi-badge.fi-color-primary {
    background: var(--gal-grad) !important;
    color: #ffffff !important;
    border: 0 !important;
}

/* --- Stat KPI (.fi-wi-stats-overview-stat-value): display font, accento --- */
.fi-wi-stats-overview-stat-value {
    font-family: var(--gal-ff-display, "Bricolage Grotesque"), sans-serif;
    color: var(--gal-brand-deep) !important;
    font-weight: 700;
    letter-spacing: -0.03em;
    font-variant-numeric: tabular-nums lining-nums;
}
.fi-wi-stats-overview-stat-label {
    color: #51635a !important;
    font-weight: 550;
}

/* --- Pagination buttons: gradiente brand (stile sul bottone, non sul <li>) --- */
.fi-pagination-item.fi-active .fi-pagination-item-btn {
    background: var(--gal-grad) !important;
    color: #ffffff !important;
}
.fi-pagination-item.fi-active .fi-pagination-item-label {
    color: #ffffff !important;
}

/* --- Form input focus: in F5.6 il bordo visibile è sul wrapper (.fi-input-wrp) --- */
.fi-input-wrp:focus-within {
    border-color: var(--gal-brand-light) !important;
    box-shadow: 0 0 0 4px var(--gal-brand-glow) !important;
}

/* --- Link colorati brand --- */
.fi-link,
a.fi-link {
    color: var(--gal-brand) !important;
}
.fi-link:hover {
    color: var(--gal-brand-light) !important;
}

/* --- Tabella ordini: intestazione + righe in stile V3 --- */
.fi-ta-header-cell {
    color: var(--gal-ink-mute) !important;
}
.fi-ta-text-item,
.fi-ta-table tbody td {
    color: var(--gal-ink) !important;
}

.fi-page .fi-wi {
    transition: opacity 0.3s ease;
}

/* --- Loading overlay Livewire: velo leggerissimo + spinner, NON offuscante (R5) --- */
.gal-loading-overlay {
    position: fixed;
    inset: 0;
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.06);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
}
.gal-loading-overlay.active {
    opacity: 1;
    pointer-events: auto;
}
.gal-loading-spinner {
    width: 36px;
    height: 36px;
    border: 3px solid rgba(0, 102, 54, 0.18);
    border-top-color: var(--gal-brand-light);
    border-radius: 50%;
    animation: gal-spin 0.7s linear infinite;
}
@keyframes gal-spin {
    to { transform: rotate(360deg); }
}

/* --- Drag-and-drop globale: overlay con card "Rilascia qui" ---
   NB: il JS crea l'elemento con class="gal-drop-overlay" (non id), quindi le
   regole di posizionamento/visibilità DEVONO stare sul selettore di classe. --- */
.gal-drop-overlay {
    position: fixed;
    inset: 0;
    z-index: 99999;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.18s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}
.gal-drop-overlay.active {
    opacity: 1;
    pointer-events: auto;
}
/* --- Toast inline per errori di import --- */
.gal-toast {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 99998;
    background: #ffffff;
    border-radius: 12px;
    padding: 14px 18px;
    box-shadow: 0 12px 28px rgba(0, 0, 0, 0.18);
    border-left: 4px solid #10b981;
    max-width: 420px;
    opacity: 0;
    transform: translateX(24px);
    transition: opacity 0.22s ease, transform 0.22s ease;
}
.gal-toast.show {
    opacity: 1;
    transform: translateX(0);
}
.gal-toast.error {
    border-left-color: #ef4444;
}
.gal-toast-title {
    font-weight: 600;
    color: #1e2332;
    font-size: 0.95rem;
}
.gal-toast-body {
    color: #4b5563;
    margin-top: 4px;
    font-size: 0.85rem;
}

/* ============ Cinematic drop overlay (F1) — palette V3 ============ */
.gal-drop-overlay {
    background: radial-gradient(60% 60% at 50% 38%, rgba(0, 74, 39, 0.58), rgba(0, 40, 22, 0.74)) !important;
    backdrop-filter: blur(14px) saturate(120%);
    -webkit-backdrop-filter: blur(14px) saturate(120%);
}

.gal-drop-card {
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.98), rgba(247, 251, 248, 0.98));
    border: 1px solid rgba(255, 255, 255, 0.6);
    border-radius: 24px;
    padding: 28px 32px;
    min-width: 440px;
    max-width: 520px;
    box-shadow: 0 40px 100px -30px rgba(0, 40, 22, 0.7), inset 0 1px 0 rgba(255, 255, 255, 0.8);
    position: relative;
    overflow: hidden;
    animation: gal-card-pop 0.25s ease;
}
@keyframes gal-card-pop {
    from { transform: scale(0.92); opacity: 0; }
    to   { transform: scale(1); opacity: 1; }
}
.gal-drop-card::before {
    content: ""; position: absolute; inset: 0;
    background: linear-gradient(135deg, #006636 0%, #00a86b 100%);
    opacity: 0.05; pointer-events: none;
}
.gal-drop-card .gal-top { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.gal-drop-card .gal-icon-wrap {
    width: 44px; height: 44px; border-radius: 12px;
    background: linear-gradient(135deg, #006636 0%, #00a86b 100%);
    display: flex; align-items: center; justify-content: center;
    box-shadow: 0 6px 16px rgba(0,102,54,0.35);
}
.gal-drop-card .gal-icon-wrap svg {
    width: 22px; height: 22px; stroke: white; stroke-width: 2; fill: none;
}
.gal-drop-card h3 { margin: 0; font-size: 1.05rem; font-weight: 700; letter-spacing: -0.01em; }
.gal-drop-card .gal-step { font-size: 0.78rem; color: #475569; }

.gal-drop-fields {
    display: grid; grid-template-columns: 1fr 1fr; gap: 8px 14px;
    background: #fafbfc; padding: 14px 16px; border-radius: 12px;
    margin-top: 4px; border: 1px solid #e2e8f0;
}
.gal-drop-field { font-size: 0.85rem; opacity: 0; transform: translateY(4px);
                   transition: opacity 0.3s ease, transform 0.3s ease; }
.gal-drop-field.show { opacity: 1; transform: translateY(0); }
.gal-drop-field .gal-k { color: #475569; font-size: 0.72rem; }
.gal-drop-field .gal-v { font-weight: 600; }

.gal-drop-footer { margin-top: 14px; display: flex; align-items: center; gap: 10px;
                    justify-content: space-between; }
.gal-drop-progress { flex: 1; height: 6px; border-radius: 999px; background: #e2e8f0; overflow: hidden; }
.gal-drop-progress > div {
    height: 100%; width: 30%;
    background: linear-gradient(90deg, #006636 0%, #00a86b 100%);
    animation: gal-progress-stripe 1.5s ease-in-out infinite;
}
@keyframes gal-progress-stripe {
    0%   { margin-left: -30%; width: 30%; }
    50%  { width: 50%; }
    100% { margin-left: 100%; width: 30%; }
}
.gal-drop-overlay[data-state="ok"] .gal-drop-progress > div {
    width: 100%; margin-left: 0; animation: none;
}
.gal-drop-overlay[data-state="err"] .gal-icon-wrap {
    background: #ef4444; box-shadow: 0 6px 16px rgba(239,68,68,0.35);
}
.gal-drop-overlay[data-state="err"] .gal-drop-progress > div {
    background: #ef4444; animation: none; width: 100%;
}
.gal-drop-overlay[data-state="wrong"] .gal-icon-wrap {
    background: #f59e0b; box-shadow: 0 6px 16px rgba(245,158,11,0.35);
}
.gal-drop-overlay[data-state="wrong"] .gal-drop-progress > div {
    background: #f59e0b; animation: none; width: 30%;
}
.gal-drop-cta {
    padding: 8px 14px; border-radius: 8px; font-weight: 600; font-size: 0.85rem;
    background: linear-gradient(135deg, #006636 0%, #00a86b 100%); color: white;
    box-shadow: 0 4px 12px rgba(0,102,54,0.3); border: 0; cursor: pointer;
    font-family: inherit; transition: transform 0.12s ease, filter 0.18s ease;
}
.gal-drop-cta:hover { transform: translateY(-1px); filter: brightness(1.06); }
.gal-drop-cta[disabled] { opacity: 0.5; cursor: not-allowed; }

/* Overlay drag responsive su schermi stretti */
@media (max-width: 520px) {
    .gal-drop-card {
        min-width: 0;
        width: calc(100vw - 32px);
        padding: 20px 18px;
    }
    .gal-drop-fields {
        grid-template-columns: 1fr;
    }
}

/* ============ Login sfondo "Molecole" (F1) ============ */
body:has(.gal-mol-canvas) .fi-simple-layout {
    background: linear-gradient(160deg, #f0f7f2 0%, #d4ebde 100%) !important;
}
.gal-mol-canvas {
    position: fixed; inset: 0; z-index: 0; pointer-events: none; overflow: hidden;
}
/* La card del login (bianca, col form) DEVE stare sopra le molecole animate:
   le molecole restano sullo sfondo, mai sopra il riquadro bianco. */
.gal-mol-canvas + *,
.fi-simple-main,
.fi-simple-header,
.fi-simple-footer {
    position: relative;
    z-index: 1;
}
.gal-mol {
    position: absolute; width: 120px; height: 120px;
    animation: gal-mol-drift 28s ease-in-out infinite;
}
@keyframes gal-mol-drift {
    0%, 100% { transform: translate(0, 0) rotate(0deg); }
    33% { transform: translate(60px, -40px) rotate(120deg); }
    66% { transform: translate(-50px, 30px) rotate(240deg); }
}
.gal-atom {
    position: absolute; width: 14px; height: 14px; border-radius: 50%;
    background: radial-gradient(circle at 35% 30%, #50d8a0, #006636);
    box-shadow: 0 0 12px rgba(0,168,107,0.6);
}
.gal-bond {
    position: absolute; height: 1.5px;
    background: linear-gradient(90deg, rgba(0,102,54,0.5), rgba(0,168,107,0.3), rgba(0,102,54,0.5));
    transform-origin: left center;
}

/* ============ Strip urgenza (F2) ============ */
.fi-ta-table tbody tr.gal-row-urgent-pay td:first-child {
    border-left: 4px solid #ef4444;
}
/* Ritardo pianificazione (UAT §4.2: bordo più evidente) — strip + leggero alone */
.fi-ta-table tbody tr.gal-row-urgent-prod td {
    background: rgba(239, 68, 68, 0.06);
}
.fi-ta-table tbody tr.gal-row-urgent-prod td:first-child {
    border-left: 4px solid #ef4444;
}

/* ============ Mobile table scroll (F5) ============ */
@media (max-width: 1023px) {
    .fi-ta-content {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    .fi-ta-table {
        min-width: 720px;
    }
}

/* ============ Skeleton loader (F5) ============ */
.gal-skeleton {
    background: linear-gradient(90deg, #f1f5f9 0%, #e2e8f0 50%, #f1f5f9 100%);
    background-size: 200% 100%;
    animation: gal-skel 1.4s ease-in-out infinite;
    border-radius: 6px;
}
@keyframes gal-skel {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* ============ Row hover: wash verde V3 (F5) ============ */
.fi-ta-table tbody tr {
    transition: background-color 0.15s ease;
}
.fi-ta-table tbody tr:hover {
    background-image: linear-gradient(90deg, rgba(0, 168, 107, 0.06), transparent) !important;
}

/* ============ Rispetto delle preferenze di riduzione del movimento ============ */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}
