/**
 * Tema visual alinhado ao Comercial Pronto Afeto (sidebar, topbar, tokens).
 * Uso: CRM em deploy isolado, sem depender de /comercial/assets.
 */
:root {
    --roxo-escuro: rgb(119, 76, 174);
    --roxo-claro: rgb(186, 183, 253);
    --rosa: rgb(241, 112, 157);
    --rosa-claro: rgba(241, 112, 157, 0.85);
    --vermelho: #dc3545;
    --preto: rgb(0, 0, 0);
    --gradiente-roxo: linear-gradient(135deg, rgb(119, 76, 174), rgb(186, 183, 253));
    --gradiente-rosa: linear-gradient(135deg, rgb(241, 112, 157), rgba(241, 112, 157, 0.85));
    --gradiente-preto-roxo: linear-gradient(135deg, rgb(0, 0, 0), rgb(119, 76, 174));
    --gradiente-vermelho-rosa: linear-gradient(135deg, #dc3545, rgb(241, 112, 157));
    --fundo-lavanda: rgba(186, 183, 253, 0.15);
    --branco: #ffffff;
    --cinza-claro: #f8fafc;
    --cinza-medio: #e9ecef;
    --texto-escuro: #1a1a1a;
    --texto-medio: #6c757d;
}

* {
    box-sizing: border-box;
}

body.crm-shell {
    margin: 0;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--fundo-lavanda);
    position: relative;
    overflow-x: hidden;
    color: var(--texto-escuro);
    min-height: 100vh;
    max-width: 100vw;
}

.crm-bg-decoration {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    pointer-events: none;
    overflow: hidden;
    z-index: 0;
}

.crm-bg-circle {
    position: absolute;
    border-radius: 50%;
    opacity: 0.08;
    animation: crmFloat 12s ease-in-out infinite;
    filter: blur(40px);
}

.crm-bg-circle-1 {
    width: 400px;
    height: 400px;
    top: 10%;
    right: -100px;
    background: var(--gradiente-roxo);
}

.crm-bg-circle-2 {
    width: 300px;
    height: 300px;
    bottom: 20%;
    left: -50px;
    background: var(--gradiente-rosa);
    animation-delay: 4s;
}

.crm-bg-circle-3 {
    width: 250px;
    height: 250px;
    top: 60%;
    left: 5%;
    background: var(--gradiente-vermelho-rosa);
    animation-delay: 8s;
}

@keyframes crmFloat {
    0%, 100% { transform: translateY(0) scale(1) rotate(0deg); }
    50% { transform: translateY(-30px) scale(1.05) rotate(5deg); }
}

.crm-sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: 280px;
    height: 100vh;
    background: var(--gradiente-roxo);
    box-shadow: 4px 0 20px rgba(119, 76, 174, 0.2);
    z-index: 1000;
    overflow-y: auto;
    transition: transform 0.3s ease;
}

