/* ============================================================
   CRM Studio — style.css
   Personalizzazioni Bootstrap 5
   ============================================================ */

/* ------------------------------------------------------------
   Variabili colori brand

   Identità CREA+ (creapiu.it): fucsia come colore del marchio,
   blu-grigio per le superfici scure, grigi neutri per il testo.
   Per personalizzare l'applicativo per un altro cliente basta
   cambiare questi valori: tutto il resto del foglio li usa.

   Le varianti *-rgb servono dove serve trasparenza — rgba() non
   accetta una variabile che contenga già un colore esadecimale.
   ------------------------------------------------------------ */
:root {
    --brand-primary:     #334862;   /* navbar, sidebar, intestazioni card */
    --brand-primary-dk:  #24334a;   /* stati premuti e bordi scuri       */
    --brand-primary-rgb: 51, 72, 98;
    --brand-accent:      #d5105e;   /* fucsia del marchio: azioni e voci attive */
    --brand-accent-hover:#b00d4e;
    --brand-accent-rgb:  213, 16, 94;
    --brand-light:       #f1f1f1;   /* sfondo pagina, come sul sito      */
    --brand-testo:       #777777;   /* testo corrente                    */
    --brand-font:        'Montserrat', 'Segoe UI', system-ui, -apple-system, sans-serif;
    --brand-radius:      12px;      /* raggio dei pulsanti, come sul sito */
    --brand-sidebar-w:   260px;
    --brand-sidebar-collapsed-w: 64px;
    --brand-header-h:    56px;
}

/* ============================================================
   LAYOUT GENERALE
   ============================================================ */
body {
    background: var(--brand-light);
    font-family: var(--brand-font);
    font-size: .9rem;
    color: var(--brand-testo);
}

/* ============================================================
   NAVBAR HEADER
   ============================================================ */
.crm-navbar {
    background: var(--brand-primary);
    height: var(--brand-header-h);
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 1030;
    display: flex;
    align-items: center;
    padding: 0 1rem;
    box-shadow: 0 2px 8px rgba(0,0,0,.2);
}

.crm-navbar .brand {
    color: #fff;
    font-weight: 700;
    font-size: 1.05rem;
    letter-spacing: .4px;
    text-decoration: none;
    display: flex;
    align-items: center;
    gap: .5rem;
    white-space: nowrap;
}

.crm-navbar .brand i {
    color: #fff;
    font-size: 1.2rem;
}

.crm-navbar .nav-right {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: .25rem;
}

.crm-navbar .btn-icon {
    background: transparent;
    border: none;
    color: rgba(255,255,255,.75);
    width: 38px;
    height: 38px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background .15s, color .15s;
    cursor: pointer;
}

.crm-navbar .btn-icon:hover {
    background: rgba(255,255,255,.12);
    color: #fff;
}

.crm-navbar .avatar-sm {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid var(--brand-accent);
}

.crm-navbar .user-name {
    color: #fff;
    font-size: .85rem;
    font-weight: 500;
}

/* ============================================================
   SIDEBAR
   ============================================================ */
.crm-sidebar {
    background: var(--brand-primary);
    width: var(--brand-sidebar-w);
    position: fixed;
    top: var(--brand-header-h);
    left: 0;
    bottom: 0;
    overflow-y: auto;
    overflow-x: hidden;
    z-index: 1020;
    transition: transform .25s ease;
    scrollbar-width: thin;
    scrollbar-color: rgba(255,255,255,.15) transparent;
}

.crm-sidebar::-webkit-scrollbar { width: 4px; }
.crm-sidebar::-webkit-scrollbar-thumb { background: rgba(255,255,255,.15); border-radius: 4px; }

/* Pannello utente sidebar */
.sidebar-user {
    padding: 1rem 1rem .75rem;
    border-bottom: 1px solid rgba(255,255,255,.08);
    display: flex;
    align-items: center;
    gap: .75rem;
}

.sidebar-user img {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid var(--brand-accent);
    flex-shrink: 0;
}

.sidebar-user .avatar-placeholder {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--brand-accent);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 1rem;
    flex-shrink: 0;
}

.sidebar-user .user-info .name {
    color: #fff;
    font-weight: 600;
    font-size: .85rem;
    line-height: 1.2;
}

.sidebar-user .user-info .role {
    color: rgba(255,255,255,.5);
    font-size: .72rem;
}

/* Navigazione sidebar */
.sidebar-nav {
    padding: .5rem 0;
}

.sidebar-label {
    color: rgba(255,255,255,.35);
    font-size: .65rem;
    font-weight: 600;
    letter-spacing: 1.2px;
    text-transform: uppercase;
    padding: .75rem 1rem .25rem;
}

.sidebar-nav .nav-item { margin: 1px .5rem; }

