/* ============================================
   ESTILOS - Sistema de Relaciones
   ============================================ */

/* === RESET Y BASE === */
* { 
    margin: 0; 
    padding: 0; 
    box-sizing: border-box; 
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: #f3f4f6;
    padding: 10px;
    font-size: 14px;
}

/* === CONTAINERS === */
.container {
    max-width: 1400px;
    margin: 0 auto;
}

.container.fullscreen {
    background: white;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    padding: 15px;
    height: calc(100vh - 20px);
    display: flex;
    flex-direction: column;
}

/* === HEADER === */
.header {
    background: white;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    padding: 15px 20px;
    margin-bottom: 15px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 15px;
}

h1 {
    color: #1f2937;
    font-size: 1.5em;
    display: flex;
    align-items: center;
    gap: 10px;
}

.volver-link {
    color: #3b82f6;
    text-decoration: none;
    padding: 8px 16px;
    background: #eff6ff;
    border-radius: 6px;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    transition: background 0.2s;
    white-space: nowrap;
}

.volver-link:hover {
    background: #dbeafe;
}

/* === BÃšSQUEDA PRINCIPAL === */
.selector-contacto {
    margin-bottom: 15px;
    display: flex;
    gap: 8px;
    align-items: stretch;
    flex-shrink: 0;
}

.busqueda-wrapper {
    flex: 1;
    position: relative;
}

.selector-contacto input,
.busqueda-input {
    width: 100%;
    padding: 10px 80px 10px 10px;
    font-size: 14px;
    border: 2px solid #e5e7eb;
    border-radius: 6px;
    transition: all 0.2s;
}

.selector-contacto input:focus,
.busqueda-input:focus {
    outline: none;
    border-color: #3b82f6;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.buscar-btn {
    position: absolute;
    right: 3px;
    top: 50%;
    transform: translateY(-50%);
    background: #3b82f6;
    color: white;
    border: none;
    padding: 6px 12px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 13px;
}

.filtro-btn {
    padding: 10px 15px;
    background: white;
    border: 2px solid #e5e7eb;
    border-radius: 6px;
    cursor: pointer;
    font-size: 13px;
    white-space: nowrap;
}

.filtro-btn.activo {
    background: #10b981;
    color: white;
    border-color: #10b981;
}

/* === RESULTADOS BÃšSQUEDA === */
.resultados-busqueda {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: white;
    border: 2px solid #e5e7eb;
    border-radius: 6px;
    margin-top: 3px;
    max-height: 300px;
    overflow-y: auto;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    z-index: 1000;
    display: none;
}

.resultados-busqueda.show { 
    display: block; 
}

.resultado-item {
    padding: 8px 12px;
    cursor: pointer;
    border-bottom: 1px solid #f3f4f6;
    font-size: 13px;
}

.resultado-item:hover { 
    background: #f3f4f6; 
}

.resultado-nombre {
    font-weight: 600;
    color: #1f2937;
}

.resultado-etiqueta,
.persona-etiqueta,
.contacto-etiqueta {
    color: #1e40af;
    font-size: 11px;
    margin-left: 6px;
    font-style: italic;
}

.resultado-detalle {
    color: #6b7280;
    font-size: 12px;
    margin-top: 2px;
}

/* === CONTACTO SELECCIONADO === */
.contacto-seleccionado {
    background: #eff6ff;
    padding: 10px;
    border-radius: 6px;
    margin-bottom: 15px;
    border-left: 3px solid #3b82f6;
    display: none;
    font-size: 13px;
    flex-shrink: 0;
    cursor: pointer;
    transition: background 0.2s;
}

.contacto-seleccionado:hover {
    background: #dbeafe;
}

.contacto-seleccionado.show { 
    display: block; 
}

.contacto-seleccionado-nombre {
    font-size: 1.1em;
    font-weight: 600;
    color: #1f2937;
}

.contacto-seleccionado-etiqueta {
    color: #1e40af;
    font-size: 0.9em;
    margin-left: 8px;
    font-style: italic;
}

/* === FILTROS === */
.filtro-relaciones {
    margin-bottom: 15px;
    display: none;
    position: relative;
    flex-shrink: 0;
}

