/* Stili custom applicativo Gestionale Preventivi */

/* ---------------------------------------------------------------------
 * Tema "Grafite": ridefinisce le CSS variabili di Bootstrap 5.3 — non solo
 * il primario, ma l'intera famiglia semantica (secondary/success/danger/
 * warning/info) intonata alla stessa palette fredda, così i bottoni non
 * ricadono sui colori di default di Bootstrap. Si propaga automaticamente
 * a bottoni, badge, link, alert, form senza toccare le singole view.
 * --------------------------------------------------------------------- */
:root {
    /* Primario: blu cobalto, l'unico colore usato per le azioni principali */
    --bs-primary: #2f6fed;
    --bs-primary-rgb: 47, 111, 237;
    --bs-primary-text-emphasis: #1e4fb0;
    --bs-primary-bg-subtle: #e3ecfd;
    --bs-primary-border-subtle: #b9cdf7;

    --bs-secondary: #5b6472;
    --bs-secondary-rgb: 91, 100, 114;
    --bs-secondary-text-emphasis: #3a414c;
    --bs-secondary-bg-subtle: #e7e9ec;
    --bs-secondary-border-subtle: #cfd3d9;

    --bs-success: #1f8a4c;
    --bs-success-rgb: 31, 138, 76;
    --bs-success-text-emphasis: #145c33;
    --bs-success-bg-subtle: #dcf3e5;
    --bs-success-border-subtle: #b3e2c6;

    --bs-danger: #d23c3c;
    --bs-danger-rgb: 210, 60, 60;
    --bs-danger-text-emphasis: #932121;
    --bs-danger-bg-subtle: #fbdedb;
    --bs-danger-border-subtle: #f3bcb8;

    --bs-warning: #c4790f;
    --bs-warning-rgb: 196, 121, 15;
    --bs-warning-text-emphasis: #7a4a08;
    --bs-warning-bg-subtle: #fbebd2;
    --bs-warning-border-subtle: #f0cf9e;

    --bs-info: #0d90a8;
    --bs-info-rgb: 13, 144, 168;
    --bs-info-text-emphasis: #0a5e6d;
    --bs-info-bg-subtle: #d9f1f5;
    --bs-info-border-subtle: #a9dfe8;

    --bs-dark: #242b34;
    --bs-dark-rgb: 36, 43, 52;

    --bs-link-color: #2f6fed;
    --bs-link-color-rgb: 47, 111, 237;
    --bs-link-hover-color: #1e4fb0;
    --bs-link-hover-color-rgb: 30, 79, 176;

    --bs-body-bg: #f4f5f7;
    --bs-body-color: #1b2028;
    --bs-border-radius: 0.625rem;
    --bs-border-radius-sm: 0.4rem;
    --bs-border-radius-lg: 0.875rem;
    --bs-border-radius-xl: 1.25rem;

    /* Antracite: colore di "chrome" per sidebar/brand, indipendente dal
       primario cobalto usato per le azioni — così i due ruoli restano distinti */
    --app-charcoal: #38424f;
    --app-charcoal-dark: #242b34;
    --app-charcoal-darker: #171b21;

    --sidebar-width: 260px;
    --sidebar-collapsed-width: 76px;
    --topbar-height: 60px;
}

/* Riduce del 10% tutta la tipografia (e le spaziature in rem che ne dipendono):
   più efficace di abbassare i singoli font-size, perché scala coerentemente
   bottoni, badge, form e tabelle insieme al testo. */
html {
    font-size: 90%;
}

