/* ═══════════════════════════════════════════════════
   CRM — Gestión de Casos
   ═══════════════════════════════════════════════════ */

/* ── Container & Kanban board ── */
#crm-kanban {
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 10px;
}

.kanban-board {
    display: flex;
    gap: 14px;
    padding: 4px 2px 14px 2px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    align-items: flex-start;
    min-width: max-content;
    width: 100%;
    min-height: calc(100vh - 160px);
}

/* Custom Scrollbar for Kanban */
#crm-kanban::-webkit-scrollbar,
.kanban-board::-webkit-scrollbar,
.kanban-cards::-webkit-scrollbar {
    height: 8px;
    width: 6px;
}
#crm-kanban::-webkit-scrollbar-track,
.kanban-board::-webkit-scrollbar-track,
.kanban-cards::-webkit-scrollbar-track {
    background: #F1F5F9;
    border-radius: 8px;
}
#crm-kanban::-webkit-scrollbar-thumb,
.kanban-board::-webkit-scrollbar-thumb,
.kanban-cards::-webkit-scrollbar-thumb {
    background: #CBD5E1;
    border-radius: 8px;
}
#crm-kanban::-webkit-scrollbar-thumb:hover,
.kanban-board::-webkit-scrollbar-thumb:hover,
.kanban-cards::-webkit-scrollbar-thumb:hover {
    background: #94A3B8;
}

.kanban-col {
    width: 270px;
    min-width: 270px;
    max-width: 290px;
    display: flex;
    flex-direction: column;
    border: 1.5px solid #E2E8F0;
    border-radius: 14px;
    background: #F8FAFC;
    overflow: hidden;
    box-shadow: 0 1px 3px rgba(15, 23, 42, 0.04);
    flex-shrink: 0;
}

.kanban-col-hdr {
    background: #FFFFFF;
    border-bottom: 1.5px solid #E2E8F0;
    padding: 12px 14px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

.kanban-col-hdr-title {
    font-family: var(--font-display, 'Plus Jakarta Sans', system-ui, sans-serif);
    font-size: 11.5px;
    font-weight: 700;
    color: #1E293B;
    letter-spacing: .4px;
    text-transform: uppercase;
}

.kanban-count {
    background: #EFF6FF;
    border: 1px solid #BFDBFE;
    color: #2563EB;
    font-size: 10.5px;
    font-weight: 700;
    border-radius: 100px;
    padding: 2px 8px;
    min-width: 20px;
    text-align: center;
    font-family: var(--font-display, inherit);
}

.kanban-cards {
    padding: 10px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    flex: 1;
    overflow-y: auto;
    max-height: calc(100vh - 230px);
}

.kanban-empty {
    font-size: 12px;
    color: #94A3B8;
    text-align: center;
    padding: 28px 12px;
    border: 1.5px dashed #E2E8F0;
    border-radius: 10px;
    margin: 4px;
    background: #FFFFFF;
}

/* ── Case card ── */
.caso-card {
    background: #FFFFFF;
    border: 1.5px solid #E2E8F0;
    border-left: 4px solid #3B82F6;
    border-radius: 11px;
    padding: 12px 14px;
    cursor: pointer;
    box-shadow: 0 1px 3px rgba(15, 23, 42, 0.04);
    transition: all .15s ease;
}

.caso-card:hover {
    border-color: #CBD5E1;
    border-left-color: #1D4ED8;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(15, 23, 42, 0.08);
}

.caso-card.estado-resuelto  { border-left-color: #059669; }
.caso-card.estado-archivado { border-left-color: #94A3B8; opacity: .75; }

/* ── CRM Table View ── */
#crm-tabla {
    background: #FFFFFF;
    border: 1.5px solid #E2E8F0;
    border-radius: 14px;
    box-shadow: 0 1px 3px rgba(15, 23, 42, 0.04);
    overflow-x: auto;
    width: 100%;
}
#crm-tabla table {
    width: 100%;
    min-width: 850px;
    border-collapse: collapse;
    font-size: 13px;
}
#crm-tabla thead th {
    background: #F8FAFC;
    color: #475569;
    font-family: var(--font-display, 'Plus Jakarta Sans', system-ui, sans-serif);
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.6px;
    padding: 12px 14px;
    border-top: none;
    border-left: none;
    border-right: none;
    border-bottom: 1.5px solid #E2E8F0;
    text-align: left;
    white-space: nowrap;
}
#crm-tabla tbody td {
    padding: 12px 14px;
    border-top: none;
    border-left: none;
    border-right: none;
    border-bottom: 1px solid #F1F5F9;
    color: #1E293B;
    vertical-align: middle;
}
#crm-tabla tbody tr {
    transition: background .12s ease;
}
#crm-tabla tbody tr:hover {
    background: #F8FAFC !important;
    cursor: pointer;
}
#crm-tabla tbody tr:last-child td {
    border-bottom: none;
}

