:root {
    --pe-dark: #1b2a4a;
    --pe-dark-2: #24365e;
    --pe-grey: #5a6472;
    --pe-grey-light: #f4f5f7;
    --pe-accent: #e06c1f;
    --pe-border: #e2e5eb;
}

body {
    background-color: var(--pe-grey-light);
    color: #26313f;
}

.pe-sidebar {
    background: var(--pe-dark);
    min-height: 100vh;
    color: #fff;
}

.pe-sidebar .brand {
    font-weight: 700;
    font-size: 1.15rem;
    padding: 1.1rem 1.25rem;
    border-bottom: 1px solid rgba(255,255,255,0.08);
}

.pe-sidebar .nav-link {
    color: rgba(255,255,255,0.75);
    padding: 0.6rem 1.25rem;
    border-left: 3px solid transparent;
}

.pe-sidebar .nav-link:hover {
    color: #fff;
    background: rgba(255,255,255,0.05);
}

.pe-sidebar .nav-link.active {
    color: #fff;
    background: rgba(255,255,255,0.08);
    border-left-color: var(--pe-accent);
    font-weight: 600;
}

.pe-topbar {
    background: #fff;
    border-bottom: 1px solid var(--pe-border);
}

.pe-card {
    background: #fff;
    border: 1px solid var(--pe-border);
    border-radius: 10px;
}

.pe-stat-card {
    background: #fff;
    border: 1px solid var(--pe-border);
    border-radius: 10px;
    padding: 1.1rem 1.3rem;
}

.pe-stat-card .value {
    font-size: 1.7rem;
    font-weight: 700;
    color: var(--pe-dark);
}

.pe-stat-card .label {
    color: var(--pe-grey);
    font-size: 0.85rem;
}

