@import url('https://fonts.googleapis.com/css2?family=IBM+Plex+Sans:wght@400;500;600;700&display=swap');

:root {
    --crm-bg: #f3f5f7;
    --crm-surface: #ffffff;
    --crm-border: #d7dce3;
    --crm-border-strong: #c4ccd7;
    --crm-text: #141922;
    --crm-text-muted: #5b6473;
    --crm-primary: #0d4bb1;
    --crm-primary-hover: #0a3d91;
    --crm-radius: 10px;
    --crm-radius-sm: 8px;
    --crm-shadow: 0 2px 10px rgba(17, 24, 39, 0.05);
}

body.crm-app,
body.crm-login {
    background-color: var(--crm-bg) !important;
    color: var(--crm-text);
    font-family: 'IBM Plex Sans', 'Segoe UI', sans-serif;
    line-height: 1.45;
}

.crm-page {
    max-width: 1240px;
    padding-top: 1.5rem;
    padding-bottom: 2rem;
}

.crm-userbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.75rem;
}

.crm-bell-btn {
    position: relative;
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding-right: 0.6rem;
}

.crm-bell-icon {
    width: 14px;
    height: 14px;
    display: block;
}

.crm-bell-badge {
    position: absolute;
    top: -7px;
    right: -7px;
    font-size: 0.66rem;
    line-height: 1;
    padding: 0.22rem 0.34rem;
    border: 2px solid #fff;
    min-width: 20px;
    text-align: center;
}

.crm-user-pill {
    background-color: #fff !important;
    border: 1px solid var(--crm-border) !important;
    color: var(--crm-text) !important;
    font-weight: 600;
}

.crm-nav {
    border: 1px solid var(--crm-border);
    border-radius: var(--crm-radius-sm);
    overflow: hidden;
    background: #fff;
}

.crm-nav .btn {
    border: 0;
    border-right: 1px solid var(--crm-border);
    border-radius: 0 !important;
    min-height: 42px;
    font-weight: 500;
    padding-left: 1rem;
    padding-right: 1rem;
}

.crm-nav .btn:last-child {
    border-right: 0;
}

.crm-nav .btn.btn-primary {
    background-color: var(--crm-primary);
    border-color: var(--crm-primary);
}

.crm-nav .btn.btn-primary:hover,
.crm-nav .btn.btn-primary:focus {
    background-color: var(--crm-primary-hover);
    border-color: var(--crm-primary-hover);
}

.crm-page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.crm-page-title {
    font-size: 2rem;
    letter-spacing: -0.02em;
    font-weight: 600;
    margin: 0;
}

.crm-page-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.crm-card {
    border: 1px solid var(--crm-border);
    border-radius: var(--crm-radius);
    box-shadow: var(--crm-shadow) !important;
}

.crm-card .card-header {
    background: #fff;
    border-bottom: 1px solid var(--crm-border);
    font-weight: 600;
}

.crm-card .card-body {
    padding: 1rem 1.1rem;
}

