/* ==========================================================================
   CONFIGURAZIONE BASE & VARIABILI
   ========================================================================== */
:root {
    --bg-color: #121212;
    --card-bg: #1e1e1e;
    --text-color: #e0e0e0;
    --accent-color: #bb86fc;
    --danger-color: #d32f2f;
    --success-color: #27ae60;
}

* { 
    box-sizing: border-box !important; 
}

html, body {
    overflow-x: hidden !important;
    max-width: 100vw !important;
}

body { 
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; 
    background-color: var(--bg-color); 
    color: var(--text-color);
    margin: 0; 
    padding-bottom: 90px;
}

/* ==========================================================================
   LAYOUT & STRUTTURA GENERALE
   ========================================================================== */
.container {
    display: flex;
    flex-direction: column;
    width: 100%;
}

.box { 
    background-color: var(--card-bg); 
    padding: 20px; 
    border-radius: 12px; 
    border: 1px solid #333; 
    margin: 15px auto; 
    max-width: 900px;
}

.header { 
    text-align: center; 
    padding: 20px; 
    margin-bottom: 20px; 
}

.logo { 
    max-width: 150px; 
    height: auto; 
    display: block; 
    margin: 0 auto; 
}

.link-back { 
    display: block; 
    text-align: center; 
    margin-top: 20px; 
    color: #888; 
    text-decoration: none; 
}

.hidden { 
    display: none !important; 
}

/* ==========================================================================
   HEADER PRINCIPALE & NAVBAR
   ========================================================================== */
.main-header {
    background: #000;
    padding: 10px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 2px solid #444;
}

.logo-container {
    display: flex;
    align-items: center;
    gap: 10px;
}

.logo-container img {
    width: 40px;
    height: 40px;
    border-radius: 5px;
}

.user-info {
    font-size: 0.9em;
    text-align: right;
}

.navbar {
    position: fixed; 
    bottom: 0; 
    left: 0; 
    width: 100%; 
    background: #000;
    display: flex; 
    justify-content: space-around; 
    padding: 15px 0;
    border-top: 1px solid #444; 
    z-index: 9999;
}

.navbar a { 
    text-decoration: none; 
    color: #888; 
    font-size: 14px; 
}

.navbar a.active { 
    color: var(--accent-color); 
    font-weight: bold; 
}

/* Barra in alto sempre fissa e visibile */
.navbar-top, header {
    position: sticky;
    top: 0;
    z-index: 1050;
    background: #000000;
    border-bottom: 1px solid #222222;
    backdrop-filter: blur(8px); /* effetto vetro moderno */
}
/* ==========================================================================
   GRIGLIE & DASHBOARD
   ========================================================================== */
.dashboard-grid { 
    display: grid; 
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); 
    gap: 20px; 
    padding: 20px;
    max-width: 900px;
    margin: 0 auto;
}

