/* ==========================================================================
   TIMBRA.CSS - FOGLIO DI STILE PRINCIPALE
   Indice delle Sezioni:
   1. VARIABLES & GLOBALS
   2. LAYOUT & GRID (Main Page)
   3. CARD: TIMBRATURE (Left)
      3.1 Header & Date
      3.2 Turno Previsto
      3.3 Fasce Orarie (Grid 2x2 & Placeholder)
      3.4 Form Actions
   4. CARD: RIEPILOGO (Nuovo Layout Espanso)
   5. CARD: STORICO (Right & Table)
   6. MODALS & POPUPS
   7. TOAST NOTIFICATIONS (Nuovo Design Glassmorphism)
   8. RESPONSIVE DESIGN
========================================================================== */

/* ==========================================================================
   1. VARIABLES & GLOBALS
========================================================================== */
:root {
    --primary: #003366;
    --primary-hover: #002244;
    --accent: #0055A4;
    --accent-hover: #003d7a;
    --bg-body: #f4f7f6;
    --surface: #ffffff;
    --text-main: #1e293b;
    --text-secondary: #475569;
    --text-light: #94a3b8;
    --border: #cbd5e1;
    --success: #10B981;
    --danger: #EF4444;
    --radius: 8px;
    --shadow: 0 10px 25px -5px rgba(0, 51, 102, 0.1), 0 8px 10px -6px rgba(0, 51, 102, 0.1);
    --font-heading: 'Outfit', sans-serif;
    --font-sans: 'Inter', system-ui, -apple-system, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { height: 100%; }
.main-content .content-area { background-color: transparent; }
.hidden { display: none !important; }

/* ==========================================================================
   2. LAYOUT & GRID (Main Page)
========================================================================== */
.timbra-grid-layout {
    display: grid;
    grid-template-columns: 1fr 2fr;
    gap: 24px;
    height: calc(100vh - 120px);
    min-height: 600px;
    width: 100%;
}

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    height: 100%;
}

@media (max-width: 1024px) {
    .timbra-grid-layout { 
        grid-template-columns: 1fr; 
        height: auto; 
        max-height: none;
    }
    .card { 
        height: 600px; /* Altezza fissa su mobile per permettere lo scrolling interno */
    }
}

/* ==========================================================================
   3. CARD: TIMBRATURE (Left)
========================================================================== */
.timbra-card { justify-content: space-between; }
.section-input { padding: 1.5rem; background: #FFFFFF; }

/* --- 3.1 Header & Date --- */
.section-input-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.25rem;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid var(--border);
}

.card-main-title {
    font-family: var(--font-heading);
    font-size: 1.15rem;
    font-weight: 700;
    color: #1E293B;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin: 0;
}

.header-date input {
    width: 135px;
    padding: 8px 12px;
    font-size: 13px;
    font-weight: 600;
    font-family: var(--font-sans);
    color: #1E293B;
    background: #F8FAFC;
    border: 1px solid var(--border);
    border-radius: 6px;
    outline: none;
    transition: all 0.2s;
    cursor: pointer;
}
.header-date input:focus {
    background: #FFFFFF;
    border-color: #D8B4FE;
    box-shadow: 0 0 0 3px rgba(216, 180, 254, 0.2);
}

