/* CRM shell — ispirazione layout tipo Zoho CRM */

:root {
    --crm-sidebar-bg: #0f1f3a;
    --crm-sidebar-hover: rgba(255, 255, 255, 0.08);
    --crm-sidebar-active: rgba(38, 107, 239, 0.35);
    --crm-accent: #266bef;
    --crm-accent-soft: #e8eefc;
    --crm-text: #1a1d26;
    --crm-text-muted: #5c6378;
    --crm-border: #e2e6ef;
    --crm-header-bg: #fff;
    --crm-content-bg: #f4f6fa;
    --crm-font: "Segoe UI", system-ui, -apple-system, sans-serif;
}

*,
*::before,
*::after {
    box-sizing: border-box;
}

html, body {
    margin: 0;
    height: 100%;
}

.crm-body {
    font-family: var(--crm-font);
    font-size: 14px;
    color: var(--crm-text);
    background: var(--crm-content-bg);
}

.crm-app {
    display: flex;
    min-height: 100vh;
}

.crm-sidebar {
    width: 260px;
    flex-shrink: 0;
    background: var(--crm-sidebar-bg);
    color: #e8ecf4;
    display: flex;
    flex-direction: column;
    border-right: 1px solid rgba(0, 0, 0, 0.15);
}

.crm-sidebar__brand {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 18px 16px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.crm-sidebar__logo {
    font-weight: 600;
    font-size: 1.05rem;
    letter-spacing: 0.02em;
}

.crm-sidebar__close {
    display: none;
    flex-shrink: 0;
    width: 36px;
    height: 36px;
    margin: 0;
    padding: 0;
    border: 0;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.12);
    color: #fff;
    font-size: 1.5rem;
    line-height: 1;
    cursor: pointer;
    align-items: center;
    justify-content: center;
}

.crm-sidebar__close:hover {
    background: rgba(255, 255, 255, 0.2);
}

.crm-nav {
    flex: 1;
    overflow-y: auto;
    padding: 8px 0 24px;
}

.crm-nav__link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 14px 8px 16px;
    color: #c5ccda;
    text-decoration: none;
    font-size: 13px;
    line-height: 1.35;
    border-left: 3px solid transparent;
    transition: background 0.12s ease, color 0.12s ease;
}

.crm-nav__link:hover {
    background: var(--crm-sidebar-hover);
    color: #fff;
}

.crm-nav__link.is-active {
    background: var(--crm-sidebar-active);
    color: #fff;
    border-left-color: var(--crm-accent);
}

.crm-nav__icon {
    flex-shrink: 0;
    opacity: 0.9;
    display: flex;
}

.crm-nav__icon .crm-icon {
    stroke: currentColor;
}

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

.crm-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 28px;
    background: var(--crm-header-bg);
    border-bottom: 1px solid var(--crm-border);
    min-height: 56px;
}

.crm-header__left {
    display: flex;
    align-items: center;
    gap: 10px;
}

.crm-header__title h1 {
    margin: 0;
    font-size: 1.25rem;
    font-weight: 600;
}

.crm-mobile-menu-btn {
    display: none;
    border: 1px solid var(--crm-border);
    background: #fff;
    border-radius: 8px;
    width: 40px;
    height: 40px;
    padding: 9px 8px;
    cursor: pointer;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.crm-mobile-menu-btn span {
    display: block;
    width: 100%;
    height: 2px;
    margin: 4px 0;
    background: #344054;
    border-radius: 2px;
}

.crm-mobile-overlay {
    display: none;
}


.crm-header__env {
    font-size: 12px;
    color: var(--crm-text-muted);
}

.crm-content {
    flex: 1;
    padding: 24px 28px 40px;
}

.crm-dashboard .crm-cards {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 20px;
}

.crm-section {
    margin-bottom: 22px;
}

.crm-section__title {
    margin: 0 0 10px;
    font-size: 0.98rem;
    font-weight: 700;
    letter-spacing: 0.01em;
    color: #2c3754;
}

.crm-kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 14px;
    margin-bottom: 20px;
}