.card { 
    background: var(--card-bg); 
    padding: 25px; 
    border-radius: 16px; 
    box-shadow: 0 4px 15px rgba(0,0,0,0.3);
    border-top: 5px solid var(--accent-color);
    text-align: center;
    transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.card:hover { 
    transform: translateY(-5px); 
    box-shadow: 0 8px 20px rgba(0,0,0,0.2); 
}

.card a { 
    text-decoration: none; 
    font-weight: bold; 
    color: var(--text-color); 
    display: block; 
    font-size: 1.1em; 
}

.card-full { 
    grid-column: 1 / -1; 
}

/* COLORI BORDI SUPERIORI CARD (Raggruppati per funzione) */
.border-operativo { border-top-color: #e0480b !important; } /* Attività Operative */
.border-gestione  { border-top-color: #2b5c8f !important; } /* Gestione & Analisi */
.border-richieste { border-top-color: #2e7d32 !important; } /* Risorse Umane & Richieste */
.border-utilita   { border-top-color: #718096 !important; } /* Utilità & Strumenti */
.border-danger    { border-top-color: #c53030 !important; } /* Uscita / Logout */

/* Stile base dei pulsanti della dashboard */
.btn-card {
    display: flex;
    align-items: center;
    justify-content: center;
    background: #1c1c1c;
    text-decoration: none;
    color: #fff;
    font-weight: 800;
    border-radius: 16px;
    border: 2px solid;
    transition: transform 0.15s ease, background 0.15s ease;
}
.btn-card:active {
    transform: scale(0.97);
}

/* Modalità 1: LISTA (Larghi e orizzontali) */
.view-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}
.view-list .btn-card {
    padding: 16px 20px;
    font-size: 1.05rem;
    gap: 12px;
}
.view-list .btn-icon {
    font-size: 1.3rem;
}

/* Modalità 2: GRIGLIA 2x2 (Quadrati affiancati) */
.view-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}
.view-grid .btn-card {
    flex-direction: column;
    padding: 22px 10px;
    font-size: 0.95rem;
    text-align: center;
    gap: 8px;
    min-height: 110px;
}
.view-grid .btn-icon {
    font-size: 1.8rem;
}

/* ==========================================================================
   LAYOUT DINAMICO PULSANTI DASHBOARD (LISTA vs GRIGLIA 2x2)
   ========================================================================== */

/* 1. Modalità LISTA (Pulsanti orizzontali a larghezza intera) */
.view-list {
    display: flex !important;
    flex-direction: column !important;
    gap: 12px !important;
    width: 100% !important;
}
.view-list .card {
    width: 100% !important;
    padding: 16px 20px !important;
    border-radius: 16px !important;
    border-left: 1px solid #333 !important;
    border-right: 1px solid #333 !important;
    border-bottom: 1px solid #333 !important;
    border-top-width: 5px !important;
}
.view-list .card a {
    font-size: 1.05rem !important;
}

/* 2. Modalità GRIGLIA 2x2 (Tessere affiancate due a due) */
.view-grid {
    display: grid !important;
    grid-template-columns: 1fr 1fr !important;
    gap: 12px !important;
    width: 100% !important;
}
.view-grid .card {
    padding: 20px 10px !important;
    border-radius: 16px !important;
    border-left: 1px solid #333 !important;
    border-right: 1px solid #333 !important;
    border-bottom: 1px solid #333 !important;
    border-top-width: 5px !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    min-height: 95px !important;
}
.view-grid .card a {
    font-size: 0.95rem !important;
    text-align: center !important;
    line-height: 1.3 !important;
}
/* In griglia, Manuale e Logout occupano tutta la riga inferiore */
.view-grid .card-wide {
    grid-column: 1 / -1 !important;
}

/* ==========================================================================
   FORM, INPUT, TEXTAREA & ETICHETTE
   ========================================================================== */
.form-group { 
    margin-bottom: 15px; 
}

label { 
    display: block; 
    margin-top: 10px; 
    margin-bottom: 5px;
    font-size: 0.9em; 
    color: var(--text-color);
}

input, select, textarea { 
    width: 100%; 
    padding: 12px; 
    margin: 8px 0; 
    background: #2c2c2c; 
    color: #ffffff; 
    border: 1px solid #444; 
    border-radius: 8px; 
    font-size: 16px; 
    box-sizing: border-box;
    font-family: inherit;
}

textarea {
    resize: vertical;
    min-height: 80px;
}

input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--accent-color);
    box-shadow: 0 0 0 2px rgba(187, 134, 252, 0.2);
}

.input-ok { 
    border: 2px solid #2e7d32 !important; 
    box-shadow: 0 0 5px rgba(46, 125, 50, 0.5) !important; 
}

.input-error { 
    border: 2px solid #c62828 !important; 
    box-shadow: 0 0 5px rgba(198, 40, 40, 0.5) !important; 
}

.filter-bar { 
    margin-bottom: 20px; 
}

.filter-bar select {
    width: 100%;
    padding: 10px;
    background: #2c2c2c;
    color: white;
    border: 1px solid #444;
    border-radius: 6px;
}

/* ==========================================================================
   PULSANTI
   ========================================================================== */
.btn-salva { 
    width: 100%; 
    border: none; 
    padding: 16px; 
    border-radius: 8px; 
    font-weight: bold; 
    margin-top: 15px; 
    cursor: pointer; 
    color: white; 
    background-color: var(--success-color); 
}

.btn-success { background-color: var(--success-color); }
.btn-edit { background-color: #1976d2; }

.btn-add-cantiere { 
    background: #555; 
    color: white; 
    border: none; 
    padding: 10px; 
    width: 100%; 
    margin-top: 10px; 
    border-radius: 8px; 
    cursor: pointer; 
}

.btn-modifica { 
    padding: 10px; 
    background: #e0e0e0; 
    text-decoration: none; 
    color: black; 
    border-radius: 5px; 
    font-size: 0.9em; 
}

.btn-elimina { 
    padding: 10px; 
    background: #ffebee; 
    text-decoration: none; 
    color: var(--danger-color); 
    border-radius: 5px; 
    font-size: 0.9em; 
}

.btn-group-actions { 
    display: flex; 
    gap: 5px; 
    justify-content: flex-end; 
}

.btn-small { 
    padding: 5px 10px; 
    border: none; 
    border-radius: 4px; 
    cursor: pointer; 
    color: white; 
    font-size: 11px; 
    text-decoration: none; 
}

.btn-blue { background: #1976d2; }
.btn-red { background: #d32f2f; }

/* ==========================================================================
   TABELLE & DATI
   ========================================================================== */
.table-container {
    overflow-x: auto;
    margin-top: 20px;
    width: 100%;
    padding: 10px;
    box-sizing: border-box;
}

table {
    width: 100%;
    border-collapse: collapse;
    background: #181818;
    border-radius: 8px;
    overflow: hidden;
    table-layout: auto;
    margin-top: 10px;
    font-size: 0.9em;
}

th {
    background: #252525;
    padding: 12px 15px;
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: #aaa;
    text-align: left;
    position: sticky;
    top: 0;
    z-index: 10;
    border-bottom: 2px solid #444;
}

td {
    padding: 12px 15px;
    border-bottom: 1px solid #333;
    font-size: 0.95rem;
}

tr:hover { 
    background-color: #2a2a2a; 
    transition: background 0.2s ease; 
}

tr:nth-child(even) { 
    background-color: #1a1a1a; 
}

.table-utenti { 
    width: 100%; 
    border-collapse: collapse; 
    margin-top: 10px; 
}

.table-utenti td { 
    border-bottom: 1px solid #333; 
    padding: 12px 5px; 
}

.table-dark { 
    background-color: #1e1e1e !important; 
    color: #e0e0e0; 
}

/* Colonna ore e totali */
.td-ore, .text-right {
    text-align: right;
    font-weight: bold;
    color: #4CAF50;
}

/* ==========================================================================
   STORICO & SEZIONI GIORNATA
   ========================================================================== */
.box-riepilogo { 
    background: #333; 
    padding: 15px; 
    border-radius: 8px; 
    margin-bottom: 20px; 
    border: 1px solid #444; 
}

.giornata-card { 
    border: 1px solid #333; 
    margin-bottom: 10px; 
    padding: 15px; 
    border-radius: 8px; 
    background: var(--card-bg); 
}

.giornata-header { 
    cursor: pointer; 
    padding: 5px; 
}

.giornata-info { 
    display: flex; 
    justify-content: space-between; 
    font-size: 1.1em; 
}

.dettagli-giornata { 
    margin-top: 15px; 
    padding-top: 10px; 
    border-top: 1px solid #333; 
}

.btn-azione-container { 
    margin-top: 15px; 
    display: flex; 
    gap: 15px; 
}

/* ==========================================================================
   BADGE, MESSAGGI FLASH & POPUP
   ========================================================================== */
.badge {
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: bold;
    display: inline-block;
    text-transform: uppercase;
}

.badge-success { background: rgba(39, 174, 96, 0.2); color: #27ae60; border: 1px solid #27ae60; }
.badge-warning { background: rgba(243, 156, 18, 0.2); color: #f39c12; border: 1px solid #f39c12; }
.badge-danger  { background: rgba(211, 47, 47, 0.2);  color: #d32f2f; border: 1px solid #d32f2f; }

.flash-msg { 
    padding: 15px; 
    border: 1px solid; 
    border-radius: 8px; 
    margin-bottom: 20px; 
    text-align: center; 
    font-weight: bold; 
    cursor: pointer; 
}

.flash-success { 
    background: rgba(46, 125, 50, 0.15); 
    color: #4caf50; 
    border-color: #2e7d32; 
}

.flash-danger { 
    background: rgba(198, 40, 40, 0.15); 
    color: #e57373; 
    border-color: #c62828; 
}

.modal-overlay {
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background: rgba(0, 0, 0, 0.75);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 10000;
}

.modal-content {
    background: var(--card-bg);
    padding: 25px;
    border-radius: 12px;
    max-width: 500px;
    width: 90%;
    border: 1px solid #444;
    box-shadow: 0 10px 25px rgba(0,0,0,0.5);
}

.info-box { 
    margin-top: 30px; 
    border-top: 1px solid #444; 
    padding-top: 20px; 
    color: #888; 
    font-size: 0.85em; 
    text-align: center;
}

.text-muted { 
    color: #888; 
}

/* ==========================================================================
   PAGINA DI LOGIN
   ========================================================================== */
.login-card { 
    max-width: 350px; 
    margin: 50px auto; 
    text-align: left; 
    border-top: 5px solid #e0480b; 
}

.login-title { 
    text-align: center; 
    margin-top: 0; 
}

/* ==========================================================================
   MEDIA QUERIES (RESPONSIVE & STAMPA)
   ========================================================================== */
@media (max-width: 767.98px) {
    .vista-pc { display: none !important; }
    .vista-mobile { display: block !important; }
}

@media (min-width: 768px) {
    .vista-pc { display: block !important; }
    .vista-mobile { display: none !important; }
    .box {
        max-width: 1200px;
        width: 92%;
    }
    input[name="ore_cantieri[]"], select, input[type="time"] {
        padding: 15px 20px !important;
        font-size: 1.1rem;
    }
    .container {
        flex-direction: row;
        flex-wrap: wrap;
        gap: 20px;
    }
}

@media print {
    .navbar, .btn, .btn-salva, .btn-modifica, .btn-elimina, .no-print, .filter-bar, .link-back { 
        display: none !important; 
    }
    
    body { 
        background: white !important; 
        color: black !important; 
        padding: 0 !important; 
    }
    
    .box, table { 
        background: white !important; 
        color: black !important; 
        border: 1px solid #ccc !important; 
        width: 100% !important; 
        margin: 0 !important; 
    }
    
    .container { 
        width: 100% !important; 
        max-width: 100% !important; 
        margin: 0 !important; 
    }
    
    .scheda-cantiere { 
        border: none !important; 
        box-shadow: none !important; 
    }
    
    th { 
        background: #eee !important; 
        color: black !important; 
    }
    
    .note-stampa { 
        display: block !important; 
    }
}

/* ==========================================================================
   RIPRISTINO STILE TAB PREVENTIVATORE (Compatibile con codice JS/HTML esistente)
   ========================================================================== */

/* Contenitore dei pulsanti tab */
.nav-tabs, 
.tabs-container, 
[class*="tab-header"], 
[class*="nav-tab"] {
    display: flex !important;
    gap: 8px;
    margin-bottom: 20px;
    border-bottom: 2px solid var(--border-color, #333);
    padding-bottom: 0;
}

/* Pulsanti dei tab */
.nav-tabs button, 
.tabs-container button, 
.tab-button, 
.tab-link {
    background-color: #252525;
    color: #aaa;
    border: 1px solid #444;
    border-bottom: none;
    padding: 10px 18px;
    border-radius: 6px 6px 0 0;
    cursor: pointer;
    font-weight: 600;
    transition: all 0.2s ease-in-out;
}

.nav-tabs button:hover, 
.tab-button:hover {
    background-color: #333;
    color: #fff;
}

/* Stato del pulsante Tab Attivo */
.nav-tabs button.active, 
.tabs-container button.active, 
.tab-button.active, 
.tab-link.active {
    background-color: var(--card-bg, #1e1e1e) !important;
    color: var(--accent-color, #00d26a) !important;
    border-color: var(--accent-color, #00d26a) var(--accent-color, #00d26a) transparent var(--accent-color, #00d26a) !important;
    border-bottom: 2px solid var(--card-bg, #1e1e1e) !important;
    margin-bottom: -2px;
}

/* Gestione Visibilità Sezioni Tab */
.tab-pane, 
.tab-content, 
.tab-section {
    display: block;
}

.tab-pane.hidden, 
.tab-content.hidden, 
.tab-section.hidden,
[data-tab-content].hidden {
    display: none !important;
}

/* TABELLA PREVENTIVATORE PDC & FV UNIFORMATI */
.tabella-preventivo-pdc {
  table-layout: fixed !important;
  width: 100% !important;
  margin-bottom: 0 !important;
}

.tabella-preventivo-pdc th, 
.tabella-preventivo-pdc td {
  overflow: hidden;
  text-overflow: ellipsis;
  vertical-align: middle;
  padding: 0.6rem 0.5rem !important;
}

.tabella-preventivo-pdc input.form-control {
  background-color: #2b2b2b !important;
  color: #fff !important;
  border: 1px solid #444 !important;
  padding: 0.25rem 0.4rem !important;
  font-size: 0.85rem !important;
  border-radius: 6px;
}

.tabella-preventivo-pdc input.form-control:focus {
  border-color: #0dcaf0 !important;
  box-shadow: 0 0 0 0.15rem rgba(13, 202, 240, 0.25) !important;
}