.filtro-relaciones.show { 
    display: block; 
}

.filtro-relaciones input {
    width: 100%;
    padding: 8px 40px 8px 10px;
    border: 2px solid #e5e7eb;
    border-radius: 6px;
    font-size: 13px;
}

.filtro-relaciones input:focus {
    outline: none;
    border-color: #3b82f6;
}

.limpiar-filtro-btn,
.clear-btn {
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    background: #ef4444;
    color: white;
    border: none;
    width: 26px;
    height: 26px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
    font-weight: bold;
    display: none;
    align-items: center;
    justify-content: center;
}

.limpiar-filtro-btn.show,
.clear-btn.show {
    display: flex;
}

.limpiar-filtro-btn:hover,
.clear-btn:hover {
    background: #dc2626;
}

/* === FILTROS DE TIPOS === */
.filtros-container {
    background: white;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    padding: 12px 15px;
    margin-bottom: 15px;
}

.filtros-titulo {
    font-size: 13px;
    font-weight: 600;
    color: #6b7280;
    margin-bottom: 10px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.filtros-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.filtro-tipo {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 10px;
    border: 2px solid #e5e7eb;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s;
    background: white;
    font-size: 12px;
}

.filtro-tipo:hover {
    border-color: #3b82f6;
    background: #f9fafb;
}

.filtro-tipo.activo {
    border-color: #3b82f6;
    background: #eff6ff;
}

.filtro-color {
    width: 16px;
    height: 16px;
    border-radius: 3px;
    border: 1px solid rgba(0,0,0,0.1);
    flex-shrink: 0;
}

.filtro-numero {
    font-weight: 700;
    color: #6b7280;
    min-width: 14px;
}

.filtro-nombre {
    font-weight: 500;
    color: #374151;
}

.filtro-contador {
    background: #e5e7eb;
    color: #6b7280;
    padding: 2px 6px;
    border-radius: 10px;
    font-size: 10px;
    font-weight: 600;
}

.filtro-tipo.activo .filtro-contador {
    background: #3b82f6;
    color: white;
}

/* === TOOLBAR === */
.toolbar {
    background: white;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    padding: 15px;
    margin-bottom: 15px;
    display: flex;
    gap: 15px;
    align-items: center;
    flex-wrap: wrap;
}

.toolbar .busqueda-wrapper {
    flex: 1;
    min-width: 250px;
}

.search-icon {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: #6b7280;
}

.toolbar .busqueda-input {
    padding: 10px 40px 10px 40px;
}

.stats {
    color: #6b7280;
    font-size: 13px;
    white-space: nowrap;
    font-weight: 500;
}

.stats strong {
    color: #1f2937;
    font-weight: 600;
}

/* === LISTA DE RELACIONES === */
.relaciones-container {
    display: none;
    flex: 1;
    overflow-y: auto;
    margin-bottom: 15px;
    padding-right: 5px;
}

.relaciones-container.active { 
    display: block; 
}

.persona-relacion {
    background: #f9fafb;
    border: 1px solid #e5e7eb;
    border-radius: 6px;
    padding: 10px;
    margin-bottom: 8px;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 15px;
    transition: padding-right 0.3s ease;
}

.persona-relacion:has(.damero.editable) {
    padding-right: 90px;
}

.persona-relacion.oculto { 
    display: none; 
}

.persona-info {
    flex: 1;
    min-width: 0;
}

/* Wrapper para el nombre con el botÃ³n de flecha */
.persona-nombre-wrapper {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 4px;
}

/* BotÃ³n de ver relaciones (flecha arriba) */
.btn-ver-relaciones {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    padding: 0;
    background: #f0f0f0;
    border: 1px solid #ddd;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.btn-ver-relaciones:hover {
    background: #3b82f6;
    border-color: #3b82f6;
}

.btn-ver-relaciones:hover .icon-flecha-arriba {
    stroke: white;
}

.btn-ver-relaciones:active {
    transform: translateY(-2px);
}

/* Icono de la flecha */
.icon-flecha-arriba {
    width: 14px;
    height: 14px;
    stroke: #666;
    transition: stroke 0.2s ease;
}

.persona-nombre {
    font-size: 15px;
    font-weight: 600;
    color: #1f2937;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    cursor: pointer;
    transition: color 0.2s;
    flex: 1;
}

.persona-nombre:hover {
    color: #3b82f6;
}

.persona-detalle {
    color: #6b7280;
    font-size: 12px;
    margin-top: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* === COMENTARIOS === */
.comentario-wrapper {
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px dashed #e5e7eb;
}

.comentario-label {
    font-size: 11px;
    color: #6b7280;
    margin-bottom: 4px;
    font-weight: 500;
}

.comentario-input {
    width: 100%;
    padding: 4px 8px;
    font-size: 11px;
    border: 1px solid #d1d5db;
    border-radius: 4px;
    resize: none;
    min-height: 32px;
    max-height: 60px;
    font-family: inherit;
    line-height: 1.3;
}

.comentario-input:focus {
    outline: none;
    border-color: #3b82f6;
}

.comentario-contador {
    font-size: 10px;
    color: #9ca3af;
    text-align: right;
    margin-top: 2px;
}


/* === LEYENDA === */
.leyenda {
    display: flex;
    flex-wrap: nowrap;
    gap: 12px;
    padding: 12px;
    background: #f9fafb;
    border-radius: 6px;
    font-size: 12px;
    overflow-x: auto;
    flex-shrink: 0;
    border: 2px solid #e5e7eb;
}

.leyenda::-webkit-scrollbar {
    height: 6px;
}

.leyenda::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 3px;
}

.leyenda::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 3px;
}