.sidebar-nav .nav-link {
    color: rgba(255,255,255,.75);
    border-radius: 8px;
    padding: .55rem .75rem;
    display: flex;
    align-items: center;
    gap: .6rem;
    font-size: .875rem;
    transition: background .15s, color .15s;
    text-decoration: none;
}

.sidebar-nav .nav-link i {
    width: 18px;
    text-align: center;
    font-size: .9rem;
    flex-shrink: 0;
}

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

.sidebar-nav .nav-link.active {
    background: var(--brand-accent);
    color: #fff;
    font-weight: 500;
}

/* Submenu */
.sidebar-submenu {
    list-style: none;
    padding: .25rem 0 .25rem 2.5rem;
    margin: 0;
}

.sidebar-submenu .nav-link {
    font-size: .82rem;
    padding: .35rem .75rem;
    color: rgba(255,255,255,.6);
}

.sidebar-submenu .nav-link::before {
    content: '›';
    margin-right: .4rem;
    font-size: 1rem;
    line-height: 1;
}

.sidebar-submenu .nav-link:hover,
.sidebar-submenu .nav-link.active {
    color: #fff;
    background: rgba(255,255,255,.08);
}

/* Toggle freccia submenu */
.nav-link .arrow {
    margin-left: auto;
    font-size: .7rem;
    transition: transform .2s;
}

.nav-link[aria-expanded="true"] .arrow {
    transform: rotate(-90deg);
}

/* ============================================================
   CONTENUTO PRINCIPALE
   ============================================================ */
.crm-main {
    margin-left: var(--brand-sidebar-w);
    margin-top: var(--brand-header-h);
    min-height: calc(100vh - var(--brand-header-h));
    display: flex;
    flex-direction: column;
}

.page-header {
    background: #fff;
    border-bottom: 1px solid #e5e9f0;
    padding: .85rem 1.5rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.page-header h1 {
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--brand-primary);
    margin: 0;
    display: flex;
    align-items: center;
    gap: .5rem;
}

.page-header h1 i { color: var(--brand-accent); }

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

/* ============================================================
   CARD
   ============================================================ */
.card {
    border: none;
    border-radius: 10px;
    box-shadow: 0 1px 6px rgba(0,0,0,.07);
}

