/* ============================================================================
   JuiceCRM — Componentes visuales VitaKids (Zip 1)
   ----------------------------------------------------------------------------
   Este archivo se carga DESPUÉS de app.css y añade los componentes
   reutilizables del design system de VitaKids. No pisa la paleta del
   tenant: reutiliza --primary, --bg-card, --border, etc. ya definidas
   en app.css.

   Componentes incluidos:
     · .stat-g + .sc/.sl/.sv/.sc-pill/.sc-progress         (KPI strip facturación)
     · .sp-* (status pills)
     · .tl-item / .ti-* (timeline + iconos por tipo de interacción)
     · .star-rating + .sr (rating con medias estrellas)
     · .quick-form / .qf-btn-add
     · .vk-tabs (tabs de ficha)
     · .vk-table (tabla con header uppercase tracking)
   ============================================================================ */

/* ----------------------------------------------------------------------------
   Tipografía Inter ya está cargada por base.html. Solo aseguramos kerning.
   ---------------------------------------------------------------------------- */
body { letter-spacing: -0.005em; }

/* ============================================================================
   Status pills — sp-*
   ============================================================================ */
.sp {
    display: inline-flex;
    align-items: center;
    padding: 3px 9px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 700;
    border: 1px solid transparent;
    letter-spacing: 0.01em;
    line-height: 1.4;
    white-space: nowrap;
}
.sp-default     { background: #F1F5F9; color: #475569; border-color: #CBD5E1; }
.sp-info        { background: #EFF6FF; color: #1D4ED8; border-color: #BFDBFE; }
.sp-cobrada,
.sp-success    { background: #EAF3DE; color: #27500A; border-color: #C0DD97; }
.sp-abonada,
.sp-purple      { background: #EEEDFE; color: #3C3489; border-color: #CECBF6; }
.sp-amber,
.sp-presupuesto { background: #FAEEDA; color: #633806; border-color: #FAC775; }
.sp-impagada,
.sp-error       { background: #FCEBEB; color: #A32D2D; border-color: #F7C1C1; }
.sp-borrador,
.sp-draft       { background: #F1EFE8; color: #444441; border-color: #D3D1C7; }
.sp-pendiente   { background: #FEF9C3; color: #854D0E; border-color: #FDE68A; }
.sp-anulada     { background: #F1F5F9; color: #64748B; border-color: #CBD5E1; }

/* ============================================================================
   KPI strip — formato facturación VitaKids
   --------------------------------------------------------------------------
   Uso:
     <div class="stat-g cols-4">
       <div class="sc blue">
         <div class="sl">Etiqueta</div>
         <div class="sv-row">
           <div class="sv">123 €</div>
           <span class="sc-pill pct-good">85%</span>
         </div>
         <div class="sc-progress"><div class="sc-progress-bar bar-good" style="width:85%"></div></div>
         <div class="sc-desc">Texto descriptivo</div>
       </div>
       ...
     </div>
   ============================================================================ */
.stat-g          { display: grid; grid-template-columns: repeat(5, 1fr); gap: 12px; margin-bottom: 18px; }
.stat-g.cols-2   { grid-template-columns: repeat(2, 1fr); }
.stat-g.cols-3   { grid-template-columns: repeat(3, 1fr); }
.stat-g.cols-4   { grid-template-columns: repeat(4, 1fr); }

.sc {
    border-radius: 14px;
    padding: 14px 16px;
    border: 0.5px solid transparent;
    display: flex;
    flex-direction: column;
    position: relative;
    min-height: 128px;
}
.sc.blue   { background: #EFF6FF; border-color: #BFDBFE; }
.sc.green  { background: #EAF3DE; border-color: #C0DD97; }
.sc.red    { background: #FCEBEB; border-color: #F7C1C1; }
.sc.purple { background: #EEEDFE; border-color: #CECBF6; }
.sc.amber  { background: #FAEEDA; border-color: #FAC775; }

.sl {
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    margin-bottom: 10px;
}
.sc.blue   .sl { color: #1D4ED8; }
.sc.green  .sl { color: #27500A; }
.sc.red    .sl { color: #A32D2D; }
.sc.purple .sl { color: #3C3489; }
.sc.amber  .sl { color: #633806; }

.sv-row { display: flex; align-items: baseline; gap: 10px; margin-bottom: 11px; flex-wrap: wrap; }
.sv {
    font-size: 24px;
    font-weight: 700;
    line-height: 1;
    font-variant-numeric: tabular-nums;
}
.sc.blue   .sv { color: #1D4ED8; }
.sc.green  .sv { color: #16A34A; }
.sc.red    .sv { color: #A32D2D; }
.sc.purple .sv { color: #3C3489; }
.sc.amber  .sv { color: #854F0B; }

.sc-pill {
    font-size: 11px;
    font-weight: 700;
    padding: 3px 10px;
    border-radius: 999px;
    background: #fff;
    border: 0.5px solid;
    font-variant-numeric: tabular-nums;
    line-height: 1.2;
}
.sc.blue   .sc-pill { color: #1D4ED8; border-color: #BFDBFE; }
.sc.green  .sc-pill { color: #16A34A; border-color: #C0DD97; }
.sc.red    .sc-pill { color: #A32D2D; border-color: #F7C1C1; }
.sc.purple .sc-pill { color: #3C3489; border-color: #CECBF6; }
.sc.amber  .sc-pill { color: #854F0B; border-color: #FAC775; }

.sc-progress {
    height: 4px;
    border-radius: 999px;
    background: rgba(15, 23, 42, 0.08);
    overflow: hidden;
    margin-bottom: 9px;
}
.sc-progress-bar { height: 100%; border-radius: 999px; transition: width 0.3s ease; }
.sc.blue   .sc-progress-bar { background: #1D4ED8; }
.sc.green  .sc-progress-bar { background: #16A34A; }
.sc.red    .sc-progress-bar { background: #A32D2D; }
.sc.purple .sc-progress-bar { background: #3C3489; }
.sc.amber  .sc-progress-bar { background: #854F0B; }

.sc-desc { font-size: 11.5px; color: #64748B; margin-top: auto; line-height: 1.3; }

.bar-good { background: #16A34A !important; }
.bar-warn { background: #D97706 !important; }
.bar-bad  { background: #DC2626 !important; }
.pct-good { background: #EAF3DE; color: #27500A; border-color: #C0DD97; }
.pct-warn { background: #FAEEDA; color: #854F0B; border-color: #FAC775; }
.pct-bad  { background: #FCEBEB; color: #A32D2D; border-color: #F7C1C1; }

/* Pantallas medias 901-1100: 5 columnas pero más compactas */
@media (max-width: 1100px) and (min-width: 901px) {
    .stat-g    { gap: 8px; }
    .sc        { padding: 11px 12px; min-height: 118px; }
    .sv        { font-size: 20px; }
    .sl        { font-size: 9px; margin-bottom: 8px; }
    .sc-pill   { font-size: 10px; padding: 2px 8px; }
    .sc-desc   { font-size: 10.5px; }
}
/* Tabletas pequeñas 768-900: 5 columnas no caben — pasamos a 3 */
@media (max-width: 900px) and (min-width: 768px) {
    .stat-g { grid-template-columns: repeat(3, 1fr); gap: 10px; }
    .sc     { padding: 13px 14px; min-height: auto; }
    .sv     { font-size: 20px; }
    .sl     { font-size: 10px; }
}
/* Móvil <768px: tarjeta resumen única con filas (label izq / val+pill der) */
@media (max-width: 767px) {
    .stat-g {
        display: block;
        background: #fff;
        border: 0.5px solid #E2E8F0;
        border-radius: 12px;
        padding: 4px 14px;
    }
    .stat-g .sc {
        background: transparent !important;
        border: none !important;
        border-bottom: 0.5px solid #F1F5F9 !important;
        border-radius: 0 !important;
        padding: 11px 0 !important;
        min-height: auto !important;
        flex-direction: row !important;
        align-items: center;
        justify-content: space-between;
        gap: 8px;
    }
    .stat-g .sc:last-child { border-bottom: none !important; }
    .stat-g .sl { margin: 0 !important; font-size: 11px !important; flex-shrink: 0; }
    .stat-g .sv-row { margin: 0 !important; }
    .stat-g .sc-progress, .stat-g .sc-desc { display: none !important; }
}

/* ============================================================================
   Timeline — historial de interacciones
   ============================================================================ */
.tl-item {
    display: flex;
    gap: 10px;
    margin-bottom: 14px;
    position: relative;
}
.tl-item:not(:last-child)::before {
    content: '';
    position: absolute;
    left: 11px;
    top: 22px;
    bottom: -4px;
    width: 0.5px;
    background: #E2E8F0;
}
.tl-ic {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    display: grid;
    place-items: center;
    flex-shrink: 0;
}
.tl-ic svg { width: 11px; height: 11px; }

/* Iconos por tipo de interacción */
.ti-llamada    { background: #DBEAFE; color: #1D4ED8; }
.ti-visita     { background: #EEEDFE; color: #3C3489; }
.ti-mensaje    { background: #E0E7FF; color: #3730A3; }
.ti-presupuesto{ background: #FAEEDA; color: #854F0B; }
.ti-etapa      { background: #EAF3DE; color: #27500A; }
.ti-puntuacion { background: #FEF9C3; color: #854D0E; }
.ti-nota,
.ti-lead       { background: #F1F5F9; color: #475569; }

.tl-b { flex: 1; min-width: 0; }
.tl-t { font-size: 13px; font-weight: 500; color: #1E293B; }
.tl-m { font-size: 12px; color: #64748B; margin-top: 2px; }
.tl-n {
    font-size: 12px;
    color: #64748B;
    margin-top: 5px;
    padding: 6px 9px;
    background: #F8FAFC;
    border-radius: 5px;
    border-left: 2px solid #E2E8F0;
    line-height: 1.45;
}
.tl-d {
    font-size: 11px;
    color: #94A3B8;
    white-space: nowrap;
    margin-top: 2px;
}

/* ============================================================================
   Star rating con medias estrellas (idéntico VitaKids)
   ============================================================================ */
.star-rating {
    display: flex;
    gap: 1px;
    align-items: center;
    user-select: none;
}
.sr {
    font-size: 18px;
    cursor: pointer;
    position: relative;
    display: inline-block;
    width: 20px;
    line-height: 1;
    color: #E2E8F0;
}
.sr.half::before {
    content: '★';
    position: absolute;
    left: 0;
    width: 50%;
    overflow: hidden;
    color: #EF9F27;
}
.sr.full { color: #EF9F27; }

/* ============================================================================
   Quick form — formulario de añadir interacción
   ============================================================================ */
.quick-form {
    background: #F8FAFC;
    border: 0.5px solid #E2E8F0;
    border-radius: 9px;
    padding: 14px;
    margin-bottom: 14px;
    display: none;
}
.quick-form.open { display: block; }
.qf-btn-add {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 9px 16px;
    background: #16A34A;
    color: #fff;
    border: none;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    margin-bottom: 12px;
    font-family: inherit;
}
.qf-btn-add:hover { background: #15803D; }
.qf-btn-add svg { width: 14px; height: 14px; }

/* ============================================================================
   Tabs de ficha — versión refinada VitaKids
   ============================================================================ */
.vk-tabs {
    display: flex;
    border-bottom: 0.5px solid #E2E8F0;
    background: #F8FAFC;
    border-radius: 10px 10px 0 0;
    overflow-x: auto;
}
.vk-tab {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 11px 16px;
    font-size: 13px;
    font-weight: 500;
    color: #64748B;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    white-space: nowrap;
    background: none;
    border-top: none;
    border-left: none;
    border-right: none;
    font-family: inherit;
}
.vk-tab.active { color: var(--primary); border-bottom-color: var(--primary); background: #fff; }
.vk-tab:hover:not(.active) { color: #1E293B; }
.vk-tab svg { width: 13px; height: 13px; }
.vk-tab-pane { display: none; padding: 16px; }
.vk-tab-pane.active { display: block; }

/* B3.C — Tabs en móvil: select desplegable, no scroll horizontal */
.vk-tabs-mobile {
    display: none;
    width: 100%;
    padding: 12px 14px;
    font-size: 14px;
    font-weight: 500;
    color: #1E293B;
    background: #F8FAFC;
    border: none;
    border-bottom: 0.5px solid #E2E8F0;
    border-radius: 10px 10px 0 0;
    font-family: inherit;
    appearance: none;
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='none' stroke='%2364748B' stroke-width='1.5' d='M3 4.5l3 3 3-3'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 14px center;
    padding-right: 36px;
    cursor: pointer;
}
@media (max-width: 640px) {
    .vk-tabs-desktop { display: none; }
    .vk-tabs-mobile { display: block; }
}

/* ============================================================================
   Mini-card panels (right column en lead_detail)
   ============================================================================ */
.sc-card {
    background: #fff;
    border: 0.5px solid #E2E8F0;
    border-radius: 10px;
    padding: 13px 15px;
}
.sc-card .sc-t {
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: #64748B;
    margin-bottom: 10px;
}
.sc-card .sc-row {
    display: flex;
    justify-content: space-between;
    margin-bottom: 6px;
    align-items: flex-start;
}
.sc-card .sc-l { font-size: 12px; color: #64748B; }
.sc-card .sc-v { font-size: 12px; font-weight: 500; color: #1E293B; text-align: right; }

/* ============================================================================
   Contact chips (header de ficha)
   ============================================================================ */
.contact-chips {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 7px;
    margin-top: 12px;
}
@media (max-width: 700px) {
    .contact-chips { grid-template-columns: 1fr; }
}
.cc {
    display: flex;
    align-items: center;
    gap: 7px;
    padding: 8px 11px;
    background: #F8FAFC;
    border-radius: 8px;
}
.cc svg { width: 13px; height: 13px; color: #94A3B8; flex-shrink: 0; }
.cc-l   { font-size: 9px; color: #94A3B8; text-transform: uppercase; letter-spacing: 0.05em; }
.cc-v   { font-size: 12px; color: #1E293B; font-weight: 500; }

/* ============================================================================
   Meta strip (fila de metadata bajo cabecera de ficha)
   ============================================================================ */
.meta-strip {
    display: flex;
    border-bottom: 0.5px solid #F1F5F9;
    background: #fff;
    flex-wrap: wrap;
}
.meta-strip .ms {
    flex: 1 1 140px;
    padding: 9px 16px;
    border-right: 0.5px solid #F1F5F9;
}
.meta-strip .ms:last-child { border-right: none; }
.meta-strip .ms-l {
    font-size: 9px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: #94A3B8;
}
.meta-strip .ms-v { font-size: 13px; color: #1E293B; margin-top: 3px; }

/* ============================================================================
   Tabla mejorada — header uppercase tracking, pillable rows
   --------------------------------------------------------------------------
   Variante .vk-table: aplica encima de .table existente sin tocar el resto.
   ============================================================================ */
.vk-table { width: 100%; border-collapse: collapse; }
.vk-table thead th {
    color: var(--text-tertiary);
    font-weight: 700;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    text-align: left;
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
    background: var(--bg-muted);
}
.vk-table tbody td {
    padding: 12px;
    border-bottom: 1px solid #F1F5F9;
    font-size: 13px;
}
.vk-table tbody tr:hover { background: var(--bg-muted); }
.vk-table tbody tr:last-child td { border-bottom: none; }

/* ============================================================================
   Link en celda nombre (lista clientes)
   ============================================================================ */
a.row-link-name {
    color: var(--text-primary);
    font-weight: 600;
    text-decoration: none;
}
a.row-link-name:hover { color: var(--primary); text-decoration: underline; }

/* ============================================================================
   Override: kanban con scroll horizontal correcto
   --------------------------------------------------------------------------
   El .kanban actual usa grid-auto-columns: minmax(260px, 1fr) → fuerza
   columnas a llenar el viewport y la última se corta cuando no caben.
   Lo sustituimos por columnas de ancho fijo que generen scroll horizontal
   limpio cuando no hay espacio.
   ============================================================================ */
.kanban {
    grid-auto-columns: 280px !important;
    padding-bottom: 12px !important;
}
.kanban-col { min-width: 280px; }

/* En pantallas anchas (>1700px) las columnas pueden crecer un poco */
@media (min-width: 1700px) {
    .kanban { grid-auto-columns: minmax(280px, 1fr) !important; }
}