.caso-card-nombre {
    font-size: 12px;
    font-weight: 600;
    color: #1A3060;
    margin-bottom: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.caso-card-beneficio {
    font-size: 11px;
    color: #5A6878;
    margin-bottom: 6px;
}

.caso-card-meta {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 6px;
}

.caso-card-fecha            { font-size: 10.5px; color: #64748B; font-weight: 500; display: inline-flex; align-items: center; gap: 3px; }
.caso-card-fecha.vence-pronto { color: #D97706; font-weight: 600; background: #FEF3C7; padding: 1px 6px; border-radius: 4px; }
.caso-card-fecha.vence-grave  { color: #DC2626; font-weight: 700; background: #FEE2E2; padding: 1px 6px; border-radius: 4px; }

.caso-card-badges { display: flex; gap: 4px; }

.crm-badge {
    font-size: 10px;
    padding: 1px 6px;
    border-radius: 2px;
    font-weight: 500;
    white-space: nowrap;
}

.crm-badge-task  { background: #DCE8F8; color: #2B4478; border: 1px solid #A8C4E0; }
.crm-badge-doc   { background: #D8F0E4; color: #1a5c38; border: 1px solid #90D4A8; }
.crm-badge-alert { background: #FDE8E8; color: #7A2020; border: 1px solid #F0A0A0; }

/* ── CRM vista toggle ── */
.crm-view-toggle {
    display: flex;
    align-items: center;
    border-left: 1px solid rgba(255,255,255,.2);
}

.crm-view-btn {
    cursor: pointer;
    padding: 0 10px;
    font-size: 11px;
    color: #1A3060;
    background: transparent;
    border: none;
    border-radius: 0;
    font-family: inherit;
    min-height: 30px;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    transition: background .1s;
    border-right: 1px solid rgba(0,0,0,.08);
}

.crm-view-btn:hover  { background: rgba(255,255,255,.45); }
.crm-view-btn.active { color: var(--accent); font-weight: 700; }

/* ── Modal overlay ── */
.crm-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.45);
    z-index: 900;
    align-items: center;
    justify-content: center;
}

.crm-overlay.open { display: flex; }

.crm-modal {
    background: #F8FAFC;
    border: 1px solid #E2E8F0;
    border-radius: 12px;
    width: min(840px, 96vw);
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 12px 40px rgba(15, 23, 42, 0.15);
    overflow: hidden;
}

.crm-modal-hdr {
    background: var(--primary);
    border-bottom: 1px solid rgba(255,255,255,.08);
    padding: 16px 20px;
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
}

.crm-modal-title {
    font-family: var(--font-display, 'Plus Jakarta Sans', system-ui, sans-serif);
    font-size: 15px;
    font-weight: 700;
    color: #fff;
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    letter-spacing: 0.3px;
}

.crm-modal-etapa { 
    font-size: 11px; 
    color: #94A3B8; 
    background: rgba(255,255,255,0.06);
    padding: 3px 10px;
    border-radius: 20px;
    font-weight: 500; 
}

.crm-modal-close {
    cursor: pointer;
    background: transparent;
    border: none;
    color: #94A3B8;
    font-size: 16px;
    line-height: 1;
    padding: 6px;
    border-radius: 6px;
    font-family: inherit;
    transition: all .15s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.crm-modal-close:hover { 
    color: #fff; 
    background: rgba(255,255,255,0.08);
}

.crm-modal-tabs {
    display: flex;
    background: #F1F5F9;
    border-bottom: 1px solid #E2E8F0;
    padding: 0 8px;
    flex-shrink: 0;
    gap: 4px;
}

.crm-modal-tab {
    cursor: pointer;
    padding: 12px 16px;
    font-size: 13px;
    font-weight: 600;
    color: #64748B;
    background: transparent;
    border: none;
    border-bottom: 3px solid transparent;
    font-family: inherit;
    transition: all .15s ease-in-out;
}

.crm-modal-tab:hover  { 
    color: #1E293B; 
    background: rgba(0,0,0,0.02);
}

.crm-modal-tab.active { 
    color: #3B82F6; 
    border-bottom-color: #3B82F6;
}

.crm-modal-body {
    flex: 1;
    overflow-y: auto;
    background: #fff;
    min-height: 420px;
    height: 420px;
}

.crm-tab-panel         { display: none; padding: 20px; }
.crm-tab-panel.active  { display: block; }

/* ── Resumen tab ── */
.crm-resumen-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin-bottom: 16px;
}

.crm-field              { display: flex; flex-direction: column; gap: 3px; }
.crm-field-full         { grid-column: 1 / -1; }

.crm-field label {
    font-size: 10px;
    font-weight: 600;
    color: #5A6878;
    text-transform: uppercase;
    letter-spacing: .4px;
}

.crm-field input,
.crm-field select,
.crm-field textarea {
    border: 1px solid #CBD5E1;
    border-radius: 6px;
    font-size: 13px;
    padding: 6px 10px;
    color: #1E293B;
    background: #fff;
    font-family: inherit;
    outline: none;
    transition: all .15s ease-in-out;
}

.crm-field textarea       { resize: vertical; min-height: 80px; }
.crm-field input:focus,
.crm-field select:focus,
.crm-field textarea:focus { 
    border-color: #3B82F6; 
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.crm-etapa-select { 
    display: flex; 
    gap: 4px; 
    flex-wrap: wrap; 
    margin-bottom: 20px; 
    background: #F1F5F9;
    padding: 4px;
    border-radius: 8px;
    border: 1px solid #E2E8F0;
}

.crm-etapa-btn {
    cursor: pointer;
    flex: 1;
    min-width: 90px;
    padding: 6px 10px;
    font-size: 11px;
    font-weight: 600;
    color: #475569;
    background: transparent;
    border: none;
    border-radius: 6px;
    font-family: inherit;
    text-align: center;
    transition: all .15s ease-in-out;
}

.crm-etapa-btn:hover  { 
    background: rgba(255, 255, 255, 0.5); 
    color: #1E293B;
}

.crm-etapa-btn.active {
    background: #3B82F6;
    color: #fff;
    box-shadow: 0 1px 3px rgba(59, 130, 246, 0.2);
}

/* ── Timeline tab ── */
.timeline {
    display: flex;
    flex-direction: column;
    gap: 0;
    position: relative;
}

.timeline::before {
    content: '';
    position: absolute;
    left: 15px;
    top: 0; bottom: 0;
    width: 1px;
    background: #C8D8E8;
}

.timeline-item       { display: flex; gap: 12px; padding: 8px 0; position: relative; }

.timeline-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #4A6FA0;
    border: 2px solid #fff;
    box-shadow: 0 0 0 1px #A0B4C8;
    flex-shrink: 0;
    margin-top: 3px;
    position: relative;
    z-index: 1;
    margin-left: 11px;
}

.timeline-dot.tipo-etapa     { background: #2B4478; }
.timeline-dot.tipo-tarea     { background: #2e7d4f; }
.timeline-dot.tipo-nota      { background: #4A6FA0; }
.timeline-dot.tipo-documento { background: #8050B0; }

.timeline-body { flex: 1; min-width: 0; }
.timeline-meta { font-size: 10px; color: #8096B0; margin-bottom: 2px; }
.timeline-desc { font-size: 12px; color: #1E2530; line-height: 1.5; }

.timeline-add {
    display: flex;
    gap: 6px;
    padding: 12px 0 4px;
    border-top: 1px solid #D0DDE8;
    margin-top: 10px;
    align-items: flex-start;
}

.timeline-add textarea {
    flex: 1;
    border: 1px solid #A0B4C8;
    border-radius: 2px;
    font-size: 12px;
    padding: 5px 8px;
    font-family: inherit;
    resize: none;
    height: 52px;
    outline: none;
}

.timeline-add textarea:focus { border-color: var(--accent); }

/* ── Tareas tab ── */
.task-list { display: flex; flex-direction: column; gap: 4px; margin-bottom: 14px; }

.task-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 7px 9px;
    background: #F4F8FC;
    border: 1px solid #C8D8E8;
    border-radius: 2px;
}

.task-item.completada {
    background: #F0F8F2;
    border-color: #B0D8BC;
    opacity: .75;
}

.task-item input[type="checkbox"] {
    width: 14px;
    height: 14px;
    cursor: pointer;
    flex-shrink: 0;
    accent-color: var(--accent);
}

.task-desc           { flex: 1; font-size: 12px; color: #1E2530; min-width: 0; }
.task-item.completada .task-desc { text-decoration: line-through; color: #8096B0; }

.task-vence          { font-size: 10px; color: #8096B0; white-space: nowrap; }
.task-vence.vencida  { color: #b94040; font-weight: 600; }

.task-del {
    cursor: pointer;
    background: transparent;
    border: none;
    color: #A0B4C8;
    font-size: 14px;
    padding: 0 2px;
    line-height: 1;
    transition: color .1s;
}

.task-del:hover { color: #b94040; }

.task-add-form {
    display: flex;
    gap: 6px;
    padding-top: 10px;
    border-top: 1px solid #D0DDE8;
    flex-wrap: wrap;
    align-items: flex-end;
}

.task-add-form input[type="text"] {
    flex: 1;
    min-width: 140px;
    border: 1px solid #A0B4C8;
    border-radius: 2px;
    font-size: 12px;
    padding: 4px 7px;
    font-family: inherit;
    outline: none;
}

.task-add-form input[type="text"]:focus { border-color: var(--accent); }

.task-add-form input[type="date"] {
    border: 1px solid #A0B4C8;
    border-radius: 2px;
    font-size: 12px;
    padding: 4px 6px;
    font-family: inherit;
    outline: none;
    color: #1E2530;
}

/* ── Documentos tab ── */
.doc-list { display: flex; flex-direction: column; gap: 4px; margin-bottom: 14px; }

.doc-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 9px;
    background: #F4F8FC;
    border: 1px solid #C8D8E8;
    border-radius: 2px;
}

.doc-estado-btn {
    cursor: pointer;
    font-size: 10px;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 2px;
    border: 1px solid;
    font-family: inherit;
    white-space: nowrap;
    transition: background .1s;
}

.doc-estado-btn.pendiente { background: #FDE8D8; color: #7A3820; border-color: #F0B090; }
.doc-estado-btn.recibido  { background: #D8F0E4; color: #1a5c38; border-color: #90D4A8; }
.doc-estado-btn.enviado   { background: #D8E8F8; color: #1A3060; border-color: #90B8DC; }

.doc-nombre { flex: 1; font-size: 12px; color: #1E2530; }

.doc-del {
    cursor: pointer;
    background: transparent;
    border: none;
    color: #A0B4C8;
    font-size: 14px;
    padding: 0 2px;
    line-height: 1;
    transition: color .1s;
}

.doc-del:hover { color: #b94040; }

.doc-add-form {
    display: flex;
    gap: 6px;
    padding-top: 10px;
    border-top: 1px solid #D0DDE8;
}

.doc-add-form input {
    flex: 1;
    border: 1px solid #A0B4C8;
    border-radius: 2px;
    font-size: 12px;
    padding: 4px 7px;
    font-family: inherit;
    outline: none;
}

.doc-add-form input:focus { border-color: var(--accent); }

/* ── Botones compartidos CRM ── */
.btn-crm {
    cursor: pointer;
    padding: 5px 12px;
    font-size: 12px;
    font-weight: 600;
    background: #3B82F6;
    color: #fff;
    border: 1px solid #2A4A7C;
    border-radius: 2px;
    font-family: inherit;
    transition: background .1s;
    white-space: nowrap;
}

.btn-crm:hover { background: #2F6FEB; }

.btn-crm-ghost {
    cursor: pointer;
    padding: 5px 12px;
    font-size: 12px;
    font-weight: 400;
    background: #EEF4FC;
    color: #1A3060;
    border: 1px solid #A0B4C8;
    border-radius: 2px;
    font-family: inherit;
    transition: background .1s;
}

.btn-crm-ghost:hover { background: #D8E8F4; }

.crm-modal-footer {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
    padding: 10px 14px;
    background: #E8EEF6;
    border-top: 1px solid #C8D6E8;
    flex-shrink: 0;
}

/* ── Etapa badges ── */
.etapa-badge {
    font-size: 10px;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 2px;
    border: 1px solid;
    white-space: nowrap;
}

.etapa-analisis    { background: #DCE8F8; color: #1A3060; border-color: #A8C4E0; }
.etapa-armado      { background: #E8DCF8; color: #3A1A60; border-color: #C4A8E0; }
.etapa-presentado  { background: #DCF0E8; color: #1A5038; border-color: #A8D4BC; }
.etapa-en_tramite  { background: #F8ECD8; color: #60380A; border-color: #E0C090; }
.etapa-observado   { background: #FDE8E8; color: #7A2020; border-color: #F0A0A0; }
.etapa-resolucion  { background: #D8F4E8; color: #144D2C; border-color: #7ED4A8; }
.etapa-recurso     { background: #F0E8F8; color: #44106C; border-color: #C890E4; }

.estado-resuelto   { background: #D8F0E4; color: #1a5c38; }
.estado-archivado  { background: #E8E8E8; color: #5A6878; }