.crm-sidebar-header {
    padding: 1.5rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.crm-sidebar-brand {
    color: #fff !important;
    font-size: 1.25rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    text-decoration: none;
    gap: 0.5rem;
}

.crm-sidebar-brand:hover {
    color: var(--rosa) !important;
}

.crm-sidebar-brand img {
    height: 40px;
    width: auto;
    object-fit: contain;
}

.crm-sidebar-nav {
    padding: 1rem 0;
    list-style: none;
    margin: 0;
}

.crm-sidebar-nav .nav-item {
    margin: 0.3rem 0;
}

.crm-sidebar-nav .nav-link {
    color: #fff !important;
    padding: 0.85rem 1.5rem !important;
    display: flex;
    align-items: center;
    transition: all 0.3s ease;
    text-decoration: none;
    border-left: 3px solid transparent;
}

.crm-sidebar-nav .nav-link:hover {
    background: rgba(255, 255, 255, 0.15);
    border-left-color: var(--rosa);
    padding-left: 1.8rem;
}

.crm-sidebar-nav .nav-link.active {
    background: rgba(255, 255, 255, 0.25);
    font-weight: 600;
    border-left-color: #fff;
}

.crm-sidebar-nav .nav-link i {
    width: 24px;
    margin-right: 0.75rem;
    font-size: 1.1rem;
}

.crm-top-bar {
    position: fixed;
    top: 0;
    left: 280px;
    right: 0;
    height: 70px;
    background: #fff;
    box-shadow: 0 2px 10px rgba(119, 76, 174, 0.1);
    z-index: 999;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    padding: 0 2rem;
    gap: 1rem;
}

.crm-top-bar-user {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.35rem 0.75rem;
    border-radius: 12px;
    background: rgba(119, 76, 174, 0.1);
    color: var(--roxo-escuro);
    font-weight: 600;
    font-size: 0.9rem;
    max-width: min(100%, 280px);
}

.crm-top-bar-user i {
    font-size: 1.5rem;
    flex-shrink: 0;
}

.crm-top-bar-user span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.crm-top-bar .btn-logout {
    border-radius: 12px;
    font-weight: 600;
    border: 2px solid var(--roxo-escuro);
    color: var(--roxo-escuro);
    background: #fff;
    padding: 0.45rem 1rem;
}

.crm-top-bar .btn-logout:hover {
    background: var(--gradiente-roxo);
    color: #fff;
    border-color: transparent;
}

.crm-main-content {
    margin-left: 280px;
    margin-top: 70px;
    padding: 2rem;
    padding-left: max(2rem, env(safe-area-inset-left));
    padding-right: max(2rem, env(safe-area-inset-right));
    min-height: calc(100vh - 70px);
    position: relative;
    z-index: 1;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
}

.crm-sidebar-toggle {
    display: none;
    position: fixed;
    top: 1rem;
    left: 1rem;
    z-index: 1001;
    background: var(--gradiente-roxo);
    color: #fff;
    border: none;
    width: 45px;
    height: 45px;
    border-radius: 12px;
    box-shadow: 0 4px 15px rgba(119, 76, 174, 0.3);
    cursor: pointer;
}

.crm-sidebar-toggle:hover {
    background: var(--gradiente-rosa);
}

.crm-page-heading {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--roxo-escuro);
    margin-bottom: 0.25rem;
}

.crm-page-sub {
    color: var(--texto-medio);
    margin-bottom: 1.5rem;
}

/* Cards e botoes (comercial) */
.crm-shell .card {
    border: none;
    border-radius: 20px;
    box-shadow: 0 8px 30px rgba(119, 76, 174, 0.12);
    background: #fff;
    transition: box-shadow 0.3s ease, transform 0.3s ease;
}

.crm-shell .card:hover {
    box-shadow: 0 12px 36px rgba(119, 76, 174, 0.18);
}

.crm-shell .btn-primary-custom {
    background: var(--gradiente-roxo);
    border: none;
    color: #fff;
    font-weight: 600;
    padding: 0.75rem 1.5rem;
    border-radius: 50px;
    transition: all 0.3s ease;
    box-shadow: 0 4px 15px rgba(119, 76, 174, 0.3);
}

.crm-shell .btn-primary-custom:hover {
    color: #fff;
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(119, 76, 174, 0.4);
}

.crm-shell .btn-outline-primary-custom {
    border: 2px solid var(--roxo-escuro);
    color: var(--roxo-escuro);
    font-weight: 600;
    padding: 0.75rem 1.5rem;
    border-radius: 50px;
    background: #fff;
    transition: all 0.3s ease;
}

.crm-shell .btn-outline-primary-custom:hover {
    background: var(--gradiente-roxo);
    color: #fff;
    border-color: transparent;
}

/* Tabelas dentro do CRM */
.crm-shell .table thead th {
    background: var(--fundo-lavanda);
    color: var(--roxo-escuro);
    font-weight: 600;
    border: none;
    padding: 0.85rem 1rem;
}

.crm-shell .table tbody tr:hover {
    background: rgba(186, 183, 253, 0.12);
}

/* Login / auth (fundo sem sidebar) */
body.crm-auth-body {
    margin: 0;
    min-height: 100vh;
    max-width: 100vw;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--fundo-lavanda);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem 1rem;
    position: relative;
    overflow-x: hidden;
    color: var(--texto-escuro);
}

.crm-auth-card {
    width: 100%;
    max-width: 420px;
    background: #fff;
    border-radius: 20px;
    box-shadow: 0 8px 30px rgba(119, 76, 174, 0.15);
    padding: 2rem;
    position: relative;
    z-index: 1;
}