/* Sottotitoli sezione nei form lunghi (es. contatto/azienda) — legacy */
.crm-form-section-title {
    font-size: 0.78rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--crm-muted, #64748b);
    margin: 0.75rem 0 0.25rem;
    padding-bottom: 0.4rem;
    border-bottom: 1px solid var(--crm-border, #e5e7eb);
}
.crm-form-section-title:first-child,
.row > .col-12:first-child > .crm-form-section-title {
    margin-top: 0;
}

/* Sotto-card per sezioni di form lunghi */
.crm-form-subcard {
    border: 1px solid var(--crm-border, #e5e7eb);
    border-radius: var(--crm-radius, 0.5rem);
    background: #fff;
    overflow: hidden;
}

.crm-form-subcard__header {
    background: #f8fafc;
    border-bottom: 1px solid var(--crm-border, #e5e7eb);
    padding: 0.65rem 1rem;
    display: flex;
    align-items: flex-start;
    gap: 0.65rem;
}

.crm-form-subcard__icon {
    font-size: 1.05rem;
    line-height: 1.4;
    flex-shrink: 0;
    width: 1.4rem;
    text-align: center;
}

.crm-form-subcard__heading {
    flex: 1;
    min-width: 0;
}

.crm-form-subcard__title {
    font-size: 0.78rem;
    font-weight: 700;
    margin: 0;
    color: var(--crm-text, #1e293b);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    line-height: 1.4;
}

.crm-form-subcard__desc {
    font-size: 0.8rem;
    color: var(--crm-muted, #64748b);
    margin: 0.05rem 0 0;
    line-height: 1.3;
}

.crm-form-subcard__body {
    padding: 1rem;
}

.crm-form-required {
    color: #dc2626;
    margin-left: 0.15rem;
    font-weight: 600;
}

/* Settings - sezioni raggruppate */
.crm-settings-group + .crm-settings-group {
    margin-top: 1.25rem;
    padding-top: 1rem;
    border-top: 1px solid var(--crm-border, #e5e7eb);
}

.crm-settings-group__header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.6rem;
}

.crm-settings-group__icon {
    font-size: 1rem;
    line-height: 1;
}

.crm-settings-group__title {
    font-size: 0.78rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--crm-muted, #64748b);
    margin: 0;
}

.crm-settings-link {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 0.55rem 0.75rem;
    border: 1px solid var(--crm-border, #e5e7eb);
    border-radius: var(--crm-radius, 0.5rem);
    background: #fff;
    text-decoration: none;
    color: var(--crm-text, #1e293b);
    transition: background-color 0.15s ease, border-color 0.15s ease;
}

.crm-settings-link + .crm-settings-link {
    margin-top: 0.4rem;
}

.crm-settings-link:hover,
.crm-settings-link:focus {
    background: #f8fafc;
    border-color: #94a3b8;
    color: var(--crm-text, #1e293b);
}

.crm-settings-link__main {
    flex: 1;
    min-width: 0;
}

.crm-settings-link__title {
    font-weight: 600;
    font-size: 0.95rem;
    line-height: 1.3;
}

.crm-settings-link__desc {
    font-size: 0.82rem;
    color: var(--crm-muted, #64748b);
    margin-top: 0.1rem;
    line-height: 1.3;
}

.crm-settings-link__chevron {
    color: var(--crm-muted, #94a3b8);
    font-size: 1rem;
    line-height: 1.2;
    flex-shrink: 0;
}

/* Sub-nav marketing tra le 4 pagine collegate */
.crm-settings-subnav {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
    padding: 0.45rem;
    background: #f1f5f9;
    border: 1px solid var(--crm-border, #e5e7eb);
    border-radius: var(--crm-radius, 0.5rem);
    margin-bottom: 1rem;
}

.crm-settings-subnav__link {
    padding: 0.3rem 0.7rem;
    border-radius: 0.4rem;
    font-size: 0.85rem;
    font-weight: 500;
    text-decoration: none;
    color: var(--crm-muted, #475569);
    background: transparent;
    border: 1px solid transparent;
    transition: background-color 0.15s ease, color 0.15s ease;
}

.crm-settings-subnav__link:hover {
    background: #ffffff;
    color: var(--crm-text, #1e293b);
}

.crm-settings-subnav__link.is-active {
    background: #ffffff;
    border-color: var(--crm-border, #e5e7eb);
    color: var(--crm-text, #1e293b);
    font-weight: 600;
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.06);
}

.crm-settings-subnav__sep {
    align-self: center;
    color: #cbd5e1;
    font-size: 0.85rem;
}

.crm-settings-subnav__count {
    display: inline-block;
    margin-left: 0.35rem;
    padding: 0 0.4rem;
    border-radius: 0.6rem;
    background: #e2e8f0;
    color: #475569;
    font-size: 0.72rem;
    font-weight: 600;
    line-height: 1.3;
    vertical-align: middle;
}

.crm-settings-subnav__link.is-active .crm-settings-subnav__count {
    background: #1e40af;
    color: #ffffff;
}

/* Tabelle settings: select inline non devono troncare il testo */
.crm-table td > select.form-select-sm,
.crm-table td > .form-select-sm {
    min-width: 100%;
}

/* Numeri tabulari per importi nelle stat/cost tables */
.crm-table .text-end {
    font-variant-numeric: tabular-nums;
}

.crm-filter-card .card-body {
    padding: 0.95rem 1rem;
}

.crm-table-wrap {
    border: 1px solid var(--crm-border);
    border-radius: var(--crm-radius);
    box-shadow: var(--crm-shadow) !important;
    background: #fff;
}

.crm-table {
    margin-bottom: 0;
    font-size: 0.96rem;
}

.crm-table thead th {
    white-space: nowrap;
    font-weight: 600;
    color: #1f2937;
    background: #f8fafc !important;
    border-bottom-width: 1px;
    border-color: var(--crm-border-strong);
}

.crm-table td,
.crm-table th {
    border-color: var(--crm-border);
    vertical-align: middle;
}

.crm-table .btn-sm {
    min-height: 34px;
    padding-left: 0.65rem;
    padding-right: 0.65rem;
}

.crm-inline-actions {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.btn {
    border-radius: var(--crm-radius-sm);
    font-weight: 500;
}

.btn-primary {
    background-color: var(--crm-primary);
    border-color: var(--crm-primary);
}

.btn-primary:hover,
.btn-primary:focus {
    background-color: var(--crm-primary-hover);
    border-color: var(--crm-primary-hover);
}

.form-label {
    color: #1f2937;
    font-weight: 600;
    font-size: 0.93rem;
    margin-bottom: 0.35rem;
}

.form-control,
.form-select {
    border-color: var(--crm-border-strong);
    border-radius: var(--crm-radius-sm);
    min-height: 40px;
}

textarea.form-control {
    min-height: initial;
}

.form-control:focus,
.form-select:focus {
    border-color: #9ab3df;
    box-shadow: 0 0 0 0.22rem rgba(13, 75, 177, 0.12);
}

.badge {
    font-weight: 600;
    letter-spacing: 0.01em;
}

.crm-muted {
    color: var(--crm-text-muted);
}

.crm-login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
}

.crm-login-card {
    border: 1px solid var(--crm-border);
    border-radius: var(--crm-radius);
    box-shadow: var(--crm-shadow) !important;
}

@media (max-width: 991.98px) {
    .crm-page-title {
        font-size: 1.75rem;
    }
}

@media (max-width: 767.98px) {
    .crm-page {
        padding-top: 1rem;
        padding-bottom: 1.5rem;
    }

    .crm-userbar {
        justify-content: space-between;
    }

    .crm-nav {
        display: flex !important;
        width: 100%;
    }

    .crm-nav .btn {
        flex: 1 1 0;
        padding-left: 0.65rem;
        padding-right: 0.65rem;
        font-size: 0.95rem;
    }

    .crm-page-header {
        flex-direction: column;
        align-items: stretch;
    }

    .crm-page-actions {
        justify-content: stretch;
    }

    .crm-page-actions .btn,
    .crm-page-actions .badge {
        width: 100%;
        text-align: center;
    }

    .crm-table {
        font-size: 0.92rem;
    }

    .crm-table th,
    .crm-table td {
        white-space: nowrap;
    }

    .crm-inline-actions {
        justify-content: flex-start;
    }
}

.crm-suggest-box {
    position: absolute;
    left: 0;
    right: 0;
    top: calc(100% + 2px);
    z-index: 1050;
    background: #fff;
    border: 1px solid var(--crm-border);
    border-radius: var(--crm-radius-sm);
    box-shadow: var(--crm-shadow);
    max-height: 260px;
    overflow-y: auto;
}

.crm-suggest-item {
    padding: 0.55rem 0.75rem;
    cursor: pointer;
    border-bottom: 1px solid #eef2f7;
}

.crm-suggest-item:last-child {
    border-bottom: 0;
}

.crm-suggest-item:hover,
.crm-suggest-item:focus {
    background: #f7f9fc;
}



.crm-suggest-meta {
    font-size: 0.82rem;
    color: var(--crm-text-muted);
}


.crm-form-card .card-body {
    padding: 0.95rem 1rem;
}

.crm-subcard {
    margin: 0;
    padding: 0.9rem;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    background: #fbfdff;
}

.crm-inline-panel {
    border: 1px solid #dbe4f2;
    border-radius: 10px;
    padding: 0.8rem 0.9rem;
    background: #f8fbff;
}

.crm-tip-box {
    border: 1px solid #dbe4f2;
    border-left: 4px solid var(--crm-primary);
    border-radius: 8px;
    background: #f8fbff;
    padding: 0.6rem 0.75rem;
    color: #334155;
    font-size: 0.92rem;
}

.crm-form-actions {
    align-items: center;
}

.crm-decision-modal {
    position: fixed;
    inset: 0;
    z-index: 1200;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    background: rgba(15, 23, 42, 0.42);
}

.crm-decision-modal.is-open {
    display: flex;
}

.crm-decision-modal__dialog {
    width: min(560px, 96vw);
    background: #fff;
    border: 1px solid #d7dce3;
    border-radius: 12px;
    box-shadow: 0 20px 40px rgba(15, 23, 42, 0.2);
}

.crm-decision-modal__header {
    padding: 0.9rem 1rem;
    border-bottom: 1px solid #e5eaf1;
}

.crm-decision-modal__title {
    margin: 0;
    font-size: 1.15rem;
    font-weight: 600;
}

.crm-decision-modal__body {
    padding: 0.9rem 1rem;
    color: #334155;
}

.crm-decision-modal__actions {
    padding: 0.85rem 1rem 1rem;
    border-top: 1px solid #e5eaf1;
    display: flex;
    gap: 0.5rem;
    justify-content: flex-end;
    flex-wrap: wrap;
}

@media (max-width: 767.98px) {
    .crm-form-actions .btn {
        flex: 1 1 auto;
    }
}

/* Blocco duplicati POST */
.crm-dup-block {
    border-radius: var(--crm-radius);
    overflow: hidden;
    border: 2px solid transparent;
}

.crm-dup-block--warning {
    border-color: #f59e0b;
    background: #fff;
}

.crm-dup-block--danger {
    border-color: #dc2626;
    background: #fff;
}

.crm-dup-block__header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 1rem;
    font-weight: 600;
    font-size: 0.97rem;
}

.crm-dup-block--warning .crm-dup-block__header {
    background: #fffbeb;
    color: #92400e;
    border-bottom: 1px solid #fde68a;
}

.crm-dup-block--danger .crm-dup-block__header {
    background: #fef2f2;
    color: #991b1b;
    border-bottom: 1px solid #fecaca;
}

.crm-dup-block__icon {
    font-size: 1.1rem;
    flex-shrink: 0;
}

.crm-dup-block__body {
    padding: 0 0.75rem;
    overflow-x: auto;
}

.crm-dup-block__footer {
    display: flex;
    gap: 0.5rem;
    padding: 0.65rem 1rem;
    border-top: 1px solid #eef2f7;
    background: #fafbfc;
}

/* Gruppi consenso nel form contatto */
.crm-consent-group {
    border: 1px solid var(--crm-border);
    border-radius: var(--crm-radius-sm);
    background: #fafbfc;
    padding: 0.75rem 0.9rem;
    height: 100%;
}

.crm-consent-group .form-check {
    margin-bottom: 0.6rem;
}

.crm-consent-group .form-check-label {
    font-weight: 600;
    font-size: 0.93rem;
}

.crm-consent-flags {
    display: flex;
    gap: 2rem;
    align-items: center;
    padding: 0.5rem 0;
}

/* Suggest duplicati inline (sotto riga nome+cognome) */
.crm-dup-suggest-panel {
    border: 2px solid #f59e0b;
    border-top: none;
    border-radius: 0 0 var(--crm-radius-sm) var(--crm-radius-sm);
    background: #fff;
    box-shadow: 0 4px 12px rgba(17, 24, 39, 0.08);
    overflow: hidden;
}

.crm-dup-suggest-panel .crm-suggest-item {
    border-bottom: 1px solid #eef2f7;
}

.crm-dup-suggest-panel .crm-suggest-item:last-child {
    border-bottom: 0;
}

.crm-dup-suggest-item-name {
    font-weight: 600;
    font-size: 0.95rem;
    color: var(--crm-text);
}

.crm-dup-suggest-item-meta {
    font-size: 0.82rem;
    color: var(--crm-text-muted);
    margin-top: 0.1rem;
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
    align-items: center;
}

.crm-dup-suggest-item-match {
    display: inline-block;
    font-size: 0.75rem;
    font-weight: 600;
    background: #fef9c3;
    color: #713f12;
    border-radius: 4px;
    padding: 0 0.35rem;
}

/* Badge tipo cliente nella lista lavori */
.crm-type-badge {
    display: inline-block;
    font-size: 0.68rem;
    font-weight: 700;
    border-radius: 4px;
    padding: 1px 5px;
    vertical-align: middle;
    margin-right: 0.3rem;
    line-height: 1.4;
}

.crm-type-badge--az {
    background: transparent;
    color: #64748b;
    border: 1px solid #94a3b8;
}

/* Cella troncata con ellipsis */
.crm-cell-truncate {
    max-width: 200px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