.leyenda-item {
    display: flex;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
    cursor: pointer;
    padding: 6px 10px;
    border-radius: 4px;
    transition: all 0.2s;
    border: 2px solid transparent;
}

.leyenda-item:hover {
    background: #e5e7eb;
}

.leyenda-item.activo {
    background: #dbeafe;
    border-color: #3b82f6;
}

.leyenda-color {
    width: 16px;
    height: 16px;
    border-radius: 3px;
    border: 1px solid rgba(0,0,0,0.1);
    flex-shrink: 0;
}

.leyenda-num {
    font-weight: 700;
    color: #6b7280;
}

/* === MODAL === */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.5);
    z-index: 2000;
    align-items: center;
    justify-content: center;
}

.modal.show {
    display: flex;
}

.modal-contenido {
    background: white;
    border-radius: 12px;
    padding: 30px;
    max-width: 500px;
    width: 90%;
    max-height: 100vh;
    overflow-y: auto;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.modal-titulo {
    font-size: 1.5em;
    font-weight: 600;
    color: #1f2937;
}

.modal-cerrar {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: #6b7280;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
}

.modal-cerrar:hover {
    background: #f3f4f6;
}

.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    margin-bottom: 8px;
    font-weight: 500;
    color: #374151;
}

.form-group input,
.form-group textarea {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    font-size: 14px;
}

.form-group input:focus,
.form-group textarea:focus {
    outline: none;
    border-color: #3b82f6;
}

.form-group small {
    display: block;
    margin-top: 4px;
    color: #6b7280;
    font-size: 12px;
}

.form-acciones {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
}

.btn-cancelar {
    padding: 10px 20px;
    background: #e5e7eb;
    color: #374151;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 500;
}

.btn-cancelar:hover {
    background: #d1d5db;
}

.btn-guardar {
    padding: 10px 20px;
    background: #3b82f6;
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 500;
}

.btn-guardar:hover {
    background: #2563eb;
}

/* === TABLA === */
.tabla-relaciones {
    width: 100%;
    border-collapse: collapse;
}

.tabla-relaciones thead {
    background: #f9fafb;
    position: sticky;
    top: 0;
    z-index: 10;
}

.tabla-relaciones th {
    padding: 12px 15px;
    text-align: left;
    font-weight: 600;
    color: #374151;
    border-bottom: 2px solid #e5e7eb;
    font-size: 13px;
}

.tabla-relaciones th:nth-child(2) {
    text-align: center;
}

.tabla-relaciones td {
    padding: 12px 15px;
    border-bottom: 1px solid #e5e7eb;
    font-size: 13px;
    vertical-align: top;
}