.crm-kpi {
    background: #fff;
    border: 1px solid var(--crm-border);
    border-radius: 10px;
    padding: 14px 16px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.crm-kpi span {
    font-size: 12px;
    color: var(--crm-text-muted);
}

.crm-kpi strong {
    font-size: 1.12rem;
    font-weight: 700;
    color: var(--crm-text);
    display: flex;
    align-items: baseline;
    gap: 8px;
}

.crm-kpi small {
    color: #8a92a8;
    font-size: 11px;
    line-height: 1.35;
}

.crm-trend {
    font-style: normal;
    font-size: 11px;
    font-weight: 700;
}

.crm-trend.up {
    color: #067647;
}

.crm-trend.down {
    color: #c4322b;
}

.crm-cards--two {
    grid-template-columns: repeat(2, minmax(280px, 1fr));
}

.crm-cards--three {
    grid-template-columns: repeat(3, minmax(220px, 1fr));
}

.crm-card {
    background: #fff;
    border: 1px solid var(--crm-border);
    border-radius: 10px;
    padding: 20px;
    box-shadow: 0 1px 2px rgba(15, 31, 58, 0.04);
}

.crm-card__title {
    margin: 0 0 12px;
    font-size: 0.92rem;
    font-weight: 700;
    letter-spacing: 0.01em;
    text-transform: uppercase;
    color: #3b4460;
}

.crm-card__ok {
    margin: 0;
    color: #0d7a4f;
    font-weight: 500;
}

.crm-card__err {
    margin: 0 0 8px;
    color: #b42318;
    font-weight: 500;
}

.crm-card__trace {
    margin: 0;
    font-size: 11px;
    white-space: pre-wrap;
    word-break: break-word;
    color: var(--crm-text-muted);
    max-height: 120px;
    overflow: auto;
}

.crm-card__muted {
    margin: 0;
    color: var(--crm-text-muted);
    line-height: 1.5;
}

.crm-list {
    margin: 0;
    padding: 0;
    list-style: none;
    display: grid;
    gap: 8px;
}

.crm-list li {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    border-bottom: 1px dashed var(--crm-border);
    padding-bottom: 7px;
}

.crm-list li:last-child {
    border-bottom: none;
    padding-bottom: 0;
}

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

.crm-list strong {
    font-weight: 600;
}

.crm-card--table {
    padding: 14px;
}

.crm-table-wrap {
    overflow-x: auto;
}

.crm-table {
    width: 100%;
    border-collapse: collapse;
    min-width: 820px;
}

.crm-table th,
.crm-table td {
    text-align: left;
    border-bottom: 1px solid var(--crm-border);
    padding: 11px 9px;
    font-size: 13px;
}

.crm-table th {
    color: var(--crm-text-muted);
    font-weight: 600;
    background: #fafbfe;
}

.crm-table--matrix th,
.crm-table--matrix td {
    text-align: center;
}

.crm-table--matrix th:first-child,
.crm-table--matrix td:first-child {
    text-align: left;
    font-weight: 600;
    width: 180px;
}

.crm-mini-table {
    width: 100%;
    border-collapse: collapse;
}

.crm-mini-table th,
.crm-mini-table td {
    text-align: left;
    font-size: 12px;
    border-bottom: 1px solid var(--crm-border);
    padding: 9px 4px;
}

.crm-mini-table th {
    color: var(--crm-text-muted);
    font-weight: 600;
}

.crm-placeholder__box {
    background: #fff;
    border: 1px dashed var(--crm-border);
    border-radius: 10px;
    padding: 48px 32px;
    text-align: center;
    max-width: 560px;
}

.crm-placeholder__heading {
    margin: 0 0 12px;
    font-size: 1.2rem;
}

.crm-placeholder__text {
    margin: 0;
    color: var(--crm-text-muted);
    line-height: 1.55;
}

/* Lead module */
.crm-lead {
    display: grid;
    gap: 12px;
}

.crm-lead__toolbar {
    background: #fff;
    border: 1px solid var(--crm-border);
    border-radius: 10px;
    padding: 10px 12px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
}

.crm-lead__views {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.crm-lead__views a {
    text-decoration: none;
    color: #344054;
    padding: 6px 10px;
    border-radius: 8px;
    border: 1px solid transparent;
    font-weight: 600;
    font-size: 13px;
}

.crm-lead__views a.is-active {
    background: #eff4ff;
    color: #1d4ed8;
    border-color: #dbe7ff;
}

.crm-lead__actions {
    display: flex;
    gap: 8px;
    align-items: center;
}

.crm-inline-form {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
}

.crm-input {
    height: 36px;
    border: 1px solid var(--crm-border);
    border-radius: 8px;
    padding: 0 10px;
    min-width: 140px;
    background: #fff;
}

.crm-alert {
    border-radius: 10px;
    padding: 10px 12px;
    border: 1px solid;
    font-weight: 600;
}

.crm-alert--ok {
    border-color: #a9e6c1;
    background: #ecfdf3;
    color: #087443;
}

.crm-btn {
    border: 1px solid var(--crm-border);
    border-radius: 8px;
    padding: 8px 12px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    background: #fff;
}

.crm-btn--ghost {
    color: #344054;
}

.crm-btn--primary {
    background: #2563eb;
    color: #fff;
    border-color: #1e4fd7;
}

.crm-btn--arrow {
    padding-left: 8px;
    padding-right: 8px;
}

.crm-split-btn {
    position: relative;
    display: inline-flex;
}

.crm-split-btn .crm-btn:first-child {
    border-top-right-radius: 0;
    border-bottom-right-radius: 0;
}

.crm-split-btn .crm-btn:last-child {
    border-top-left-radius: 0;
    border-bottom-left-radius: 0;
}

.crm-split-btn__menu {
    position: absolute;
    right: 0;
    top: calc(100% + 6px);
    background: #fff;
    border: 1px solid var(--crm-border);
    border-radius: 10px;
    min-width: 320px;
    box-shadow: 0 10px 24px rgba(2, 6, 23, 0.16);
    z-index: 25;
    padding: 6px;
    display: none;
}

.crm-split-btn__menu.is-open {
    display: block;
}

.crm-split-btn__menu button {
    display: block;
    width: 100%;
    border: 0;
    text-align: left;
    background: transparent;
    padding: 10px 10px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
}

.crm-split-btn__menu button:hover {
    background: #f3f6ff;
}

.crm-lead__body {
    display: grid;
    grid-template-columns: 280px 1fr;
    gap: 12px;
    min-height: 520px;
}

.crm-lead__filters {
    background: #fff;
    border: 1px solid var(--crm-border);
    border-radius: 10px;
    padding: 12px;
}

.crm-lead__filters h3,
.crm-lead__filters h4 {
    margin: 0 0 8px;
    font-size: 15px;
}

.crm-lead__filters h4 {
    margin-top: 12px;
    color: #344054;
}

.crm-lead__filters ul {
    list-style: none;
    margin: 0;
    padding: 0;
}

.crm-lead__filters li {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 6px 0;
    border-bottom: 1px solid #f2f4f7;
}

.crm-lead__filters a {
    color: #344054;
    text-decoration: none;
}

.crm-lead__filters li:last-child {
    border-bottom: 0;
}

.crm-lead__filters input[type="text"] {
    width: 100%;
    height: 34px;
    border: 1px solid var(--crm-border);
    border-radius: 8px;
    padding: 0 10px;
}

.crm-lead__checks li {
    justify-content: flex-start;
}

.crm-lead__checks label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
}

.crm-lead__table-wrap {
    background: #fff;
    border: 1px solid var(--crm-border);
    border-radius: 10px;
    overflow: auto;
}

.crm-lead__table {
    width: 100%;
    min-width: 900px;
    border-collapse: collapse;
}

.crm-lead__table th,
.crm-lead__table td {
    border-bottom: 1px solid #edf0f6;
    padding: 10px;
    font-size: 13px;
    text-align: left;
    white-space: nowrap;
}

.crm-lead__table th {
    background: #fafbff;
    color: #475467;
    font-weight: 700;
}

.crm-pill {
    display: inline-flex;
    align-items: center;
    border-radius: 999px;
    padding: 2px 10px;
    font-size: 12px;
    font-weight: 700;
    color: #fff;
}

.crm-pill.red { background: #ef4444; }
.crm-pill.green { background: #22c55e; }
.crm-pill.blue { background: #1d4ed8; }
.crm-pill.cyan { background: #0ea5e9; }
.crm-pill.olive { background: #65a30d; }
.crm-pill.gray { background: #4b5563; }
.crm-pill.purple { background: #c026d3; }
.crm-pill.burgundy { background: #9f1239; }

.crm-lead__footer {
    padding: 8px 10px;
    color: #475467;
    font-size: 13px;
}

.crm-modal {
    position: fixed;
    inset: 0;
    display: none;
    z-index: 1200;
}

.crm-modal.is-open {
    display: block;
}

.crm-modal__overlay {
    position: absolute;
    inset: 0;
    background: rgba(2, 6, 23, 0.45);
}

.crm-modal__panel {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: min(95vw, 430px);
    background: #fff;
    border: 1px solid var(--crm-border);
    border-radius: 12px;
    padding: 16px;
}

.crm-modal__panel h3 {
    margin: 0 0 12px;
}

.crm-modal__form {
    display: grid;
    gap: 10px;
}

.crm-modal__form label {
    display: grid;
    gap: 6px;
    font-size: 13px;
    color: #344054;
}

.crm-modal__actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}

/* Mobile / tablet: menu hamburger + drawer con slide + fade */
@media (max-width: 1024px) {
    .crm-app {
        display: block;
        position: relative;
        min-height: 100vh;
    }

    .crm-mobile-menu-btn {
        display: inline-flex;
    }

    .crm-sidebar__close {
        display: inline-flex;
    }

    .crm-sidebar {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        width: min(88vw, 300px);
        max-width: 100%;
        z-index: 1001;
        display: flex;
        flex-direction: column;
        transform: translate3d(-100%, 0, 0);
        opacity: 0;
        visibility: hidden;
        pointer-events: none;
        transition:
            transform 0.3s cubic-bezier(0.4, 0, 0.2, 1),
            opacity 0.28s ease,
            visibility 0.28s ease,
            box-shadow 0.28s ease;
        box-shadow: none;
        border-right: 1px solid rgba(0, 0, 0, 0.2);
    }

    .crm-body.crm-menu-open .crm-sidebar {
        transform: translate3d(0, 0, 0);
        opacity: 1;
        visibility: visible;
        pointer-events: auto;
        box-shadow: 12px 0 40px rgba(2, 6, 23, 0.35);
    }

    .crm-nav {
        display: block;
        padding: 8px 0 24px;
        -webkit-overflow-scrolling: touch;
    }

    .crm-nav__link {
        border-left: 3px solid transparent;
        border-radius: 0;
    }

    .crm-nav__link.is-active {
        border-left: 3px solid var(--crm-accent);
    }

    .crm-main {
        width: 100%;
        min-height: 100vh;
    }

    .crm-header {
        padding: 12px 16px;
        position: sticky;
        top: 0;
        z-index: 50;
    }

    .crm-content {
        padding: 16px;
    }

    .crm-mobile-overlay {
        display: block;
        position: fixed;
        inset: 0;
        background: rgba(15, 23, 42, 0.5);
        border: 0;
        padding: 0;
        margin: 0;
        cursor: pointer;
        z-index: 1000;
        opacity: 0;
        visibility: hidden;
        pointer-events: none;
        transition: opacity 0.28s ease, visibility 0.28s ease;
    }

    .crm-body.crm-menu-open .crm-mobile-overlay {
        opacity: 1;
        visibility: visible;
        pointer-events: auto;
    }

    .crm-body.crm-menu-open {
        overflow: hidden;
    }

    .crm-cards--two,
    .crm-cards--three {
        grid-template-columns: 1fr;
    }

    .crm-kpi-grid {
        grid-template-columns: 1fr 1fr;
    }
}

@media (max-width: 640px) {
    .crm-header__env {
        display: none;
    }

    .crm-header__title h1 {
        font-size: 1.02rem;
    }

    .crm-kpi-grid {
        grid-template-columns: 1fr;
    }

    .crm-lead__toolbar {
        align-items: stretch;
    }

    .crm-lead__actions {
        width: 100%;
        justify-content: flex-end;
        flex-wrap: wrap;
    }

    .crm-inline-form {
        width: 100%;
    }

    .crm-inline-form .crm-input {
        flex: 1 1 100%;
    }

    .crm-split-btn__menu {
        min-width: 250px;
    }
}

@media (max-width: 1200px) {
    .crm-lead__body {
        grid-template-columns: 1fr;
    }
}