.crm-auth-card h1 {
    font-size: 1.35rem;
    font-weight: 700;
    color: var(--roxo-escuro);
}

.crm-auth-logo {
    display: block;
    max-height: 72px;
    width: auto;
    max-width: min(260px, 100%);
    height: auto;
    margin: 0 auto 1rem;
    object-fit: contain;
}

body.crm-auth-body .btn-primary-custom {
    background: var(--gradiente-roxo);
    border: none;
    color: #fff;
    font-weight: 600;
    padding: 0.75rem 1.5rem;
    border-radius: 50px;
    transition: all 0.3s ease;
    box-shadow: 0 4px 15px rgba(119, 76, 174, 0.3);
}

body.crm-auth-body .btn-primary-custom:hover {
    color: #fff;
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(119, 76, 174, 0.4);
}

/* WhatsApp flutuante (CRM inicio) */
.crm-whatsapp-float {
    position: fixed;
    bottom: 30px;
    right: 30px;
    background-color: #25d366;
    color: #fff;
    width: 60px;
    height: 60px;
    border-radius: 50px;
    text-align: center;
    font-size: 30px;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.15);
    z-index: 1020;
    display: flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
    transition: transform 0.3s ease, background 0.3s ease;
}

.crm-whatsapp-float:hover {
    background-color: #128c7e;
    color: #fff;
    transform: scale(1.08);
}

.crm-feature-icon {
    font-size: 2.5rem;
    margin-bottom: 1rem;
    color: var(--roxo-escuro);
}