.tabla-relaciones tbody tr {
    transition: background 0.2s;
}

.tabla-relaciones tbody tr:hover {
    background: #f9fafb;
}

.tabla-relaciones tbody tr.oculto {
    display: none;
}

.contacto-cell {
    max-width: 350px;
}

.contacto-nombre {
    font-weight: 600;
    color: #1f2937;
    margin-bottom: 3px;
    cursor: pointer;
    transition: color 0.2s;
}

.contacto-nombre:hover {
    color: #3b82f6;
}

.contacto-detalle {
    color: #6b7280;
    font-size: 12px;
    line-height: 1.4;
}

.contacto-comentario {
    margin-top: 6px;
    padding: 6px 10px;
    background: #fef3c7;
    border-left: 3px solid #f59e0b;
    border-radius: 4px;
    font-size: 12px;
    color: #78350f;
    font-style: italic;
}

.relacion-cell {
    text-align: center;
    min-width: 120px;
}

.relacion-cell .damero {
    display: inline-grid;
    grid-template-columns: repeat(3, 28px);
    grid-template-rows: repeat(3, 28px);
    gap: 4px;
    padding: 6px;
    border-radius: 6px;
    background: #f9fafb;
    border: 2px solid #e5e7eb;
}

.relacion-cell .casilla {
    width: 28px;
    height: 28px;
    font-size: 14px;
    background: white;
}

/* Estilos específicos para admin_etiquetas.php */
.etiquetas-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 15px;
    margin-bottom: 20px;
}

.etiqueta-card {
    background: white;
    border: 2px solid #e5e7eb;
    border-radius: 8px;
    padding: 15px;
    display: flex;
    align-items: center;
    gap: 12px;
    transition: all 0.2s;
}

.etiqueta-card:hover {
    border-color: #3b82f6;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.etiqueta-numero-grande {
    width: 48px;
    height: 48px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    font-weight: 700;
    color: white;
    flex-shrink: 0;
    border: 2px solid rgba(0,0,0,0.1);
}

.etiqueta-info {
    flex: 1;
    min-width: 0;
}

.etiqueta-nombre-grande {
    font-size: 16px;
    font-weight: 600;
    color: #1f2937;
    margin-bottom: 4px;
}

.etiqueta-color-hex {
    font-size: 12px;
    color: #6b7280;
    font-family: monospace;
}

.etiqueta-acciones {
    display: flex;
    gap: 6px;
}

.btn-icono {
    width: 36px;
    height: 36px;
    padding: 0;
    border: 2px solid #e5e7eb;
    background: white;
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.btn-icono:hover {
    border-color: #3b82f6;
    background: #eff6ff;
}

.btn-icono.eliminar:hover {
    border-color: #ef4444;
    background: #fee;
}

.color-picker-wrapper {
    display: flex;
    gap: 10px;
    align-items: center;
}

.color-preview {
    width: 50px;
    height: 50px;
    border-radius: 6px;
    border: 2px solid #e5e7eb;
}

input[type="color"] {
    width: 60px;
    height: 50px;
    border: 2px solid #e5e7eb;
    border-radius: 6px;
    cursor: pointer;
}

/* === MENSAJES === */
.loading {
    text-align: center;
    padding: 20px;
    color: #6b7280;
    font-size: 13px;
}

.sin-contactos,
.sin-resultados {
    text-align: center;
    padding: 30px;
    color: #6b7280;
}

.sin-resultados svg {
    width: 64px;
    height: 64px;
    margin-bottom: 15px;
    opacity: 0.5;
}

.sin-resultados h3 {
    font-size: 18px;
    margin-bottom: 8px;
    color: #374151;
}

.sin-resultados p {
    font-size: 14px;
}

/* === ICONOS === */
.icon {
    width: 18px;
    height: 18px;
    display: inline-block;
    vertical-align: middle;
}

/* === SCROLLBARS === */
.relaciones-container::-webkit-scrollbar {
    width: 8px;
}

.relaciones-container::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 4px;
}

.relaciones-container::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 4px;
}

.relaciones-container::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}