.card-header-brand {
    background: var(--brand-primary);
    color: #fff;
    border-radius: 10px 10px 0 0 !important;
    padding: .75rem 1rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.card-header-brand .card-title {
    margin: 0;
    font-size: .95rem;
    display: flex;
    align-items: center;
    gap: .5rem;
}

/* ============================================================
   BOTTONI
   ============================================================ */
.btn { border-radius: 7px; font-size: .85rem; }
.btn-brand {
    background: var(--brand-accent);
    color: #fff;
    border: none;
    border-radius: var(--brand-radius);
    font-weight: 600;
}
.btn-brand:hover { background: var(--brand-accent-hover); color: #fff; }
.btn-brand:focus-visible { box-shadow: 0 0 0 3px rgba(var(--brand-accent-rgb), .35); }

/* ============================================================
   BREADCRUMB
   ============================================================ */
.breadcrumb {
    background: transparent;
    padding: 0;
    margin: 0;
    font-size: .8rem;
}
.breadcrumb-item + .breadcrumb-item::before { color: #adb5bd; }

/* ============================================================
   TABELLE
   ============================================================ */
.table thead th {
    background: var(--brand-light);
    color: var(--brand-primary);
    font-weight: 600;
    font-size: .8rem;
    text-transform: uppercase;
    letter-spacing: .5px;
    border-bottom: 2px solid #dde3ed;
    white-space: nowrap;
}

.table tbody tr:hover { background: #f5f8ff; }

/* ============================================================
   BADGE RUOLI
   ============================================================ */
.badge-admin        { background: #e74c3c; color: #fff; }
.badge-manager      { background: #f39c12; color: #fff; }
.badge-collaboratore{ background: #27ae60; color: #fff; }
.badge-agente       { background: #8e44ad; color: #fff; }
.badge-rivenditore  { background: #2980b9; color: #fff; }

/* ============================================================
   FOOTER
   ============================================================ */
.crm-footer {
    background: #fff;
    border-top: 1px solid #e5e9f0;
    padding: .6rem 1.5rem;
    font-size: .78rem;
    color: #adb5bd;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

/* ============================================================
   LOGIN PAGE
   ============================================================ */
.login-page {
    min-height: 100vh;
    background: linear-gradient(135deg, var(--brand-primary) 0%, var(--brand-primary-dk) 100%);
    display: flex;
    align-items: center;
    justify-content: center;
}

.login-box {
    width: 100%;
    max-width: 400px;
    padding: 1rem;
}

.login-card {
    border-radius: 14px;
    box-shadow: 0 12px 48px rgba(0,0,0,.35);
    border: none;
}

.login-card .card-body { padding: 2rem; }

.login-logo {
    text-align: center;
    margin-bottom: 1.5rem;
    color: #fff;
}

.login-logo h1 {
    font-size: 1.5rem;
    font-weight: 700;
    margin: .5rem 0 .25rem;
}

.login-logo small {
    color: rgba(255,255,255,.5);
    font-size: .8rem;
}

/* ============================================================
   UPLOAD PREVIEW
   ============================================================ */
.avatar-preview {
    width: 100px;
    height: 100px;
    border-radius: 50%;
    object-fit: cover;
    border: 3px solid var(--brand-accent);
    cursor: pointer;
    transition: opacity .2s;
}
.avatar-preview:hover { opacity: .85; }

.logo-preview-wrap {
    min-height: 70px;
    border: 2px dashed #dee2e6;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #adb5bd;
    cursor: pointer;
    transition: border-color .2s;
}
.logo-preview-wrap:hover { border-color: var(--brand-accent); }

/* ============================================================
   SIDEBAR MOBILE
   ============================================================ */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.45);
    z-index: 1015;
}

@media (max-width: 991.98px) {
    .crm-sidebar { transform: translateX(-100%); }
    .crm-sidebar.open { transform: translateX(0); }
    .crm-main { margin-left: 0; }
    .sidebar-overlay.show { display: block; }
    .page-header { padding: .75rem 1rem; }
    .page-content { padding: 1rem; }
}

/* ----------------------------------------------------------
   Avvisi in navbar
   ---------------------------------------------------------- */
.avviso-item { color: inherit; transition: background .15s; }
.avviso-item:hover { background: #f4f6f8; }
.avviso-item:last-child { border-bottom: 0 !important; }

/* ============================================================
   SIDEBAR COMPRESSA (desktop)
   La classe .sidebar-collapsed è applicata a <body> dal server,
   così al primo render non c'è alcuno sfarfallio.
   ============================================================ */
@media (min-width: 992px) {
    body.sidebar-collapsed .crm-sidebar { width: var(--brand-sidebar-collapsed-w, 64px); }
    body.sidebar-collapsed .crm-main    { margin-left: var(--brand-sidebar-collapsed-w, 64px); }

    /* Testi nascosti, restano solo le icone centrate */
    body.sidebar-collapsed .sidebar-label,
    body.sidebar-collapsed .sidebar-user .user-info,
    body.sidebar-collapsed .nav-link .arrow,
    body.sidebar-collapsed .sidebar-submenu { display: none !important; }

    body.sidebar-collapsed .crm-sidebar .nav-link {
        justify-content: center;
        padding-left: 0;
        padding-right: 0;
        position: relative;
    }
    body.sidebar-collapsed .crm-sidebar .nav-link i:first-child {
        margin-right: 0;
        font-size: 1.05rem;
    }
    /* Nasconde il testo della voce lasciando l'icona */
    body.sidebar-collapsed .crm-sidebar .nav-link {
        font-size: 0;
        letter-spacing: 0;
    }
    body.sidebar-collapsed .crm-sidebar .nav-link i { font-size: 1.05rem; }

    body.sidebar-collapsed .sidebar-user {
        justify-content: center;
        padding-left: .5rem;
        padding-right: .5rem;
    }

    /* Etichetta al passaggio del mouse, per non perdere la leggibilità */
    body.sidebar-collapsed .crm-sidebar .nav-link::after {
        content: attr(data-titolo);
        position: absolute;
        left: calc(100% + 8px);
        top: 50%;
        transform: translateY(-50%);
        background: #1b2a4a;
        color: #fff;
        font-size: .78rem;
        letter-spacing: normal;
        padding: .3rem .6rem;
        border-radius: 6px;
        white-space: nowrap;
        opacity: 0;
        pointer-events: none;
        transition: opacity .15s;
        z-index: 1030;
        box-shadow: 0 2px 10px rgba(0,0,0,.2);
    }
    body.sidebar-collapsed .crm-sidebar .nav-link:hover::after { opacity: 1; }

    .crm-sidebar, .crm-main { transition: width .2s ease, margin-left .2s ease; }
}

/* Il burger resta visibile anche su desktop */
#sidebarToggle { display: inline-flex !important; }

/* ----------------------------------------------------------
   Selettore libreria disegni tipologie
   ---------------------------------------------------------- */
.lib-item {
    border: 2px solid transparent; border-radius: 8px;
    background: #fff; cursor: pointer; transition: border-color .15s, box-shadow .15s;
}
.lib-item:hover { border-color: var(--brand-accent); }
.lib-item.scelto {
    border-color: var(--brand-primary);
    box-shadow: 0 0 0 3px rgba(var(--brand-accent-rgb), .18);
}
.lib-nome {
    font-size: .68rem; color: #6c757d; line-height: 1.2;
    margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* ----------------------------------------------------------
   Disegno tipologia specchiato: il verso scelto nel preventivo
   è opposto a quello rappresentato dal disegno caricato.
   ---------------------------------------------------------- */
.img-specchiata { transform: scaleX(-1); }