/* --- 3.2 Turno Previsto --- */
.turno-field { margin-bottom: 1.5rem; }
.turno-toggle {
    display: flex;
    background: #F1F5F9;
    padding: 0.25rem;
    border-radius: 8px;
    border: 1px solid var(--border);
}
.turno-option { flex: 1; text-align: center; cursor: pointer; position: relative; }
.turno-option input { display: none; }
.turno-option span {
    display: block; padding: 0.5rem 0; font-size: 0.8rem; font-weight: 700;
    color: #64748B; border-radius: 6px; font-family: var(--font-heading);
    text-transform: uppercase; transition: 0.2s;
}
.turno-option input:checked + span { background: #FFFFFF; color: #1E293B; box-shadow: 0 1px 3px rgba(0,0,0,0.1); }

/* --- 3.3 Fasce Orarie (Grid 2x2 & Placeholder) --- */
.fasce-wrapper {
    display: grid;
    grid-template-columns: 1fr 1fr; /* Layout Compattato a due colonne */
    gap: 12px;
    margin-bottom: 1.5rem;
}

.time-section {
    display: flex; align-items: center; background: #F8FAFC;
    border: 1px solid transparent; border-radius: 8px; padding: 6px 8px; gap: 8px; transition: all 0.2s;
}
.time-section:focus-within { border-color: #D8B4FE; background: #FDF9FF; }

.time-badge {
    background: #E2E8F0; color: #475569; width: 28px; height: 28px; border-radius: 6px;
    display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 13px; font-family: var(--font-heading); flex-shrink: 0;
}

.time-inputs { display: flex; flex: 1; align-items: center; gap: 4px; }
.input-group { flex: 1; }

.entrata-input, .uscita-input {
    width: 100%; text-align: center; padding: 10px 4px;
    border: 1px solid var(--border); border-radius: 6px; background: #FFFFFF;
    font-family: var(--font-sans); font-size: 14px; font-weight: 600;
    color: #1E293B; outline: none; transition: 0.2s;
}
.entrata-input:focus, .uscita-input:focus { border-color: #D8B4FE; }

/* Stile speciale per i placeholder "Entrata" / "Uscita" */
.entrata-input::placeholder, .uscita-input::placeholder {
    color: #94A3B8; font-family: var(--font-sans); font-size: 11px; font-weight: 500; letter-spacing: 0.05em;
}

.time-sep { color: #94A3B8; width: 14px; height: 14px; flex-shrink: 0; }

/* --- 3.4 Form Actions --- */
.form-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.btn-action {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px;
    border-radius: 10px;
    font-family: var(--font-sans);
    font-weight: 600;
    font-size: 14px;
    cursor: pointer;
    border: 1px solid transparent;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    overflow: hidden;
}

.btn-action i {
    width: 18px;
    height: 18px;
    transition: transform 0.3s ease;
}

.btn-action:hover i {
    transform: scale(1.1);
}

.btn-action:active {
    transform: scale(0.97);
}

/* CALCOLA - Premium Dark Gradient */
.btn-calcola {
    grid-column: 1 / -1;
    background: linear-gradient(135deg, #0F172A 0%, #1E293B 100%);
    color: #FFFFFF;
    box-shadow: 0 4px 12px rgba(15, 23, 42, 0.15), 0 2px 4px rgba(15, 23, 42, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.btn-calcola:hover {
    background: linear-gradient(135deg, #1E293B 0%, #334155 100%);
    box-shadow: 0 8px 20px rgba(15, 23, 42, 0.25);
    transform: translateY(-2px);
}

/* SALVA - Clean Modern White */
.btn-aggiungi {
    background: #FFFFFF;
    color: #0F172A;
    border-color: #E2E8F0;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

.btn-aggiungi:hover {
    background: #F8FAFC;
    border-color: #38BDF8;
    color: #0284C7;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(2, 132, 199, 0.1);
}

/* ASSENZA - Subtle Glassmorphism */
.btn-assenza {
    background: rgba(241, 245, 249, 0.5);
    color: #475569;
    border-color: #E2E8F0;
    backdrop-filter: blur(4px);
}

.btn-assenza:hover {
    background: rgba(255, 255, 255, 0.8);
    border-color: #F472B6;
    color: #DB2777;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(219, 39, 119, 0.1);
}

.btn-assenza.has-value {
    background: rgba(253, 242, 248, 0.8);
    border-color: #F472B6;
    color: #BE185D;
    font-weight: 700;
}

/* ==========================================================================
   4. CARD: RIEPILOGO (Nuovo Layout Espanso)
========================================================================== */
.section-data { 
    padding: 1.5rem; 
    background: #FFFFFF; 
    border-top: 1px solid var(--border); 
    flex-grow: 1;
    display: flex;
    flex-direction: column;
}
.data-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1rem; }

.btn-icon-clear {
    background: transparent; border: none; color: #94A3B8; cursor: pointer;
    padding: 6px; border-radius: 6px; transition: 0.2s; display: flex;
}
.btn-icon-clear:hover { color: var(--danger); background: #FEF2F2; }
.btn-icon-clear i { width: 18px; height: 18px; }

/* Stato vuoto estetico */
.empty-state {
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    padding: 2rem 1rem; text-align: center; color: #94A3B8;
}
.empty-state-icon {
    background: #F1F5F9; width: 48px; height: 48px; border-radius: 50%;
    display: flex; align-items: center; justify-content: center; margin-bottom: 12px; color: #64748B;
}
.empty-state p { font-size: 13px; font-weight: 500; }

/* Pannello Risultati - Professional & Compact Layout */
.result-panel {
    display: flex;
    flex-direction: column;
    gap: 12px;
    width: 100%;
    flex-grow: 1; /* Permette al pannello di espandersi */
}

.summary-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    border-bottom: 1px solid var(--border);
    padding-bottom: 12px;
}

.summary-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px 0;
    transition: all 0.2s;
}

.summary-item .s-label {
    font-size: 11px;
    font-weight: 600;
    color: #64748B;
    display: flex;
    align-items: center;
    gap: 8px;
}
.summary-item .s-label i { width: 14px; height: 14px; opacity: 0.6; }

.summary-item .s-value {
    font-family: var(--font-heading);
    font-size: 14px;
    font-weight: 700;
    color: #1E293B;
}

.summary-item.highlight-target {
    border-radius: 6px;
    margin: 0 -4px;
    padding: 6px 8px;
    background: #F0F9FF;
}
.summary-item.highlight-target .s-label { color: #0284C7; }
.summary-item.highlight-target .s-value { color: #0369A1; }

/* Fasce Eccesso Dinamiche - Professional List */
.dynamic-fasce-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.fascia-item {
    padding: 4px 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px dashed #E2E8F0;
}
.fascia-item:last-child { border-bottom: none; }

.fascia-label {
    font-size: 11px;
    font-weight: 500;
    color: #94A3B8;
}

.fascia-value {
    font-family: var(--font-sans);
    font-size: 12px;
    color: #64748B;
}
.fascia-value b { color: #D97706; font-weight: 700; }

/* Eccesso Totale - Sleek Technical Box */
.result-highlight-box {
    margin-top: auto; /* Sposta il banner in fondo alla scheda */
    padding: 14px 18px;
    background: #0F172A;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: space-between; /* Spinge il valore a destra */
    border: 1px solid rgba(255,255,255,0.1);
}

.highlight-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.highlight-icon {
    width: 18px;
    height: 18px;
    color: #94A3B8;
    opacity: 0.5;
}

.highlight-text {
    display: flex;
    flex-direction: column;
}

.highlight-label {
    font-size: 10px;
    font-weight: 700;
    color: #94A3B8;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.highlight-value {
    font-family: var(--font-heading);
    font-size: 18px;
    font-weight: 800;
    color: #FFFFFF;
    line-height: 1;
}

.highlight-value.positive { color: #10B981; }
.highlight-value.negative { color: #EF4444; }

/* ==========================================================================
   5. CARD: STORICO (Right & Table)
========================================================================== */
.history-card { display: flex; flex-direction: column; background: #FFFFFF; }
.history-header { display: flex; justify-content: space-between; align-items: center; padding: 20px; border-bottom: 1px solid var(--border); flex-wrap: wrap; gap: 12px; }

.history-actions { display: flex; align-items: center; gap: 8px; }
.total-excess-pill {
    font-size: 13px; font-weight: 700; color: #1E293B; background: #FFFFFF;
    border: 1px solid var(--border); padding: 8px 12px; border-radius: 20px;
}
.total-excess-pill .positive { color: var(--success); }
.total-excess-pill .negative { color: var(--danger); }

/* Pulsanti Superiori Tabella (Più Compatti) */
.btn-history {
    display: inline-flex; align-items: center; gap: 4px; padding: 6px 10px;
    font-size: 11px; font-weight: 600; border-radius: 6px; font-family: var(--font-sans); cursor: pointer; transition: 0.2s;
}
.btn-history i { width: 12px; height: 12px; }
.btn-danger-outline { background: #FFFFFF; color: var(--danger); border: 1px solid #FECACA; }
.btn-danger-outline:hover { background: #FEF2F2; border-color: #F87171; }
.btn-dark { background: #111827; color: #FFFFFF; border: 1px solid transparent; }
.btn-dark:hover { background: #1F2937; transform: translateY(-1px); box-shadow: 0 2px 4px rgba(0,0,0,0.1); }

/* Corpo Tabella */
.history-body { flex-grow: 1; position: relative; overflow: hidden; display: flex; flex-direction: column; }
.history-scroll-area { flex-grow: 1; overflow-y: auto; overflow-x: auto; scrollbar-width: thin; scrollbar-color: #cbd5e1 transparent; }
.history-scroll-area::-webkit-scrollbar { width: 6px; }
.history-scroll-area::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 10px; }

#history-table { width: 100%; border-collapse: collapse; min-width: 600px; }
#history-table th {
    position: sticky; top: 0; z-index: 10; background: #F8FAFC; color: #64748B;
    font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em;
    padding: 10px 12px; border-bottom: 1px solid var(--border); text-align: center;
}
#history-table td { padding: 10px 12px; border-bottom: 1px solid #F1F5F9; color: #334155; font-size: 13px; text-align: center; vertical-align: middle; }
#history-table tbody tr:hover td { background: #F8FAFC; }
.empty-cell { height: 100%; text-align: center; vertical-align: middle !important; padding: 40px 0; }

/* Pulsanti Azione Riga Tabella (Molto più piccoli e discreti) */
.row-actions { display: flex; justify-content: center; gap: 4px; }
.btn-detail, .btn-delete {
    width: 24px; height: 24px; /* Dimensione ridotta */
    border-radius: 4px; border: none; background: transparent; cursor: pointer; transition: 0.2s;
    display: inline-flex; align-items: center; justify-content: center;
}
.btn-detail svg, .btn-delete svg { width: 14px; height: 14px; /* Icone più piccole */ }
.btn-detail { color: #64748B; }
.btn-detail:hover { background: #F1F5F9; color: #1E293B; }
.btn-delete { color: #94A3B8; }
.btn-delete:hover { background: #FEF2F2; color: var(--danger); }

.card-footer { padding: 14px; background: #F8FAFC; border-top: 1px solid var(--border); text-align: center; color: #94A3B8; font-size: 11px; font-weight: 500; }

/* ==========================================================================
   6. MODALS & POPUPS
/* ==========================================================================
   7. DETTAGLIO TIMBRATURA (POPUP)
========================================================================== */
.popup-overlay { position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: rgba(15, 23, 42, 0.6); backdrop-filter: blur(6px); display: flex; justify-content: center; align-items: center; z-index: 3000; opacity: 1; transition: 0.2s; padding: 16px; }
.popup-card { background: #FFFFFF; border-radius: 16px; box-shadow: 0 20px 40px -10px rgba(0,0,0,0.2); width: 100%; max-width: 440px; transform: scale(1) translateY(0); transition: 0.2s; display: flex; flex-direction: column; }
.popup-overlay.hidden { opacity: 0; pointer-events: none; }
.popup-overlay.hidden .popup-card { transform: scale(0.96) translateY(10px); }

.popup-header { display: flex; justify-content: space-between; align-items: center; padding: 20px 24px; border-bottom: 1px solid #F1F5F9; }
.popup-header h3 { font-family: var(--font-heading); font-size: 17px; font-weight: 700; color: #0F172A; margin: 0; }
.popup-close { background: #F8FAFC; border: none; color: #64748B; cursor: pointer; padding: 6px; border-radius: 50%; transition: 0.2s; display: flex; align-items: center; justify-content: center; }
.popup-close:hover { background: #F1F5F9; color: var(--danger); transform: rotate(90deg); }

.popup-body { padding: 24px; }
.popup-label { font-size: 11px; font-weight: 700; color: #64748B; text-transform: uppercase; letter-spacing: 0.06em; display: block; margin-bottom: 10px; }
.popup-input-wrapper { display: flex; gap: 8px; margin-bottom: 12px; height: 48px; }
.popup-time-input { flex: 1; text-align: center; font-family: 'JetBrains Mono', monospace; font-size: 24px; font-weight: 700; color: #0F172A; border: 1px solid var(--border); border-radius: 12px; background: #F8FAFC; outline: none; transition: 0.2s; letter-spacing: 4px; }
.popup-time-input:focus { border-color: #D8B4FE; background: #FFFFFF; box-shadow: 0 0 0 3px rgba(216, 180, 254, 0.2); }
.popup-paste { width: 48px; height: 100%; border: 1px solid var(--border); border-radius: 10px; background: #F1F5F9; color: #64748B; cursor: pointer; transition: 0.2s; display: flex; align-items: center; justify-content: center; }
.popup-paste:hover { background: #E2E8F0; color: #A855F7; border-color: #A855F7; }
.popup-hint { font-size: 12px; color: #94A3B8; margin: 0; }

/* Dettaglio Popup */
.popup-card-detail { max-width: 440px; }
.detail-section { display: flex; flex-direction: column; gap: 0; }
.detail-row { display: flex; justify-content: space-between; align-items: center; padding: 12px 4px; border-bottom: 1px solid #F1F5F9; }
.detail-row:last-child { border-bottom: none; }
.detail-label { font-size: 13px; font-weight: 500; color: #64748B; }
.detail-value { font-weight: 700; color: #0F172A; font-size: 14px; }
.detail-mono { font-family: 'JetBrains Mono', monospace; font-size: 13px; }
.detail-fascia { color: #B45309; background: #FEF3C7; padding: 4px 10px; border-radius: 20px; font-size: 12px; font-family: 'JetBrains Mono', monospace; font-weight: 600; }
.detail-divider { border: none; height: 1px; background: #E2E8F0; margin: 4px 0; }
.detail-highlight { background: #FFFFFF; border: 1px solid #E2E8F0; border-radius: 14px; padding: 16px; margin-top: 12px; display: flex; justify-content: space-between; align-items: center; border-left: 4px solid #003366; }
.detail-eccesso { font-size: 22px; font-weight: 800; font-family: var(--font-heading); }
.detail-eccesso.positive { color: var(--success); }
.detail-eccesso.negative { color: var(--danger); }

/* ==========================================================================
   8. RESPONSIVE DESIGN
========================================================================== */
@media (max-width: 1024px) {
    .fasce-wrapper { grid-template-columns: 1fr; } /* Su tablet torna 1 colonna */
}
@media (max-width: 768px) {
    .section-input, .section-data { padding: 1.25rem; }
    .history-header { flex-direction: column; align-items: flex-start; }
    .history-actions { width: 100%; justify-content: space-between; }
    #history-table { font-size: 12px; }
    .toast-container { bottom: 20px; right: 20px; left: 20px; align-items: center; }
    .toast { min-width: 100%; }
}
@media (max-width: 480px) {
    .form-actions { grid-template-columns: 1fr; }
    .btn-calcola { grid-column: span 1; }
    .header-date input { width: 100%; }
}

/* ==========================================================================
   FLATPICKR CUSTOMIZATION
========================================================================== */
.flatpickr-calendar {
    font-family: var(--font-sans); /* Usa il tuo font Inter */
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
    border-radius: var(--radius);
}

.flatpickr-day.selected, 
.flatpickr-day.startRange, 
.flatpickr-day.endRange, 
.flatpickr-day.selected.inRange, 
.flatpickr-day.startRange.inRange, 
.flatpickr-day.endRange.inRange, 
.flatpickr-day.selected:focus, 
.flatpickr-day.startRange:focus, 
.flatpickr-day.endRange:focus, 
.flatpickr-day.selected:hover, 
.flatpickr-day.startRange:hover, 
.flatpickr-day.endRange:hover, 
.flatpickr-day.selected.prevMonthDay, 
.flatpickr-day.startRange.prevMonthDay, 
.flatpickr-day.endRange.prevMonthDay, 
.flatpickr-day.selected.nextMonthDay, 
.flatpickr-day.startRange.nextMonthDay, 
.flatpickr-day.endRange.nextMonthDay {
    background: var(--primary); /* Il tuo blu scuro */
    border-color: var(--primary);
}

/* Stile per l'input generato da Flatpickr per fargli avere il focus viola che hai impostato */
input.flatpickr-input[type="text"] {
    width: 135px;
    padding: 8px 12px;
    font-size: 13px;
    font-weight: 600;
    font-family: var(--font-sans);
    color: #1E293B;
    background: #F8FAFC;
    border: 1px solid var(--border);
    border-radius: 6px;
    outline: none;
    transition: all 0.2s;
}

input.flatpickr-input[type="text"]:focus {
    background: #FFFFFF;
    border-color: #D8B4FE;
    box-shadow: 0 0 0 3px rgba(216, 180, 254, 0.2);
}

/* ==========================================================================
   INPUT DATA CON ICONA (Wrapper & Placeholder)
========================================================================== */

/* Il contenitore che ci permette di posizionare l'icona in modo assoluto */
.date-input-wrapper {
    position: relative;
    display: flex;
    align-items: center;
}

/* Posizionamento e comportamento dell'icona del calendario */
.date-icon {
    position: absolute;
    left: 10px;
    width: 16px;
    height: 16px;
    color: #94A3B8; 
    pointer-events: auto; /* MODIFICATO: ora intercetta il click! */
    cursor: pointer;      /* AGGIUNTO: mostra la manina quando ci passi sopra */
    z-index: 10;          /* Aumentato per stare sicuramente sopra l'input */
}

/* Aggiorniamo il padding per fare spazio all'icona a sinistra */
.header-date input, 
input.flatpickr-input[type="text"] {
    width: 150px; /* Leggermente allargato per bilanciare la presenza dell'icona */
    padding: 8px 12px 8px 34px !important; /* 34px di spazio a sinistra per l'icona */
}

/* Forza lo stile del testo in grigio chiaro quando il campo è vuoto */
input.flatpickr-input[type="text"]::placeholder {
    color: #94A3B8;
    font-weight: 500;
    opacity: 1; /* Su Firefox/Safari a volte il placeholder è semitrasparente di default */
}