/* === RESPONSIVE === */
@media (max-width: 768px) {
    body { 
        font-size: 13px; 
        padding: 5px; 
    }
    
    .container { 
        padding: 10px; 
    }
    
    .container.fullscreen {
        padding: 10px;
    }
    
    h1 { 
        font-size: 1.3em; 
        margin-bottom: 10px; 
    }
    
    .header {
        flex-direction: column;
        align-items: stretch;
        text-align: center;
    }
    
    .header h1 {
        justify-content: center;
    }
    
    .selector-contacto { 
        flex-direction: column; 
    }
    
    .filtro-btn { 
        width: 100%; 
    }
    
    .filtros-grid {
        gap: 6px;
    }
    
    .filtro-tipo {
        padding: 5px 8px;
        font-size: 11px;
    }
    
    .filtro-color {
        width: 14px;
        height: 14px;
    }
    
    .toolbar {
        flex-direction: column;
        align-items: stretch;
    }
    
    .toolbar .busqueda-wrapper {
        min-width: 100%;
    }
    
/*    .persona-relacion { 
        flex-direction: column; 
        align-items: flex-start;
        gap: 10px;
    }
    
/* kimet diu */
/* Fija el ancho de la columna del damero en index */
.persona-relacion {
    display: flex !important;
    justify-content: space-between !important;
    align-items: flex-start !important;
}


    .persona-relacion:has(.damero.editable) {
        padding-right: 10px;
    }
    
    .persona-info { 
        width: 100%; 
    }
    
    .damero-wrapper { 
        align-self: flex-start; 
    }

/* kimet diu */
.damero-wrapper {
    width: 90px !important;          /* ← mismo ancho que en admin */
    min-width: 90px !important;      /* ← no se encoge */
    display: flex !important;
    justify-content: center !important;
    align-items: center !important;
    margin-left: 0 !important;       /* ← elimina empuje */
    flex-shrink: 0 !important;       /* ← no se reduce */
}


.damero {
    margin: 0 auto !important;       /* ← centrado real */
}
    
    .damero {
        grid-template-columns: repeat(3, 18px);
        grid-template-rows: repeat(3, 18px);
        gap: 3px;
    }
    
    .casilla {
        width: 18px;
        height: 18px;
        font-size: 10px;
    }
    
    .damero.editable {
        grid-template-columns: repeat(3, 26px);
        grid-template-rows: repeat(3, 26px);
        gap: 4px;

            margin: 0 auto !important;
    }
    
    .damero.editable .casilla {
        width: 26px;
        height: 26px;
        font-size: 13px;
    }
    
    .leyenda { 
        font-size: 11px; 
        gap: 8px; 
    }
    
    .leyenda-color { 
        width: 14px; 
        height: 14px; 
    }
    
    /* Tabla responsive */
    .tabla-relaciones {
        display: block;
    }
    
    .tabla-relaciones thead {
        display: none;
    }
    
    .tabla-relaciones tbody,
    .tabla-relaciones tr,
    .tabla-relaciones td {
        display: block;
    }
    
    .tabla-relaciones tr {
        margin-bottom: 15px;
        border: 1px solid #e5e7eb;
        border-radius: 6px;
        padding: 12px;
        background: white;
    }
    
    .tabla-relaciones td {
        border: none;
        padding: 8px 0;
    }
    
    .tabla-relaciones td:not(:last-child) {
        border-bottom: 1px solid #f3f4f6;
        padding-bottom: 10px;
        margin-bottom: 10px;
    }
    
    .contacto-cell {
        max-width: 100%;
    }
    
    .relacion-cell {
        text-align: left;
    }
    
    .relacion-cell .damero {
        grid-template-columns: repeat(3, 24px);
        grid-template-rows: repeat(3, 24px);
        gap: 3px;
        padding: 5px;
    }
    
    .relacion-cell .casilla {
        width: 24px;
        height: 24px;
        font-size: 12px;
    }
    
    .tabla-relaciones td::before {
        content: attr(data-label);
        font-weight: 600;
        color: #6b7280;
        display: block;
        margin-bottom: 4px;
        font-size: 11px;
        text-transform: uppercase;
    }
    
    .etiquetas-grid {
        grid-template-columns: 1fr;
    }
}