.btn-accent {
    background-color: var(--pe-accent);
    border-color: var(--pe-accent);
    color: #fff;
}
.btn-accent:hover { background-color: #c85d18; border-color: #c85d18; color: #fff; }

.btn-dark-pe {
    background-color: var(--pe-dark);
    border-color: var(--pe-dark);
    color: #fff;
}
.btn-dark-pe:hover { background-color: var(--pe-dark-2); border-color: var(--pe-dark-2); color: #fff; }

.table-pe thead th {
    background: var(--pe-dark);
    color: #fff;
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    border: none;
}

.badge-status-draft { background: #adb5bd; }
.badge-status-generated { background: #0d6efd; }
.badge-status-sent { background: #6f42c1; }
.badge-status-accepted { background: #198754; }
.badge-status-rejected { background: #dc3545; }
.badge-status-expired { background: #6c757d; }

.category-block {
    border: 1px solid var(--pe-border);
    border-radius: 8px;
    margin-bottom: 1.1rem;
    overflow: hidden;
}
.category-block .category-header {
    background: var(--pe-grey-light);
    padding: 0.5rem 0.8rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 0.5rem;
}
.category-block .category-header input {
    flex: 1 1 160px;
    min-width: 0;
}

/* Banner "sei offline" (vedi base.html + templates/sw.js): fascia fissa in alto,
   mostrata/nascosta in base agli eventi online/offline del browser. Avvisa
   l'utente che sta consultando dati salvati in precedenza e che azioni come
   salvataggi o generazione AI potrebbero non funzionare in questo momento. */
.offline-banner {
    position: sticky;
    top: 0;
    z-index: 2060;
    background: #6c757d;
    color: #fff;
    text-align: center;
    font-size: 0.85rem;
    padding: 0.4rem 0.8rem;
}

/* Indicatore "salvato": toast flottante mostrato dopo ogni modifica salvata via
   HTMX (riga, categoria, impostazioni). Fondamentale su mobile, dove il salvataggio
   automatico è altrimenti silenzioso. hx-swap-oob="true" sostituisce l'intero nodo
   ad ogni salvataggio, quindi l'animazione riparte automaticamente da capo. */
.saved-toast {
    position: fixed;
    left: 50%;
    bottom: 1.25rem;
    transform: translateX(-50%);
    z-index: 2050;
    display: flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.5rem 1rem;
    border-radius: 999px;
    background: #198754;
    color: #fff;
    font-size: 0.875rem;
    font-weight: 600;
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.18);
    opacity: 0;
    pointer-events: none;
}
.saved-toast.is-visible {
    animation: saved-toast-pop 1.8s ease forwards;
}
@keyframes saved-toast-pop {
    0% { opacity: 0; transform: translateX(-50%) translateY(8px); }
    12% { opacity: 1; transform: translateX(-50%) translateY(0); }
    75% { opacity: 1; transform: translateX(-50%) translateY(0); }
    100% { opacity: 0; transform: translateX(-50%) translateY(-6px); }
}
@media (min-width: 992px) {
    .saved-toast {
        left: auto;
        right: 1.5rem;
        bottom: 1.5rem;
        transform: none;
    }
    .saved-toast.is-visible { animation-name: saved-toast-pop-desktop; }
    @keyframes saved-toast-pop-desktop {
        0% { opacity: 0; transform: translateY(8px); }
        12% { opacity: 1; transform: translateY(0); }
        75% { opacity: 1; transform: translateY(0); }
        100% { opacity: 0; transform: translateY(-6px); }
    }
}

.ai-loading-overlay {
    position: fixed;
    inset: 0;
    background: rgba(27, 42, 74, 0.92);
    color: #fff;
    z-index: 2000;
    display: none;
    align-items: center;
    justify-content: center;
    flex-direction: column;
}
.ai-loading-overlay.active { display: flex; }
.ai-loading-overlay .spinner-border { width: 3rem; height: 3rem; }
.ai-loading-step {
    margin-top: 1.2rem;
    font-size: 1.05rem;
    min-height: 1.6em;
}

/* Pulsante microfono per l'input vocale (Web Speech API, vedi static/js/voice-input.js).
   Lo stato "in ascolto" è reso ben visibile (colore pieno + puntino animato) perché
   sul cantiere, con rumore di fondo, l'utente deve capire a colpo d'occhio se il
   microfono sta registrando. */
.voice-input-btn {
    position: relative;
    flex-shrink: 0;
}
.voice-input-btn.is-listening {
    background-color: #dc3545;
    border-color: #dc3545;
    color: #fff;
}
.voice-input-btn.is-listening::after {
    content: "";
    position: absolute;
    top: -2px;
    right: -2px;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #dc3545;
    animation: voice-input-pulse 1.2s ease-in-out infinite;
}
@keyframes voice-input-pulse {
    0% { box-shadow: 0 0 0 0 rgba(220, 53, 69, 0.6); }
    70% { box-shadow: 0 0 0 8px rgba(220, 53, 69, 0); }
    100% { box-shadow: 0 0 0 0 rgba(220, 53, 69, 0); }
}

/* Su mobile il riepilogo totali è mostrato per primo (vedi order-* in
   quotation_edit.html) e resta statico per non occupare permanentemente
   spazio prezioso sullo schermo; da tablet in su ("lg") diventa una barra
   laterale che segue lo scroll. */
.totals-sticky { position: static; }
@media (min-width: 992px) {
    .totals-sticky { position: sticky; top: 1rem; }
}

.htmx-request.htmx-indicator,
.htmx-request .htmx-indicator { display: inline-block !important; }
.htmx-indicator { display: none; }

/* ---------------------------------------------------------------------
   Editor preventivo: tabella lavorazioni -> card verticali sotto i 768px.
   L'app viene usata molto da telefono (es. in cantiere), quindi la vista
   più utilizzata (editor) deve restare comoda da toccare col pollice,
   senza scroll orizzontale e senza dover fare zoom per leggere un campo.
   Sopra i 768px resta invece una normale tabella, più efficiente su
   schermi larghi. Le stesse righe <tr>/<td> restano nel DOM: cambia solo
   la resa visiva via CSS, quindi gli endpoint HTMX (che puntano a
   "closest tr" / "closest tbody") continuano a funzionare invariati.
   ------------------------------------------------------------------- */
@media (max-width: 767.98px) {
    .table-cards thead {
        position: absolute;
        width: 1px; height: 1px;
        overflow: hidden;
        clip: rect(0 0 0 0);
        white-space: nowrap;
    }
    .table-cards, .table-cards tbody, .table-cards tr, .table-cards td {
        display: block;
        width: 100%;
    }
    .table-cards {
        border-spacing: 0;
    }
    .table-cards tr {
        background: #fff;
        border: 1px solid var(--pe-border);
        border-radius: 10px;
        margin-bottom: 0.75rem;
        padding: 0.75rem 0.85rem;
        box-shadow: 0 1px 2px rgba(0,0,0,.04);
    }
    .table-cards td {
        border: none !important;
        padding: 0.4rem 0;
    }
    .table-cards td[data-label]::before {
        content: attr(data-label);
        display: block;
        font-size: 0.72rem;
        font-weight: 600;
        text-transform: uppercase;
        letter-spacing: 0.03em;
        color: var(--pe-grey);
        margin-bottom: 0.2rem;
    }
    .table-cards td.totals-cell {
        display: flex;
        justify-content: space-between;
        align-items: center;
        background: var(--pe-grey-light);
        border-radius: 8px;
        padding: 0.5rem 0.6rem;
        margin-top: 0.2rem;
    }
    .table-cards td.totals-cell::before { content: none; }
    .table-cards td.actions-cell {
        display: flex;
        justify-content: flex-end;
        gap: 0.5rem;
        padding-top: 0.6rem;
        margin-top: 0.4rem;
        border-top: 1px solid var(--pe-border) !important;
    }
    .table-cards td.actions-cell::before { content: none; }

    /* Input più grandi: dimensione tocco adeguata (min ~44px) e font >=16px
       per evitare che iOS Safari faccia lo zoom automatico al focus. */
    .table-cards input.form-control,
    .table-cards input.form-control-sm {
        min-height: 44px;
        font-size: 1rem;
        padding: 0.5rem 0.65rem;
    }
    .table-cards .btn-group-sm > .btn,
    .table-cards .btn-sm {
        min-width: 44px;
        min-height: 44px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }
}
