/* ============================================
   Dashboard CRM - Estilos
   Coherente con el panel (clean, tarjetas, bordes suaves)
   ============================================ */

#crm-dashboard {
    padding: 20px;
}

/* --- Header --- */
.crmd-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: wrap;
    margin-bottom: 16px;
}

.crmd-header-left h1 {
    font-size: 22px;
    font-weight: 700;
    color: #111827;
    margin: 0;
}

.crmd-subtitle {
    font-size: 13px;
    color: #6b7280;
    margin: 4px 0 0;
}

.crmd-header-right {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

/* Selector de periodo */
.crmd-period {
    display: inline-flex;
    background: #f3f4f6;
    border-radius: 10px;
    padding: 3px;
    gap: 2px;
    flex-wrap: wrap;
}

.crmd-period-btn {
    border: none;
    background: transparent;
    color: #6b7280;
    font-size: 13px;
    font-weight: 500;
    padding: 7px 14px;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.15s ease;
    white-space: nowrap;
}

.crmd-period-btn:hover { color: #111827; }

.crmd-period-btn.active {
    background: #fff;
    color: #111827;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

.crmd-period-btn-custom {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.crmd-period-btn-custom svg {
    flex-shrink: 0;
    opacity: 0.7;
}

.crmd-period-btn-custom.active svg {
    opacity: 1;
    stroke: #4338ca;
}

/* --- Filtro de fuentes --- */
.crmd-sources {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    margin-bottom: 20px;
}

.crmd-sources:empty { margin: 0; }

.crmd-sources-label {
    font-size: 12px;
    font-weight: 600;
    color: #6b7280;
    text-transform: uppercase;
    letter-spacing: 0.4px;
}

.crmd-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    border: 1px solid #e5e7eb;
    background: #fff;
    color: #6b7280;
    font-size: 12px;
    font-weight: 500;
    padding: 6px 12px;
    border-radius: 999px;
    cursor: pointer;
    transition: all 0.15s ease;
}

.crmd-chip:hover { border-color: #d1d5db; }

.crmd-chip.active {
    border-color: #6366f1;
    color: #4338ca;
    background: #eef2ff;
}

.crmd-chip-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    display: inline-block;
}

.crmd-chip-all {
    border-style: dashed;
}

/* --- KPIs --- */
.crmd-kpis {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 14px;
    margin-bottom: 10px;
}

.crmd-kpi {
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 12px;
    padding: 16px 18px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    transition: box-shadow 0.15s ease;
}

.crmd-kpi:hover { box-shadow: 0 2px 8px rgba(0,0,0,0.06); }

.crmd-kpi-label {
    font-size: 11px;
    font-weight: 600;
    color: #6b7280;
    text-transform: uppercase;
    letter-spacing: 0.4px;
}

.crmd-kpi-value {
    font-size: 26px;
    font-weight: 700;
    color: #111827;
    letter-spacing: -0.5px;
    line-height: 1.15;
}

.crmd-kpi-delta {
    font-size: 11px;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.crmd-kpi-delta.positive { color: #059669; }
.crmd-kpi-delta.negative { color: #dc2626; }
.crmd-kpi-delta.neutral { color: #9ca3af; font-weight: 500; }

.crmd-kpi-delta-ref {
    color: #9ca3af;
    font-weight: 400;
}

.crmd-cmp-note {
    font-size: 12px;
    color: #9ca3af;
    margin: 4px 2px 0;
}

/* --- Bloques y tarjetas --- */
.crmd-block-title {
    font-size: 15px;
    font-weight: 700;
    color: #111827;
    margin: 28px 0 14px;
    padding-bottom: 8px;
    border-bottom: 1px solid #f1f5f9;
}

.crmd-grid {
    display: grid;
    gap: 16px;
    margin-bottom: 4px;
}

.crmd-grid-2 {
    grid-template-columns: repeat(2, 1fr);
}

.crmd-card {
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 12px;
    padding: 18px;
    margin-bottom: 16px;
}

.crmd-grid .crmd-card { margin-bottom: 0; }

.crmd-card-wide { grid-column: 1 / -1; }

.crmd-card-title {
    font-size: 14px;
    font-weight: 600;
    color: #374151;
    margin-bottom: 12px;
}

.crmd-chart {
    min-height: 280px;
}

.crmd-chart-empty,
.crmd-inline-empty {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 240px;
    color: #9ca3af;
    font-size: 13px;
    text-align: center;
    padding: 20px;
    background: #fafafa;
    border-radius: 8px;
}

.crmd-inline-empty { min-height: 80px; }

/* --- Embudo de conversión --- */
.crmd-funnel {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 0;
    padding: 8px 12px 4px;
    min-height: 260px;
}

.crmd-funnel-step {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-bottom: 6px;
}

.crmd-funnel-bar {
    width: 100%;
    height: 56px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-weight: 700;
    font-size: 18px;
    letter-spacing: -0.5px;
    clip-path: polygon(
        calc(50% - var(--top-width) / 2) 0,
        calc(50% + var(--top-width) / 2) 0,
        calc(50% + var(--bottom-width) / 2) 100%,
        calc(50% - var(--bottom-width) / 2) 100%
    );
    transition: clip-path 0.25s ease;
}

.crmd-funnel-count {
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.15);
}

.crmd-funnel-meta {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: 6px 10px;
    margin-top: 6px;
    text-align: center;
}

.crmd-funnel-name {
    font-size: 13px;
    font-weight: 600;
    color: #374151;
}

.crmd-funnel-pct,
.crmd-funnel-conv {
    font-size: 11px;
    color: #9ca3af;
}

.crmd-funnel-conv {
    color: #6366f1;
    font-weight: 500;
}

/* --- Atención / seguimiento --- */
.crmd-attention { display: flex; flex-direction: column; }

.crmd-att-group { margin-bottom: 14px; }
.crmd-att-group:last-child { margin-bottom: 0; }

.crmd-att-head {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    font-weight: 600;
    color: #6b7280;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    margin-bottom: 8px;
}

.crmd-dot {
    width: 8px; height: 8px; border-radius: 50%;
}
.crmd-dot-red { background: #ef4444; }
.crmd-dot-amber { background: #f59e0b; }
.crmd-dot-green { background: #10b981; }

.crmd-att-list { list-style: none; margin: 0; padding: 0; }

.crmd-att-list li {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    padding: 7px 0;
    border-bottom: 1px solid #f3f4f6;
}
.crmd-att-list li:last-child { border-bottom: none; }

.crmd-att-name { font-size: 13px; color: #111827; font-weight: 500; }
.crmd-att-meta { font-size: 11px; color: #9ca3af; text-align: right; }

.crmd-att-empty { font-size: 12px; color: #9ca3af; padding: 4px 0 8px; }

/* --- Tabla campañas --- */
.crmd-table-wrap { overflow-x: auto; }

.crmd-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

.crmd-table th {
    text-align: left;
    font-size: 11px;
    font-weight: 600;
    color: #6b7280;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    padding: 8px 10px;
    border-bottom: 1px solid #e5e7eb;
    white-space: nowrap;
}

.crmd-table td {
    padding: 10px;
    border-bottom: 1px solid #f3f4f6;
    color: #374151;
    white-space: nowrap;
}

.crmd-table tbody tr:hover { background: #fafafa; }

.crmd-muted { color: #9ca3af; }
.crmd-pos { color: #059669; font-weight: 600; }
.crmd-neg { color: #dc2626; font-weight: 600; }

/* --- Estados vacíos --- */
.crmd-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 60px 20px;
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 12px;
}

.crmd-empty-icon { font-size: 40px; margin-bottom: 12px; }
.crmd-empty-title { font-size: 17px; font-weight: 700; color: #111827; margin-bottom: 6px; }
.crmd-empty-text { font-size: 13px; color: #6b7280; max-width: 420px; margin-bottom: 16px; }
.crmd-empty-actions { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }

.crmd-empty-btn {
    border: none;
    background: #6366f1;
    color: #fff;
    font-size: 13px;
    font-weight: 600;
    padding: 9px 16px;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.15s ease;
}
.crmd-empty-btn:hover { background: #4f46e5; }

/* Estado de carga */
.crmd-loading { opacity: 0.5; pointer-events: none; transition: opacity 0.15s ease; }

/* --- Responsive --- */
@media (max-width: 1024px) {
    .crmd-grid-2 { grid-template-columns: 1fr; }
}

@media (max-width: 768px) {
    #crm-dashboard { padding: 14px; }
    .crmd-header { flex-direction: column; }
    .crmd-period { width: 100%; justify-content: flex-start; }
    .crmd-kpis { grid-template-columns: repeat(2, 1fr); gap: 10px; }
    .crmd-kpi-value { font-size: 22px; }
    .crmd-block-title { margin-top: 22px; }
}

@media (max-width: 420px) {
    .crmd-kpis { grid-template-columns: 1fr; }
    .crmd-period-btn { padding: 7px 10px; font-size: 12px; }
}

/* --- Modal periodo personalizado --- */
body.crmd-modal-open { overflow: hidden; }

.crmd-modal-overlay {
    position: fixed;
    inset: 0;
    z-index: 1200;
    background: rgba(17, 24, 39, 0.45);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.crmd-modal {
    width: 100%;
    max-width: 440px;
    background: #fff;
    border-radius: 16px;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.18);
    overflow: hidden;
    animation: crmdModalIn 0.2s ease;
}

@keyframes crmdModalIn {
    from { opacity: 0; transform: translateY(12px) scale(0.98); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

.crmd-modal-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    padding: 20px 22px 12px;
    border-bottom: 1px solid #f3f4f6;
}

.crmd-modal-header h3 {
    margin: 0;
    font-size: 17px;
    font-weight: 700;
    color: #111827;
}

.crmd-modal-sub {
    margin: 4px 0 0;
    font-size: 13px;
    color: #6b7280;
}

.crmd-modal-close {
    border: none;
    background: #f3f4f6;
    color: #6b7280;
    width: 32px;
    height: 32px;
    border-radius: 8px;
    font-size: 22px;
    line-height: 1;
    cursor: pointer;
    flex-shrink: 0;
}

.crmd-modal-close:hover {
    background: #e5e7eb;
    color: #111827;
}

.crmd-modal-body {
    padding: 18px 22px;
}

.crmd-date-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
}

.crmd-date-field label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    color: #374151;
    margin-bottom: 6px;
}

.crmd-date-input-wrap {
    display: flex;
    align-items: center;
    gap: 10px;
    border: 1px solid #e5e7eb;
    border-radius: 10px;
    padding: 10px 12px;
    background: #fafafa;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.crmd-date-input-wrap:focus-within {
    border-color: #6366f1;
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.12);
    background: #fff;
}

.crmd-date-input-wrap svg {
    color: #9ca3af;
    flex-shrink: 0;
}

.crmd-date-input {
    border: none;
    background: transparent;
    width: 100%;
    font-size: 14px;
    color: #111827;
    font-family: inherit;
    outline: none;
}

.crmd-date-input::-webkit-calendar-picker-indicator {
    cursor: pointer;
    opacity: 0.6;
}

.crmd-date-input::-webkit-calendar-picker-indicator:hover {
    opacity: 1;
}

.crmd-date-presets {
    margin-top: 18px;
}

.crmd-date-presets-label {
    display: block;
    font-size: 11px;
    font-weight: 600;
    color: #9ca3af;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    margin-bottom: 8px;
}

.crmd-date-presets-row {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.crmd-date-preset {
    border: 1px solid #e5e7eb;
    background: #fff;
    color: #374151;
    font-size: 12px;
    font-weight: 500;
    padding: 7px 12px;
    border-radius: 999px;
    cursor: pointer;
    transition: all 0.15s ease;
}

.crmd-date-preset:hover {
    border-color: #6366f1;
    color: #4338ca;
    background: #eef2ff;
}

.crmd-date-error {
    margin-top: 12px;
    font-size: 12px;
    color: #dc2626;
    background: #fef2f2;
    border: 1px solid #fecaca;
    border-radius: 8px;
    padding: 8px 10px;
}

.crmd-modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    padding: 14px 22px 20px;
    border-top: 1px solid #f3f4f6;
}

.crmd-btn-secondary,
.crmd-btn-primary {
    border: none;
    font-size: 13px;
    font-weight: 600;
    padding: 9px 16px;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.15s ease;
}

.crmd-btn-secondary {
    background: #f3f4f6;
    color: #374151;
}

.crmd-btn-secondary:hover { background: #e5e7eb; }

.crmd-btn-primary {
    background: #6366f1;
    color: #fff;
}

.crmd-btn-primary:hover { background: #4f46e5; }

@media (max-width: 480px) {
    .crmd-date-grid { grid-template-columns: 1fr; }
    .crmd-modal-overlay { padding: 12px; }
}