body {
    background-color: var(--bs-body-bg);
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

h1, h2, h3, h4, h5, h6, .app-sidebar-brand-link {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-weight: 700;
    letter-spacing: -0.01em;
}

/* ---------------------------------------------------------------------
 * Layout a shell: sidebar sinistra (fissa, collassabile a rail di icone)
 * + colonna principale con topbar sottile e area contenuto.
 * --------------------------------------------------------------------- */
.app-shell {
    display: flex;
    align-items: stretch;
    min-height: 100vh;
}

.app-sidebar {
    width: var(--sidebar-width);
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    background: linear-gradient(180deg, var(--app-charcoal) 0%, var(--app-charcoal-dark) 65%, var(--app-charcoal-darker) 100%);
    box-shadow: 2px 0 14px rgba(20, 23, 28, .18);
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
    overflow-x: hidden;
    z-index: 1030;
    transition: width .2s ease;
}

html.sidebar-collapsed .app-sidebar {
    width: var(--sidebar-collapsed-width);
}

.app-sidebar-brand {
    display: flex;
    align-items: center;
    gap: .6rem;
    min-height: var(--topbar-height);
    padding: 0 1rem;
    border-bottom: 1px solid rgba(255, 255, 255, .14);
    flex-shrink: 0;
}

.app-sidebar-brand-link {
    display: flex;
    align-items: center;
    gap: .6rem;
    color: #fff;
    text-decoration: none;
    font-weight: 800;
    font-size: 1.05rem;
    letter-spacing: -0.02em;
    white-space: nowrap;
    overflow: hidden;
}

.app-sidebar-brand-link i {
    font-size: 1.4rem;
    flex-shrink: 0;
}

.app-sidebar-toggle {
    margin-left: auto;
    flex-shrink: 0;
    width: 28px;
    height: 28px;
    border: none;
    border-radius: 50%;
    background: rgba(255, 255, 255, .12);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color .15s ease, transform .2s ease;
}

.app-sidebar-toggle:hover {
    background: rgba(255, 255, 255, .22);
}

html.sidebar-collapsed .app-sidebar-toggle i {
    transform: rotate(180deg);
}

html.sidebar-collapsed .app-sidebar-brand {
    justify-content: center;
    padding: 0 .5rem;
}

html.sidebar-collapsed .app-sidebar-toggle {
    margin-left: 0;
}

html.sidebar-collapsed .app-sidebar-brand-text,
html.sidebar-collapsed .nav-label {
    display: none;
}

.app-sidebar-nav {
    padding: .75rem .6rem;
    flex: 1;
}

.app-sidebar-nav .nav-link {
    display: flex;
    align-items: center;
    gap: .75rem;
    color: rgba(255, 255, 255, .82);
    padding: .6rem .75rem;
    border-radius: var(--bs-border-radius-sm);
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    margin-bottom: .15rem;
    transition: background-color .15s ease, color .15s ease;
}

.app-sidebar-section-title {
    padding: .9rem .75rem .3rem;
    font-size: .68rem;
    font-weight: 700;
    letter-spacing: .06em;
    text-transform: uppercase;
    color: rgba(255, 255, 255, .45);
    white-space: nowrap;
    overflow: hidden;
}

html.sidebar-collapsed .app-sidebar-section-title {
    padding: .75rem 0 .5rem;
    margin: 0 .5rem;
    border-top: 1px solid rgba(255, 255, 255, .15);
}

.app-sidebar-nav .nav-link i {
    font-size: 1.1rem;
    width: 1.4rem;
    text-align: center;
    flex-shrink: 0;
}

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

.app-sidebar-nav .nav-link.active {
    background-color: rgba(255, 255, 255, .18);
    color: #fff;
    font-weight: 600;
}

html.sidebar-collapsed .app-sidebar-nav .nav-link {
    justify-content: center;
    padding-left: 0;
    padding-right: 0;
}

.app-main {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.app-topbar {
    height: var(--topbar-height);
    flex-shrink: 0;
    display: flex;
    align-items: center;
    padding: 0 1.25rem;
    background-color: #fff;
    border-bottom: 1px solid rgba(20, 23, 28, .08);
    position: sticky;
    top: 0;
    z-index: 1020;
}

.app-topbar .nav-link {
    color: var(--bs-body-color);
    font-weight: 500;
}

.app-sidebar-mobile-toggle {
    background: none;
    border: none;
    font-size: 1.35rem;
    color: var(--bs-body-color);
}

.app-content {
    padding: 1.5rem;
    flex: 1;
}

.app-sidebar-backdrop {
    display: none;
}

/* Sotto i 992px la sidebar diventa un drawer fuori schermo */
@media (max-width: 991.98px) {
    .app-sidebar {
        position: fixed;
        left: 0;
        top: 0;
        width: var(--sidebar-width) !important;
        transform: translateX(-100%);
        transition: transform .25s ease;
    }

    html.sidebar-mobile-open .app-sidebar {
        transform: translateX(0);
    }

    /* Nel drawer mobile le etichette restano sempre visibili, indipendentemente dallo stato "collapsed" desktop */
    .app-sidebar .app-sidebar-brand-text,
    .app-sidebar .nav-label {
        display: inline;
    }

    .app-sidebar-toggle {
        display: none;
    }

    html.sidebar-mobile-open .app-sidebar-backdrop {
        display: block;
        position: fixed;
        inset: 0;
        background: rgba(15, 17, 21, .45);
        z-index: 1025;
    }
}

@media (min-width: 992px) {
    .app-sidebar-mobile-toggle {
        display: none;
    }
}

/* ---------------------------------------------------------------------
 * Tabelle su mobile: scroll orizzontale più fluido e "leggibile" invece
 * del semplice overflow di Bootstrap — indicatore visivo che si può
 * scorrere, testo/celle più compatti, prima colonna fissa per non perdere
 * il contesto della riga (es. il nome del cliente/progetto) durante lo scroll.
 * --------------------------------------------------------------------- */
@media (max-width: 767.98px) {
    .table-responsive {
        -webkit-overflow-scrolling: touch;
        position: relative;
    }

    .table-responsive::after {
        content: '';
        position: absolute;
        top: 0;
        right: 0;
        bottom: 0;
        width: 16px;
        pointer-events: none;
        background: linear-gradient(to right, transparent, rgba(20, 23, 28, .12));
    }

    .table-responsive > .table {
        font-size: .8rem;
    }

    .table-responsive > .table > :not(caption) > * > * {
        padding: .5rem .55rem;
        white-space: nowrap;
    }

    .table-responsive > .table th:first-child,
    .table-responsive > .table td:first-child {
        position: sticky;
        left: 0;
        z-index: 2;
        background-color: #fff;
        box-shadow: 2px 0 4px rgba(20, 23, 28, .08);
    }

    .table-responsive > .table thead th:first-child {
        z-index: 3;
        background-color: #f8f9fa;
    }
}

/* Card più rifinite: ombra morbida, bordo leggero, intestazione neutra
   (niente tinta colorata sull'header: il colore resta riservato alle azioni) */
.card {
    border-color: rgba(20, 23, 28, .08);
    box-shadow: 0 1px 2px rgba(20, 23, 28, .04), 0 6px 16px rgba(20, 23, 28, .05);
}

.card-header {
    font-weight: 600;
    background-color: rgba(20, 23, 28, .03);
    border-bottom-color: rgba(20, 23, 28, .08);
}

/* Pulsanti leggermente più marcati */
.btn {
    font-weight: 600;
    border-radius: var(--bs-border-radius-sm);
}

.btn-primary {
    box-shadow: 0 2px 6px rgba(47, 111, 237, .3);
}

.btn-success {
    box-shadow: 0 2px 6px rgba(31, 138, 76, .25);
}

.btn-danger {
    box-shadow: 0 2px 6px rgba(210, 60, 60, .25);
}

/* Intestazioni tabella più curate, senza toccare i colori di table-light */
.table > thead > tr > th {
    font-weight: 600;
    font-size: .76rem;
    text-transform: uppercase;
    letter-spacing: .03em;
    color: #4b5563;
}

/* Alert con accento laterale invece del bordo pieno standard */
.alert {
    border: none;
    border-left: 4px solid;
    border-radius: var(--bs-border-radius);
}

.alert-success {
    border-left-color: var(--bs-success);
}

.alert-danger {
    border-left-color: var(--bs-danger);
}

.alert-warning {
    border-left-color: var(--bs-warning);
}

.alert-info {
    border-left-color: var(--bs-info);
}

/* Allinea le colonne numeriche nelle tabelle (importi, quantità) */
.table td.text-end {
    font-variant-numeric: tabular-nums;
}

.stat-tile {
    border-top: 3px solid var(--bs-primary);
}

.stat-tile .stat-value {
    font-size: 1.75rem;
    font-weight: 700;
    line-height: 1.2;
    color: var(--bs-primary-text-emphasis);
}

/* Tabelle e immagini inserite nell'editor rich-text (descrizione iniziale preventivo) */
.quote-rich-content table {
    border-collapse: collapse;
    width: 100%;
}

.quote-rich-content th,
.quote-rich-content td {
    border: 1px solid #dee2e6;
    padding: 0.375rem 0.5rem;
}

.quote-rich-content img {
    max-width: 100%;
    height: auto;
}