/* Dashboard CRM: badges */
.crm-dash-priority-badge {
    padding: 6px 12px;
    border-radius: 15px;
    font-size: 0.85rem;
    font-weight: 500;
}
.crm-dash-priority-high { background-color: #dc3545; color: #fff; }
.crm-dash-priority-medium { background-color: #ffc107; color: #000; }
.crm-dash-priority-low { background-color: #198754; color: #fff; }

.crm-dash-status-badge {
    padding: 6px 12px;
    border-radius: 15px;
    font-size: 0.85rem;
    font-weight: 500;
}
.crm-dash-status-qualification { background-color: #0d6efd; color: #fff; }
.crm-dash-status-proposal { background-color: #ffc107; color: #000; }
.crm-dash-status-closed { background-color: #198754; color: #fff; }

.crm-dash-owner-avatar {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: var(--fundo-lavanda);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin-right: 5px;
    color: var(--roxo-escuro);
    font-size: 0.8rem;
    font-weight: 600;
}

.crm-dash-btn-delete {
    padding: 4px 8px;
    font-size: 0.8rem;
    background-color: #dc3545;
    color: #fff;
    border: none;
    border-radius: 8px;
}
.crm-dash-btn-delete:hover { background-color: #bb2d3b; color: #fff; }

.crm-shell .form-control:focus {
    border-color: var(--roxo-claro);
    box-shadow: 0 0 0 0.2rem rgba(119, 76, 174, 0.2);
}

@media (max-width: 992px) {
    .crm-sidebar {
        transform: translateX(-100%);
        width: min(280px, calc(100vw - 48px));
        max-width: 100%;
        box-shadow: 8px 0 32px rgba(0, 0, 0, 0.18);
    }
    .crm-sidebar.show {
        transform: translateX(0);
    }
    .crm-top-bar {
        left: 0;
        height: 64px;
        padding-left: max(4.25rem, calc(env(safe-area-inset-left) + 3.5rem));
        padding-right: max(1rem, env(safe-area-inset-right));
        padding-top: env(safe-area-inset-top);
    }
    .crm-main-content {
        margin-left: 0;
        margin-top: 64px;
        min-height: calc(100vh - 64px);
        padding: 1.25rem 1rem;
        padding-bottom: max(1.25rem, env(safe-area-inset-bottom));
    }
    .crm-sidebar-toggle {
        display: block !important;
        top: max(0.65rem, env(safe-area-inset-top));
        left: max(0.75rem, env(safe-area-inset-left));
    }
}

@media (max-width: 576px) {
    .crm-page-heading {
        font-size: 1.35rem;
        line-height: 1.3;
        word-break: break-word;
    }
    .crm-page-heading.d-flex {
        flex-direction: column !important;
        align-items: stretch !important;
        gap: 0.75rem !important;
    }
    .crm-page-heading.d-flex > span:last-child {
        width: 100%;
    }
    .crm-page-heading .d-flex.gap-2 {
        flex-wrap: wrap;
        width: 100%;
        justify-content: flex-start !important;
    }
    .crm-page-sub {
        font-size: 0.9rem;
        margin-bottom: 1rem;
    }
    .crm-main-content {
        padding: 1rem 0.75rem;
        padding-left: max(0.75rem, env(safe-area-inset-left));
        padding-right: max(0.75rem, env(safe-area-inset-right));
    }
    .crm-top-bar {
        padding-left: max(3.65rem, calc(env(safe-area-inset-left) + 3.25rem));
        padding-right: max(0.65rem, env(safe-area-inset-right));
    }
    .crm-top-bar-user {
        max-width: min(200px, 48vw);
        font-size: 0.78rem;
        padding: 0.3rem 0.45rem;
    }
    .crm-top-bar .btn-logout {
        padding: 0.35rem 0.6rem;
        font-size: 0.78rem;
        white-space: nowrap;
    }
    .crm-shell .card {
        border-radius: 16px;
    }
    .crm-shell .btn-primary-custom,
    .crm-shell .btn-outline-primary-custom {
        padding: 0.65rem 1.1rem;
        font-size: 0.9rem;
    }
    .crm-feature-icon {
        font-size: 2rem;
    }
    .crm-sidebar-nav .nav-link {
        min-height: 48px;
        padding-top: 0.7rem !important;
        padding-bottom: 0.7rem !important;
    }
    .crm-whatsapp-float {
        width: 52px;
        height: 52px;
        font-size: 24px;
        bottom: max(1rem, env(safe-area-inset-bottom));
        right: max(0.75rem, env(safe-area-inset-right));
    }
    .crm-perfil-page .btn-floating {
        width: 52px;
        height: 52px;
        font-size: 20px;
        bottom: max(5.5rem, calc(env(safe-area-inset-bottom) + 4.75rem));
        right: max(0.75rem, env(safe-area-inset-right));
    }
    .crm-status-page .d-flex.gap-2 {
        flex-direction: column;
        align-items: stretch !important;
    }
    .crm-status-page .d-flex.gap-2 .btn {
        width: 100%;
    }
    .crm-estatisticas-page .btn-periodo,
    .crm-estat-adv-page .btn-periodo {
        font-size: 0.8rem;
        padding: 0.25rem 0.45rem;
        margin-right: 0.25rem;
    }
    .crm-estatisticas-page .chart-container,
    .crm-estat-adv-page .chart-container {
        min-height: 240px;
        padding: 8px 4px;
    }
    .crm-estatisticas-page .stat-card h3,
    .crm-estat-adv-page .stat-card h3 {
        font-size: 1.65rem;
    }
    .crm-shell .modal-dialog {
        margin: 0.5rem auto;
        max-width: calc(100% - 1rem);
    }
    .crm-shell .modal-dialog.modal-lg {
        max-width: calc(100% - 0.75rem);
    }
    .crm-shell .table {
        font-size: 0.875rem;
    }
    .crm-shell .table thead th,
    .crm-shell .table tbody td {
        padding: 0.5rem 0.45rem;
    }
}

@media (max-width: 400px) {
    body.crm-auth-body {
        padding: 1rem 0.75rem;
        padding-top: max(1rem, env(safe-area-inset-top));
        align-items: flex-start;
    }
    .crm-auth-card {
        padding: 1.25rem 1rem;
        border-radius: 16px;
    }
    .crm-auth-card h1 {
        font-size: 1.15rem;
    }
}

/* Tabelas: scroll suave em touch; evita estourar a largura */
.crm-shell .table-responsive {
    -webkit-overflow-scrolling: touch;
    overflow-x: auto;
    max-width: 100%;
}

.crm-shell .container,
.crm-shell .container-fluid {
    max-width: 100%;
}

@media (prefers-reduced-motion: reduce) {
    .crm-bg-circle {
        animation: none;
    }
    .crm-shell .card,
    .crm-shell .btn-primary-custom,
    .crm-whatsapp-float {
        transition: none;
    }
}
